@Override public boolean getAsBoolean() { try { return Reflection.toClass("javafx.beans.Observable") != null; } catch (ClassNotFoundException e) { return false; } } }
/** * Return the class for the given string, correctly handling * primitive types. If the given class loader is null, the context * loader of the current thread will be used. * * @throws RuntimeException on load error */ public static Class<?> toClass(String className, ClassLoader loader) throws ClassNotFoundException { return toClass(className, false, loader); }
/** * Return the class for the given string, correctly handling * primitive types. If the given class loader is null, the context * loader of the current thread will be used. * * @throws RuntimeException on load error */ public static Class toClass(String className, ClassLoader loader) throws ClassNotFoundException { return toClass(className, false, loader); }
/** * Return the class for the given string, correctly handling * primitive types. If the given class loader is null, the context * loader of the current thread will be used. * * @throws RuntimeException on load error */ public static Class<?> toClass(String className, ClassLoader loader) throws ClassNotFoundException { return toClass(className, false, loader); }
@Override public boolean getAsBoolean() { try { return Reflection.toClass("javafx.beans.Observable") != null; } catch (ClassNotFoundException e) { return false; } } }
private static Class<?> getObjectFactory(Class<?> type) throws ClassNotFoundException { final String className = String.format("%s.%s", type.getPackage().getName(), "ObjectFactory"); return Reflection.toClass(className, type.getClassLoader()); }
private static Class<?> getObjectFactory(Class<?> type) throws ClassNotFoundException { final String className = String.format("%s.%s", type.getPackage().getName(), "ObjectFactory"); return Reflection.toClass(className, type.getClassLoader()); }
/** * Find the named class. * * @param className * @return Class found or null */ protected Class<?> findLocalClass(String className) { if (className != null) { try { return Reflection.toClass(className); } catch (ClassNotFoundException e) { log.log(Level.FINE, String.format("Class not found: %s", className), e); } } return null; }
public static Class<?> toClass(String className) throws ClassNotFoundException { return toClass(className, loaderFromClassOrThread(Reflection.class)); }
public static Class<?> toClass(String className) throws ClassNotFoundException { ClassLoader cl = getClassLoader(Reflection.class); return toClass(className, cl); }
public static Class<?> toClass(String className) throws ClassNotFoundException { return toClass(className, loaderFromThreadOrClass(Reflection.class)); }
private void initValidationLookup() throws Exception { final HashMap<String, XMLMetaValidator> map = new HashMap<String, XMLMetaValidator>(validators.size()); for (XMLMetaValidator xv : validators) { if (xv.getJava() != null) { Validation validation = (Validation) Reflection.toClass(xv.getJava()).newInstance(); xv.setValidation(validation); map.put(xv.getId(), xv); } } validationLookup = new ConcurrentHashMap<String, XMLMetaValidator>(map); }
private static Stream<ValueExtractor<?>> loadValueExtractors(String containerClassName) { try { final Class<? extends BooleanSupplier> activation = Reflection.toClass(containerClassName + "$Activation").asSubclass(BooleanSupplier.class); if (!newInstance(activation).getAsBoolean()) { return Stream.empty(); } } catch (ClassNotFoundException e) { // always active } final Class<?> containerClass; try { containerClass = Reflection.toClass(containerClassName); } catch (ClassNotFoundException e) { throw new IllegalStateException(e); } return Stream.of(containerClass.getClasses()).filter(ValueExtractor.class::isAssignableFrom).map(c -> { @SuppressWarnings("unchecked") final Class<? extends ValueExtractor<?>> result = (Class<? extends ValueExtractor<?>>) c.asSubclass(ValueExtractor.class); return result; }).map(ValueExtractors::newInstance); }
private static Stream<ValueExtractor<?>> loadValueExtractors(String containerClassName) { try { final Class<? extends BooleanSupplier> activation = Reflection.toClass(containerClassName + "$Activation").asSubclass(BooleanSupplier.class); if (!newInstance(activation).getAsBoolean()) { return Stream.empty(); } } catch (ClassNotFoundException e) { // always active } final Class<?> containerClass; try { containerClass = Reflection.toClass(containerClassName); } catch (ClassNotFoundException e) { throw new IllegalStateException(e); } return Stream.of(containerClass.getClasses()).filter(ValueExtractor.class::isAssignableFrom).map(c -> { @SuppressWarnings("unchecked") final Class<? extends ValueExtractor<?>> result = (Class<? extends ValueExtractor<?>>) c.asSubclass(ValueExtractor.class); return result; }).map(ValueExtractors::newInstance); }
@Override public <T> T unwrap(Class<T> type) { // FIXME 2011-03-27 jw: // This code is unsecure. // It should allow only a fixed set of classes. // Can't fix this because don't know which classes this method should support. if (type.isAssignableFrom(getClass())) { @SuppressWarnings("unchecked") final T result = (T) this; return result; } if (!(type.isInterface() || Modifier.isAbstract(type.getModifiers()))) { return newInstance(type); } try { final Class<?> cls = Reflection.toClass(type.getName() + "Impl"); if (type.isAssignableFrom(cls)) { @SuppressWarnings("unchecked") final Class<? extends T> implClass = (Class<? extends T>) cls; return newInstance(implClass); } } catch (ClassNotFoundException e) { } throw new ValidationException("Type " + type + " not supported"); }
@Override public <T> T unwrap(Class<T> type) { // FIXME 2011-03-27 jw: // This code is unsecure. // It should allow only a fixed set of classes. // Can't fix this because don't know which classes this method should support. if (type.isAssignableFrom(getClass())) { @SuppressWarnings("unchecked") final T result = (T) this; return result; } if (!(type.isInterface() || Modifier.isAbstract(type.getModifiers()))) { return newInstance(type); } try { final Class<?> cls = Reflection.toClass(type.getName() + "Impl"); if (type.isAssignableFrom(cls)) { @SuppressWarnings("unchecked") final Class<? extends T> implClass = (Class<? extends T>) cls; return newInstance(implClass); } } catch (ClassNotFoundException e) { } throw new ValidationException("Type " + type + " not supported"); }
} else { validatorFactoryClass = Reflection.toClass(validatorFactoryClassname).asSubclass(ValidatorFactory.class);
} else { validatorFactoryClass = Reflection.toClass(validatorFactoryClassname).asSubclass(ValidatorFactory.class);
public void mergeInto(MetaProperty prop) throws ClassNotFoundException { mergeFeaturesInto(prop); if (getType() != null && getType().length() > 0) { prop.setType(Reflection.toClass(getType())); // enhancement: or use getGenericType() ? } if (getHidden() != null) { prop.putFeature(HIDDEN, getHidden().booleanValue()); } if (getMandatory() != null) { prop.putFeature(MANDATORY, getMandatory().equals("true")); } if (getMaxLength() != null) { prop.putFeature(MAX_LENGTH, getMaxLength()); } if (getMinLength() != null) { prop.putFeature(MIN_LENGTH, getMinLength()); } if (getReadonly() != null) { prop.putFeature(READONLY, getReadonly()); } if (getDenied() != null) { prop.putFeature(DENIED, getDenied()); } } }