List of usage examples for org.apache.commons.lang3 ClassUtils getClass
public static Class<?> getClass(final ClassLoader classLoader, final String className, final boolean initialize) throws ClassNotFoundException
From source file:edu.umich.flowfence.common.ParamInfo.java
public Class<?> getType(ClassLoader loader) throws ClassNotFoundException { return ClassUtils.getClass(loader, typeName, true); }
From source file:edu.umich.flowfence.client.QuarentineModule.java
private static <T> Class<? extends T> checkClass(String className, Class<T> clazz, ClassLoader loader) throws ClassNotFoundException { Class<?> resultClazz;/*from w ww . j ava 2 s . c om*/ if ("void".equals(className)) { if ("void".equals(clazz.getName())) { return clazz; } else if ("java.lang.Void".equals(clazz.getName())) { return clazz; } else { throw new ClassCastException("Void type in non-void context"); } } resultClazz = ClassUtils.getClass(loader, className, true); // Special handling for primitives. // If we can be handled by one of the primitive conversions, allow it. if (resultClazz.isPrimitive()) { if (ClassUtils.isAssignable(resultClazz, clazz, true)) { return clazz; } else { throw new ClassCastException("Cannot convert " + className + " to " + clazz.getName()); } } return resultClazz.asSubclass(clazz); }
From source file:edu.umich.flowfence.client.QuarentineModule.java
public Class<?> getDeclaringClass(ClassLoader loader) throws ClassNotFoundException { return ClassUtils.getClass(loader, descriptor.definingClass.getClassName(), true); }
From source file:edu.umich.oasis.sandbox.ResolvedSoda.java
public ResolvedSoda(SandboxService sandbox, SodaDescriptor descriptor, boolean bestMatch) throws Exception { //if (localLOGD) { Log.d(TAG, "Resolving " + descriptor.toString()); //}/*from w w w . j a v a 2 s.c o m*/ mSandbox = sandbox; mContext = mSandbox.getContextForPackage(descriptor.definingClass.getPackageName()); //if (localLOGD) { Log.d(TAG, "Got package context"); //} final ClassLoader loader = mContext.getClassLoader(); mDefiningClass = ClassUtils.getClass(loader, descriptor.definingClass.getClassName(), true); Class<?>[] paramClasses = classNamesToClasses(descriptor.paramTypes, loader); switch (descriptor.kind) { case SodaDescriptor.KIND_INSTANCE: mMemberData = resolveInstance(mDefiningClass, descriptor.methodName, paramClasses, bestMatch); break; case SodaDescriptor.KIND_STATIC: mMemberData = resolveStatic(mDefiningClass, descriptor.methodName, paramClasses, bestMatch); break; case SodaDescriptor.KIND_CTOR: mMemberData = resolveConstructor(mDefiningClass, paramClasses, bestMatch); break; default: throw new IllegalArgumentException("Unknown SodaDescriptor type"); } // Check that return type can be marshalled. if (!ParceledPayload.canParcelType(mMemberData.getReturnType(), true)) { throw new BadParcelableException("Cannot parcel type " + mMemberData.getReturnType().getName()); } mOriginalDescriptor = descriptor; }
From source file:edu.umich.flowfence.sandbox.ResolvedQM.java
public ResolvedQM(SandboxService sandbox, QMDescriptor descriptor, boolean bestMatch) throws Exception { //if (localLOGD) { Log.d(TAG, "Resolving " + descriptor.toString()); //}// www.j a v a 2 s . c o m mSandbox = sandbox; mContext = mSandbox.getContextForPackage(descriptor.definingClass.getPackageName()); //if (localLOGD) { Log.d(TAG, "Got package context"); //} final ClassLoader loader = mContext.getClassLoader(); mDefiningClass = ClassUtils.getClass(loader, descriptor.definingClass.getClassName(), true); Class<?>[] paramClasses = classNamesToClasses(descriptor.paramTypes, loader); switch (descriptor.kind) { case QMDescriptor.KIND_INSTANCE: mMemberData = resolveInstance(mDefiningClass, descriptor.methodName, paramClasses, bestMatch); break; case QMDescriptor.KIND_STATIC: mMemberData = resolveStatic(mDefiningClass, descriptor.methodName, paramClasses, bestMatch); break; case QMDescriptor.KIND_CTOR: mMemberData = resolveConstructor(mDefiningClass, paramClasses, bestMatch); break; default: throw new IllegalArgumentException("Unknown QMDescriptor type"); } // Check that return type can be marshalled. if (!ParceledPayload.canParcelType(mMemberData.getReturnType(), true)) { throw new BadParcelableException("Cannot parcel type " + mMemberData.getReturnType().getName()); } mOriginalDescriptor = descriptor; }
From source file:org.apache.bval.jsr.resolver.DefaultTraversableResolver.java
/** Tries to load detect and load JPA. */ @SuppressWarnings("unchecked") private void initJpa() { final ClassLoader classLoader = Reflection.getClassLoader(DefaultTraversableResolver.class); try {// w ww .jav a 2 s. c o m Reflection.getClass(classLoader, PERSISTENCE_UTIL_CLASSNAME); if (LOG_FINEST) { log.log(Level.FINEST, String.format("Found %s on classpath.", PERSISTENCE_UTIL_CLASSNAME)); } } catch (final Exception e) { log.log(Level.FINEST, String.format("Cannot find %s on classpath. All properties will per default be traversable.", PERSISTENCE_UTIL_CLASSNAME)); return; } try { Class<? extends TraversableResolver> jpaAwareResolverClass = (Class<? extends TraversableResolver>) ClassUtils .getClass(classLoader, JPA_AWARE_TRAVERSABLE_RESOLVER_CLASSNAME, true); jpaTR = jpaAwareResolverClass.newInstance(); if (LOG_FINEST) { log.log(Level.FINEST, String.format("Instantiated an instance of %s.", JPA_AWARE_TRAVERSABLE_RESOLVER_CLASSNAME)); } } catch (final Exception e) { log.log(Level.WARNING, String.format( "Unable to load or instantiate JPA aware resolver %s. All properties will per default be traversable.", JPA_AWARE_TRAVERSABLE_RESOLVER_CLASSNAME), e); } }
From source file:org.apache.bval.util.reflection.Reflection.java
/** * Get the named {@link Class} from the specified {@link ClassLoader}. * @param classLoader//from w ww . ja v a2 s . co m * @param className * @return Class * @throws Exception */ public static Class<?> getClass(final ClassLoader classLoader, final String className) throws Exception { return ClassUtils.getClass(classLoader, className, true); }