net.nexttext.behaviour.control
Class Chain

java.lang.Object
  extended by net.nexttext.behaviour.AbstractAction
      extended by net.nexttext.behaviour.control.Chain
All Implemented Interfaces:
Action

public class Chain
extends AbstractAction

A series of Actions, each of which is executed when the previous one is complete.

The current action in the chain is remembered for each TextObject. When behave is called, that action is called. If that action returns complete or won't complete and returns an event, then the current action is moved to the next action, to be called next time.

If the current action is incremented, then ActionResult.event is returned, unless there is no next action, in which case ActionResult.complete is returned.


Nested Class Summary
 
Nested classes/interfaces inherited from interface net.nexttext.behaviour.Action
Action.ActionResult
 
Constructor Summary
Chain()
          Create a new Chain with no actions.
Chain(java.util.List<Action> actions)
          Creates a new Chain with the given actions.
 
Method Summary
 void add(Action action)
          Add an action to the end of the Chain.
 Action.ActionResult behave(TextObject to)
          Process the current action for the given TextObject.
 void complete(TextObject to)
          The chain has ended for this TextObject, forget internal state.
 java.util.Map<java.lang.String,Property> getRequiredProperties()
          The required properties are the union of all properties in the action chain.
 
Methods inherited from class net.nexttext.behaviour.AbstractAction
behave, behave, getDisplayName, makeBehaviour, properties, setDisplayName
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Chain

public Chain(java.util.List<Action> actions)
Creates a new Chain with the given actions.

Parameters:
actions - a List containing Action objects.

Chain

public Chain()
Create a new Chain with no actions.

Method Detail

add

public void add(Action action)
Add an action to the end of the Chain.


behave

public Action.ActionResult behave(TextObject to)
Process the current action for the given TextObject.

If the action is completed, update current action.

Specified by:
behave in interface Action
Overrides:
behave in class AbstractAction
Returns:
ActionResult with event set if the current action was incremented, and complete set if it was incremented past the end of the chain.

complete

public void complete(TextObject to)
The chain has ended for this TextObject, forget internal state.

Specified by:
complete in interface Action
Overrides:
complete in class AbstractAction

getRequiredProperties

public java.util.Map<java.lang.String,Property> getRequiredProperties()
The required properties are the union of all properties in the action chain.

Specified by:
getRequiredProperties in interface Action
Overrides:
getRequiredProperties in class AbstractAction