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.