Package org.codehaus.plexus.util
Class ReflectionUtils
- java.lang.Object
-
- org.codehaus.plexus.util.ReflectionUtils
-
public final class ReflectionUtils extends java.lang.Object
Operations on a class' fields and their setters.- Version:
- $Id$
-
-
Constructor Summary
Constructors Constructor Description ReflectionUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static void
gatherVariablesAndValuesIncludingSuperclasses(java.lang.Object object, java.util.Map<java.lang.String,java.lang.Object> map)
populates a map of the fields and values on a given object, also pulls from superclassesstatic java.lang.reflect.Field
getFieldByNameIncludingSuperclasses(java.lang.String fieldName, java.lang.Class<?> clazz)
static java.util.List<java.lang.reflect.Field>
getFieldsIncludingSuperclasses(java.lang.Class<?> clazz)
static java.lang.reflect.Method
getSetter(java.lang.String fieldName, java.lang.Class<?> clazz)
Finds a setter in the given class for the given field.static java.util.List<java.lang.reflect.Method>
getSetters(java.lang.Class<?> clazz)
Finds all setters in the given class and super classes.static java.lang.Class<?>
getSetterType(java.lang.reflect.Method method)
Returns the class of the argument to the setter.static java.lang.Object
getValueIncludingSuperclasses(java.lang.String variable, java.lang.Object object)
Generates a map of the fields and values on a given object, also pulls from superclassesstatic java.util.Map<java.lang.String,java.lang.Object>
getVariablesAndValuesIncludingSuperclasses(java.lang.Object object)
Generates a map of the fields and values on a given object, also pulls from superclassesstatic boolean
isSetter(java.lang.reflect.Method method)
static void
setVariableValueInObject(java.lang.Object object, java.lang.String variable, java.lang.Object value)
attempts to set the value to the variable in the object passed in
-
-
-
Method Detail
-
getFieldByNameIncludingSuperclasses
public static java.lang.reflect.Field getFieldByNameIncludingSuperclasses(java.lang.String fieldName, java.lang.Class<?> clazz)
-
getFieldsIncludingSuperclasses
public static java.util.List<java.lang.reflect.Field> getFieldsIncludingSuperclasses(java.lang.Class<?> clazz)
-
getSetter
public static java.lang.reflect.Method getSetter(java.lang.String fieldName, java.lang.Class<?> clazz)
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
public static java.util.List<java.lang.reflect.Method> getSetters(java.lang.Class<?> clazz)
Finds all setters in the given class and super classes.
-
getSetterType
public static java.lang.Class<?> getSetterType(java.lang.reflect.Method method)
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(java.lang.Object object, java.lang.String variable, java.lang.Object value) throws java.lang.IllegalAccessException
attempts to set the value to the variable in the object passed in- Parameters:
object
-variable
-value
-- Throws:
java.lang.IllegalAccessException
-
getValueIncludingSuperclasses
public static java.lang.Object getValueIncludingSuperclasses(java.lang.String variable, java.lang.Object object) throws java.lang.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:
java.lang.IllegalAccessException
-
getVariablesAndValuesIncludingSuperclasses
public static java.util.Map<java.lang.String,java.lang.Object> getVariablesAndValuesIncludingSuperclasses(java.lang.Object object) throws java.lang.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:
java.lang.IllegalAccessException
-
isSetter
public static boolean isSetter(java.lang.reflect.Method method)
-
gatherVariablesAndValuesIncludingSuperclasses
private static void gatherVariablesAndValuesIncludingSuperclasses(java.lang.Object object, java.util.Map<java.lang.String,java.lang.Object> map) throws java.lang.IllegalAccessException
populates 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:
java.lang.IllegalAccessException
-
-