Package org.jolokia.server.core.util
Class ClassUtil
java.lang.Object
org.jolokia.server.core.util.ClassUtil
Utility for class lookup.
- Since:
- 19.04.11
- Author:
- roland
-
Method Summary
Modifier and TypeMethodDescriptionstatic ObjectapplyMethod(Object pObject, String pMethod, Object... pArgs) Apply a method to a given object with optional arguments.static booleancheckForClass(String pClassName) Check for the existence of a given classstatic <T> Class<T>classForName(String pClassName, boolean pInitialize, ClassLoader... pClassLoaders) Load a certain class.static <T> Class<T>classForName(String pClassName, ClassLoader... pClassLoaders) Lookup a class.static InputStreamgetResourceAsStream(String pPath) Get the given path as an input stream or returnnullif not foundgetResources(String pResource) Get all resources from the classpath which are specified by the given path.static <T> TnewInstance(Class<T> pClass, Object... pArguments) Instantiate an instance of the given class with its default constructorstatic <T> TnewInstance(String pClassName, Object... pArguments) Instantiate an instance of the given class with its default constructor.static LogHandlernewLogHandlerInstance(String pLogHandlerClass, String pLogHandlerName, boolean pIsDebug)
-
Method Details
-
classForName
Lookup a class. SeeclassForName(String, boolean,ClassLoader[])for details. The class gets initialized during lookup.- Parameters:
pClassName- name to lookup.- Returns:
- the class found or null if no class could be found.
-
classForName
public static <T> Class<T> classForName(String pClassName, boolean pInitialize, ClassLoader... pClassLoaders) Load a certain class. Several class loader are tried: Fires the current thread's context class loader, then its parents. If this doesn't work, the class loader which loaded this class is used (and its parents)- Parameters:
pClassName- class name to loadpInitialize- whether the class must be initializedpClassLoaders- optional class loaders which are tried as well- Returns:
- the class class found or null if no class could be loaded
-
getResourceAsStream
Get the given path as an input stream or returnnullif not found- Parameters:
pPath- path to lookup- Returns:
- input stream or null if not found.
-
checkForClass
Check for the existence of a given class- Parameters:
pClassName- class name to check- Returns:
- true if the class could be loaded by the thread's conext class loader, false otherwise
-
newInstance
Instantiate an instance of the given class with its default constructor. The context class loader is used to lookup the class- Type Parameters:
T- type object type- Parameters:
pClassName- name of class to instantiatepArguments- optional constructor arguments. Works only for objects with the same class as declared in the constructor types (no subclasses)- Returns:
- instantiated object
- Throws:
IllegalArgumentException- if the class could not be found or instantiated
-
newInstance
Instantiate an instance of the given class with its default constructor- Type Parameters:
T- type object type- Parameters:
pClass- class to instantiatepArguments- optional constructor arguments. Works only for objects with the same class as declared in the constructor types (no subclasses)- Returns:
- instantiated object
- Throws:
IllegalArgumentException- if the class could not be found or instantiated
-
newLogHandlerInstance
public static LogHandler newLogHandlerInstance(String pLogHandlerClass, String pLogHandlerName, boolean pIsDebug) -
applyMethod
Apply a method to a given object with optional arguments. The method is looked up the whole class hierarchy.- Parameters:
pObject- object on which to apply the methodpMethod- the method namepArgs- optional arguments- Returns:
- return value (if any)
-
getResources
Get all resources from the classpath which are specified by the given path.- Parameters:
pResource- resource specification to use for lookup- Returns:
- the list or URLs to loookup
- Throws:
IOException
-