Class ReflectionValueExtractor
java.lang.Object
org.codehaus.plexus.interpolation.reflection.ReflectionValueExtractor
NOTE: 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 ClassesModifier and TypeClassDescription(package private) static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Class<?>[]
private static final Map
<Class<?>, WeakReference<ClassMap>> Use a WeakHashMap here, so the keys (Class objects) can be garbage collected.(package private) static final int
(package private) static final char
(package private) static final char
(package private) static final char
(package private) static final char
private static final Object[]
(package private) static final char
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Object
The implementation supports indexed, nested and mapped properties.static Object
The implementation supports indexed, nested and mapped properties.private static ClassMap
getClassMap
(Class<?> clazz) private static Object
getIndexedValue
(String expression, int from, int to, Object value, String indexStr) private static Object
getMappedValue
(String expression, int from, int to, Object value, String key) private static Object
getPropertyValue
(Object value, String property)
-
Field Details
-
CLASS_ARGS
-
OBJECT_ARGS
-
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:
-
PROPERTY_START
static final char PROPERTY_START- See Also:
-
INDEXED_START
static final char INDEXED_START- See Also:
-
INDEXED_END
static final char INDEXED_END- See Also:
-
MAPPED_START
static final char MAPPED_START- See Also:
-
MAPPED_END
static final char MAPPED_END- See Also:
-
-
Constructor Details
-
ReflectionValueExtractor
private ReflectionValueExtractor()
-
-
Method Details
-
evaluate
The 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:
Exception
- if any
-
evaluate
public static Object evaluate(String expression, Object root, boolean trimRootToken) throws Exception The 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:
Exception
- if any
-
getMappedValue
private static Object getMappedValue(String expression, int from, int to, Object value, String key) throws Exception - Throws:
Exception
-
getIndexedValue
private static Object getIndexedValue(String expression, int from, int to, Object value, String indexStr) throws Exception - Throws:
Exception
-
getPropertyValue
- Throws:
Exception
-
getClassMap
-