public class ReflectionValueExtractor
extends java.lang.Object
Using simple dotted expressions to extract the values from an Object instance,
For example we might want to extract a value like: project.build.sourceDirectory
The implementation supports indexed, nested and mapped properties similar to the JSP way.
Modifier and Type | Class and Description |
---|---|
(package private) static class |
ReflectionValueExtractor.Tokenizer |
Modifier and Type | Field and Description |
---|---|
private static java.lang.Class<?>[] |
CLASS_ARGS |
private static java.util.Map<java.lang.Class<?>,ClassMap> |
CLASS_MAPS
Use a WeakHashMap here, so the keys (Class objects) can be garbage collected.
|
(package private) static int |
EOF |
(package private) static char |
INDEXED_END |
(package private) static char |
INDEXED_START |
(package private) static char |
MAPPED_END |
(package private) static char |
MAPPED_START |
private static java.lang.Object[] |
OBJECT_ARGS |
(package private) static char |
PROPERTY_START |
Modifier | Constructor and Description |
---|---|
private |
ReflectionValueExtractor() |
Modifier and Type | Method and Description |
---|---|
static java.lang.Object |
evaluate(java.lang.String expression,
java.lang.Object root)
The implementation supports indexed, nested and mapped properties.
|
static java.lang.Object |
evaluate(java.lang.String expression,
java.lang.Object root,
boolean trimRootToken)
The implementation supports indexed, nested and mapped properties.
|
private static ClassMap |
getClassMap(java.lang.Class<?> clazz) |
private static java.lang.Object |
getIndexedValue(java.lang.String expression,
int from,
int to,
java.lang.Object value,
java.lang.String indexStr) |
private static java.lang.Object |
getMappedValue(java.lang.String expression,
int from,
int to,
java.lang.Object value,
java.lang.String key) |
private static java.lang.Object |
getPropertyValue(java.lang.Object value,
java.lang.String property) |
private static final java.lang.Class<?>[] CLASS_ARGS
private static final java.lang.Object[] OBJECT_ARGS
private static final java.util.Map<java.lang.Class<?>,ClassMap> CLASS_MAPS
static final int EOF
static final char PROPERTY_START
static final char INDEXED_START
static final char INDEXED_END
static final char MAPPED_START
static final char MAPPED_END
public static java.lang.Object evaluate(@Nonnull java.lang.String expression, @Nullable java.lang.Object root) throws IntrospectionException
The implementation supports indexed, nested and mapped properties.
(\\w+)\\[(\\d+)\\]
pattern, i.e. "user.addresses[1].street"(\\w+)\\((.+)\\)
pattern,
i.e. "user.addresses(myAddress).street"expression
- not null expressionroot
- not null objectIntrospectionException
- if anypublic static java.lang.Object evaluate(@Nonnull java.lang.String expression, @Nullable java.lang.Object root, boolean trimRootToken) throws IntrospectionException
The implementation supports indexed, nested and mapped properties.
(\\w+)\\[(\\d+)\\]
pattern, i.e. "user.addresses[1].street"(\\w+)\\((.+)\\)
pattern, i.e.
"user.addresses(myAddress).street"expression
- not null expressionroot
- not null objecttrimRootToken
- trim root token yes/no.IntrospectionException
- if anyprivate static java.lang.Object getMappedValue(java.lang.String expression, int from, int to, java.lang.Object value, java.lang.String key) throws IntrospectionException
IntrospectionException
private static java.lang.Object getIndexedValue(java.lang.String expression, int from, int to, java.lang.Object value, java.lang.String indexStr) throws IntrospectionException
IntrospectionException
private static java.lang.Object getPropertyValue(java.lang.Object value, java.lang.String property) throws IntrospectionException
IntrospectionException
private static ClassMap getClassMap(java.lang.Class<?> clazz)