public class DispatchLookupCommand extends LookupCommand implements Filter
This command combines elements of the LookupCommand
with the
DispatchCommand
. Look up a specified Command
(which could
also be a Chain
) in a
Catalog
, and delegate execution to
it. Introspection is used to lookup the appropriate method to delegate
execution to. If the delegated-to Command
is also a
Filter
, its postprocess()
method will also be invoked
at the appropriate time.
The name of the Command
can be specified either directly (via
the name
property) or indirectly (via the nameKey
property). Exactly one of these must be set.
The name of the method to be called can be specified either directly
(via the method
property) or indirectly (via the
methodKey
property). Exactly one of these must be set.
If the optional
property is set to true
,
failure to find the specified command in the specified catalog will be
silently ignored. Otherwise, a lookup failure will trigger an
IllegalArgumentException
.
Modifier and Type | Field | Description |
---|---|---|
private 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 |
|
private java.lang.String |
methodKey |
|
private java.util.WeakHashMap |
methods |
CONTINUE_PROCESSING, PROCESSING_COMPLETE
Constructor | Description |
---|---|
DispatchLookupCommand() |
Create an instance with an unspecified
catalogFactory property. |
DispatchLookupCommand(CatalogFactory factory) |
Create an instance and initialize the
catalogFactory property
to given factory . |
Modifier and Type | Method | Description |
---|---|---|
boolean |
execute(Context context) |
Look up the specified command, and (if found) execute it.
|
private java.lang.reflect.Method |
extractMethod(Command command,
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.
|
postprocess
getCatalog, getCatalogFactory, getCatalogName, getCommand, getCommandName, getName, getNameKey, isIgnoreExecuteResult, isIgnorePostprocessResult, isOptional, postprocess, setCatalogFactory, setCatalogName, setIgnoreExecuteResult, setIgnorePostprocessResult, setName, setNameKey, setOptional
private static final java.lang.Class[] DEFAULT_SIGNATURE
Context
as their only argument.private java.util.WeakHashMap methods
private java.lang.String method
private java.lang.String methodKey
public DispatchLookupCommand()
catalogFactory
property.
This property can be set later using setProperty
, or if it is not set,
the static singleton instance from CatalogFactory.getInstance()
will be used.public DispatchLookupCommand(CatalogFactory factory)
catalogFactory
property
to given factory
.factory
- The Catalog Factory.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.public boolean execute(Context context) throws java.lang.Exception
Look up the specified command, and (if found) execute it.
execute
in interface Command
execute
in class LookupCommand
context
- The context for this requestfalse
if no command is found.java.lang.Exception
- if no such Command
can be found and the
optional
property is set to false
protected java.lang.Class[] getSignature()
Return a Class[]
describing the expected signature of
the method. The default is a signature that just accepts the command's
Context
. The method can be overidden to provide a different
method signature.
protected java.lang.Object[] getArguments(Context context)
getSignature()
context
- The context associated with the requestprivate java.lang.reflect.Method extractMethod(Command command, Context context) throws java.lang.NoSuchMethodException
method
property at the name of a method
to look up, or, if that is not defined, uses the
methodKey
to lookup the method name in the context.command
- The commmand that contains the method to be
executed.context
- The context associated with this requestjava.lang.NoSuchMethodException
- if no method can be found under the
specified name.java.lang.NullPointerException
- if no methodName can be determined