Interface Command<C extends Context>

Type Parameters:
C - Type of the context associated with this command
All Known Subinterfaces:
Chain<C>, Filter<C>
All Known Implementing Classes:
ChainBase, CopyCommand, DispatchCommand, DispatchLookupCommand, FacesGetLocaleCommand, FacesGetLocaleCommand, FacesSetLocaleCommand, FacesSetLocaleCommand, GetLocaleCommand, GetLocaleCommand, LookupCommand, PathInfoMapper, PathInfoMapper, PortletGetLocaleCommand, PortletSetLocaleCommand, RemoveCommand, RequestParameterMapper, RequestParameterMapper, ServletGetLocaleCommand, ServletGetLocaleCommand, ServletPathMapper, ServletPathMapper, ServletSetLocaleCommand, ServletSetLocaleCommand, SetLocaleCommand, SetLocaleCommand

public interface Command<C extends Context>
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 a Context. Individual Commands can be assembled into a Chain, which allows them to either complete the required processing or delegate further processing to the next Command in the Chain.

Command implementations should be designed in a thread-safe manner, suitable for inclusion in multiple Chains that might be processed by different threads simultaneously. In general, this implies that Command classes should not maintain state information in instance variables. Instead, state information should be maintained via suitable modifications to the attributes of the Context that is passed to the execute() command.

Command implementations typically retrieve and store state information in the Context instance that is passed as a parameter to the execute() method, using particular keys into the Map that can be acquired via Context.getAttributes(). To improve interoperability of Command implementations, a useful design pattern is to expose the key values used as JavaBeans properties of the Command implementation class itself. For example, a Command 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$ $Date$
Author:
Craig R. McClanahan
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final boolean
    Commands should return CONTINUE_PROCESSING if the processing of the given Context should be delegated to a subsequent Command in an enclosing Chain.
    static final boolean
    Commands should return PROCESSING_COMPLETE if the processing of the given Context has been completed.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    execute(C context)
    Execute a unit of processing work to be performed.
  • Field Details

  • Method Details

    • execute

      boolean execute(C context) throws Exception
      Execute a unit of processing work to be performed. This Command may either complete the required processing and return true, or delegate remaining processing to the next Command in a Chain containing this Command by returning false.
      Parameters:
      context - The Context to be processed by this Command
      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:
      Exception - general purpose exception return to indicate abnormal termination
      IllegalArgumentException - if context is null