Package org.apache.camel.util
Class ReflectionHelper
java.lang.Object
org.apache.camel.util.ReflectionHelper
Helper for working with reflection on classes.
This code is based on org.apache.camel.spring.util.ReflectionUtils class.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Action to take on each class.static interface
Callback interface invoked on each field in the hierarchy.static interface
Action to take on each method. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
doWithClasses
(Class<?> clazz, ReflectionHelper.ClassCallback cc) Perform the given callback operation on the nested (inner) classes.static void
doWithFields
(Class<?> clazz, ReflectionHelper.FieldCallback fc) Invoke the given callback on all fields in the target class, going up the class hierarchy to get all declared fields.static void
doWithMethods
(Class<?> clazz, ReflectionHelper.MethodCallback mc) Perform the given callback operation on all matching methods of the given class and superclasses (or given interface and super-interfaces).static Method
findMethod
(Class<?> clazz, String name, Class<?>... paramTypes) Attempt to find aMethod
on the supplied class with the supplied name and parameter types.static Object
static void
-
Method Details
-
doWithClasses
public static void doWithClasses(Class<?> clazz, ReflectionHelper.ClassCallback cc) throws IllegalArgumentException Perform the given callback operation on the nested (inner) classes.- Parameters:
clazz
- class to start looking atcc
- the callback to invoke for each inner class (excluding the class itself)- Throws:
IllegalArgumentException
-
doWithFields
public static void doWithFields(Class<?> clazz, ReflectionHelper.FieldCallback fc) throws IllegalArgumentException Invoke the given callback on all fields in the target class, going up the class hierarchy to get all declared fields.- Parameters:
clazz
- the target class to analyzefc
- the callback to invoke for each field- Throws:
IllegalArgumentException
-
doWithMethods
public static void doWithMethods(Class<?> clazz, ReflectionHelper.MethodCallback mc) throws IllegalArgumentException Perform the given callback operation on all matching methods of the given class and superclasses (or given interface and super-interfaces). Important: This method does not take thebridge methods
into account.- Parameters:
clazz
- class to start looking atmc
- the callback to invoke for each method- Throws:
IllegalArgumentException
-
findMethod
Attempt to find aMethod
on the supplied class with the supplied name and parameter types. Searches all superclasses up toObject
.Returns
null
if noMethod
can be found.- Parameters:
clazz
- the class to introspectname
- the name of the methodparamTypes
- the parameter types of the method (may benull
to indicate any signature)- Returns:
- the Method object, or
null
if none found
-
setField
-
getField
-