|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.openbp.common.ReflectUtil
public final class ReflectUtil
This class contains various static utility methods concerning reflections and class processing.
| Field Summary | |
|---|---|
static int |
CM_PRINT
Print error message to standard error |
static int |
CM_THROW
Re-throw any exceptions |
| Method Summary | |
|---|---|
static java.lang.Object |
callMethod(java.lang.Object o,
java.lang.reflect.Method method,
java.lang.Object[] argValues,
int errorHandlingMode)
Calls a method using Java reflection. |
static java.lang.Object |
callMethod(java.lang.Object o,
java.lang.String methodName,
java.lang.Class[] argClasses,
java.lang.Object[] argValues,
int errorHandlingMode)
Calls a method using Java reflection. |
static java.lang.Class |
determineClass(java.lang.String stringRepresentation)
Determines the class object by type string. |
static java.lang.reflect.Method |
findByQualifiedMethodSignature(java.lang.String signature)
Finds a method according to its signature. |
static java.lang.reflect.Method |
findByUnqualifiedMethodSignature(java.lang.Class objectClass,
java.lang.String signature)
Finds a method according to its signature. |
static java.lang.Class |
findClassInPackageList(java.lang.String className,
java.util.List packageList)
Searches for a particular class in a list of packages. |
static java.lang.Class |
findClassInPackageList(java.lang.String className,
java.util.List packageList,
java.lang.ClassLoader cl)
Searches for a particular class in a list of packages. |
static java.lang.reflect.Field |
getFieldOrNull(java.lang.Class cls,
java.lang.String name)
Get a field using reflections. |
static java.lang.reflect.Method |
getMethodOrNull(java.lang.Class cls,
java.lang.String name,
java.lang.Class[] args)
Get a method using reflections. |
static java.lang.String |
getPrintableClassName(java.lang.Class cls)
Gets a printable form of a class name. |
static java.lang.String |
getQualifiedMethodSignature(java.lang.reflect.Method method)
Creates a string that specifies the method signature containing a fullly qualified method name. |
static java.lang.String |
getUnqualifiedMethodSignature(java.lang.reflect.Method method)
Creates a string that specifies the method signature containing an unqualified method name. |
static java.lang.Object |
instantiate(java.lang.Class cls,
java.lang.ClassLoader cl,
java.lang.Class type,
java.lang.String displayName)
Creates an object instance given its class using the default constructor. |
static java.lang.Object |
instantiate(java.lang.Class cls,
java.lang.Class type,
java.lang.String displayName)
Creates an object instance given its class using the default constructor. |
static java.lang.Object |
instantiate(java.lang.String className,
java.lang.ClassLoader cl,
java.lang.Class type,
java.lang.String displayName)
Creates an object instance by its fully qualified class name using the default constructor. |
static java.lang.Object |
instantiate(java.lang.String className,
java.lang.Class type,
java.lang.String displayName)
Creates a class by its fully qualified class name using the default constructor (convenience method). |
static java.lang.Object |
instantiateByConstructor(java.lang.Class cls,
java.lang.Class[] argTypes,
java.lang.Object[] args,
java.lang.Class type,
java.lang.String displayName,
boolean allowDefaultConstructor)
Creates an object instance given its class using the constructor with the given argument types. |
static java.lang.Class |
loadClass(java.lang.String className)
Loads a class by its fully qualified class name. |
static java.lang.Class |
loadClass(java.lang.String className,
java.lang.ClassLoader cl)
Loads a class by its fully qualified class name. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int CM_PRINT
public static final int CM_THROW
| Method Detail |
|---|
public static java.lang.Class findClassInPackageList(java.lang.String className,
java.util.List packageList)
className - Unqualified name of the classpackageList - List of package to search the class in (contains strings)
public static java.lang.Class findClassInPackageList(java.lang.String className,
java.util.List packageList,
java.lang.ClassLoader cl)
className - Unqualified name of the classpackageList - List of package to search the class in (contains strings)cl - The class loader which shall load the class or null for the default loader
public static java.lang.Class loadClass(java.lang.String className)
className - Qualified class name
public static java.lang.Class loadClass(java.lang.String className,
java.lang.ClassLoader cl)
className - Qualified class namecl - The class loader which shall load the class or null for the default loader
public static java.lang.Object instantiate(java.lang.String className,
java.lang.ClassLoader cl,
java.lang.Class type,
java.lang.String displayName)
className - Qualified class namecl - The class loader which shall load the class or null for the default loadertype - If not null, the method will check if the instantiated class matches the given typedisplayName - Display name of the type of object to instantiate for error messages
ReflectException - On any error. The exception message will describe the cause of the error.
The exception will encapsulate the exception that led to the error.
public static java.lang.Object instantiate(java.lang.Class cls,
java.lang.Class type,
java.lang.String displayName)
cls - Object class to use for the instantiationtype - If not null, the method will check if the instantiated class matches the given typedisplayName - Display name of the type of object to instantiate for error messages
ReflectException - On any error. The exception message will describe the cause of the error.
The exception will encapsulate the exception that led to the error.
public static java.lang.Object instantiate(java.lang.Class cls,
java.lang.ClassLoader cl,
java.lang.Class type,
java.lang.String displayName)
cls - Object class to use for the instantiationcl - The class loader which shall load the class or null for the default loadertype - If not null, the method will check if the instantiated class matches the given typedisplayName - Display name of the type of object to instantiate for error messages
ReflectException - On any error. The exception message will describe the cause of the error.
The exception will encapsulate the exception that led to the error.
public static java.lang.Object instantiate(java.lang.String className,
java.lang.Class type,
java.lang.String displayName)
className - Qualified class nametype - If not null, the method will check if the instantiated class matches the given typedisplayName - Display name of the type of object to instantiate for error messages
ReflectException - On any error. The exception message will describe the cause of the error.
The exception will encapsulate the exception that led to the error.
public static java.lang.Object instantiateByConstructor(java.lang.Class cls,
java.lang.Class[] argTypes,
java.lang.Object[] args,
java.lang.Class type,
java.lang.String displayName,
boolean allowDefaultConstructor)
cls - Object class to use for the instantiationargTypes - Object classes of the constructor argumentsargs - constructor argumentstype - If not null, the method will check if the instantiated class matches the given typedisplayName - Display name of the type of object to instantiate for error messagesallowDefaultConstructor - If true, the default constructor will be used, if no constructor
with the given argument types could be found. This might result in an error, if the Class has no
accessible default constructor.
ReflectException - On any error. The exception message will describe the cause of the error.
The exception will encapsulate the exception that led to the error.
public static java.lang.Object callMethod(java.lang.Object o,
java.lang.String methodName,
java.lang.Class[] argClasses,
java.lang.Object[] argValues,
int errorHandlingMode)
throws java.lang.Exception
o - Object to invoke the method uponmethodName - Name of the methodargClasses - Argument classes or nullargValues - Argument values or nullerrorHandlingMode - Mode that describes how errors are to be handled.CM_PRINT | CM_THROW)
java.lang.Exception - If an error occurred and errorHandlingMode was set to CM_THROW
public static java.lang.Object callMethod(java.lang.Object o,
java.lang.reflect.Method method,
java.lang.Object[] argValues,
int errorHandlingMode)
throws java.lang.Exception
o - Object to invoke the method uponmethod - Method to invokeargValues - Argument values or nullerrorHandlingMode - Mode that describes how errors are to be handled.CM_PRINT | CM_THROW)
java.lang.Exception - If an error occurred and errorHandlingMode was set to CM_THROWpublic static java.lang.String getQualifiedMethodSignature(java.lang.reflect.Method method)
method - Method
public static java.lang.String getUnqualifiedMethodSignature(java.lang.reflect.Method method)
method - Method
public static java.lang.reflect.Method findByQualifiedMethodSignature(java.lang.String signature)
throws java.lang.NoSuchMethodException,
java.lang.ClassNotFoundException
signature - Signature as generated by getQualifiedMethodSignature(java.lang.reflect.Method)
java.lang.NoSuchMethodException - If no matching method was found
java.lang.ClassNotFoundException - If an argument class could not be loaded by the thread or standard class loader
public static java.lang.reflect.Method findByUnqualifiedMethodSignature(java.lang.Class objectClass,
java.lang.String signature)
throws java.lang.NoSuchMethodException,
java.lang.ClassNotFoundException
objectClass - Class to search for the methodsignature - Signature as generated by getQualifiedMethodSignature(java.lang.reflect.Method)
java.lang.NoSuchMethodException - If no matching method was found
java.lang.ClassNotFoundException - If an argument class could not be loaded by the thread or standard class loaderpublic static java.lang.String getPrintableClassName(java.lang.Class cls)
cls - The class to get the name for
public static java.lang.Class determineClass(java.lang.String stringRepresentation)
stringRepresentation - Example: java.lang.String or java.lang.String[] or int
public static java.lang.reflect.Method getMethodOrNull(java.lang.Class cls,
java.lang.String name,
java.lang.Class[] args)
cls - Classname - Name of the method to locateargs - Arguments of the method signature looking for
public static java.lang.reflect.Field getFieldOrNull(java.lang.Class cls,
java.lang.String name)
cls - Classname - Name of the field to locate
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||