Class ClassUtils
java.lang.Object
org.apache.shiro.lang.util.ClassUtils
Utility method library used to conveniently interact with
Classes, such as acquiring them from the
application ClassLoaders and instantiating Objects from them.- Since:
- 0.1
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Class<T> Attempts to load the specified class name from the current thread'scontext class loader, then the current ClassLoader (ClassUtils.class.getClassLoader()), then the system/application ClassLoader (ClassLoader.getSystemClassLoader(), in that order.getAnnotatedMethods(Class<?> type, Class<? extends Annotation> annotation) static Constructor<?> getConstructor(Class<?> clazz, Class<?>... argTypes) static InputStreamgetResourceAsStream(String name) Returns the specified resource by checking the current thread'scontext class loader, then the current ClassLoader (ClassUtils.class.getClassLoader()), then the system/application ClassLoader (ClassLoader.getSystemClassLoader(), in that order, usinggetResourceAsStream(name).static Objectinstantiate(Constructor<?> ctor, Object... args) static booleanisAvailable(String fullyQualifiedClassName) static ObjectnewInstance(Class<?> clazz) static ObjectnewInstance(Class<?> clazz, Object... args) static ObjectnewInstance(String fqcn) static ObjectnewInstance(String fqcn, Object... args) static voidRemoves the additional ClassLoader set bysetAdditionalClassLoader(ClassLoader).static voidsetAdditionalClassLoader(ClassLoader classLoader) Sets additional ClassLoader forgetResourceAsStream(String)andforName(String)to use It is used in addition to the thread context class loader and the system class loader.
-
Method Details
-
getResourceAsStream
Returns the specified resource by checking the current thread'scontext class loader, then the current ClassLoader (ClassUtils.class.getClassLoader()), then the system/application ClassLoader (ClassLoader.getSystemClassLoader(), in that order, usinggetResourceAsStream(name).- Parameters:
name- the name of the resource to acquire from the classloader(s).- Returns:
- the InputStream of the resource found, or
nullif the resource cannot be found from any of the three mentioned ClassLoaders. - Since:
- 0.9
-
forName
Attempts to load the specified class name from the current thread'scontext class loader, then the current ClassLoader (ClassUtils.class.getClassLoader()), then the system/application ClassLoader (ClassLoader.getSystemClassLoader(), in that order. If any of them cannot locate the specified class, anUnknownClassExceptionis thrown (our RuntimeException equivalent of the JRE'sClassNotFoundException.- Parameters:
fqcn- the fully qualified class name to load- Returns:
- the located class
- Throws:
UnknownClassException- if the class cannot be found.
-
isAvailable
-
newInstance
-
newInstance
-
newInstance
-
newInstance
-
getConstructor
-
instantiate
-
getAnnotatedMethods
public static List<Method> getAnnotatedMethods(Class<?> type, Class<? extends Annotation> annotation) - Parameters:
type-annotation-- Returns:
- Since:
- 1.3
-
setAdditionalClassLoader
Sets additional ClassLoader forgetResourceAsStream(String)andforName(String)to use It is used in addition to the thread context class loader and the system class loader.- Parameters:
classLoader- class loader to use- Since:
- 2.0.4
-
removeAdditionalClassLoader
Removes the additional ClassLoader set bysetAdditionalClassLoader(ClassLoader). This must be called to avoid memory leaks.- Since:
- 2.0.4
-