|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecteu.beesoft.gaia.util.Reflection
public class Reflection
Utility class for Java reflection.
Method Summary | |
---|---|
static java.lang.Object |
createArrayInstance(java.lang.Class<?> componentType,
int length)
Creates an array instance with the given component type and length. |
static java.lang.Object |
createArrayInstance(java.lang.String componentTypeName,
int length)
Creates an array instance with the type of the given name and length. |
static java.lang.Object |
createInstance(java.lang.Class<?> creator)
Creates a new instance of the given class. |
static java.lang.Object |
createInstance(java.lang.Class<?> creator,
java.lang.Object... arguments)
Creates a new instance of the given class with the given arguments for constructor. |
static java.lang.Object |
createInstance(java.lang.Class<?> creator,
java.lang.Object argument)
Creates a new instance of the given class with the given argument for constructor. |
static java.lang.Object |
createInstance(java.lang.String className)
Creates a new instance of the class with given name. |
static java.lang.Class<?> |
getClass(java.lang.String className)
Returns class with given className . |
static java.lang.reflect.Field |
getField(java.lang.String fieldName,
java.lang.Object objectOrClass)
Returns a field with given fieldName in an
objectOrClass . |
static java.lang.reflect.Field |
getFieldIgnoreCase(java.lang.String fieldName,
java.lang.Object objectOrClass)
Returns a field with given fieldName in an
objectOrClass . |
static java.lang.Object |
getFieldValue(java.lang.reflect.Field field,
java.lang.Object object)
Returns value from given field of the object. |
static java.lang.reflect.Method |
getGetter(java.lang.String fieldName,
java.lang.Object objectOrClass)
Returns getter method for property with given name in the given object or class. |
static java.lang.reflect.Method |
getMethod(java.lang.String methodName,
java.lang.Object objectOrClass)
Returns the method with given methodName and without any
parameters. |
static java.lang.reflect.Method |
getMethod(java.lang.String methodName,
java.lang.Object objectOrClass,
java.lang.Class<?>... argumentTypes)
Returns the method with given methodName and requested
argumentTypes . |
static java.lang.reflect.Method |
getMethod(java.lang.String methodName,
java.lang.Object objectOrClass,
java.lang.Object... arguments)
Returns the method with given methodName and requested
arguments . |
static java.lang.reflect.Method[] |
getMethods(java.lang.String methodName,
java.lang.Object objectOrClass)
Returns all methods with given methodName from the
objectOrClass (which can be object or its class) and its
superclasses. |
static java.lang.reflect.Method |
getSetter(java.lang.String fieldName,
java.lang.Object objectOrClass)
Returns setter method for property with given name in the given object or class. |
static java.lang.Object |
invoke(java.lang.reflect.Method method,
java.lang.Object objectOrClass)
Invokes given method on the objectOrClass . |
static java.lang.Object |
invoke(java.lang.reflect.Method method,
java.lang.Object objectOrClass,
java.lang.Object... arguments)
Invokes given method on the objectOrClass with
arguments . |
static void |
setFieldValue(java.lang.reflect.Field field,
java.lang.Object object,
java.lang.Object value)
Sets the field represented by the field on the specified
object argument to the specified new 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.reflect.Field getField(java.lang.String fieldName, java.lang.Object objectOrClass)
fieldName
in an
objectOrClass
. This can be any object or its class. The
given class, and if not found, its superclass(es), is scanned for a
field.
fieldName
- - name of field to searchobjectOrClass
- - object or its class
public static java.lang.reflect.Field getFieldIgnoreCase(java.lang.String fieldName, java.lang.Object objectOrClass)
fieldName
in an
objectOrClass
. This can be any object or its class. The
given class, and if not found, its superclass(es), is scanned for a
field. The case of the field name is ignored.
fieldName
- - name of field to searchobjectOrClass
- - object or its class
public static java.lang.Object getFieldValue(java.lang.reflect.Field field, java.lang.Object object)
field
- - a field instance used for accessobject
- - object from which the represented field's value is to be
extracted
java.lang.RuntimeException
- if some error occurspublic static void setFieldValue(java.lang.reflect.Field field, java.lang.Object object, java.lang.Object value)
field
on the specified
object argument to the specified new value. The new value is
automatically unwrapped if the underlying field has a primitive type. No
exception is thrown.
field
- - a field instance used for accessobject
- - the object whose field should be modifiedvalue
- - the new value for the field of object being modifiedpublic static java.lang.reflect.Method getMethod(java.lang.String methodName, java.lang.Object objectOrClass)
methodName
and without any
parameters. Method is searched in object or class represented by
objectOrClass
and its superclasses. Returns null, if no
method was found.
methodName
- - name of method to searchobjectOrClass
- - object or its class to search
public static java.lang.reflect.Method getMethod(java.lang.String methodName, java.lang.Object objectOrClass, java.lang.Object... arguments)
methodName
and requested
arguments
. First are obtained classes from given arguments.
Method is searched in object or class represented by
objectOrClass
and its superclasses. Returns null, if no
method was found.
methodName
- - name of method to searchobjectOrClass
- - object or its class to searcharguments
- - objects that are aguments for method (in this array may be
objects or their classes
public static java.lang.reflect.Method getMethod(java.lang.String methodName, java.lang.Object objectOrClass, java.lang.Class<?>... argumentTypes)
methodName
and requested
argumentTypes
. Method is searched in object or class
represented by objectOrClass
and its superclasses. Returns
null, if no method was found.
methodName
- - name of method to searchobjectOrClass
- - object or its class to searchargumentTypes
- - an array of classes that are agument types for the searched
method
public static java.lang.reflect.Method[] getMethods(java.lang.String methodName, java.lang.Object objectOrClass)
methodName
from the
objectOrClass
(which can be object or its class) and its
superclasses.
methodName
- - name of method to searchobjectOrClass
- - object or its class
public static java.lang.Object invoke(java.lang.reflect.Method method, java.lang.Object objectOrClass)
method
on the objectOrClass
.
method
- - method to invokeobjectOrClass
- - object or its class
public static java.lang.Object invoke(java.lang.reflect.Method method, java.lang.Object objectOrClass, java.lang.Object... arguments)
method
on the objectOrClass
with
arguments
.
method
- - method to invokeobjectOrClass
- - object or its classarguments
- - arguments to pass to method to invoke
public static java.lang.Class<?> getClass(java.lang.String className)
className
. This method works also
for primitives (boolean, byte, int, ...) and returns correct types.
className
- - the name of the class
java.lang.RuntimeException
- if cannot find such classpublic static java.lang.Object createInstance(java.lang.String className)
className
- - name of the class
java.lang.RuntimeException
- if cannot create a new instancepublic static java.lang.Object createInstance(java.lang.Class<?> creator)
creator
- - class to create instance
java.lang.RuntimeException
- if cannot create a new instancepublic static java.lang.Object createInstance(java.lang.Class<?> creator, java.lang.Object argument)
creator
- - class to create instanceargument
- - argument to create instance
java.lang.RuntimeException
- if cannot create a new instancepublic static java.lang.Object createInstance(java.lang.Class<?> creator, java.lang.Object... arguments)
creator
- - class to create instancearguments
- - arguments to create instance
java.lang.RuntimeException
- if cannot create a new instancepublic static java.lang.Object createArrayInstance(java.lang.String componentTypeName, int length)
componentTypeName
- - class name of the array component typelength
- - length of the array
public static java.lang.Object createArrayInstance(java.lang.Class<?> componentType, int length)
componentType
- - class of the array component typelength
- - length of the array
public static java.lang.reflect.Method getGetter(java.lang.String fieldName, java.lang.Object objectOrClass)
fieldName
- - name of the propertyobjectOrClass
- - object or its class from which should be a getter obtained
public static java.lang.reflect.Method getSetter(java.lang.String fieldName, java.lang.Object objectOrClass)
fieldName
- - name of the propertyobjectOrClass
- - object or its class from which should be a setter obtained
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |