/* gets target VM version from the given VMVersionMismatchException. * Note that we need to reflectively call the method because of we may * have got this from different classloader's namespace */ private static String getVMVersion(Throwable throwable) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { // assert isVMVersionMismatch(throwable), "not a VMVersionMismatch" Class expClass = throwable.getClass(); Method targetVersionMethod = expClass.getMethod("getTargetVersion", new Class[0]); return (String) targetVersionMethod.invoke(throwable); }
private void generateView( Map<String, DesignDocument.View> views, Method me, Class<?> handledType) { String name = me.getName(); if (!name.startsWith("findBy") && !name.equals("getAll")) { throw new ViewGenerationException( String.format( "The method: %s in %s annotated with GenerateView does not conform to the naming convention of 'findByXxxx'", name, me.getDeclaringClass())); } Class<?> type = resolveReturnType(me); if (type == null) { if (handledType != null) { type = handledType; } else { throw new ViewGenerationException( "Could not resolve return type for method: %s in %s", me.getName(), me.getDeclaringClass()); } } String typeDiscriminator = resolveTypeDiscriminator(type); if (name.equals("getAll")) { if (typeDiscriminator.length() < 1) { throw new ViewGenerationException( String.format( "Cannot generate 'all' view for %s. No type discriminator could be resolved. Try annotate unique field(s) with @TypeDiscriminator", type.getDeclaringClass())); } views.put("all", generateAllView(typeDiscriminator)); return; } String finderName = name.substring(6); String fieldName = resolveFieldName(me, finderName); Method getter = findMethod(type, "get" + fieldName); if (getter == null) { // try pluralis fieldName += "s"; getter = findMethod(type, "get" + fieldName); } if (getter == null) { throw new ViewGenerationException( "Could not generate view for method %s. No get method found for property %s in %s", name, name.substring(6), type); } fieldName = firstCharToLowerCase(fieldName); DesignDocument.View view; if (isIterable(getter.getReturnType())) { view = generateFindByIterableView(fieldName, typeDiscriminator); } else { view = generateFindByView(fieldName, typeDiscriminator); } views.put("by_" + firstCharToLowerCase(finderName), view); }
/** Updates the UIs of all the known Frames. */ private static void updateAllUIs() { // Check if the current UI is WindowsLookAndfeel and flush the XP style map. // Note: Change the package test if this class is moved to a different package. Class uiClass = UIManager.getLookAndFeel().getClass(); if (uiClass.getPackage().equals(DesktopProperty.class.getPackage())) { XPStyle.invalidateStyle(); } Frame appFrames[] = Frame.getFrames(); for (int j = 0; j < appFrames.length; j++) { updateWindowUI(appFrames[j]); } }
private DesignDocument.View loadViewFromFile( Map<String, DesignDocument.View> views, View input, Class<?> repositoryClass) { try { InputStream in = repositoryClass.getResourceAsStream(input.file()); if (in == null) { throw new FileNotFoundException("Could not load view file with path: " + input.file()); } String json = IOUtils.toString(in, "UTF-8"); return mapper().readValue(json.replaceAll("\n", ""), DesignDocument.View.class); } catch (Exception e) { throw Exceptions.propagate(e); } }
private String resolveTypeDiscriminator(final Class<?> persistentType) { final List<String> discrimintators = new ArrayList<String>(); TypeDiscriminator td = persistentType.getAnnotation(TypeDiscriminator.class); if (td != null) { if (td.value().length() == 0) { throw new ViewGenerationException( String.format( "@TypeDiscriminator declared on type level must specify custom discriminator condition", persistentType)); } if (hasTypeDiscriminatorFieldOrMethod(persistentType)) { throw new ViewGenerationException( String.format( "@TypeDiscriminator declared on type level may not be combined with @TypeDiscriminator in fields or on methods", persistentType)); } return td.value(); } eachField( persistentType, new Predicate<Field>() { public boolean apply(Field input) { if (hasAnnotation(input, TypeDiscriminator.class)) { discrimintators.add("doc." + input.getName()); } return false; } }); eachMethod( persistentType, new Predicate<Method>() { public boolean apply(Method input) { if (hasAnnotation(input, TypeDiscriminator.class)) { discrimintators.add("doc." + firstCharToLowerCase(input.getName().substring(3))); } return true; } }); return Joiner.join(discrimintators, " && "); }
private static Class getVMImplClassFrom(ClassLoader cl) throws ClassNotFoundException { return Class.forName("sun.jvm.hotspot.jdi.VirtualMachineImpl", true, cl); }