public abstract class MethodExecutor
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
MethodExecutor.ExecutableMethod
Annotation for methods that provide usage description.
|
Modifier and Type | Field and Description |
---|---|
protected java.lang.Object |
executionObject
The object that the operations are invoked on
|
Modifier | Constructor and Description |
---|---|
protected |
MethodExecutor(java.lang.Object executionObject)
Create new instance of MethodExecutor
|
Modifier and Type | Method and Description |
---|---|
MethodThread |
backgroundExecute(java.lang.Object... arguments)
Execute a registered method by arguments on background.
|
MethodThread |
backgroundExecute(java.lang.Object[] arguments,
Executable executeBefore,
Executable executeAfter)
Execute a registered method by arguments on background.
|
MethodThread |
backgroundExecute(java.lang.Object[] arguments,
java.util.List<Executable> executeBefore,
java.util.List<Executable> executeAfter)
Execute a registered method by arguments on background.
|
protected static java.lang.Object |
execute(java.lang.reflect.Method method,
java.lang.Object executionObject,
java.lang.Object[] arguments)
Execute specified method on exectutionObject with specified arguments and handle exceptions properly.
|
java.lang.Object |
execute(java.lang.Object... arguments)
Execute a registered method using the specified arguments.
|
protected abstract java.lang.reflect.Method |
getMethod(java.lang.Object[] arguments)
Returns the method that is appropriate for the provided arguments.
|
protected abstract java.util.Collection<java.lang.reflect.Method> |
getRegisteredMethods()
Returns all methods that are registered within this executor.
|
void |
printUsage(java.io.PrintStream out,
boolean printArguments,
boolean printDescription)
Prints usage of all methods managed by this executor.
|
static void |
printUsage(java.io.PrintStream out,
boolean printArguments,
boolean printDescription,
java.lang.reflect.Method method)
Prints the method usage built from the
MethodExecutor.ExecutableMethod annotation. |
void |
printUsage(java.io.PrintStream out,
boolean printArguments,
boolean printDescription,
java.lang.Object[] arguments)
Prints usage of method that is to be called for the given arguments.
|
protected final java.lang.Object executionObject
protected MethodExecutor(java.lang.Object executionObject) throws java.lang.IllegalArgumentException
executionObject
- an instance of the object to execute the operations onjava.lang.IllegalArgumentException
- if the execution object is nullprotected abstract java.util.Collection<java.lang.reflect.Method> getRegisteredMethods()
public static void printUsage(java.io.PrintStream out, boolean printArguments, boolean printDescription, java.lang.reflect.Method method)
MethodExecutor.ExecutableMethod
annotation.
If the annotation is not present, nothing is printed out.
Otherwise the concatenation of the method name, its argument descriptions
(in sharp parenthesis) and the method's description is printed out.out
- the print stream where the usage is printprintArguments
- flag whether to print the method's
argument descriptions
printDescription
- flag whether to print the method's
description
method
- the method for which to get the usagepublic void printUsage(java.io.PrintStream out, boolean printArguments, boolean printDescription)
out
- the print stream where the usage is printprintArguments
- flag whether to print the method's
argument descriptions
printDescription
- flag whether to print the method's
description
public void printUsage(java.io.PrintStream out, boolean printArguments, boolean printDescription, java.lang.Object[] arguments) throws java.lang.NoSuchMethodException
out
- the print stream where the usage is printprintArguments
- flag whether to print the method's
argument descriptions
printDescription
- flag whether to print the method's
description
arguments
- the arguments for the methodjava.lang.NoSuchMethodException
- if there is no method for the specified parameters in this executorprotected abstract java.lang.reflect.Method getMethod(java.lang.Object[] arguments) throws java.lang.NoSuchMethodException
arguments
- the arguments for the methodjava.lang.NoSuchMethodException
- if there is no method that can process the provided arguments in this executorprotected static java.lang.Object execute(java.lang.reflect.Method method, java.lang.Object executionObject, java.lang.Object[] arguments) throws java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException
method
- the method to executeexecutionObject
- the instance on which to invoke the methodarguments
- the method argumentsjava.lang.NoSuchMethodException
- if the arguments are not compatible with the methodjava.lang.reflect.InvocationTargetException
- if an exeception was thrown when the method was executedpublic java.lang.Object execute(java.lang.Object... arguments) throws java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException
arguments
- the array of arguments for the execution method
(must be consistent with the prototype in constructor)java.lang.NoSuchMethodException
- if there is no method that can process the provided arguments in this executorjava.lang.reflect.InvocationTargetException
- if an exeception was thrown when the method was executedpublic MethodThread backgroundExecute(java.lang.Object[] arguments, Executable executeBefore, Executable executeAfter) throws java.lang.NoSuchMethodException
arguments
- the array of arguments for the execution method
(must be consistent with the prototype in constructor)executeBefore
- method to call before registered methodexecuteAfter
- method to call after registered methodMethodThread.waitExecutionEnd()
can be used to retrieve the resultsjava.lang.NoSuchMethodException
- if there is no method that can process the provided arguments in this executorpublic MethodThread backgroundExecute(java.lang.Object[] arguments, java.util.List<Executable> executeBefore, java.util.List<Executable> executeAfter) throws java.lang.NoSuchMethodException
arguments
- The array of arguments for the execution method
(must be consistent with the prototype in constructor)executeBefore
- list of methods to call before registered methodexecuteAfter
- list of methods to call after registered methodMethodThread.waitExecutionEnd()
can be used to retrieve the resultsjava.lang.NoSuchMethodException
- if there is no method that can process the provided arguments in this executorpublic MethodThread backgroundExecute(java.lang.Object... arguments) throws java.lang.NoSuchMethodException
arguments
- the array of arguments for the execution method
(must be consistent with the prototype in constructor)MethodThread.waitExecutionEnd()
can be used to retrieve the resultsjava.lang.NoSuchMethodException
- if there is no method that can process the provided arguments in this executor