Class DispatchLookupCommand
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: 480477 $
- Author:
- Sean Schofield
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Class[]The base implementation expects dispatch methods to take aContextas their only argument.private Stringprivate Stringprivate WeakHashMapFields inherited from interface Command
CONTINUE_PROCESSING, PROCESSING_COMPLETE -
Constructor Summary
ConstructorsConstructorDescriptionCreate an instance with an unspecifiedcatalogFactoryproperty.DispatchLookupCommand(CatalogFactory factory) Create an instance and initialize thecatalogFactoryproperty to givenfactory. -
Method Summary
Modifier and TypeMethodDescriptionbooleanLook up the specified command, and (if found) execute it.private MethodextractMethod(Command command, Context context) Extract the dispatch method.protected Object[]getArguments(Context 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.voidSet the method name.voidsetMethodKey(String methodKey) Set the Context key for the method name.Methods inherited from class LookupCommand
getCatalog, getCatalogFactory, getCatalogName, getCommand, getCommandName, getName, getNameKey, isIgnoreExecuteResult, isIgnorePostprocessResult, isOptional, postprocess, setCatalogFactory, setCatalogName, setIgnoreExecuteResult, setIgnorePostprocessResult, setName, setNameKey, setOptionalMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Filter
postprocess
-
Field Details
-
DEFAULT_SIGNATURE
The base implementation expects dispatch methods to take aContextas their only argument. -
methods
-
method
-
methodKey
-
-
Constructor Details
-
DispatchLookupCommand
public DispatchLookupCommand()Create an instance with an unspecifiedcatalogFactoryproperty. 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 thecatalogFactoryproperty to givenfactory.- Parameters:
factory- The Catalog Factory.
-
-
Method Details
-
getMethod
-
getMethodKey
Return the Context key for the method name.- Returns:
- The Context key for the method name.
-
setMethod
-
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:
executein interfaceCommand- Overrides:
executein classLookupCommand- Parameters:
context- The context for this request- Returns:
- the result of executing the looked-up command's method, or
falseif no command is found. - Throws:
Exception- if no suchCommandcan be found and theoptionalproperty is set tofalse
-
getSignature
-
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
-
extractMethod
Extract the dispatch method. The base implementation uses the command'smethodproperty at the name of a method to look up, or, if that is not defined, uses themethodKeyto lookup the method name in the context.- Parameters:
command- The commmand that contains the method to be executed.context- The context associated with this request- Returns:
- the dispatch method
- Throws:
NoSuchMethodException- if no method can be found under the specified name.NullPointerException- if no methodName can be determined
-