Class PropertySetExecutor

All Implemented Interfaces:
JexlPropertySet

public class PropertySetExecutor extends AbstractExecutor.Set
Specialized executor to set a property in an object.
Since:
2.0
  • Field Details

    • SET_START_INDEX

      private static final int SET_START_INDEX
      Index of the first character of the set{p,P}roperty.
      See Also:
    • property

      protected final String property
      The property.
    • valueClass

      protected final Class<?> valueClass
      The property value class.
  • Constructor Details

    • PropertySetExecutor

      protected PropertySetExecutor(Class<?> clazz, Method method, String key, Object value)
      Creates an instance.
      Parameters:
      clazz - the class the set method applies to
      method - the method called through this executor
      key - the key to use as 1st argument to the set method
      value - the value
  • Method Details

    • discover

      public static PropertySetExecutor discover(Introspector is, Class<?> clazz, String property, Object value)
      Discovers a PropertySetExecutor.

      The method to be found should be named "set{P,p}property.

      Parameters:
      is - the introspector
      clazz - the class to find the get method from
      property - the property name to find
      value - the value to assign to the property
      Returns:
      the executor if found, null otherwise
    • discoverSet

      private static Method discoverSet(Introspector is, Class<?> clazz, String property, Object arg)
      Discovers the method for a JexlPropertySet.

      The method to be found should be named "set{P,p}property. As a special case, any empty array will try to find a valid array-setting non-ambiguous method.

      Parameters:
      is - the introspector
      clazz - the class to find the get method from
      property - the name of the property to set
      arg - the value to assign to the property
      Returns:
      the method if found, null otherwise
    • isEmptyArray

      private static boolean isEmptyArray(Object arg)
      Checks whether an argument is an empty array.
      Parameters:
      arg - the argument
      Returns:
      true if arg is an empty array
    • lookupSetEmptyArray

      private static Method lookupSetEmptyArray(Introspector is, Class<?> clazz, String methodName)
      Finds an empty array property setter method by methodName.

      This checks only one method with that name accepts an array as sole parameter.

      Parameters:
      is - the introspector
      clazz - the class to find the get method from
      methodName - the method name to find
      Returns:
      the sole method that accepts an array as parameter
    • getTargetProperty

      public Object getTargetProperty()
      Description copied from class: AbstractExecutor
      Gets the property targeted by this executor.
      Overrides:
      getTargetProperty in class AbstractExecutor
      Returns:
      the target property
    • invoke

      Description copied from interface: JexlPropertySet
      Method used to set the property value of an object.
      Parameters:
      o - Object on which the property setter will be called with the value
      argument - value to be set
      Returns:
      the value returned from the set operation (impl specific)
      Throws:
      IllegalAccessException
      InvocationTargetException
    • tryInvoke

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