|
||||||||||
| 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 Object |
call(Object pObject,
boolean pOnlyDeclared,
String pMethod,
Object... pParams)
Invokes the method of an object without changing the access to the method. |
static Object |
call(Object pObject,
Class<?> pBaseClass,
boolean pOnlyDeclared,
String pMethod,
Object... pParams)
Invokes the method of an object without changing the access to the method. |
static Object |
call(Object pObject,
String pMethod,
Object... pParams)
Invokes the method of an object without changing the access to the method. |
static Object |
construct(Class<?> pClass,
boolean pOnlyDeclared,
Object... pParams)
Invokes the constructor of a pre-loaded class. |
static Object |
construct(Class<?> pClass,
Object... pParams)
Invokes the constructor of a pre-loaded class. |
static Object |
construct(ClassLoader pClassLoader,
String pClassName,
Object... pParams)
Invokes the constructor of a desired class. |
static Object |
construct(String pClassName,
Object... pParams)
Invokes the constructor of a desired class. |
static Object |
get(Object pObject,
String pProperty)
Invokes the get method of the given property. |
static Constructor |
getConstructor(Class<?> pClass,
boolean pOnlyDeclared,
Object... pParams)
Gets the best matching constructor from the given class. |
static Constructor |
getConstructor(ClassLoader pClassLoader,
String pClassName,
Object... pParams)
Gets the best matching constructor from the given class. |
static Method |
getMethod(Class<?> pBaseClass,
boolean pOnlyDeclared,
String pMethod,
Class... pParamTypes)
Gets the method with the given types. |
static Method |
getMethod(Class<?> pBaseClass,
String pMethod,
Class... pParamTypes)
Gets the method with the given types. |
static String |
getMethodDeclaration(Class pClass,
String pMethod,
Object... pParams)
Gets the human readable method declaration of a method with its parameter list. |
static Object |
getValue(Object pObject,
Field pField)
Gets the value from a vield. |
static Object |
getValue(Object pObject,
String pFieldName)
Gets the value from a field. |
static Object |
invoke(Object pObject,
Method pMethod,
Object... pParams)
Invokes a method with parameters. |
static void |
printFields(Object pObject,
boolean pOnlyDeclared)
Prints out the fields and field values from a specific object. |
static void |
printMethods(Object pObject,
boolean pOnlyDeclared)
Prints out the methods and return values from a specific object. |
static void |
set(Object pObject,
String pProperty,
Object pValue)
Invokes the set method of the given property. |
static void |
setValue(Object pObject,
Field pField,
Object pValue)
Sets a field on a specified object value. |
static void |
setValue(Object pObject,
String pFieldName,
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 final Object construct(String pClassName,
Object... pParams)
throws Throwable
pClassName - full qualified class namepParams - parameters for the constructor
Throwable - if it is not possible to invoke the constructor
public static final Object construct(ClassLoader pClassLoader,
String pClassName,
Object... pParams)
throws Throwable
pClassLoader - an optional ClassLoader for dynamic class loadingpClassName - full qualified class namepParams - parameters for the constructor
Throwable - if it is not possible to invoke the constructor
public static final Object construct(Class<?> pClass,
Object... pParams)
throws Throwable
pClass - the pre-loaded classpParams - parameters for the constructor
Throwable - if it is not possible to invoke the constructor
public static final Object construct(Class<?> pClass,
boolean pOnlyDeclared,
Object... pParams)
throws Throwable
pClass - the pre-loaded classpOnlyDeclared - true to use only declared constructorspParams - parameters for the constructor
Throwable - if it is not possible to invoke the constructor
public static final Object call(Object pObject,
String pMethod,
Object... pParams)
throws Throwable
pObject - object with the desired methodpMethod - invocable methodpParams - parameters for the method
Throwable - if it is not possible to invoke the method
public static final Object call(Object pObject,
boolean pOnlyDeclared,
String pMethod,
Object... pParams)
throws Throwable
pObject - object with the desired methodpOnlyDeclared - true to use only declared methodspMethod - invocable methodpParams - parameters for the method
Throwable - if it is not possible to invoke the method
public static final Object call(Object pObject,
Class<?> pBaseClass,
boolean pOnlyDeclared,
String pMethod,
Object... pParams)
throws 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
Throwable - if it is not possible to invoke the method
public static final String getMethodDeclaration(Class pClass,
String pMethod,
Object... pParams)
pClass - the classpMethod - method or full qualified class namepParams - parameter list
public static void setValue(Object pObject,
String pFieldName,
Object pValue)
throws Throwable
pObject - the object with the fieldpFieldName - the field namepValue - the new value
Throwable - if it is not possible to set the desired fieldsetValue(Object, Field, Object)
public static void setValue(Object pObject,
Field pField,
Object pValue)
throws Throwable
pObject - the object with the fieldpField - the fieldpValue - the new value
Throwable - if it is not possible to set the desired field
public static Object getValue(Object pObject,
String pFieldName)
throws Throwable
pObject - the object with the fieldpFieldName - the field name
Throwable - if it is not possible to get the value of desired field or the field is not presendgetValue(Object, Field)
public static Object getValue(Object pObject,
Field pField)
throws Throwable
pObject - the object with the fieldpField - the field
Throwable - if it is not possible to get the value of desired field or the field is not presend
public static Object invoke(Object pObject,
Method pMethod,
Object... pParams)
throws Throwable
pObject - the object with the methodpMethod - the methodpParams - the method parameters
Throwable - if an error occurs during invocation
public static Object get(Object pObject,
String pProperty)
throws Throwable
pObject - the object with the methodpProperty - the property
Throwable - if an error occurs during invocation
public static void set(Object pObject,
String pProperty,
Object pValue)
throws Throwable
pObject - the object with the methodpProperty - the propertypValue - the value of the property.
Throwable - if an error occurs during invocation
public static final void printFields(Object pObject,
boolean pOnlyDeclared)
pObject - an objectpOnlyDeclared - use only declared fields
public static final void printMethods(Object pObject,
boolean pOnlyDeclared)
pObject - an objectpOnlyDeclared - use only declared methods
public static final Method getMethod(Class<?> pBaseClass,
String pMethod,
Class... pParamTypes)
throws NoSuchMethodException
pBaseClass - the object class or a super class from which the method will be calledpMethod - invocable methodpParamTypes - parameters for the method
NoSuchMethodException - if Method does not exist.
public static final Method getMethod(Class<?> pBaseClass,
boolean pOnlyDeclared,
String pMethod,
Class... pParamTypes)
throws 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
NoSuchMethodException - if Method does not exist.
public static Constructor getConstructor(ClassLoader pClassLoader,
String pClassName,
Object... pParams)
throws Exception
pClassLoader - the class loader that should load the classpClassName - the full qualified class name "com.package.classname"pParams - the parameters for the constructor
Exception - if no constructor was found
public static Constructor getConstructor(Class<?> pClass,
boolean pOnlyDeclared,
Object... pParams)
throws 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
Exception - if no constructor was found
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||