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 Set { Object set(Object property, Object value); }

    Since:
    2.0
    • Constructor Detail

      • DuckSetExecutor

        public DuckSetExecutor​(Introspector is,
                               java.lang.Class<?> clazz,
                               java.lang.Object key,
                               java.lang.Object value)
        Creates an instance.
        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
    • Method Detail

      • execute

        public java.lang.Object execute​(java.lang.Object obj,
                                        java.lang.Object value)
                                 throws java.lang.IllegalAccessException,
                                        java.lang.reflect.InvocationTargetException
        Sets the property value of an object.
        Specified by:
        execute in class AbstractExecutor.Set
        Parameters:
        obj - The object to set the property in.
        value - The value.
        Returns:
        The return value.
        Throws:
        java.lang.IllegalAccessException - Method is inaccessible.
        java.lang.reflect.InvocationTargetException - Method body throws an exception.
      • tryExecute

        public java.lang.Object tryExecute​(java.lang.Object obj,
                                           java.lang.Object key,
                                           java.lang.Object value)
        Tries to reuse this executor, checking that it is compatible with the actual set of arguments.

        Compatibility means that: o must be of the same class as this executor's target class, property must be of the same class as this executor's target property (for list and map based executors) and have the same value (for other types) and that arg must be a valid argument for this executor underlying method.

        Overrides:
        tryExecute in class AbstractExecutor.Set
        Parameters:
        obj - The object to invoke the method from.
        key - The property to set in the object.
        value - The value to use as the property value.
        Returns:
        The return value or TRY_FAILED if checking failed.