java.lang.Object
org.apache.commons.jexl3.internal.introspection.IndexedType
All Implemented Interfaces:
JexlPropertyGet

public final class IndexedType extends Object implements JexlPropertyGet
Abstract an indexed property container.

This allows getting properties from expressions like var.container.property. This stores the container name and class as well as the list of available getter and setter methods. It implements JexlPropertyGet since such a container can only be accessed from its owning instance (not set).

  • Field Details

    • container

      final String container
      The container name.
    • clazz

      final Class<?> clazz
      The container class.
    • getters

      private final Method[] getters
      The array of getter methods.
    • get

      private volatile Method get
      Last get method used.
    • setters

      private final Method[] setters
      The array of setter methods.
    • set

      private volatile Method set
      Last set method used.
  • Constructor Details

    • IndexedType

      private IndexedType(String name, Class<?> c, Method[] gets, Method[] sets)
      Creates a new indexed property container type.
      Parameters:
      name - the container name
      c - the owning class
      gets - the array of getter methods
      sets - the array of setter methods
  • Method Details

    • discover

      public static JexlPropertyGet discover(Introspector is, Object object, String name)
      Attempts to find an indexed-property getter in an object. The code attempts to find the list of methods getXXX() and setXXX(). Note that this is not equivalent to the strict bean definition of indexed properties; the type of the key is not necessarily an int and the set/get arrays are not resolved.
      Parameters:
      is - the introspector
      object - the object
      name - the container name
      Returns:
      a JexlPropertyGet is successful, null otherwise
    • invoke

      public Object invoke(Object obj) throws Exception
      Description copied from interface: JexlPropertyGet
      Method used to get the property value of an object.
      Specified by:
      invoke in interface JexlPropertyGet
      Parameters:
      obj - the object to get the property value from.
      Returns:
      the property value.
      Throws:
      Exception - on any error.
    • tryInvoke

      public Object tryInvoke(Object obj, Object key)
      Description copied from interface: JexlPropertyGet
      Attempts to reuse this JexlPropertyGet, checking that it is compatible with the actual set of arguments.
      Specified by:
      tryInvoke in interface JexlPropertyGet
      Parameters:
      obj - the object to invoke the property get upon
      key - the property key to get
      Returns:
      the result of the method invocation that should be checked by tryFailed to determine if it succeeded or failed.
    • tryFailed

      public boolean tryFailed(Object rval)
      Description copied from interface: JexlPropertyGet
      Checks whether a tryInvoke failed or not.
      Specified by:
      tryFailed in interface JexlPropertyGet
      Parameters:
      rval - the value returned by tryInvoke
      Returns:
      true if tryInvoke failed, false otherwise
    • isCacheable

      public boolean isCacheable()
      Description copied from interface: JexlPropertyGet
      Specifies if this JexlPropertyGet is cacheable and able to be reused for this class of object it was returned for.
      Specified by:
      isCacheable in interface JexlPropertyGet
      Returns:
      true if can be reused for this class, false if not
    • invokeGet

      Object invokeGet(Object object, Object key) throws Exception
      Gets the value of a property from a container.
      Parameters:
      object - the container instance (not null)
      key - the property key (not null)
      Returns:
      the property value
      Throws:
      Exception - if invocation failed; IntrospectionException if a property getter could not be found
    • invokeSet

      Object invokeSet(Object object, Object key, Object value) throws Exception
      Sets the value of a property in a container.
      Parameters:
      object - the container instance (not null)
      key - the property key (not null)
      value - the property value (not null)
      Returns:
      the result of the method invocation (frequently null)
      Throws:
      Exception - if invocation failed; IntrospectionException if a property setter could not be found