|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.beanfabrics.util.ReflectionUtil
public class ReflectionUtil
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
|
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 |
---|
public ReflectionUtil()
Method Detail |
---|
public static java.util.List<java.lang.reflect.Field> getAllFields(java.lang.Class cls)
Class
and it's
superclasses.
public static java.util.List<java.lang.reflect.Field> getAllFields(java.lang.Class cls, java.lang.String fieldName, java.lang.Class fieldType)
Class
and it's
superclasses that have the given name and are assignable to the given
type.
cls
- the class that owns the returned fieldsfieldName
- name of the returned fields or null
for no
name filteringfieldType
- the generic type of the returned fields or
null
for no type filtering
public static java.util.List<java.lang.reflect.Field> getAllFields(java.lang.Class cls, java.lang.Class annoType)
public static java.util.List<java.lang.reflect.Member> getAllMembers(java.lang.Class cls)
Class
and it's
superclasses.
cls
- the class of which to search the memberspublic static java.util.List<java.lang.reflect.Method> getAllMethods(java.lang.Class cls)
Class
and it's
superclasses.
cls
- the class of which to search the methodspublic 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)
Class
and it's
superclasses that have the given name and have a return type assignable
to the given type.
cls
- the class that owns the returned methodsmethodName
- name of the returned methods or null
for
no name filteringparameterTypes
- the parameter types of the returned methods or
null
for no parameter types filteringreturnType
- the generic type of the returned methods or
null
for no type filtering
public static java.util.List<java.lang.reflect.Method> getAllMethods(java.lang.Class cls, java.lang.Class annotationType)
Class
and it's superclasses
which are annotated with the given annotationType
.
cls
- the class of which to search the methodsannotationType
- the annotation type which mark methods to be
contained in the resultpublic static java.util.List<java.lang.Class> getAllClasses(java.lang.Class baseClass)
List
of all superclasses and all interfaces of the
given baseclass, including the baseclass.
baseClass
-
public static void callAnnotatedMethods(java.lang.Object target, java.lang.Class annotationType)
target
that are annotated with the
specified annotationType
.
target
- the Object
to call the methods fromannotationType
- the type of the annotation marking the methods to
callpublic 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
java.lang.IllegalArgumentException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
java.lang.SecurityException
java.lang.NoSuchMethodException
public static void setFieldValue(java.lang.Object owner, java.lang.reflect.Field field, java.lang.Object value) throws java.lang.IllegalArgumentException, java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.IllegalAccessException
public static java.lang.Object getFieldValue(java.lang.Object owner, java.lang.reflect.Field f) throws java.lang.IllegalArgumentException, java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.IllegalAccessException
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
java.lang.IllegalArgumentException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
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
java.lang.IllegalArgumentException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
java.lang.SecurityException
java.lang.NoSuchMethodException
java.lang.InstantiationException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |