Package org.codehaus.plexus.util
Class ReflectionUtils
java.lang.Object
org.codehaus.plexus.util.ReflectionUtils
Operations on a class' fields and their setters.
- Version:
- $Id$
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
gatherVariablesAndValuesIncludingSuperclasses
(Object object, Map<String, Object> map) populates a map of the fields and values on a given object, also pulls from superclassesstatic Field
getFieldByNameIncludingSuperclasses
(String fieldName, Class<?> clazz) getFieldsIncludingSuperclasses
(Class<?> clazz) static Method
Finds a setter in the given class for the given field.getSetters
(Class<?> clazz) Finds all setters in the given class and super classes.static Class<?>
getSetterType
(Method method) Returns the class of the argument to the setter.static Object
getValueIncludingSuperclasses
(String variable, Object object) Generates a map of the fields and values on a given object, also pulls from superclassesGenerates a map of the fields and values on a given object, also pulls from superclassesstatic boolean
static void
setVariableValueInObject
(Object object, String variable, Object value) attempts to set the value to the variable in the object passed in
-
Constructor Details
-
ReflectionUtils
public ReflectionUtils()
-
-
Method Details
-
getFieldByNameIncludingSuperclasses
-
getFieldsIncludingSuperclasses
-
getSetter
Finds a setter in the given class for the given field. It searches interfaces and superclasses too.- Parameters:
fieldName
- the name of the field (i.e. 'fooBar'); it will search for a method named 'setFooBar'.clazz
- The class to find the method in.- Returns:
- null or the method found.
-
getSetters
Finds all setters in the given class and super classes. -
getSetterType
Returns the class of the argument to the setter. Will throw an RuntimeException if the method isn't a setter. -
setVariableValueInObject
public static void setVariableValueInObject(Object object, String variable, Object value) throws IllegalAccessException attempts to set the value to the variable in the object passed in- Parameters:
object
-variable
-value
-- Throws:
IllegalAccessException
-
getValueIncludingSuperclasses
public static Object getValueIncludingSuperclasses(String variable, Object object) throws IllegalAccessException Generates a map of the fields and values on a given object, also pulls from superclasses- Parameters:
object
- the object to generate the list of fields from- Returns:
- map containing the fields and their values
- Throws:
IllegalAccessException
-
getVariablesAndValuesIncludingSuperclasses
public static Map<String,Object> getVariablesAndValuesIncludingSuperclasses(Object object) throws IllegalAccessException Generates a map of the fields and values on a given object, also pulls from superclasses- Parameters:
object
- the object to generate the list of fields from- Returns:
- map containing the fields and their values
- Throws:
IllegalAccessException
-
isSetter
-
gatherVariablesAndValuesIncludingSuperclasses
private static void gatherVariablesAndValuesIncludingSuperclasses(Object object, Map<String, Object> map) throws IllegalAccessExceptionpopulates a map of the fields and values on a given object, also pulls from superclasses- Parameters:
object
- the object to generate the list of fields frommap
- to populate- Throws:
IllegalAccessException
-