com.jalios.util
Class ReflectUtil

java.lang.Object
  extended by com.jalios.util.ReflectUtil

public class ReflectUtil
extends Object


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

REVISION

public static final String REVISION
See Also:
Constant Field Values
Constructor Detail

ReflectUtil

public ReflectUtil()
Method Detail

getGetterMethodName

public static String getGetterMethodName(Field field)
Return the name of the getter method for a field. Field's name is supposed to be conformed with JavaBeans design patterns. Examples:
 int status; -> getStatus()
 boolean isEnabled -> isEnabled();
 

Parameters:
field - the field
Since:
jcms-4.2

getField

public 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.

Parameters:
clazz - specifies the class or interface
attName - the name of the desired field

getFieldValue

public static Object getFieldValue(Object instance,
                                   Field field)
Returns the field value corresponding to the field argument

Parameters:
instance - - the instance containing the field
field - - the requested field
Returns:
the value of the field

fieldGetter

public static Object fieldGetter(Object instance,
                                 Field field)
Return the return value of a getter call from a given field on a given instance

Parameters:
instance -
field -
Since:
jcms-4.2

getSetterMethodName

public static String getSetterMethodName(Field field)
Return the name of the setter method for a field. Field's name is supposed to be conformed with JavaBeans design patterns. Examples: Examples:
 int status; -> setStatus()
 

Parameters:
field - the field
Since:
jcms-4.2

setFieldValue

public static void setFieldValue(Object storable,
                                 Field field,
                                 Object fieldValue)
Set a field to a value

Parameters:
storable - - the instance containing the field
field - - the field to set
fieldValue - - the new field value

fieldSetter

public static void fieldSetter(Object obj,
                               Field field,
                               Object fieldValue)

introspectFields

public static Map introspectFields(Object obj)
Convenient method to introspect fields of an object

Parameters:
obj - the object to introspect
Returns:
a Map of FieldName / Value
Since:
jcms-4.2

introspectFields

public static Map introspectFields(Class clazz)
Introspect a Class to retrieve public fields

Parameters:
clazz - the class to introspect
Returns:
a Map of FieldName / Field
Since:
jcms-4.2

introspectFields

public static Map introspectFields(Object instance,
                                   Map fields)
Introspect an Object by calling given fields

Parameters:
instance - the instance to introspect
fields - a Map of FieldName / Field to call
Returns:
a Map of FieldName / Value
Since:
jcms-4.2

getAllFields

public 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. This is like a union of Class.getDeclaredFields() which ignores and super-classes, and Class.getFields() which ignored non-public fields.

Parameters:
clazz - The class to introspect
Returns:
The complete list of fields

copyDeclaredFields

public 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.

Parameters:
src - Object to copy
dest - Object to set

invokeMethod

public static Object invokeMethod(Object object,
                                  String methodName,
                                  Object... args)
                           throws IllegalAccessException,
                                  InvocationTargetException,
                                  NoSuchMethodException
Invokes the underlying method represented by the method name in parameter, on the specified object with the specified parameters.

This is a convenient wrapper for MethodUtils.invokeMethod(Object, String, Object[]).

Parameters:
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.
Returns:
The value returned by the invoked method.
Throws:
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 reflection

invokeStaticMethod

public static Object invokeStaticMethod(String className,
                                        String methodName,
                                        Object... args)
                                 throws ClassNotFoundException,
                                        IllegalAccessException,
                                        InvocationTargetException,
                                        NoSuchMethodException
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.

This is a convenient wrapper for MethodUtils.invokeStaticMethod(Class, String, Object[]).

Parameters:
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.
Returns:
the result of dispatching the method represented by this object on obj with parameters params.
Throws:
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


Copyright © 2001-2010 Jalios SA. All Rights Reserved.