Class ReflectionValueExtractor

java.lang.Object
org.codehaus.plexus.util.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.

Version:
$Id$
See Also:
  • Field Details

  • Constructor Details

    • ReflectionValueExtractor

      private ReflectionValueExtractor()
  • Method Details

    • evaluate

      public static Object evaluate(String expression, Object root) 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 expression
      root - 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 expression
      root - not null object
      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

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

      private static ClassMap getClassMap(Class<?> clazz)