public class ReflectUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
REVISION |
Constructor and Description |
---|
ReflectUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
copyDeclaredFields(java.lang.Object src,
java.lang.Object dest)
Copy all fields (whatever access status, and on whatever superclass they were defined) that can be found on this class.
|
static java.lang.Object |
fieldGetter(java.lang.Object instance,
java.lang.reflect.Field field)
Return the return value of a getter call from a given field on a given instance
|
static void |
fieldSetter(java.lang.Object obj,
java.lang.reflect.Field field,
java.lang.Object fieldValue) |
static java.lang.reflect.Field[] |
getAllFields(java.lang.Class<?> clazz)
Return a list of all fields (whatever access status, and on whatever superclass they were defined) that can be found on this class.
|
static java.lang.reflect.Field |
getField(java.lang.Class<?> clazz,
java.lang.String attName)
Returns a Field object that reflects the specified declared
field of the class or interface represented by this Class object.
|
static java.lang.Object |
getFieldValue(java.lang.Object instance,
java.lang.reflect.Field field)
Returns the field value corresponding to the field argument
|
static java.lang.String |
getGetterMethodName(java.lang.reflect.Field field)
Return the name of the getter method for a field.
|
static java.lang.String |
getSetterMethodName(java.lang.reflect.Field field)
Return the name of the setter method for a field.
|
static java.util.Map |
introspectFields(java.lang.Class clazz)
Introspect a Class to retrieve public fields
|
static java.util.Map |
introspectFields(java.lang.Object obj)
Convenient method to introspect fields of an object
|
static java.util.Map |
introspectFields(java.lang.Object instance,
java.util.Map fields)
Introspect an Object by calling given fields
|
static java.lang.Object |
invokeMethod(java.lang.Object object,
java.lang.String methodName,
java.lang.Object... args)
Invokes the underlying method represented by the method name in parameter, on the specified object with the specified parameters.
|
static java.lang.Object |
invokeStaticMethod(java.lang.String className,
java.lang.String methodName,
java.lang.Object... args)
Invokes the underlying method represented by the method name in parameter, on the specified Class represented by the class name in
parameter with the specified parameters.
|
static void |
setFieldValue(java.lang.Object storable,
java.lang.reflect.Field field,
java.lang.Object fieldValue)
Set a field to a value
|
public static final java.lang.String REVISION
public static java.lang.String getGetterMethodName(java.lang.reflect.Field field)
int status; -> getStatus() boolean isEnabled -> isEnabled();
field
- the fieldpublic static java.lang.reflect.Field getField(java.lang.Class<?> clazz, java.lang.String attName)
clazz
- specifies the class or interfaceattName
- the name of the desired fieldpublic static java.lang.Object getFieldValue(java.lang.Object instance, java.lang.reflect.Field field)
instance
- - the instance containing the fieldfield
- - the requested fieldpublic static java.lang.Object fieldGetter(java.lang.Object instance, java.lang.reflect.Field field)
instance
- the objectfield
- the fieldpublic static java.lang.String getSetterMethodName(java.lang.reflect.Field field)
int status; -> setStatus()
field
- the fieldpublic static void setFieldValue(java.lang.Object storable, java.lang.reflect.Field field, java.lang.Object fieldValue)
storable
- - the instance containing the fieldfield
- - the field to setfieldValue
- - the new field valuepublic static void fieldSetter(java.lang.Object obj, java.lang.reflect.Field field, java.lang.Object fieldValue)
public static java.util.Map introspectFields(java.lang.Object obj)
obj
- the object to introspectpublic static java.util.Map introspectFields(java.lang.Class clazz)
clazz
- the class to introspectpublic static java.util.Map introspectFields(java.lang.Object instance, java.util.Map fields)
instance
- the instance to introspectfields
- a Map of FieldName / Field to callpublic static java.lang.reflect.Field[] getAllFields(java.lang.Class<?> clazz)
Class.getDeclaredFields()
which ignores and super-classes, and Class.getFields()
which ignored non-public
fields.clazz
- The class to introspectpublic static void copyDeclaredFields(java.lang.Object src, java.lang.Object dest)
src
- Object to copydest
- Object to setpublic static java.lang.Object invokeMethod(java.lang.Object object, java.lang.String methodName, java.lang.Object... args) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
MethodUtils.invokeMethod(Object, String, Object[])
.object
- The object the underlying method is invoked from.methodName
- The name of the method to invoke.args
- The arguments used for the method call.java.lang.NoSuchMethodException
- if there is no such accessible methodjava.lang.reflect.InvocationTargetException
- wraps an exception thrown by the method invokedjava.lang.IllegalAccessException
- if the requested method is not accessible via reflectionpublic static java.lang.Object invokeStaticMethod(java.lang.String className, java.lang.String methodName, java.lang.Object... args) throws java.lang.ClassNotFoundException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
MethodUtils.invokeStaticMethod(Class, String, Object[])
.className
- The name of the Class.methodName
- The name of the method to invoke.args
- The arguments used for the method call.java.lang.NoSuchMethodException
- if there is no such accessible methodjava.lang.ClassNotFoundException
- if there is no such accessible Class with the class name in parameter.java.lang.reflect.InvocationTargetException
- wraps an exception thrown by the method invokedjava.lang.IllegalAccessException
- if the requested method is not accessible via reflectionCopyright © 2001-2010 Jalios SA. All Rights Reserved.