Class LookupCommand<C extends Context>
- Type Parameters:
C- Type of the context associated with this command
- Direct Known Subclasses:
DispatchLookupCommand,PathInfoMapper,PathInfoMapper,RequestParameterMapper,RequestParameterMapper,ServletPathMapper,ServletPathMapper
Command (which could also be a
Chain)
in a Catalog, and delegate execution to it. 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.
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.
- Version:
- $Revision$ $Date$
- Author:
- Craig R. McClanahan
-
Field Summary
Fields inherited from interface org.apache.commons.chain.Command
CONTINUE_PROCESSING, PROCESSING_COMPLETE -
Constructor Summary
ConstructorsConstructorDescriptionCreate an instance, setting itscatalogFactoryproperty to the value ofCatalogFactory.getInstance().LookupCommand(CatalogFactory<C> factory) Create an instance and initialize thecatalogFactoryproperty to givenfactory. -
Method Summary
Modifier and TypeMethodDescriptionbooleanLook up the specified command, and (if found) execute it.getCatalog(C context) Return theCatalogFactoryfrom which lookups will be performed.getCommand(C context) Return theCommandinstance to be delegated to.protected StringgetCommandName(C context) Return the name of theCommandinstance to be delegated to.getName()Return the name of theCommandthat we will look up and delegate execution to.Return the context attribute key under which theCommandname is stored.booleanReturntrueif this command should ignore the return value from executing the looked-up command.booleanReturntrueif this command is a Filter and should ignore the return value from executing the looked-up Filter'spostprocess()method.booleanReturntrueif locating the specified command is optional.booleanpostprocess(C context, Exception exception) voidsetCatalogFactory(CatalogFactory<C> catalogFactory) Set theCatalogFactoryfrom which lookups will be performed.voidsetCatalogName(String catalogName) voidsetIgnoreExecuteResult(boolean ignoreReturn) Set the rules for whether or not this class will ignore or pass through the value returned from executing the looked up command.voidsetIgnorePostprocessResult(boolean ignorePostprocessResult) Set the rules for whether or not this class will ignore or pass through the value returned from executing the looked up Filter'spostprocess()method.voidSet the name of theCommandthat we will look up and delegate execution to.voidsetNameKey(String nameKey) Set the context attribute key under which theCommandname is stored.voidsetOptional(boolean optional) Set the optional flag for finding the specified command.
-
Constructor Details
-
LookupCommand
public LookupCommand()Create an instance, setting itscatalogFactoryproperty to the value ofCatalogFactory.getInstance().- Since:
- Chain 1.1
-
LookupCommand
Create an instance and initialize thecatalogFactoryproperty to givenfactory.- Parameters:
factory- The Catalog Factory.- Since:
- Chain 1.1
-
-
Method Details
-
setCatalogFactory
Set theCatalogFactoryfrom which lookups will be performed.- Parameters:
catalogFactory- The Catalog Factory.- Since:
- Chain 1.1
-
getCatalogFactory
Return theCatalogFactoryfrom which lookups will be performed.- Returns:
- The Catalog factory.
- Since:
- Chain 1.1
-
getCatalogName
- Returns:
- The Catalog name.
-
setCatalogName
- Parameters:
catalogName- The newCatalogname ornull
-
getName
Return the name of theCommandthat we will look up and delegate execution to.- Returns:
- The name of the Command.
-
setName
Set the name of theCommandthat we will look up and delegate execution to.- Parameters:
name- The new command name
-
getNameKey
Return the context attribute key under which theCommandname is stored.- Returns:
- The context key of the Command.
-
setNameKey
Set the context attribute key under which theCommandname is stored.- Parameters:
nameKey- The new context attribute key
-
isOptional
Returntrueif locating the specified command is optional.- Returns:
trueif the Command is optional.
-
setOptional
Set the optional flag for finding the specified command.- Parameters:
optional- The new optional flag
-
isIgnoreExecuteResult
Returntrueif this command should ignore the return value from executing the looked-up command. Defaults tofalse, which means that the return result of executing this lookup will be whatever is returned from that command.- Returns:
trueif result of the looked up Command should be ignored.- Since:
- Chain 1.1
-
setIgnoreExecuteResult
Set the rules for whether or not this class will ignore or pass through the value returned from executing the looked up command.If you are looking up a chain which may be "aborted" and you do not want this class to stop chain processing, then this value should be set to
true.- Parameters:
ignoreReturn-trueif result of the looked up Command should be ignored.- Since:
- Chain 1.1
-
isIgnorePostprocessResult
Returntrueif this command is a Filter and should ignore the return value from executing the looked-up Filter'spostprocess()method.Defaults to
false, which means that the return result of executing this lookup will be whatever is returned from that Filter.- Returns:
trueif result of the looked up Filter'spostprocess()method should be ignored.- Since:
- Chain 1.1
-
setIgnorePostprocessResult
Set the rules for whether or not this class will ignore or pass through the value returned from executing the looked up Filter'spostprocess()method.If you are looking up a Filter which may be "aborted" and you do not want this class to stop chain processing, then this value should be set to
true.- Parameters:
ignorePostprocessResult-trueif result of the looked up Filter'spostprocess()method should be ignored.- Since:
- Chain 1.1
-
execute
Look up the specified command, and (if found) execute it. UnlessignoreExecuteResultis set totrue, return the result of executing the found command. If no command is found, returnfalse, unless theoptionalproperty isfalse, in which case anIllegalArgumentExceptionwill be thrown.- Specified by:
executein interfaceCommand<C extends Context>- Parameters:
context- The context for this request- Returns:
- the result of executing the looked-up command, or
falseif no command is found or if the command is found but theignoreExecuteResultproperty of this instance istrue - Throws:
IllegalArgumentException- if no suchCommandcan be found and theoptionalproperty is set tofalseException- if and error occurs in the looked-up Command.
-
postprocess
- Specified by:
postprocessin interfaceFilter<C extends Context>- Parameters:
context- The context for this requestexception- AnyExceptionthrown by command execution- Returns:
- the result of executing the
postprocessmethod of the looked-up command, unlessignorePostprocessResultistrue. If no command is found, returnfalse, unless theoptionalproperty isfalse, in which caseIllegalArgumentExceptionwill be thrown.
-
getCatalog
- Parameters:
context-Contextfor this request- Returns:
- The catalog.
- Throws:
IllegalArgumentException- if noCatalogcan be found- Since:
- Chain 1.2
-
getCommand
Return theCommandinstance to be delegated to.- Parameters:
context-Contextfor this request- Returns:
- The looked-up Command.
- Throws:
IllegalArgumentException- if no suchCommandcan be found and theoptionalproperty is set tofalse
-
getCommandName
Return the name of theCommandinstance to be delegated to.
-