Keel 2.1RC2

org.keel.models.util
Class Sequence

java.lang.Object
  extended byorg.keel.services.model.StandardModel
      extended byorg.keel.services.model.StandardLogEnabledModel
          extended byorg.keel.models.util.Sequence
All Implemented Interfaces:
Configurable, LogEnabled, Model, Poolable

public class Sequence
extends StandardLogEnabledModel
implements Poolable

A Sequence Model runs other models in a specified sequence. The sequence is highly configurable. To use a sequence, you must specify a "sequence" element in configuration, like so:

 <sequence id="somesequence">
     <model name="somemodel"/>
     <model name="someothermodel"/>
 </sequence>
 

This sequence would be called with "model=somesequence" (in Struts) or with /model/somesequence.html (in Cocoon), just like any other model. It would (as configured above) execute "somemodel" and return the results to the user. When the user submitted their next request, it would run whatever that request was (presumably a "submit" of a command emitted by "somemodel"), then immediately run "someothermodel", again returning the response to the user.
By specifying the attribute "return" with value "false" on a "model" line within a sequence, you can skip the return to the user - this has the effect of "combining" or "merging" the responses from the two models into a single response, then returning that combined response to the user. For example:
Also, you can specify an attribute "merge" with a value of "true" or "false". By default, all responses from each running model in the sequence are merged. If you do not want that (annoying for command-line models) specify merge="false" for each model in the sequence definition.
 <sequence id="somesequence">
     <model name="nav.navigate" return="false"/>
     <model name="somemodel"/>
 </sequence>
 

Would return the results from "somemodel" which would now include any results produced by "nav.navigate" - this can be useful when displaying a navigation menu with the "somemodel" output.
As another example, say a particular model must be run only by users who are logged in to the system:
 <sequence id="somesequence">
     <model name="register.verify-login" return="ifinput"/>
     <model name="somemodel"/>
 </sequence>
 

In the above configuration, the special value "ifinput" is used on the register.verify-login model. If this model's execution emits any Input objects, control will be returned to the user at that point. If not, execution continues with the "somemodel" model. This can be very useful in controlling the flow of a sequence. A sequence can be called in either of the following two ways:
model=mySequence?seq=1 (calls the first step of mySequence) or
model=mySequence?step=1 (also calls the first step of mySequence). The "step" parameter was added for naming clarity. The "seq" parameter was left in to ensure backwards compatibility.

Version:
$Revision: 1.6 $ $Date: 2004/03/29 22:12:34 $
Author:
Michael Nash

Field Summary
private  java.util.Map params
           
static java.lang.String SEQUENCE_NAME
           
static java.lang.String SEQUENCE_NUMBER
           
(package private) static boolean sequenceWideMergeDefaultIfNotSpecified
           
 
Fields inherited from class org.keel.services.model.StandardLogEnabledModel
log
 
Fields inherited from class org.keel.services.model.StandardModel
configuration
 
Fields inherited from interface org.keel.services.model.Model
ROLE
 
Constructor Summary
Sequence()
           
 
Method Summary
private  void clearSequence(ModelRequest req)
           
private  boolean containsInputs(ModelResponse res)
           
private  boolean containsInputs(ResponseElement re)
           
 ModelResponse execute(ModelRequest req)
           
protected  java.lang.String getModelName(Configuration modelConfig, ModelRequest request)
           
protected  int getNextSequence(int seq, ModelRequest req)
           
private  ModelResponse runIfTrue(Configuration ifConfig)
           
private  ModelResponse runModel(Configuration modelConfig, ModelRequest req, ModelResponse existingResponse, int seqNumber, java.lang.String seqName, SequenceContext seqContext)
           
private  ModelResponse runSequence(Configuration myConf, ModelRequest req, boolean mergeDefaultForThisSequence)
           
private  SequenceContext setNewSequenceContext(java.lang.String modelName, int seq, Configuration[] children, boolean mergeDefault, ModelRequest req, ModelResponse res)
           
 
Methods inherited from class org.keel.services.model.StandardLogEnabledModel
enableLogging
 
Methods inherited from class org.keel.services.model.StandardModel
configure, getConfiguration
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

params

private java.util.Map params

SEQUENCE_NAME

public static final java.lang.String SEQUENCE_NAME
See Also:
Constant Field Values

SEQUENCE_NUMBER

public static final java.lang.String SEQUENCE_NUMBER
See Also:
Constant Field Values

sequenceWideMergeDefaultIfNotSpecified

static final boolean sequenceWideMergeDefaultIfNotSpecified
See Also:
Constant Field Values
Constructor Detail

Sequence

public Sequence()
Method Detail

execute

public ModelResponse execute(ModelRequest req)
                      throws ModelException
Specified by:
execute in interface Model
Throws:
ModelException

runSequence

private ModelResponse runSequence(Configuration myConf,
                                  ModelRequest req,
                                  boolean mergeDefaultForThisSequence)
                           throws ModelException,
                                  ConfigurationException
Throws:
ModelException
ConfigurationException

setNewSequenceContext

private SequenceContext setNewSequenceContext(java.lang.String modelName,
                                              int seq,
                                              Configuration[] children,
                                              boolean mergeDefault,
                                              ModelRequest req,
                                              ModelResponse res)
                                       throws ModelException
Parameters:
children -
req -
res -
Throws:
ModelException

clearSequence

private void clearSequence(ModelRequest req)
                    throws ModelException
Throws:
ModelException

runModel

private ModelResponse runModel(Configuration modelConfig,
                               ModelRequest req,
                               ModelResponse existingResponse,
                               int seqNumber,
                               java.lang.String seqName,
                               SequenceContext seqContext)
                        throws ConfigurationException,
                               ModelException
Throws:
ConfigurationException
ModelException

runIfTrue

private ModelResponse runIfTrue(Configuration ifConfig)

containsInputs

private boolean containsInputs(ModelResponse res)

containsInputs

private boolean containsInputs(ResponseElement re)

getNextSequence

protected int getNextSequence(int seq,
                              ModelRequest req)

getModelName

protected java.lang.String getModelName(Configuration modelConfig,
                                        ModelRequest request)
                                 throws ConfigurationException
Throws:
ConfigurationException

Keel 2.1RC2

Please see keelframework.org for information about new Keel releases.