| java.lang.Object org.springframework.util.ReflectionUtils
ReflectionUtils | abstract public class ReflectionUtils (Code) | | Simple utility class for handling reflection exceptions.
Only intended for internal use.
author: Juergen Hoeller author: Rob Harrop author: Rod Johnson author: Costin Leau since: 1.2.2 |
Inner Class :public static interface MethodCallback | |
Inner Class :public static interface MethodFilter | |
Inner Class :public static interface FieldCallback | |
Inner Class :public static interface FieldFilter | |
Field Summary | |
public static FieldFilter | COPYABLE_FIELDS Pre-built FieldFilter that matches all non-static, non-final fields. |
Method Summary | |
public static boolean | declaresException(Method method, Class exceptionType) Determine whether the given method explicitly declares the given exception
or one of its superclasses, which means that an exception of that type
can be propagated as-is within a reflective invocation. | public static void | doWithFields(Class targetClass, FieldCallback fc) Invoke the given callback on all fields in the target class,
going up the class hierarchy to get all declared fields. | public static void | doWithFields(Class targetClass, FieldCallback fc, FieldFilter ff) Invoke the given callback on all fields in the target class,
going up the class hierarchy to get all declared fields. | public static void | doWithMethods(Class targetClass, MethodCallback mc) Perform the given callback operation on all matching methods of the
given class and superclasses. | public static void | doWithMethods(Class targetClass, MethodCallback mc, MethodFilter mf) Perform the given callback operation on all matching methods of the
given class and superclasses. | public static Method | findMethod(Class clazz, String name, Class[] paramTypes) Attempt to find a
Method on the supplied type with the supplied name
and parameter types. | public static Method[] | getAllDeclaredMethods(Class leafClass) Get all declared methods on the leaf class and all superclasses. | public static void | handleInvocationTargetException(InvocationTargetException ex) Handle the given invocation target exception. | public static void | handleReflectionException(Exception ex) Handle the given reflection exception. | public static Object | invokeMethod(Method method, Object target) Invoke the specified
Method against the supplied target object
with no arguments. | public static Object | invokeMethod(Method method, Object target, Object[] args) Invoke the specified
Method against the supplied target object
with the supplied arguments. | public static boolean | isPublicStaticFinal(Field field) Determine whether the given field is a "public static final" constant. | public static void | makeAccessible(Field field) Make the given field accessible, explicitly setting it accessible if necessary. | public 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. |
COPYABLE_FIELDS | public static FieldFilter COPYABLE_FIELDS(Code) | | Pre-built FieldFilter that matches all non-static, non-final fields.
|
declaresException | public static boolean declaresException(Method method, Class exceptionType)(Code) | | Determine whether the given method explicitly declares the given exception
or one of its superclasses, which means that an exception of that type
can be propagated as-is within a reflective invocation.
Parameters: method - the declaring method Parameters: exceptionType - the exception to throw true if the exception can be thrown as-is;false if it needs to be wrapped |
doWithFields | public static void doWithFields(Class targetClass, FieldCallback fc) throws IllegalArgumentException(Code) | | Invoke the given callback on all fields in the target class,
going up the class hierarchy to get all declared fields.
Parameters: targetClass - the target class to analyze Parameters: fc - the callback to invoke for each field |
doWithFields | public static void doWithFields(Class targetClass, FieldCallback fc, FieldFilter ff) throws IllegalArgumentException(Code) | | Invoke the given callback on all fields in the target class,
going up the class hierarchy to get all declared fields.
Parameters: targetClass - the target class to analyze Parameters: fc - the callback to invoke for each field Parameters: ff - the filter that determines the fields to apply the callback to |
doWithMethods | public static void doWithMethods(Class targetClass, MethodCallback mc) throws IllegalArgumentException(Code) | | Perform the given callback operation on all matching methods of the
given class and superclasses.
The same named method occurring on subclass and superclass will
appear twice, unless excluded by a
MethodFilter .
Parameters: targetClass - class to start looking at Parameters: mc - the callback to invoke for each method See Also: ReflectionUtils.doWithMethods(Class,MethodCallback,MethodFilter) |
doWithMethods | public static void doWithMethods(Class targetClass, MethodCallback mc, MethodFilter mf) throws IllegalArgumentException(Code) | | Perform the given callback operation on all matching methods of the
given class and superclasses.
The same named method occurring on subclass and superclass will
appear twice, unless excluded by the specified
MethodFilter .
Parameters: targetClass - class to start looking at Parameters: mc - the callback to invoke for each method Parameters: mf - the filter that determines the methods to apply the callback to |
findMethod | public static Method findMethod(Class clazz, String name, Class[] paramTypes)(Code) | | Attempt to find a
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.
Parameters: clazz - the class to introspect Parameters: name - the name of the method Parameters: paramTypes - the parameter types of the method the Method object, or null if none found |
getAllDeclaredMethods | public static Method[] getAllDeclaredMethods(Class leafClass) throws IllegalArgumentException(Code) | | Get all declared methods on the leaf class and all superclasses.
Leaf class methods are included first.
|
handleInvocationTargetException | public static void handleInvocationTargetException(InvocationTargetException ex)(Code) | | Handle the given invocation target exception. Should only be called if
no checked exception is expected to be thrown by the target method.
Throws the underlying RuntimeException or Error in case of such
a root cause. Throws an IllegalStateException else.
Parameters: ex - the invocation target exception to handle |
handleReflectionException | public static void handleReflectionException(Exception ex)(Code) | | Handle the given reflection exception. Should only be called if
no checked exception is expected to be thrown by the target method.
Throws the underlying RuntimeException or Error in case of an
InvocationTargetException with such a root cause. Throws an
IllegalStateException with an appropriate message else.
Parameters: ex - the reflection exception to handle |
isPublicStaticFinal | public static boolean isPublicStaticFinal(Field field)(Code) | | Determine whether the given field is a "public static final" constant.
Parameters: field - the field to check |
makeAccessible | public static void makeAccessible(Field field)(Code) | | Make the given field accessible, explicitly setting it accessible if necessary.
The setAccessible(true) method is only called when actually necessary,
to avoid unnecessary conflicts with a JVM SecurityManager (if active).
Parameters: field - the field to make accessible See Also: java.lang.reflect.Field.setAccessible |
shallowCopyFieldState | public static void shallowCopyFieldState(Object src, Object dest) throws IllegalArgumentException(Code) | | Given the source object and the destination, which must be the same class
or a subclass, copy all fields, including inherited fields. Designed to
work on objects with public no-arg constructors.
throws: IllegalArgumentException - if the arguments are incompatible |
|
|