|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sibvisions.util.Reflective
public final class Reflective
This is a utility class to call different methods of classes via java.lang.reflect package.
Nested Class Summary | |
---|---|
static class |
Reflective.Parameter
The Parameter class is a placeholder for parameters. |
Method Summary | |
---|---|
static java.lang.Object |
call(java.lang.Object pObject,
boolean pOnlyDeclared,
java.lang.String pMethod,
java.lang.Object... pParams)
Invokes the method of an object without changing the access to the method. |
static java.lang.Object |
call(java.lang.Object pObject,
java.lang.Class<?> pBaseClass,
boolean pOnlyDeclared,
java.lang.String pMethod,
java.lang.Object... pParams)
Invokes the method of an object without changing the access to the method. |
static java.lang.Object |
call(java.lang.Object pObject,
java.lang.reflect.Method pMethod,
java.lang.Object... pParams)
Invokes the given method. |
static java.lang.Object |
call(java.lang.Object pObject,
java.lang.String pMethod,
java.lang.Object... pParams)
Invokes the method of an object without changing the access to the method. |
static java.lang.Object |
construct(java.lang.Class<?> pClass,
boolean pOnlyDeclared,
java.lang.Object... pParams)
Invokes the constructor of a pre-loaded class. |
static java.lang.Object |
construct(java.lang.Class<?> pClass,
java.lang.Object... pParams)
Invokes the constructor of a pre-loaded class. |
static java.lang.Object |
construct(java.lang.ClassLoader pClassLoader,
java.lang.String pClassName,
java.lang.Object... pParams)
Invokes the constructor of a desired class. |
static java.lang.Object |
construct(java.lang.String pClassName,
java.lang.Object... pParams)
Invokes the constructor of a desired class. |
static java.lang.Object |
get(java.lang.Object pObject,
java.lang.String pProperty)
Invokes the get method of the given property. |
static java.lang.Class |
getAutoboxClass(java.lang.Class pClass)
Gets the outerboxed class when primitive class or the object class itself. |
static java.lang.reflect.Constructor |
getConstructor(java.lang.Class<?> pClass,
boolean pOnlyDeclared,
java.lang.Object... pParams)
Gets the best matching constructor from the given class. |
static java.lang.reflect.Constructor |
getConstructor(java.lang.ClassLoader pClassLoader,
java.lang.String pClassName,
java.lang.Object... pParams)
Gets the best matching constructor from the given class. |
static java.lang.reflect.Method |
getMethod(java.lang.Class<?> pBaseClass,
boolean pOnlyDeclared,
java.lang.String pMethod,
java.lang.Class... pParamTypes)
Gets the method with the given types. |
static java.lang.reflect.Method |
getMethod(java.lang.Class<?> pBaseClass,
java.lang.String pMethod,
java.lang.Class... pParamTypes)
Gets the method with the given types. |
static java.lang.String |
getMethodDeclaration(java.lang.Class pClass,
java.lang.String pMethod,
java.lang.Object... pParams)
Gets the human readable method declaration of a method with its parameter list. |
static java.lang.reflect.Method |
getMethodForCall(java.lang.Class<?> pBaseClass,
boolean pOnlyDeclared,
java.lang.String pMethod,
java.lang.Object... pParams)
Gets the method for a possible call. |
static java.lang.reflect.Method |
getMethodForCall(java.lang.Class<?> pBaseClass,
java.lang.String pMethod,
java.lang.Object... pParams)
Gets the method for a possible call. |
static java.lang.reflect.Method[] |
getMethodsByReturnValue(java.lang.Class<?> pClass,
java.lang.Class<?> pReturn,
boolean pOnlyDeclared)
Gets all methods (without parameters) which has a return value that is assignable from the given return value. |
static java.lang.Class |
getOuterBoxClass(java.lang.Class pClass)
Deprecated. since 2.7, use getAutoboxClass(Class) instead. |
static java.lang.Object |
getValue(java.lang.Object pObject,
java.lang.reflect.Field pField)
Gets the value from a vield. |
static java.lang.Object |
getValue(java.lang.Object pObject,
java.lang.String pFieldName)
Gets the value from a field. |
static java.lang.Object |
invoke(java.lang.Object pObject,
java.lang.reflect.Method pMethod,
java.lang.Object... pParams)
Invokes a method with parameters. |
static boolean |
isParamTypeListValid(java.lang.Class<?>[] pTypes,
java.lang.Class[] pParamTypes,
boolean pVarArg)
Checks if the class definitions of a parameter list are equal to a desired class list. |
static void |
printFields(java.lang.Object pObject,
boolean pOnlyDeclared)
Prints out the fields and field values from a specific object. |
static void |
printMethods(java.lang.Object pObject,
boolean pOnlyDeclared)
Prints out the methods and return values from a specific object. |
static void |
set(java.lang.Object pObject,
java.lang.String pProperty,
java.lang.Object pValue)
Invokes the set method of the given property. |
static void |
setValue(java.lang.Object pObject,
java.lang.reflect.Field pField,
java.lang.Object pValue)
Sets a field on a specified object value. |
static void |
setValue(java.lang.Object pObject,
java.lang.String pFieldName,
java.lang.Object pValue)
Sets a field on a specified object value. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static java.lang.Class getAutoboxClass(java.lang.Class pClass)
pClass
- the primitive or object class
@Deprecated public static java.lang.Class getOuterBoxClass(java.lang.Class pClass)
getAutoboxClass(Class)
instead.
pClass
- the primitive or object class
public static final java.lang.Object construct(java.lang.String pClassName, java.lang.Object... pParams) throws java.lang.Throwable
pClassName
- full qualified class namepParams
- parameters for the constructor
java.lang.Throwable
- if it is not possible to invoke the constructorpublic static final java.lang.Object construct(java.lang.ClassLoader pClassLoader, java.lang.String pClassName, java.lang.Object... pParams) throws java.lang.Throwable
pClassLoader
- an optional ClassLoader
for dynamic class loadingpClassName
- full qualified class namepParams
- parameters for the constructor
java.lang.Throwable
- if it is not possible to invoke the constructorpublic static final java.lang.Object construct(java.lang.Class<?> pClass, java.lang.Object... pParams) throws java.lang.Throwable
pClass
- the pre-loaded classpParams
- parameters for the constructor
java.lang.Throwable
- if it is not possible to invoke the constructorpublic static final java.lang.Object construct(java.lang.Class<?> pClass, boolean pOnlyDeclared, java.lang.Object... pParams) throws java.lang.Throwable
pClass
- the pre-loaded classpOnlyDeclared
- true
to use only declared constructorspParams
- parameters for the constructor
java.lang.Throwable
- if it is not possible to invoke the constructorpublic static final java.lang.Object call(java.lang.Object pObject, java.lang.String pMethod, java.lang.Object... pParams) throws java.lang.Throwable
pObject
- object with the desired methodpMethod
- invocable methodpParams
- parameters for the method
java.lang.Throwable
- if it is not possible to invoke the methodpublic static final java.lang.Object call(java.lang.Object pObject, boolean pOnlyDeclared, java.lang.String pMethod, java.lang.Object... pParams) throws java.lang.Throwable
pObject
- object with the desired methodpOnlyDeclared
- true
to use only declared methodspMethod
- invocable methodpParams
- parameters for the method
java.lang.Throwable
- if it is not possible to invoke the methodpublic static final java.lang.Object call(java.lang.Object pObject, java.lang.Class<?> pBaseClass, boolean pOnlyDeclared, java.lang.String pMethod, java.lang.Object... pParams) throws java.lang.Throwable
pObject
- object with the desired methodpBaseClass
- the object class or a super class from which the method will be calledpOnlyDeclared
- true
to use only declared methodspMethod
- invocable methodpParams
- parameters for the method
java.lang.Throwable
- if it is not possible to invoke the methodpublic static final java.lang.Object call(java.lang.Object pObject, java.lang.reflect.Method pMethod, java.lang.Object... pParams) throws java.lang.Throwable
call(Object, Class, boolean, String, Object...)
.
pMethod
- the method to callpObject
- the caller objectpParams
- the method parameters
java.lang.Throwable
- if it is not possible to invoke the method
java.lang.NullPointerException
- if pMethod
is null
public static final java.lang.String getMethodDeclaration(java.lang.Class pClass, java.lang.String pMethod, java.lang.Object... pParams)
pClass
- the classpMethod
- method or full qualified class namepParams
- parameter list
public static void setValue(java.lang.Object pObject, java.lang.String pFieldName, java.lang.Object pValue) throws java.lang.Throwable
pObject
- the object with the fieldpFieldName
- the field namepValue
- the new value
java.lang.Throwable
- if it is not possible to set the desired fieldsetValue(Object, Field, Object)
public static void setValue(java.lang.Object pObject, java.lang.reflect.Field pField, java.lang.Object pValue) throws java.lang.Throwable
pObject
- the object with the fieldpField
- the fieldpValue
- the new value
java.lang.Throwable
- if it is not possible to set the desired fieldpublic static java.lang.Object getValue(java.lang.Object pObject, java.lang.String pFieldName) throws java.lang.Throwable
pObject
- the object with the fieldpFieldName
- the field name
java.lang.Throwable
- if it is not possible to get the value of desired field or the field is not presendgetValue(Object, Field)
public static java.lang.Object getValue(java.lang.Object pObject, java.lang.reflect.Field pField) throws java.lang.Throwable
pObject
- the object with the fieldpField
- the field
java.lang.Throwable
- if it is not possible to get the value of desired field or the field is not presendpublic static java.lang.Object invoke(java.lang.Object pObject, java.lang.reflect.Method pMethod, java.lang.Object... pParams) throws java.lang.Throwable
pObject
- the object with the methodpMethod
- the methodpParams
- the method parameters
java.lang.Throwable
- if an error occurs during invocationpublic static java.lang.Object get(java.lang.Object pObject, java.lang.String pProperty) throws java.lang.Throwable
pObject
- the object with the methodpProperty
- the property
java.lang.Throwable
- if an error occurs during invocationpublic static void set(java.lang.Object pObject, java.lang.String pProperty, java.lang.Object pValue) throws java.lang.Throwable
pObject
- the object with the methodpProperty
- the propertypValue
- the value of the property.
java.lang.Throwable
- if an error occurs during invocationpublic static final void printFields(java.lang.Object pObject, boolean pOnlyDeclared)
pObject
- an objectpOnlyDeclared
- use only declared fieldspublic static final void printMethods(java.lang.Object pObject, boolean pOnlyDeclared)
pObject
- an objectpOnlyDeclared
- use only declared methodspublic static final boolean isParamTypeListValid(java.lang.Class<?>[] pTypes, java.lang.Class[] pParamTypes, boolean pVarArg)
pTypes
- desired class listpParamTypes
- parameter listpVarArg
- check varArg parameter.
public static final java.lang.reflect.Method getMethod(java.lang.Class<?> pBaseClass, java.lang.String pMethod, java.lang.Class... pParamTypes) throws java.lang.NoSuchMethodException
pBaseClass
- the object class or a super class from which the method will be calledpMethod
- invocable methodpParamTypes
- parameters for the method
java.lang.NoSuchMethodException
- if Method does not exist.public static final java.lang.reflect.Method getMethod(java.lang.Class<?> pBaseClass, boolean pOnlyDeclared, java.lang.String pMethod, java.lang.Class... pParamTypes) throws java.lang.NoSuchMethodException
pBaseClass
- the object class or a super class from which the method will be calledpOnlyDeclared
- true
to use only declared methodspMethod
- invocable methodpParamTypes
- parameters for the method
java.lang.NoSuchMethodException
- if Method does not exist.public static final java.lang.reflect.Method getMethodForCall(java.lang.Class<?> pBaseClass, java.lang.String pMethod, java.lang.Object... pParams) throws java.lang.Throwable
pBaseClass
- the object class or a super class from which the method will be calledpMethod
- invocable methodpParams
- parameters for the method
java.lang.Throwable
- if it is not possible to invoke the methodgetMethodForCall(Class, boolean, String, Object...)
public static final java.lang.reflect.Method getMethodForCall(java.lang.Class<?> pBaseClass, boolean pOnlyDeclared, java.lang.String pMethod, java.lang.Object... pParams) throws java.lang.Throwable
call(Object, Class, boolean, String, Object...)
.
pBaseClass
- the object class or a super class from which the method will be calledpOnlyDeclared
- true
to use only declared methodspMethod
- invocable methodpParams
- parameters for the method
java.lang.Throwable
- if it is not possible to invoke the methodpublic static java.lang.reflect.Constructor getConstructor(java.lang.ClassLoader pClassLoader, java.lang.String pClassName, java.lang.Object... pParams) throws java.lang.Exception
pClassLoader
- the class loader that should load the classpClassName
- the full qualified class name "com.package.classname"pParams
- the parameters for the constructor
java.lang.Exception
- if no constructor was foundpublic static java.lang.reflect.Constructor getConstructor(java.lang.Class<?> pClass, boolean pOnlyDeclared, java.lang.Object... pParams) throws java.lang.Exception
pClass
- the class that should checkedpOnlyDeclared
- true
if only declared constructors should be used, false
to search
all constructorspParams
- the parameters for the constructor
java.lang.Exception
- if no constructor was foundpublic static java.lang.reflect.Method[] getMethodsByReturnValue(java.lang.Class<?> pClass, java.lang.Class<?> pReturn, boolean pOnlyDeclared)
pClass
- the class to check for the methodspReturn
- the expected return valuepOnlyDeclared
- true
to get only declared methods, false
to get all methods
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |