public class LookupCommand extends Object implements Filter
Look up a specified 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
.
CONTINUE_PROCESSING, PROCESSING_COMPLETE
Constructor and Description |
---|
LookupCommand()
Create an instance, setting its
catalogFactory property to the
value of CatalogFactory.getInstance() . |
LookupCommand(CatalogFactory factory)
Create an instance and initialize the
catalogFactory property
to given factory / |
Modifier and Type | Method and Description |
---|---|
boolean |
execute(Context context)
Look up the specified command, and (if found) execute it.
|
protected Catalog |
getCatalog(Context context)
|
CatalogFactory |
getCatalogFactory()
Return the
CatalogFactory from which lookups will be performed. |
String |
getCatalogName()
|
protected Command |
getCommand(Context context)
Return the
Command instance to be delegated to. |
protected String |
getCommandName(Context context)
Return the name of the
Command instance to be delegated to. |
String |
getName()
Return the name of the
Command that we will look up and
delegate execution to. |
String |
getNameKey()
Return the context attribute key under which the
Command
name is stored. |
boolean |
isIgnoreExecuteResult()
Return
true if this command should ignore
the return value from executing the looked-up command. |
boolean |
isIgnorePostprocessResult()
Return
true if this command is a Filter and
should ignore the return value from executing the looked-up Filter's
postprocess() method. |
boolean |
isOptional()
Return
true if locating the specified command
is optional. |
boolean |
postprocess(Context context,
Exception exception)
|
void |
setCatalogFactory(CatalogFactory catalogFactory)
Set the
CatalogFactory from which lookups will be
performed. |
void |
setCatalogName(String catalogName)
|
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.
|
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. |
void |
setName(String name)
Set the name of the
Command that we will look up and
delegate execution to. |
void |
setNameKey(String nameKey)
Set the context attribute key under which the
Command
name is stored. |
void |
setOptional(boolean optional)
Set the optional flag for finding the specified command.
|
public LookupCommand()
catalogFactory
property to the
value of CatalogFactory.getInstance()
.public LookupCommand(CatalogFactory factory)
catalogFactory
property
to given factory
/factory
- The Catalog Factory.public void setCatalogFactory(CatalogFactory catalogFactory)
Set the CatalogFactory
from which lookups will be
performed.
catalogFactory
- The Catalog Factory.public CatalogFactory getCatalogFactory()
CatalogFactory
from which lookups will be performed.public String getCatalogName()
public void setCatalogName(String catalogName)
catalogName
- The new Catalog
name or null
public String getName()
Return the name of the Command
that we will look up and
delegate execution to.
public void setName(String name)
Set the name of the Command
that we will look up and
delegate execution to.
name
- The new command namepublic String getNameKey()
Return the context attribute key under which the Command
name is stored.
public void setNameKey(String nameKey)
Set the context attribute key under which the Command
name is stored.
nameKey
- The new context attribute keypublic boolean isOptional()
Return true
if locating the specified command
is optional.
true
if the Command is optional.public void setOptional(boolean optional)
Set the optional flag for finding the specified command.
optional
- The new optional flagpublic boolean isIgnoreExecuteResult()
Return true
if this command should ignore
the return value from executing the looked-up command.
Defaults to false
, which means that the return result
of executing this lookup will be whatever is returned from that
command.
true
if result of the looked up Command
should be ignored.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
ignoreReturn
- true
if result of the
looked up Command should be ignored.public boolean isIgnorePostprocessResult()
Return true
if this command is a Filter and
should ignore the return value from executing the looked-up Filter's
postprocess()
method.
Defaults to false
, which means that the return result
of executing this lookup will be whatever is returned from that
Filter.
true
if result of the looked up Filter's
postprocess()
method should be ignored.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
ignorePostprocessResult
- true
if result of the
looked up Filter's postprocess()
method should be ignored.public boolean execute(Context context) throws Exception
Look up the specified command, and (if found) execute it.
Unless ignoreExecuteResult
is set to true
,
return the result of executing the found command. If no command
is found, return false
, unless the optional
property is false
, in which case an IllegalArgumentException
will be thrown.
execute
in interface Command
context
- The context for this requestfalse
if no command is found or if the command
is found but the ignoreExecuteResult
property of this
instance is true
IllegalArgumentException
- if no such Command
can be found and the optional
property is set
to false
Exception
- if and error occurs in the looked-up Command.public boolean postprocess(Context context, Exception exception)
postprocess
in interface Filter
context
- The context for this requestexception
- Any Exception
thrown by command executionpostprocess
method
of the looked-up command, unless ignorePostprocessResult
is
true
. If no command is found, return false
,
unless the optional
property is false
, in which
case IllegalArgumentException
will be thrown.protected Catalog getCatalog(Context context)
context
- Context
for this requestIllegalArgumentException
- if no Catalog
can be foundprotected Command getCommand(Context context)
Return the Command
instance to be delegated to.
context
- Context
for this requestIllegalArgumentException
- if no such Command
can be found and the optional
property is set
to false
Copyright © 2003–2021 The Apache Software Foundation. All rights reserved.