Class LookupCommand
- java.lang.Object
-
- org.apache.commons.chain.generic.LookupCommand
-
- Direct Known Subclasses:
DispatchLookupCommand,PathInfoMapper,RequestParameterMapper,ServletPathMapper
public class LookupCommand extends java.lang.Object implements Filter
Look up a specified
Command(which could also be aChain) in aCatalog, and delegate execution to it. If the delegated-toCommandis also aFilter, itspostprocess()method will also be invoked at the appropriate time.The name of the
Commandcan be specified either directly (via thenameproperty) or indirectly (via thenameKeyproperty). Exactly one of these must be set.If the
optionalproperty is set totrue, failure to find the specified command in the specified catalog will be silently ignored. Otherwise, a lookup failure will trigger anIllegalArgumentException.- Version:
- $Revision: 532951 $ $Date: 2007-04-27 04:59:00 +0100 (Fri, 27 Apr 2007) $
- Author:
- Craig R. McClanahan
-
-
Field Summary
Fields Modifier and Type Field Description private CatalogFactorycatalogFactoryprivate java.lang.StringcatalogNameprivate booleanignoreExecuteResultprivate booleanignorePostprocessResultprivate java.lang.Stringnameprivate java.lang.StringnameKeyprivate booleanoptional-
Fields inherited from interface org.apache.commons.chain.Command
CONTINUE_PROCESSING, PROCESSING_COMPLETE
-
-
Constructor Summary
Constructors Constructor Description LookupCommand()Create an instance, setting itscatalogFactoryproperty to the value ofCatalogFactory.getInstance().LookupCommand(CatalogFactory factory)Create an instance and initialize thecatalogFactoryproperty to givenfactory/
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanexecute(Context context)Look up the specified command, and (if found) execute it.protected CataloggetCatalog(Context context)CatalogFactorygetCatalogFactory()Return theCatalogFactoryfrom which lookups will be performed.java.lang.StringgetCatalogName()protected CommandgetCommand(Context context)Return theCommandinstance to be delegated to.protected java.lang.StringgetCommandName(Context context)Return the name of theCommandinstance to be delegated to.java.lang.StringgetName()Return the name of theCommandthat we will look up and delegate execution to.java.lang.StringgetNameKey()Return the context attribute key under which theCommandname is stored.booleanisIgnoreExecuteResult()Returntrueif this command should ignore the return value from executing the looked-up command.booleanisIgnorePostprocessResult()Returntrueif this command is a Filter and should ignore the return value from executing the looked-up Filter'spostprocess()method.booleanisOptional()Returntrueif locating the specified command is optional.booleanpostprocess(Context context, java.lang.Exception exception)voidsetCatalogFactory(CatalogFactory catalogFactory)Set theCatalogFactoryfrom which lookups will be performed.voidsetCatalogName(java.lang.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.voidsetName(java.lang.String name)Set the name of theCommandthat we will look up and delegate execution to.voidsetNameKey(java.lang.String nameKey)Set the context attribute key under which theCommandname is stored.voidsetOptional(boolean optional)Set the optional flag for finding the specified command.
-
-
-
Field Detail
-
catalogFactory
private CatalogFactory catalogFactory
-
catalogName
private java.lang.String catalogName
-
name
private java.lang.String name
-
nameKey
private java.lang.String nameKey
-
optional
private boolean optional
-
ignoreExecuteResult
private boolean ignoreExecuteResult
-
ignorePostprocessResult
private boolean ignorePostprocessResult
-
-
Constructor Detail
-
LookupCommand
public LookupCommand()
Create an instance, setting itscatalogFactoryproperty to the value ofCatalogFactory.getInstance().- Since:
- Chain 1.1
-
LookupCommand
public LookupCommand(CatalogFactory factory)
Create an instance and initialize thecatalogFactoryproperty to givenfactory/- Parameters:
factory- The Catalog Factory.- Since:
- Chain 1.1
-
-
Method Detail
-
setCatalogFactory
public void setCatalogFactory(CatalogFactory catalogFactory)
Set the
CatalogFactoryfrom which lookups will be performed.- Parameters:
catalogFactory- The Catalog Factory.- Since:
- Chain 1.1
-
getCatalogFactory
public CatalogFactory getCatalogFactory()
Return theCatalogFactoryfrom which lookups will be performed.- Returns:
- The Catalog factory.
- Since:
- Chain 1.1
-
getCatalogName
public java.lang.String getCatalogName()
- Returns:
- The Catalog name.
-
setCatalogName
public void setCatalogName(java.lang.String catalogName)
- Parameters:
catalogName- The newCatalogname ornull
-
getName
public java.lang.String getName()
Return the name of the
Commandthat we will look up and delegate execution to.- Returns:
- The name of the Command.
-
setName
public void setName(java.lang.String name)
Set the name of the
Commandthat we will look up and delegate execution to.- Parameters:
name- The new command name
-
getNameKey
public java.lang.String getNameKey()
Return the context attribute key under which the
Commandname is stored.- Returns:
- The context key of the Command.
-
setNameKey
public void setNameKey(java.lang.String nameKey)
Set the context attribute key under which the
Commandname is stored.- Parameters:
nameKey- The new context attribute key
-
isOptional
public boolean isOptional()
Return
trueif locating the specified command is optional.- Returns:
trueif the Command is optional.
-
setOptional
public void setOptional(boolean optional)
Set the optional flag for finding the specified command.
- Parameters:
optional- The new optional flag
-
isIgnoreExecuteResult
public boolean isIgnoreExecuteResult()
Return
trueif 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
public void setIgnoreExecuteResult(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.
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
public boolean isIgnorePostprocessResult()
Return
trueif this command is a Filter and should ignore the return value from executing the looked-up Filter'spostprocess()method. Defaults tofalse, 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
public void setIgnorePostprocessResult(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's
postprocess()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
public boolean execute(Context context) throws java.lang.Exception
Look up the specified command, and (if found) execute it. Unless
ignoreExecuteResultis 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- 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:
java.lang.IllegalArgumentException- if no suchCommandcan be found and theoptionalproperty is set tofalsejava.lang.Exception- if and error occurs in the looked-up Command.
-
postprocess
public boolean postprocess(Context context, java.lang.Exception exception)
- Specified by:
postprocessin interfaceFilter- 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.
-
getCommand
protected Command getCommand(Context context)
Return the
Commandinstance to be delegated to.
-
-