Class ReflectionValueExtractor

java.lang.Object
org.apache.maven.shared.utils.introspection.ReflectionValueExtractor

public class ReflectionValueExtractor extends 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.

See Also:
  • Field Details

    • CLASS_ARGS

      private static final Class<?>[] CLASS_ARGS
    • OBJECT_ARGS

      private static final Object[] OBJECT_ARGS
    • CLASS_MAPS

      private static final Map<Class<?>,ClassMap> CLASS_MAPS
      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

      public static Object evaluate(@Nonnull String expression, @Nullable Object root) throws IntrospectionException

      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 expression
      root - not null object
      Returns:
      the object defined by the expression
      Throws:
      IntrospectionException - if any
    • evaluate

      public static Object evaluate(@Nonnull String expression, @Nullable Object root, boolean trimRootToken) throws IntrospectionException

      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 expression
      root - not null object
      trimRootToken - trim root token yes/no.
      Returns:
      the object defined by the expression
      Throws:
      IntrospectionException - if any
    • getMappedValue

      private static Object getMappedValue(String expression, int from, int to, Object value, String key) throws IntrospectionException
      Throws:
      IntrospectionException
    • getIndexedValue

      private static Object getIndexedValue(String expression, int from, int to, Object value, String indexStr) throws IntrospectionException
      Throws:
      IntrospectionException
    • getPropertyValue

      private static Object getPropertyValue(Object value, String property) throws IntrospectionException
      Throws:
      IntrospectionException
    • getClassMap

      private static ClassMap getClassMap(Class<?> clazz)