Package org.apache.commons.chain.generic
Class DispatchLookupCommand<C extends Context>
java.lang.Object
org.apache.commons.chain.generic.LookupCommand<C>
org.apache.commons.chain.generic.DispatchLookupCommand<C>
- Type Parameters:
C
- Type of the context associated with this command
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
.
- Since:
- Chain 1.1
- Version:
- $Revision$
- Author:
- Sean Schofield
-
Field Summary
Fields inherited from interface org.apache.commons.chain.Command
CONTINUE_PROCESSING, PROCESSING_COMPLETE
-
Constructor Summary
ConstructorDescriptionCreate an instance with an unspecifiedcatalogFactory
property.DispatchLookupCommand
(CatalogFactory<C> factory) Create an instance and initialize thecatalogFactory
property to givenfactory
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Look up the specified command, and (if found) execute it.protected Object[]
getArguments
(C context) Get the arguments to be passed into the dispatch method.Return the method name.Return the Context key for the method name.protected Class<?>[]
Return aClass[]
describing the expected signature of the method.void
Set the method name.void
setMethodKey
(String methodKey) Set the Context key for the method name.Methods inherited from class org.apache.commons.chain.generic.LookupCommand
getCatalog, getCatalogFactory, getCatalogName, getCommand, getCommandName, getName, getNameKey, isIgnoreExecuteResult, isIgnorePostprocessResult, isOptional, postprocess, setCatalogFactory, setCatalogName, setIgnoreExecuteResult, setIgnorePostprocessResult, setName, setNameKey, setOptional
-
Constructor Details
-
DispatchLookupCommand
public DispatchLookupCommand()Create an instance with an unspecifiedcatalogFactory
property. This property can be set later usingsetProperty
, or if it is not set, the static singleton instance fromCatalogFactory.getInstance()
will be used. -
DispatchLookupCommand
Create an instance and initialize thecatalogFactory
property to givenfactory
.- Parameters:
factory
- The Catalog Factory.
-
-
Method Details
-
getMethod
Return the method name.- Returns:
- The method name.
-
getMethodKey
Return the Context key for the method name.- Returns:
- The Context key for the method name.
-
setMethod
Set the method name.- Parameters:
method
- The method name.
-
setMethodKey
Set the Context key for the method name.- Parameters:
methodKey
- The Context key for the method name.
-
execute
Look up the specified command, and (if found) execute it.- Specified by:
execute
in interfaceCommand<C extends Context>
- Overrides:
execute
in classLookupCommand<C extends Context>
- Parameters:
context
- The context for this request- Returns:
- the result of executing the looked-up command's method, or
false
if no command is found. - Throws:
Exception
- if no suchCommand
can be found and theoptional
property is set tofalse
-
getSignature
Return aClass[]
describing the expected signature of the method. The default is a signature that just accepts the command'sContext
. The method can be overidden to provide a different method signature.- Returns:
- the expected method signature
-
getArguments
Get the arguments to be passed into the dispatch method. Default implementation simply returns the context which was passed in, but subclasses could use this to wrap the context in some other type, or extract key values from the context to pass in. The length and types of values returned by this must coordinate with the return value ofgetSignature()
.- Parameters:
context
- The context associated with the request- Returns:
- the method arguments to be used
-