|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jalios.util.ReflectUtil
public class ReflectUtil
Field Summary | |
---|---|
static String |
REVISION
|
Constructor Summary | |
---|---|
ReflectUtil()
|
Method Summary | |
---|---|
static void |
copyDeclaredFields(Object src,
Object dest)
Copy all fields (whatever access status, and on whatever superclass they were defined) that can be found on this class. |
static Object |
fieldGetter(Object instance,
Field field)
Return the return value of a getter call from a given field on a given instance |
static void |
fieldSetter(Object obj,
Field field,
Object fieldValue)
|
static Field[] |
getAllFields(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 Field |
getField(Class<?> clazz,
String attName)
Returns a Field object that reflects the specified declared field of the class or interface represented by this Class object. |
static Object |
getFieldValue(Object instance,
Field field)
Returns the field value corresponding to the field argument |
static String |
getGetterMethodName(Field field)
Return the name of the getter method for a field. |
static String |
getSetterMethodName(Field field)
Return the name of the setter method for a field. |
static Map |
introspectFields(Class clazz)
Introspect a Class to retrieve public fields |
static Map |
introspectFields(Object obj)
Convenient method to introspect fields of an object |
static Map |
introspectFields(Object instance,
Map fields)
Introspect an Object by calling given fields |
static Object |
invokeMethod(Object object,
String methodName,
Object... args)
Invokes the underlying method represented by the method name in parameter, on the specified object with the specified parameters. |
static Object |
invokeStaticMethod(String className,
String methodName,
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(Object storable,
Field field,
Object fieldValue)
Set a field to a value |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String REVISION
Constructor Detail |
---|
public ReflectUtil()
Method Detail |
---|
public static String getGetterMethodName(Field field)
int status; -> getStatus() boolean isEnabled -> isEnabled();
field
- the fieldpublic static Field getField(Class<?> clazz, String attName)
clazz
- specifies the class or interfaceattName
- the name of the desired fieldpublic static Object getFieldValue(Object instance, Field field)
instance
- - the instance containing the fieldfield
- - the requested field
public static Object fieldGetter(Object instance, Field field)
instance
- field
- public static String getSetterMethodName(Field field)
int status; -> setStatus()
field
- the fieldpublic static void setFieldValue(Object storable, Field field, Object fieldValue)
storable
- - the instance containing the fieldfield
- - the field to setfieldValue
- - the new field valuepublic static void fieldSetter(Object obj, Field field, Object fieldValue)
public static Map introspectFields(Object obj)
obj
- the object to introspect
public static Map introspectFields(Class clazz)
clazz
- the class to introspect
public static Map introspectFields(Object instance, Map fields)
instance
- the instance to introspectfields
- a Map of FieldName / Field to call
public static Field[] getAllFields(Class<?> clazz)
Class.getDeclaredFields()
which ignores and super-classes, and Class.getFields()
which ignored non-public
fields.
clazz
- The class to introspect
public static void copyDeclaredFields(Object src, Object dest)
src
- Object to copydest
- Object to setpublic static Object invokeMethod(Object object, String methodName, Object... args) throws IllegalAccessException, InvocationTargetException, 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.
NoSuchMethodException
- if there is no such accessible method
InvocationTargetException
- wraps an exception thrown by the method invoked
IllegalAccessException
- if the requested method is not accessible via reflectionpublic static Object invokeStaticMethod(String className, String methodName, Object... args) throws ClassNotFoundException, IllegalAccessException, InvocationTargetException, NoSuchMethodException
MethodUtils.invokeStaticMethod(Class, String, Object[])
.
className
- The name of the Class.methodName
- The name of the method to invoke.returnClass
- The type of the returned object.args
- The arguments used for the method call.
NoSuchMethodException
- if there is no such accessible method
ClassNotFoundException
- if there is no such accessible Class with the class name in parameter.
InvocationTargetException
- wraps an exception thrown by the method invoked
IllegalAccessException
- if the requested method is not accessible via reflection
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |