public final class Reflection
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
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> |
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)
Returns the 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.
|
public static java.lang.reflect.Method getGetter(java.lang.Object pBean, java.lang.String pProperty) throws CSAppFrameworkException
pBean
- the class name.pProperty
- the property name.CSAppFrameworkException
- if an internal error occurs.public static java.lang.reflect.Method getGetter(java.lang.String pProperty, java.lang.Class<?> cl) throws CSAppFrameworkException
pProperty
- the property name.cl
- the class name.CSAppFrameworkException
- if an internal error occurs.public static java.lang.reflect.Method getSetter(java.lang.Object pBean, java.lang.String pProperty)
pBean
- the class name.pProperty
- the property name.Method
public static java.lang.reflect.Method getSetter(java.lang.Object pBean, java.lang.reflect.Method pGetter) throws CSAppFrameworkException
pBean
- the class name.pGetter
- the getter property.CSAppFrameworkException
- if an internal error occurs.public static java.lang.reflect.Method getSetter(java.lang.reflect.Method pGetter, java.lang.Class<?> pClass) throws CSAppFrameworkException
pGetter
- the getter property.pClass
- the class name.CSAppFrameworkException
- if an internal error occurs.public static java.lang.String getPropertyName(java.lang.reflect.Method pMethod) throws CSAppFrameworkException
pMethod
- the method object.CSAppFrameworkException
- if an internal error occurs.public static java.util.List<java.lang.reflect.Method> getGetters(java.lang.Class<?> beanType)
beanType
- the bean type.public static java.util.List<java.lang.reflect.Method> getGetters(java.lang.Object pBean)
pBean
- the class object.public static java.util.List<java.lang.reflect.Method> getSetters(java.lang.Object pBean)
pBean
- the class object.public static java.lang.Object getProperty(java.lang.Object pBean, java.lang.reflect.Method pMethod)
pBean
- the class object.pMethod
- the method object.public static java.lang.Object getProperty(java.lang.Object pBean, java.lang.String propertyName) throws CSAppFrameworkException
pBean
- the class object.propertyName
- the property name.CSAppFrameworkException
- if an internal error occurs.public static void setProperty(java.lang.Object pBean, java.lang.reflect.Method pSetter, java.lang.Object pValue)
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.public static <T> T newInstance(java.lang.Class<T> pClass) throws java.lang.RuntimeException
T
- Type class extending Object
pClass
- the class object.java.lang.RuntimeException
- if an internal error occurs.public static java.lang.Object newInstance(java.lang.reflect.Constructor<?> pConstructor, java.lang.Object... pParameters) throws java.lang.RuntimeException
pConstructor
- the constructor object of a class.pParameters
- the parameters of a method.java.lang.RuntimeException
- if an internal error occurs.public static java.lang.reflect.Field getField(java.lang.Class<?> pClass, java.lang.String pFieldName) throws java.lang.RuntimeException
pFieldName
in the given class, or its
superclass.pClass
- the class object.pFieldName
- the filed name.pFieldName
in the given class.java.lang.RuntimeException
- if an internal error occurs.public static void setFieldValue(java.lang.reflect.Field pField, java.lang.Object pInstance, java.lang.Object pValue) throws java.lang.RuntimeException
pField
- the java field object.pInstance
- the current instance.pValue
- the value of the instance.java.lang.RuntimeException
- if an internal error occurs.public static void setFieldValue(java.lang.Class<?> pClass, java.lang.String pFieldName, java.lang.Object pInstance, java.lang.Object pValue) throws java.lang.RuntimeException
pFieldName
in the given class, or its
superclass, and sets the fields value.pClass
- the class name.pFieldName
- the field name.pInstance
- the current instance.pValue
- the value of the instance.java.lang.RuntimeException
- if an internal error occurs.public static <T> java.lang.Class<T> loadClass(java.lang.ClassLoader pClassLoader, java.lang.String pClassName) throws CSAppFrameworkException
pClassName
via the given pClassLoader
. The class cannot be a primitive class.T
- Type class extending Object
pClassLoader
- The class loader to use.pClassName
- The class name.CSAppFrameworkException
- if an internal error occurs.public static <C> java.lang.Class<C> cast(java.lang.Class<?> pClass)
C
- Type class extending Object
pClass
- the class name.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)
T
- Type class extending Annotation
pClass
- the class object.annotationType
- the annotation type.public static java.lang.Object evaluate(java.lang.String pProperty, java.lang.Object pObject) throws CSAppFrameworkException
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.CSAppFrameworkException
- if an internal error occurs.public static boolean isSetter(java.lang.reflect.Method method)
method
- the method name.public static boolean isGetter(java.lang.reflect.Method method)
method
- the method object.public static java.lang.reflect.Method getAdder(java.lang.Object pBean, java.lang.String pProperty) throws CSAppFrameworkException
pBean
- the class name.pProperty
- the property name.Method
CSAppFrameworkException
- if an internal; error occurs.public static java.lang.reflect.Method getRemover(java.lang.Object pBean, java.lang.String pProperty) throws CSAppFrameworkException
pBean
- the class name.pProperty
- the property name.Method
CSAppFrameworkException
- if an internal error occurs.public static void addOrRemoveProperty(java.lang.Object pBean, java.lang.reflect.Method pMethod, java.lang.Object pValue)
pBean
- the class object.pMethod
- the method object.pValue
- the value of the instance.