org.apache.commons.chain.generic
Class LookupCommand

java.lang.Object
  extended by org.apache.commons.chain.generic.LookupCommand
All Implemented Interfaces:
Command, Filter

public class LookupCommand
extends java.lang.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.

Version:
$Revision: 1.10 $ $Date: 2004/11/30 05:52:23 $
Author:
Craig R. McClanahan

Field Summary
private  java.lang.String catalogName
           
private  java.lang.String name
           
private  java.lang.String nameKey
           
private  boolean optional
           
 
Constructor Summary
LookupCommand()
           
 
Method Summary
 boolean execute(Context context)
          Look up the specified command, and (if found) execute it.
 java.lang.String getCatalogName()
          Return the name of the Catalog to be searched, or null to search the default Catalog.
private  Command getCommand(Context context)
          Return the Command instance to be delegated to.
 java.lang.String getName()
          Return the name of the Command that we will look up and delegate execution to.
 java.lang.String getNameKey()
          Return the context attribute key under which the Command name is stored.
 boolean isOptional()
          Return true if locating the specified command is optional.
 boolean postprocess(Context context, java.lang.Exception exception)
          If the executed command was itself a Filter, call the postprocess() method of that Filter as well.
 void setCatalogName(java.lang.String catalogName)
          Set the name of the Catalog to be searched, or null to search the default Catalog.
 void setName(java.lang.String name)
          Set the name of the Command that we will look up and delegate execution to.
 void setNameKey(java.lang.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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

catalogName

private java.lang.String catalogName

name

private java.lang.String name

nameKey

private java.lang.String nameKey

optional

private boolean optional
Constructor Detail

LookupCommand

public LookupCommand()
Method Detail

getCatalogName

public java.lang.String getCatalogName()

Return the name of the Catalog to be searched, or null to search the default Catalog.


setCatalogName

public void setCatalogName(java.lang.String catalogName)

Set the name of the Catalog to be searched, or null to search the default Catalog.

Parameters:
catalogName - The new Catalog name or null

getName

public java.lang.String getName()

Return the name of the Command that we will look up and delegate execution to.


setName

public void setName(java.lang.String name)

Set the name of the Command that 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 Command name is stored.


setNameKey

public void setNameKey(java.lang.String nameKey)

Set the context attribute key under which the Command name is stored.

Parameters:
nameKey - The new context attribute key

isOptional

public boolean isOptional()

Return true if locating the specified command is optional.


setOptional

public void setOptional(boolean optional)

Set the optional flag for finding the specified command.

Parameters:
optional - The new optional flag

execute

public boolean execute(Context context)
                throws java.lang.Exception

Look up the specified command, and (if found) execute it.

Specified by:
execute in interface Command
Parameters:
context - The context for this request
Returns:
true if the processing of this Context has been completed, or false if the processing of this Context should be delegated to a subsequent Command in an enclosing Chain
Throws:
java.lang.IllegalArgumentException - if no such Command can be found and the optional property is set to false
java.lang.Exception - general purpose exception return to indicate abnormal termination

postprocess

public boolean postprocess(Context context,
                           java.lang.Exception exception)

If the executed command was itself a Filter, call the postprocess() method of that Filter as well.

Specified by:
postprocess in interface Filter
Parameters:
context - The context for this request
exception - Any Exception thrown by command execution
Returns:
If a non-null exception was "handled" by this method (and therefore need not be rethrown), return true; otherwise return false
Throws:
java.lang.Exception - if thrown by the postprocess() method

getCommand

private Command getCommand(Context context)

Return the Command instance to be delegated to.

Parameters:
context - Context for this request
Throws:
java.lang.IllegalArgumentException - if no such Command can be found and the optional property is set to false