com.softwareag.centrasite.appl.framework.util
Class Reflection

java.lang.Object
  extended by com.softwareag.centrasite.appl.framework.util.Reflection

public final class Reflection
extends java.lang.Object

A utility class for working with reflection.


Method Summary
static void addOrRemoveProperty(java.lang.Object pBean, java.lang.reflect.Method pMethod, java.lang.Object pValue)
          Method for adding or removing a property of a bean.
static
<C> java.lang.Class<C>
cast(java.lang.Class<?> pClass)
          Casts the given class into a matching class.
static java.lang.Object evaluate(java.lang.String pProperty, java.lang.Object pObject)
          This method evaluates a property of a given object.
static java.lang.reflect.Method getAdder(java.lang.Object pBean, java.lang.String pProperty)
          Returns the add method for a given property and bean.
static
<T extends java.lang.annotation.Annotation>
java.util.Collection<java.lang.reflect.Method>
getAnnotatedMethods(java.lang.Class<?> pClass, java.lang.Class<T> annotationType)
          Retrieves methods with given annotation type by traversing over the given class and all the its interfaces.
static java.lang.reflect.Field getField(java.lang.Class<?> pClass, java.lang.String pFieldName)
          Searches for a field named pFieldName in the given class, or its superclass.
static java.lang.reflect.Method getGetter(java.lang.Object pBean, java.lang.String pProperty)
          Returns a getter for the given property.
static java.lang.reflect.Method getGetter(java.lang.String pProperty, java.lang.Class<?> cl)
          Returns a getter for the given property.
static java.util.List<java.lang.reflect.Method> getGetters(java.lang.Class<?> beanType)
          Returns the getter methods for the given bean type.
static java.util.List<java.lang.reflect.Method> getGetters(java.lang.Object pBean)
          Returns the given objects getters.
static java.lang.Object getProperty(java.lang.Object pBean, java.lang.reflect.Method pMethod)
          Method for getting a property of a bean.
static java.lang.Object getProperty(java.lang.Object pBean, java.lang.String propertyName)
          Method for getting a property of a bean.
static java.lang.String getPropertyName(java.lang.reflect.Method pMethod)
          Returns the property name represented by the given method.
static java.lang.reflect.Method getRemover(java.lang.Object pBean, java.lang.String pProperty)
          Returns the remove method for a given property and bean.
static java.lang.reflect.Method getSetter(java.lang.reflect.Method pGetter, java.lang.Class<?> pClass)
          Returns a setter for the given getter property.
static java.lang.reflect.Method getSetter(java.lang.Object pBean, java.lang.reflect.Method pGetter)
          Returns a setter for the given getter property.
static java.lang.reflect.Method getSetter(java.lang.Object pBean, java.lang.String pProperty)
          Returns the setter method for a give property and bean.
static java.util.List<java.lang.reflect.Method> getSetters(java.lang.Object pBean)
          Returns the given objects setters.
static boolean isGetter(java.lang.reflect.Method method)
          Determines if the given method is a getter method based on its name.
static boolean isSetter(java.lang.reflect.Method method)
          Determines if the given method is a setter method based on its name.
static
<T> java.lang.Class<T>
loadClass(java.lang.ClassLoader pClassLoader, java.lang.String pClassName)
          Loads the class named pClassName via the given pClassLoader.
static
<T> T
newInstance(java.lang.Class<T> pClass)
          Creates a new instance of the given class.
static java.lang.Object newInstance(java.lang.reflect.Constructor<?> pConstructor, java.lang.Object... pParameters)
          Creates a new instance of the given class.
static void setFieldValue(java.lang.Class<?> pClass, java.lang.String pFieldName, java.lang.Object pInstance, java.lang.Object pValue)
          Searches for a field named pFieldName in the given class, or its superclass, and sets the fields value.
static void setFieldValue(java.lang.reflect.Field pField, java.lang.Object pInstance, java.lang.Object pValue)
          Sets the given fields value on the given instance.
static void setProperty(java.lang.Object pBean, java.lang.reflect.Method pSetter, java.lang.Object pValue)
          Method for setting a bean property.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getGetter

public static java.lang.reflect.Method getGetter(java.lang.Object pBean,
                                                 java.lang.String pProperty)
                                          throws CSAppFrameworkException
Returns a getter for the given property.

Throws:
CSAppFrameworkException

getGetter

public static java.lang.reflect.Method getGetter(java.lang.String pProperty,
                                                 java.lang.Class<?> cl)
                                          throws CSAppFrameworkException
Returns a getter for the given property.

Throws:
CSAppFrameworkException

getSetter

public static java.lang.reflect.Method getSetter(java.lang.Object pBean,
                                                 java.lang.String pProperty)
Returns the setter method for a give property and bean.

Parameters:
pBean -
pProperty -
Returns:
Method
Throws:
CSAppFrameworkException

getSetter

public static java.lang.reflect.Method getSetter(java.lang.Object pBean,
                                                 java.lang.reflect.Method pGetter)
                                          throws CSAppFrameworkException
Returns a setter for the given getter property.

Throws:
CSAppFrameworkException

getSetter

public static java.lang.reflect.Method getSetter(java.lang.reflect.Method pGetter,
                                                 java.lang.Class<?> pClass)
                                          throws CSAppFrameworkException
Returns a setter for the given getter property.

Throws:
CSAppFrameworkException

getPropertyName

public static java.lang.String getPropertyName(java.lang.reflect.Method pMethod)
                                        throws CSAppFrameworkException
Returns the property name represented by the given method.

Throws:
CSAppFrameworkException

getGetters

public static java.util.List<java.lang.reflect.Method> getGetters(java.lang.Class<?> beanType)
Returns the getter methods for the given bean type.


getGetters

public static java.util.List<java.lang.reflect.Method> getGetters(java.lang.Object pBean)
Returns the given objects getters.


getSetters

public static java.util.List<java.lang.reflect.Method> getSetters(java.lang.Object pBean)
Returns the given objects setters.


getProperty

public static java.lang.Object getProperty(java.lang.Object pBean,
                                           java.lang.reflect.Method pMethod)
Method for getting a property of a bean.


getProperty

public static java.lang.Object getProperty(java.lang.Object pBean,
                                           java.lang.String propertyName)
                                    throws CSAppFrameworkException
Method for getting a property of a bean.

Throws:
CSAppFrameworkException

setProperty

public static void setProperty(java.lang.Object pBean,
                               java.lang.reflect.Method pSetter,
                               java.lang.Object pValue)
Method for setting a bean property.

Parameters:
pBean - The bean, on which the property is being set.
pSetter - The setter to invoke for setting the property.
pValue - The property value to set.

newInstance

public static <T> T newInstance(java.lang.Class<T> pClass)
                     throws java.lang.RuntimeException
Creates a new instance of the given class.

Throws:
java.lang.RuntimeException

newInstance

public static java.lang.Object newInstance(java.lang.reflect.Constructor<?> pConstructor,
                                           java.lang.Object... pParameters)
                                    throws java.lang.RuntimeException
Creates a new instance of the given class.

Throws:
java.lang.RuntimeException

getField

public static java.lang.reflect.Field getField(java.lang.Class<?> pClass,
                                               java.lang.String pFieldName)
                                        throws java.lang.RuntimeException
Searches for a field named pFieldName in the given class, or its superclass.

Throws:
java.lang.RuntimeException

setFieldValue

public static void setFieldValue(java.lang.reflect.Field pField,
                                 java.lang.Object pInstance,
                                 java.lang.Object pValue)
                          throws java.lang.RuntimeException
Sets the given fields value on the given instance.

Throws:
java.lang.RuntimeException

setFieldValue

public static void setFieldValue(java.lang.Class<?> pClass,
                                 java.lang.String pFieldName,
                                 java.lang.Object pInstance,
                                 java.lang.Object pValue)
                          throws java.lang.RuntimeException
Searches for a field named pFieldName in the given class, or its superclass, and sets the fields value.

Throws:
java.lang.RuntimeException

loadClass

public static <T> java.lang.Class<T> loadClass(java.lang.ClassLoader pClassLoader,
                                               java.lang.String pClassName)
                                    throws CSAppFrameworkException
Loads the class named pClassName via the given pClassLoader. The class cannot be a primitive class.

Parameters:
pClassLoader - The class loader to use.
pClassName - The class name.
Throws:
CSAppFrameworkException

cast

public static <C> java.lang.Class<C> cast(java.lang.Class<?> pClass)
Casts the given class into a matching class.


getAnnotatedMethods

public static <T extends java.lang.annotation.Annotation> java.util.Collection<java.lang.reflect.Method> getAnnotatedMethods(java.lang.Class<?> pClass,
                                                                                                                             java.lang.Class<T> annotationType)
Retrieves methods with given annotation type by traversing over the given class and all the its interfaces.


evaluate

public static java.lang.Object evaluate(java.lang.String pProperty,
                                        java.lang.Object pObject)
                                 throws CSAppFrameworkException
This method evaluates a property of a given object.

Parameters:
pProperty - The property to evaluate. This may be a combined property in the style "a.b[1].c", in which case it is evaluated as getA().getB()[1].getC().
pObject - The object, on which the property is being evaluated.
Returns:
The property value.
Throws:
CSAppFrameworkException

isSetter

public static boolean isSetter(java.lang.reflect.Method method)
Determines if the given method is a setter method based on its name.

Parameters:
method -

isGetter

public static boolean isGetter(java.lang.reflect.Method method)
Determines if the given method is a getter method based on its name.

Parameters:
method -

getAdder

public static java.lang.reflect.Method getAdder(java.lang.Object pBean,
                                                java.lang.String pProperty)
                                         throws CSAppFrameworkException
Returns the add method for a given property and bean.

Parameters:
pBean -
pProperty -
Returns:
Method
Throws:
CSAppFrameworkException

getRemover

public static java.lang.reflect.Method getRemover(java.lang.Object pBean,
                                                  java.lang.String pProperty)
                                           throws CSAppFrameworkException
Returns the remove method for a given property and bean.

Parameters:
pBean -
pProperty -
Returns:
Method
Throws:
CSAppFrameworkException

addOrRemoveProperty

public static void addOrRemoveProperty(java.lang.Object pBean,
                                       java.lang.reflect.Method pMethod,
                                       java.lang.Object pValue)
Method for adding or removing a property of a bean.