Class DuckSetExecutor

All Implemented Interfaces:
JexlPropertySet

public final class DuckSetExecutor extends AbstractExecutor.Set
Specialized executor to set a property of an object.

Duck as in duck-typing for an interface like: interface Setable { Object set(Object property, Object value); } or interface Putable { Object put(Object property, Object value); }

Since:
2.0
  • Field Details

    • property

      private final Object property
      The property, may be null.
    • valueClass

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

    • DuckSetExecutor

      private DuckSetExecutor(Class<?> clazz, Method method, Object 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 to use as 2nd argument to the set method
  • Method Details

    • discover

      public static DuckSetExecutor discover(Introspector is, Class<?> clazz, Object key, Object value)
      Discovers a DuckSetExecutor.
      Parameters:
      is - the introspector
      clazz - the class to find the set method from
      key - the key to use as 1st argument to the set method
      value - the value to use as 2nd argument to the set method
      Returns:
      the executor if found, null otherwise
    • 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:
      obj - Object on which the property setter will be called with the value
      value - value to be set
      Returns:
      the value returned from the set operation (impl specific)
      Throws:
      IllegalAccessException
      InvocationTargetException
    • tryInvoke

      public Object tryInvoke(Object obj, Object key, Object value)
      Description copied from interface: JexlPropertySet
      Attempts to reuse this JexlPropertySet, checking that it is compatible with the actual set of arguments.
      Parameters:
      obj - the object to invoke the get upon
      key - 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.