Package org.apache.camel.util
Class ReflectionHelper
- java.lang.Object
-
- org.apache.camel.util.ReflectionHelper
-
public final class ReflectionHelper extends Object
Helper for working with reflection on classes. This code is based on org.apache.camel.spring.util.ReflectionUtils class.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceReflectionHelper.ClassCallbackAction to take on each class.static interfaceReflectionHelper.FieldCallbackCallback interface invoked on each field in the hierarchy.static interfaceReflectionHelper.MethodCallbackAction to take on each method.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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 ObjectgetField(Field f, Object instance)static voidsetField(Field f, Object instance, Object value)
-
-
-
Method Detail
-
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
public static Method findMethod(Class<?> clazz, String name, Class<?>... paramTypes)
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
-
-