org.beanfabrics.util
Class ReflectionUtil

java.lang.Object
  extended by org.beanfabrics.util.ReflectionUtil

public class ReflectionUtil
extends java.lang.Object

The ReflectionUtil is a utility class for doing reflection.


Nested Class Summary
static interface ReflectionUtil.FieldFilter
           
static interface ReflectionUtil.MethodFilter
           
 
Constructor Summary
ReflectionUtil()
           
 
Method Summary
static void callAnnotatedMethods(java.lang.Object target, java.lang.Class annotationType)
          Calls all methods of target that are annotated with the specified annotationType.
static java.util.List<java.lang.Class> getAllClasses(java.lang.Class baseClass)
          Returns a List of all superclasses and all interfaces of the given baseclass, including the baseclass.
static java.util.List<java.lang.reflect.Field> getAllFields(java.lang.Class cls)
          Returns all declared fields of the given Class and it's superclasses.
static java.util.List<java.lang.reflect.Field> getAllFields(java.lang.Class cls, java.lang.Class annoType)
           
static java.util.List<java.lang.reflect.Field> getAllFields(java.lang.Class cls, java.lang.String fieldName, java.lang.Class fieldType)
          Returns all declared fields of the given Class and it's superclasses that have the given name and are assignable to the given type.
static java.util.List<java.lang.reflect.Member> getAllMembers(java.lang.Class cls)
          Returns all declared members of the given Class and it's superclasses.
static java.util.List<java.lang.reflect.Method> getAllMethods(java.lang.Class cls)
          Returns all declared methods of the given Class and it's superclasses.
static java.util.List<java.lang.reflect.Method> getAllMethods(java.lang.Class cls, java.lang.Class annotationType)
          Returns all Methods of the given Class and it's superclasses which are annotated with the given annotationType.
static java.util.Collection<java.lang.reflect.Method> getAllMethods(java.lang.Class cls, java.lang.String methodName, java.lang.Class[] parameterTypes, java.lang.Class returnType)
          Returns all declared methods of the given Class and it's superclasses that have the given name and have a return type assignable to the given type.
static java.lang.Object getFieldValue(java.lang.Object owner, java.lang.reflect.Field f)
           
static java.lang.Object invokeMethod(java.lang.Object owner, java.lang.reflect.Method m, java.lang.Object... args)
           
static
<T> T
newInstance(java.lang.Class<T> cls)
           
static void setFieldValue(java.lang.Object owner, java.lang.reflect.Field field, java.lang.Object value)
           
static void setProperties(java.lang.Object bean, java.util.Properties props)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectionUtil

public ReflectionUtil()
Method Detail

getAllFields

public static java.util.List<java.lang.reflect.Field> getAllFields(java.lang.Class cls)
Returns all declared fields of the given Class and it's superclasses.


getAllFields

public static java.util.List<java.lang.reflect.Field> getAllFields(java.lang.Class cls,
                                                                   java.lang.String fieldName,
                                                                   java.lang.Class fieldType)
Returns all declared fields of the given Class and it's superclasses that have the given name and are assignable to the given type.

Parameters:
cls - the class that owns the returned fields
fieldName - name of the returned fields or null for no name filtering
fieldType - the generic type of the returned fields or null for no type filtering
Returns:
all declared fields that match the given filter arguments

getAllFields

public static java.util.List<java.lang.reflect.Field> getAllFields(java.lang.Class cls,
                                                                   java.lang.Class annoType)

getAllMembers

public static java.util.List<java.lang.reflect.Member> getAllMembers(java.lang.Class cls)
Returns all declared members of the given Class and it's superclasses.

Parameters:
cls - the class of which to search the members

getAllMethods

public static java.util.List<java.lang.reflect.Method> getAllMethods(java.lang.Class cls)
Returns all declared methods of the given Class and it's superclasses.

Parameters:
cls - the class of which to search the methods

getAllMethods

public static java.util.Collection<java.lang.reflect.Method> getAllMethods(java.lang.Class cls,
                                                                           java.lang.String methodName,
                                                                           java.lang.Class[] parameterTypes,
                                                                           java.lang.Class returnType)
Returns all declared methods of the given Class and it's superclasses that have the given name and have a return type assignable to the given type.

Parameters:
cls - the class that owns the returned methods
methodName - name of the returned methods or null for no name filtering
parameterTypes - the parameter types of the returned methods or null for no parameter types filtering
returnType - the generic type of the returned methods or null for no type filtering
Returns:
all declared methods that match the given filter arguments

getAllMethods

public static java.util.List<java.lang.reflect.Method> getAllMethods(java.lang.Class cls,
                                                                     java.lang.Class annotationType)
Returns all Methods of the given Class and it's superclasses which are annotated with the given annotationType.

Parameters:
cls - the class of which to search the methods
annotationType - the annotation type which mark methods to be contained in the result

getAllClasses

public static java.util.List<java.lang.Class> getAllClasses(java.lang.Class baseClass)
Returns a List of all superclasses and all interfaces of the given baseclass, including the baseclass.

Parameters:
baseClass -
Returns:
List

callAnnotatedMethods

public static void callAnnotatedMethods(java.lang.Object target,
                                        java.lang.Class annotationType)
Calls all methods of target that are annotated with the specified annotationType.

Parameters:
target - the Object to call the methods from
annotationType - the type of the annotation marking the methods to call

setProperties

public static void setProperties(java.lang.Object bean,
                                 java.util.Properties props)
                          throws java.lang.IllegalArgumentException,
                                 java.lang.IllegalAccessException,
                                 java.lang.reflect.InvocationTargetException,
                                 java.lang.SecurityException,
                                 java.lang.NoSuchMethodException
Throws:
java.lang.IllegalArgumentException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
java.lang.SecurityException
java.lang.NoSuchMethodException

setFieldValue

public static void setFieldValue(java.lang.Object owner,
                                 java.lang.reflect.Field field,
                                 java.lang.Object value)
                          throws java.lang.IllegalArgumentException,
                                 java.lang.IllegalAccessException
Throws:
java.lang.IllegalArgumentException
java.lang.IllegalAccessException

getFieldValue

public static java.lang.Object getFieldValue(java.lang.Object owner,
                                             java.lang.reflect.Field f)
                                      throws java.lang.IllegalArgumentException,
                                             java.lang.IllegalAccessException
Throws:
java.lang.IllegalArgumentException
java.lang.IllegalAccessException

invokeMethod

public static java.lang.Object invokeMethod(java.lang.Object owner,
                                            java.lang.reflect.Method m,
                                            java.lang.Object... args)
                                     throws java.lang.IllegalArgumentException,
                                            java.lang.IllegalAccessException,
                                            java.lang.reflect.InvocationTargetException
Throws:
java.lang.IllegalArgumentException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

newInstance

public static <T> T newInstance(java.lang.Class<T> cls)
                     throws java.lang.IllegalArgumentException,
                            java.lang.IllegalAccessException,
                            java.lang.reflect.InvocationTargetException,
                            java.lang.SecurityException,
                            java.lang.NoSuchMethodException,
                            java.lang.InstantiationException
Throws:
java.lang.IllegalArgumentException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
java.lang.SecurityException
java.lang.NoSuchMethodException
java.lang.InstantiationException