|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.util.ReflectionUtils
public abstract class ReflectionUtils
Simple utility class for handling reflection exceptions. Only intended for internal use.
Nested Class Summary | |
---|---|
static interface |
ReflectionUtils.FieldCallback
Callback interface invoked on each field in the hierarchy. |
static interface |
ReflectionUtils.FieldFilter
Callback optionally used to filter fields to be operated on by a field callback. |
static interface |
ReflectionUtils.MethodCallback
Action to take on each method. |
static interface |
ReflectionUtils.MethodFilter
Callback optionally used to method fields to be operated on by a method callback. |
Field Summary | |
---|---|
static ReflectionUtils.FieldFilter |
COPYABLE_FIELDS
Pre-built FieldFilter that matches all non-static, non-final fields. |
Constructor Summary | |
---|---|
ReflectionUtils()
|
Method Summary | |
---|---|
static void |
doWithFields(Class targetClass,
ReflectionUtils.FieldCallback fc)
Invoke the given callback on all private fields in the target class, going up the class hierarchy to get all declared fields. |
static void |
doWithFields(Class targetClass,
ReflectionUtils.FieldCallback fc,
ReflectionUtils.FieldFilter ff)
Invoke the given callback on all private fields in the target class, going up the class hierarchy to get all declared fields. |
static void |
doWithMethods(Class targetClass,
ReflectionUtils.MethodCallback mc)
Perform the given callback operation on all matching methods of the given class and superclasses. |
static void |
doWithMethods(Class targetClass,
ReflectionUtils.MethodCallback mc,
ReflectionUtils.MethodFilter mf)
Perform the given callback operation on all matching methods of the given class and superclasses. |
static Method |
findMethod(Class type,
String name,
Class[] paramTypes)
Attempt to find a Method on the supplied type with the supplied name
and parameter types. |
static Method[] |
getAllDeclaredMethods(Class leafClass)
Get all declared methods on the leaf class and all superclasses. |
static void |
handleInvocationTargetException(InvocationTargetException ex)
Handle the given invocation target exception. |
static void |
handleReflectionException(Exception ex)
Handle the given reflection exception. |
static Object |
invokeMethod(Method method,
Object target)
Invoke the specified Method against the supplied target object
with no arguments. |
static Object |
invokeMethod(Method method,
Object target,
Object[] args)
Invoke the specified Method against the supplied target object
with the supplied arguments. |
static boolean |
isPublicStaticFinal(Field field)
Determine whether the given field is a "public static final" constant. |
static void |
makeAccessible(Field field)
Make the given field accessible, explicitly setting it accessible if necessary. |
static void |
shallowCopyFieldState(Object src,
Object dest)
Given the source object and the destination, which must be the same class or a subclass, copy all fields, including inherited fields. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static ReflectionUtils.FieldFilter COPYABLE_FIELDS
Constructor Detail |
---|
public ReflectionUtils()
Method Detail |
---|
public static void handleReflectionException(Exception ex)
Throws the underlying RuntimeException or Error in case of an InvocationTargetException with such a root cause. Throws an IllegalStateException with an appropriate message else.
ex
- the reflection exception to handlepublic static void handleInvocationTargetException(InvocationTargetException ex)
Throws the underlying RuntimeException or Error in case of such a root cause. Throws an IllegalStateException else.
ex
- the invocation target exception to handlepublic static Method findMethod(Class type, String name, Class[] paramTypes)
Method
on the supplied type with the supplied name
and parameter types. Searches all superclasses up to Object
.
Returns null
if no Method
can be found.
public static Object invokeMethod(Method method, Object target)
Method
against the supplied target object
with no arguments. The target object can be null
when
invoking a static Method
.
Thrown exceptions are handled via a call to handleReflectionException(java.lang.Exception)
.
public static Object invokeMethod(Method method, Object target, Object[] args)
Method
against the supplied target object
with the supplied arguments. The target object can be null
when invoking a static Method
.
Thrown exceptions are handled via a call to handleReflectionException(java.lang.Exception)
.
public static boolean isPublicStaticFinal(Field field)
field
- the field to checkpublic static void makeAccessible(Field field)
setAccessible(true)
method is only called when actually necessary,
to avoid unnecessary conflicts with a JVM SecurityManager (if active).
field
- the field to make accessibleAccessibleObject.setAccessible(java.lang.reflect.AccessibleObject[], boolean)
public static void doWithMethods(Class targetClass, ReflectionUtils.MethodCallback mc) throws IllegalArgumentException
The same named method occurring on subclass and superclass will
appear twice, unless excluded by a ReflectionUtils.MethodFilter
.
targetClass
- class to start looking atmc
- the callback to invoke for each method
IllegalArgumentException
doWithMethods(Class, MethodCallback, MethodFilter)
public static void doWithMethods(Class targetClass, ReflectionUtils.MethodCallback mc, ReflectionUtils.MethodFilter mf) throws IllegalArgumentException
The same named method occurring on subclass and superclass will
appear twice, unless excluded by the specified ReflectionUtils.MethodFilter
.
targetClass
- class to start looking atmc
- the callback to invoke for each methodmf
- the filter that determines the methods to apply the callback to
IllegalArgumentException
public static Method[] getAllDeclaredMethods(Class leafClass) throws IllegalArgumentException
IllegalArgumentException
public static void doWithFields(Class targetClass, ReflectionUtils.FieldCallback fc) throws IllegalArgumentException
targetClass
- the target class to analyzefc
- the callback to invoke for each field
IllegalArgumentException
public static void doWithFields(Class targetClass, ReflectionUtils.FieldCallback fc, ReflectionUtils.FieldFilter ff) throws IllegalArgumentException
targetClass
- the target class to analyzefc
- the callback to invoke for each fieldff
- the filter that determines the fields to apply the callback to
IllegalArgumentException
public static void shallowCopyFieldState(Object src, Object dest) throws IllegalArgumentException
IllegalArgumentException
- if the arguments are incompatible
|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |