public class MethodExecutionStrategy extends java.lang.Object implements ExecutionStrategy
ExecutionStrategy that executes a specific method.
This implementation has three static constructor methods to define the method that should be called:
byMethod(Method, Object...)
to call the specified method and pass it the specified arguments.byArgumentTypes(Class, String, Class[], Object...)
to call the public method with the
specified argument types and pass it the specified arguments.byMatchingArguments(Class, String, Object...)
to call a public method that matches the specified arguments.| Modifier and Type | Method and Description |
|---|---|
static MethodExecutionStrategy |
byArgumentTypes(java.lang.Class<?> clazz,
java.lang.String methodName,
java.lang.Class<?>[] argumentTypes,
java.lang.Object... arguments)
Creates a
MethodExecutionStrategy that will call the public method with the
specified argument types and passes the specified argument list. |
static MethodExecutionStrategy |
byMainMethod(java.lang.Class<?> clazz,
java.lang.String... arguments)
Creates a
MethodExecutionStrategy that will call the public static void main(String[] args)
with the specified arguments. |
static MethodExecutionStrategy |
byMatchingArguments(java.lang.Class<?> clazz,
java.lang.String methodName,
java.lang.Object... arguments)
Creates a
MethodExecutionStrategy that will call a public method that matches the
specified arguments. |
static MethodExecutionStrategy |
byMethod(java.lang.reflect.Method method,
java.lang.Object... arguments)
Creates a
MethodExecutionStrategy that will call the specified Method. |
java.lang.Object |
execute(java.lang.Object instance)
Executes a method on an object instance, or a static method if the specified instance is
null. |
public java.lang.Object execute(java.lang.Object instance)
throws javax.script.ScriptException
ExecutionStrategynull.execute in interface ExecutionStrategyinstance - the object instance to be executed or null to execute a static methodnulljavax.script.ScriptException - if no method to execute was foundpublic static MethodExecutionStrategy byMethod(java.lang.reflect.Method method, java.lang.Object... arguments)
MethodExecutionStrategy that will call the specified Method.method - the Method to executearguments - the arguments to be passed to the methodnullpublic static MethodExecutionStrategy byMainMethod(java.lang.Class<?> clazz, java.lang.String... arguments) throws javax.script.ScriptException
MethodExecutionStrategy that will call the public static void main(String[] args)
with the specified arguments.clazz - the Classarguments - the arguments to pass to the main methodMethodExecutionStrategyjavax.script.ScriptException - if no public static void main(String[] args) method was foundpublic static MethodExecutionStrategy byArgumentTypes(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Class<?>[] argumentTypes, java.lang.Object... arguments) throws javax.script.ScriptException
MethodExecutionStrategy that will call the public method with the
specified argument types and passes the specified argument list.clazz - the ClassmethodName - the method nameargumentTypes - the argument types defining the constructor to callarguments - the arguments to pass to the constructor (may contain null)MethodExecutionStrategyjavax.script.ScriptException - if no matching public method was foundpublic static MethodExecutionStrategy byMatchingArguments(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Object... arguments) throws javax.script.ScriptException
MethodExecutionStrategy that will call a public method that matches the
specified arguments.
A method must match all specified arguments, except null values which
match any non-primitive type.
The conversion from object types into corresponding primitive types
(for example Integer into int) is handled automatically.clazz - the ClassmethodName - the method namearguments - the arguments to be passed to the methodMethodExecutionStrategyjavax.script.ScriptException - if no matching public method was found