Class MethodExecutor

  • All Implemented Interfaces:
    JexlMethod

    public final class MethodExecutor
    extends AbstractExecutor.Method
    Specialized executor to invoke a method on an object.
    Since:
    2.0
    • Field Detail

      • vaStart

        private final int vaStart
        If this method is a vararg method, vaStart is the last argument index.
      • vaClass

        private final java.lang.Class<?> vaClass
        If this method is a vararg method, vaClass is the component type of the vararg array.
    • Constructor Detail

      • MethodExecutor

        private MethodExecutor​(java.lang.Class<?> c,
                               java.lang.reflect.Method m,
                               MethodKey k)
        Creates a new instance.
        Parameters:
        c - the class this executor applies to
        m - the method
        k - the MethodKey
    • Method Detail

      • discover

        public static MethodExecutor discover​(Introspector is,
                                              java.lang.Object obj,
                                              java.lang.String method,
                                              java.lang.Object[] args)
        Discovers a MethodExecutor.

        If the object is an array, an attempt will be made to find the method in a List (see ArrayListWrapper)

        If the object is a class, an attempt will be made to find the method as a static method of that class.

        Parameters:
        is - the introspector used to discover the method
        obj - the object to introspect
        method - the name of the method to find
        args - the method arguments
        Returns:
        a filled up parameter (may contain a null method)
      • handleVarArg

        private java.lang.Object[] handleVarArg​(java.lang.Object[] args)
        Reassembles arguments if the method is a vararg method.
        Parameters:
        args - The actual arguments being passed to this method
        Returns:
        The actual parameters adjusted for the varargs in order to fit the method declaration.
      • invoke

        public java.lang.Object invoke​(java.lang.Object o,
                                       java.lang.Object... oArgs)
                                throws java.lang.IllegalAccessException,
                                       java.lang.reflect.InvocationTargetException
        Description copied from interface: JexlMethod
        Invocation method, called when the method invocation should be performed and a value returned.
        Parameters:
        o - the object
        oArgs - method parameters.
        Returns:
        the result
        Throws:
        java.lang.IllegalAccessException
        java.lang.reflect.InvocationTargetException
      • tryInvoke

        public java.lang.Object tryInvoke​(java.lang.String name,
                                          java.lang.Object obj,
                                          java.lang.Object... args)
        Description copied from interface: JexlMethod
        Attempts to reuse this JexlMethod, checking that it is compatible with the actual set of arguments. Related to isCacheable since this method is often used with cached JexlMethod instances.
        Parameters:
        name - the method name
        obj - the object to invoke the method upon
        args - the method arguments
        Returns:
        the result of the method invocation that should be checked by tryFailed to determine if it succeeded or failed.