|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.chain.generic.DispatchCommand
public abstract class DispatchCommand
An abstract base command which uses introspection to look up a method to execute. For use by developers who prefer to group related functionality into a single class rather than an inheritance family.
Field Summary | |
---|---|
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 |
Fields inherited from interface org.apache.commons.chain.Command |
---|
CONTINUE_PROCESSING, PROCESSING_COMPLETE |
Constructor Summary | |
---|---|
DispatchCommand()
|
Method Summary | |
---|---|
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
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.
Constructor Detail |
---|
public DispatchCommand()
Method Detail |
---|
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 defined
java.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 execution
protected 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.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |