public abstract class DispatchCommand extends java.lang.Object implements Command
Modifier and Type | Field and Description |
---|---|
protected static java.lang.Class[] |
DEFAULT_SIGNATURE
The base implementation expects dispatch methods to take a
Context
as their only argument. |
private java.lang.String |
method
Method name
|
private java.lang.String |
methodKey
Method key
|
private java.util.Map |
methods
Cache of methods
|
CONTINUE_PROCESSING, PROCESSING_COMPLETE
Constructor and Description |
---|
DispatchCommand() |
Modifier and Type | Method and Description |
---|---|
protected boolean |
evaluateResult(java.lang.Object o)
Evaluate the result of the method invocation as a boolean value.
|
boolean |
execute(Context context)
Look up the method specified by either "method" or "methodKey" and invoke it,
returning a boolean value as interpreted by
evaluateResult . |
protected java.lang.reflect.Method |
extractMethod(Context context)
Extract the dispatch method.
|
protected java.lang.Object[] |
getArguments(Context context)
Get the arguments to be passed into the dispatch method.
|
java.lang.String |
getMethod()
Return the method name.
|
java.lang.String |
getMethodKey()
Return the Context key for the method name.
|
protected java.lang.Class[] |
getSignature()
Return a
Class[] describing the expected signature of the method. |
void |
setMethod(java.lang.String method)
Set the method name.
|
void |
setMethodKey(java.lang.String methodKey)
Set the Context key for the method name.
|
private java.util.Map methods
private java.lang.String method
private java.lang.String methodKey
protected static final java.lang.Class[] DEFAULT_SIGNATURE
Context
as their only argument.public boolean execute(Context context) throws java.lang.Exception
evaluateResult
.execute
in interface Command
context
- The Context to be processed by this Command.java.lang.IllegalStateException
- if neither 'method' nor 'methodKey' properties are definedjava.lang.Exception
- if any is thrown by the invocation. Note that if invoking the method
results in an InvocationTargetException, the cause of that exception is thrown instead of
the exception itself, unless the cause is an Error
or other Throwable
which is not an Exception
.protected java.lang.reflect.Method extractMethod(Context context) throws java.lang.NoSuchMethodException
method
property as the name of a method to look up, or, if that is not defined,
looks up the the method name in the Context using the methodKey
.context
- The Context being processed by this Command.java.lang.NoSuchMethodException
- if no method can be found under the specified name.java.lang.NullPointerException
- if no methodName cannot be determinedprotected boolean evaluateResult(java.lang.Object o)
o
- The result of the methid executionprotected java.lang.Class[] getSignature()
Class[]
describing the expected signature of the method.protected java.lang.Object[] getArguments(Context context)
getSignature()
context
- The Context being processed by this Command.public java.lang.String getMethod()
public java.lang.String getMethodKey()
public void setMethod(java.lang.String method)
method
- The method name.public void setMethodKey(java.lang.String methodKey)
methodKey
- The Context key for the method name.