Interface Command
-
- All Known Implementing Classes:
AbstractGetLocaleCommand
,AbstractSetLocaleCommand
,ChainBase
,CopyCommand
,DispatchCommand
,DispatchLookupCommand
,LookupCommand
,PathInfoMapper
,PortletGetLocaleCommand
,PortletSetLocaleCommand
,RemoveCommand
,RequestParameterMapper
,ServletGetLocaleCommand
,ServletPathMapper
,ServletSetLocaleCommand
public interface Command
A
Command
encapsulates a unit of processing work to be performed, whose purpose is to examine and/or modify the state of a transaction that is represented by aContext
. IndividualCommand
s can be assembled into aChain
, which allows them to either complete the required processing or delegate further processing to the nextCommand
in theChain
.Command
implementations should be designed in a thread-safe manner, suitable for inclusion in multipleChain
s that might be processed by different threads simultaneously. In general, this implies thatCommand
classes should not maintain state information in instance variables. Instead, state information should be maintained via suitable modifications to the attributes of theContext
that is passed to theexecute()
command.Command
implementations typically retrieve and store state information in theContext
instance that is passed as a parameter to theexecute()
method, using particular keys into theMap
that can be acquired viaContext.getAttributes()
. To improve interoperability ofCommand
implementations, a useful design pattern is to expose the key values used as JavaBeans properties of theCommand
implementation class itself. For example, aCommand
that requires an input and an output key might implement the following properties:private String inputKey = "input"; public String getInputKey() { return (this.inputKey); } public void setInputKey(String inputKey) { this.inputKey = inputKey; } private String outputKey = "output"; public String getOutputKey() { return (this.outputKey); } public void setOutputKey(String outputKey) { this.outputKey = outputKey; }
And the operation of accessing the "input" information in the context would be executed by calling:
String input = (String) context.get(getInputKey());
instead of hard coding the attribute name. The use of the "Key" suffix on such property names is a useful convention to identify properties being used in this fashion, as opposed to JavaBeans properties that simply configure the internal operation of this
Command
.- Version:
- $Revision: 480477 $ $Date: 2006-11-29 08:34:52 +0000 (Wed, 29 Nov 2006) $
- Author:
- Craig R. McClanahan
-
-
Field Summary
Fields Modifier and Type Field Description static boolean
CONTINUE_PROCESSING
static boolean
PROCESSING_COMPLETE
Commands should returnPROCESSING_COMPLETE
if the processing of the givenContext
has been completed.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
execute(Context context)
Execute a unit of processing work to be performed.
-
-
-
Field Detail
-
CONTINUE_PROCESSING
static final boolean CONTINUE_PROCESSING
Commands should return
CONTINUE_PROCESSING
if the processing of the givenContext
should be delegated to a subsequentCommand
in an enclosingChain
.- Since:
- Chain 1.1
- See Also:
- Constant Field Values
-
PROCESSING_COMPLETE
static final boolean PROCESSING_COMPLETE
Commands should return
PROCESSING_COMPLETE
if the processing of the givenContext
has been completed.- Since:
- Chain 1.1
- See Also:
- Constant Field Values
-
-
Method Detail
-
execute
boolean execute(Context context) throws java.lang.Exception
Execute a unit of processing work to be performed. This
Command
may either complete the required processing and returntrue
, or delegate remaining processing to the nextCommand
in aChain
containing thisCommand
by returningfalse
- Parameters:
context
- TheContext
to be processed by thisCommand
- Returns:
true
if the processing of thisContext
has been completed, orfalse
if the processing of thisContext
should be delegated to a subsequentCommand
in an enclosingChain
- Throws:
java.lang.Exception
- general purpose exception return to indicate abnormal terminationjava.lang.IllegalArgumentException
- ifcontext
isnull
-
-