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 interfaceAction to take on each class.static interfaceCallback interface invoked on each field in the hierarchy.static interfaceAction to take on each method. -
Method Summary
Modifier and TypeMethodDescriptionstatic voiddoWithClasses(Class<?> clazz, ReflectionHelper.ClassCallback cc) Perform the given callback operation on the nested (inner) classes.static voiddoWithFields(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 voiddoWithMethods(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 MethodfindMethod(Class<?> clazz, String name, Class<?>... paramTypes) Attempt to find aMethodon the supplied class with the supplied name and parameter types.static Objectstatic 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 methodsinto account.- Parameters:
clazz- class to start looking atmc- the callback to invoke for each method- Throws:
IllegalArgumentException
-
findMethod
Attempt to find aMethodon the supplied class with the supplied name and parameter types. Searches all superclasses up toObject.Returns
nullif noMethodcan be found.- Parameters:
clazz- the class to introspectname- the name of the methodparamTypes- the parameter types of the method (may benullto indicate any signature)- Returns:
- the Method object, or
nullif none found
-
setField
-
getField
-