org.apache.commons.jexl3.internal.introspection
Class MethodExecutor

java.lang.Object
  extended by org.apache.commons.jexl3.internal.introspection.AbstractExecutor.Method
      extended by org.apache.commons.jexl3.internal.introspection.MethodExecutor
All Implemented Interfaces:
JexlMethod

public final class MethodExecutor
extends AbstractExecutor.Method

Specialized executor to invoke a method on an object.

Since:
2.0

Nested Class Summary
static class AbstractExecutor.Get
          Abstract class that is used to execute an arbitrary 'get' method.
static class AbstractExecutor.Method
          Abstract class that is used to execute an arbitrary method.
static class AbstractExecutor.Set
          Abstract class that is used to execute an arbitrary 'set' method.
 
Field Summary
protected  Method method
          Method to be executed.
protected  Class<?> objectClass
          The class this executor applies to.
static Object TRY_FAILED
          A marker for invocation failures in tryInvoke.
 
Fields inherited from class org.apache.commons.jexl3.internal.introspection.AbstractExecutor.Method
key
 
Method Summary
static MethodExecutor discover(Introspector is, Object obj, String method, Object[] args)
          Discovers a MethodExecutor.
 boolean equals(org.apache.commons.jexl3.internal.introspection.AbstractExecutor arg)
          Indicates whether some other executor is equivalent to this one.
 boolean equals(Object obj)
           
 Method getMethod()
          Gets the method to be executed or used as a marker.
 String getMethodName()
          Gets the method name used.
 Class<?> getTargetClass()
          Gets the object class targeted by this executor.
 int hashCode()
           
 Object invoke(Object o, Object... args)
          Invocation method, called when the method invocation should be performed and a value returned.
 boolean isAlive()
          Tell whether the executor is alive by looking at the value of the method.
 boolean isCacheable()
          Specifies if this executor is cacheable and able to be reused for this class of object it was returned for.
 boolean tryFailed(Object exec)
          Checks whether a tryExecute failed or not.
 Object tryInvoke(String name, Object obj, Object... args)
          Attempts to reuse this JexlMethod, checking that it is compatible with the actual set of arguments.
 
Methods inherited from class org.apache.commons.jexl3.internal.introspection.AbstractExecutor.Method
getReturnType, getTargetProperty
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.commons.jexl3.introspection.JexlMethod
isCacheable, tryFailed
 

Field Detail

TRY_FAILED

public static final Object TRY_FAILED
A marker for invocation failures in tryInvoke.


objectClass

protected final Class<?> objectClass
The class this executor applies to.


method

protected final Method method
Method to be executed.

Method Detail

discover

public static MethodExecutor discover(Introspector is,
                                      Object obj,
                                      String method,
                                      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)

invoke

public Object invoke(Object o,
                     Object... args)
              throws IllegalAccessException,
                     InvocationTargetException
Description copied from interface: JexlMethod
Invocation method, called when the method invocation should be performed and a value returned.

Parameters:
o - the object
args - method parameters.
Returns:
the result
Throws:
IllegalAccessException
InvocationTargetException

tryInvoke

public Object tryInvoke(String name,
                        Object obj,
                        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.

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(org.apache.commons.jexl3.internal.introspection.AbstractExecutor arg)
Indicates whether some other executor is equivalent to this one.

Parameters:
arg - the other executor to check
Returns:
true if both executors are equivalent, false otherwise

isAlive

public final boolean isAlive()
Tell whether the executor is alive by looking at the value of the method.

Returns:
boolean Whether the executor is alive.

isCacheable

public boolean isCacheable()
Specifies if this executor is cacheable and able to be reused for this class of object it was returned for.

Returns:
true if can be reused for this class, false if not

getMethod

public final Method getMethod()
Gets the method to be executed or used as a marker.

Returns:
Method The method used by execute in derived classes.

getTargetClass

public final Class<?> getTargetClass()
Gets the object class targeted by this executor.

Returns:
the target object class

getMethodName

public final String getMethodName()
Gets the method name used.

Returns:
method name

tryFailed

public final boolean tryFailed(Object exec)
Checks whether a tryExecute failed or not.

Parameters:
exec - the value returned by tryExecute
Returns:
true if tryExecute failed, false otherwise


Copyright © 2001–2017 The Apache Software Foundation. All rights reserved.