Class ReflectionValueExtractor
- java.lang.Object
-
- org.codehaus.plexus.interpolation.reflection.ReflectionValueExtractor
-
public class ReflectionValueExtractor extends java.lang.ObjectNOTE: This class was copied from plexus-utils, to allow this library to stand completely self-contained.Using simple dotted expressions extract the values from a MavenProject instance, For example we might want to extract a value like: project.build.sourceDirectory
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classReflectionValueExtractor.Tokenizer
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.Class<?>[]CLASS_ARGSprivate static java.util.Map<java.lang.Class<?>,java.lang.ref.WeakReference<ClassMap>>classMapsUse a WeakHashMap here, so the keys (Class objects) can be garbage collected.(package private) static intEOF(package private) static charINDEXED_END(package private) static charINDEXED_START(package private) static charMAPPED_END(package private) static charMAPPED_STARTprivate static java.lang.Object[]OBJECT_ARGS(package private) static charPROPERTY_START
-
Constructor Summary
Constructors Modifier Constructor Description privateReflectionValueExtractor()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.Objectevaluate(java.lang.String expression, java.lang.Object root)The implementation supports indexed, nested and mapped properties.static java.lang.Objectevaluate(java.lang.String expression, java.lang.Object root, boolean trimRootToken)The implementation supports indexed, nested and mapped properties.private static ClassMapgetClassMap(java.lang.Class<?> clazz)private static java.lang.ObjectgetIndexedValue(java.lang.String expression, int from, int to, java.lang.Object value, java.lang.String indexStr)private static java.lang.ObjectgetMappedValue(java.lang.String expression, int from, int to, java.lang.Object value, java.lang.String key)private static java.lang.ObjectgetPropertyValue(java.lang.Object value, java.lang.String property)
-
-
-
Field Detail
-
CLASS_ARGS
private static final java.lang.Class<?>[] CLASS_ARGS
-
OBJECT_ARGS
private static final java.lang.Object[] OBJECT_ARGS
-
classMaps
private static final java.util.Map<java.lang.Class<?>,java.lang.ref.WeakReference<ClassMap>> classMaps
Use a WeakHashMap here, so the keys (Class objects) can be garbage collected. This approach prevents permgen space overflows due to retention of discarded classloaders.
-
EOF
static final int EOF
- See Also:
- Constant Field Values
-
PROPERTY_START
static final char PROPERTY_START
- See Also:
- Constant Field Values
-
INDEXED_START
static final char INDEXED_START
- See Also:
- Constant Field Values
-
INDEXED_END
static final char INDEXED_END
- See Also:
- Constant Field Values
-
MAPPED_START
static final char MAPPED_START
- See Also:
- Constant Field Values
-
MAPPED_END
static final char MAPPED_END
- See Also:
- Constant Field Values
-
-
Method Detail
-
evaluate
public static java.lang.Object evaluate(java.lang.String expression, java.lang.Object root) throws java.lang.ExceptionThe implementation supports indexed, nested and mapped properties.
- nested properties should be defined by a dot, i.e. "user.address.street"
- indexed properties (java.util.List or array instance) should be contains
(\\w+)\\[(\\d+)\\]pattern, i.e. "user.addresses[1].street" - mapped properties should be contains
(\\w+)\\((.+)\\)pattern, i.e. "user.addresses(myAddress).street"
- Parameters:
expression- not null expressionroot- not null object- Returns:
- the object defined by the expression
- Throws:
java.lang.Exception- if any
-
evaluate
public static java.lang.Object evaluate(java.lang.String expression, java.lang.Object root, boolean trimRootToken) throws java.lang.ExceptionThe implementation supports indexed, nested and mapped properties.
- nested properties should be defined by a dot, i.e. "user.address.street"
- indexed properties (java.util.List or array instance) should be contains
(\\w+)\\[(\\d+)\\]pattern, i.e. "user.addresses[1].street" - mapped properties should be contains
(\\w+)\\((.+)\\)pattern, i.e. "user.addresses(myAddress).street"
- Parameters:
expression- not null expressionroot- not null objecttrimRootToken- trim the token or not.- Returns:
- the object defined by the expression
- Throws:
java.lang.Exception- if any
-
getMappedValue
private static java.lang.Object getMappedValue(java.lang.String expression, int from, int to, java.lang.Object value, java.lang.String key) throws java.lang.Exception- Throws:
java.lang.Exception
-
getIndexedValue
private static java.lang.Object getIndexedValue(java.lang.String expression, int from, int to, java.lang.Object value, java.lang.String indexStr) throws java.lang.Exception- Throws:
java.lang.Exception
-
getPropertyValue
private static java.lang.Object getPropertyValue(java.lang.Object value, java.lang.String property) throws java.lang.Exception- Throws:
java.lang.Exception
-
getClassMap
private static ClassMap getClassMap(java.lang.Class<?> clazz)
-
-