nestedstate
Class FSM

java.lang.Object
  |
  +--nestedstate.FSM

public class FSM
extends java.lang.Object

This class serves as a access point for the whole framework. An FSM object encapsulates a FSM and provides a factory method to create a FSMContext object for this FSM.


Field Summary
static java.lang.String ROOT
           
 
Constructor Summary
FSM()
          Initialize the FSM: create a root NodeState.
 
Method Summary
 void addEvent(java.lang.String name)
          This method can be used to add an event to the FSM.
 void addLeafState(FSMAction entryAction, java.lang.String statename, FSMAction exitAction, java.lang.String parentstate)
          Add a leafstate.
 void addLeafState(FSMAction entryAction, java.lang.String statename, java.lang.String parentstate)
          Add a leafstate.
 void addLeafState(java.lang.String statename, FSMAction exitAction, java.lang.String parentstate)
          Add a leafstate.
 void addLeafState(java.lang.String statename, java.lang.String parentstate)
          Add a leafstate.
 void addNodeState(java.lang.String statename, java.lang.String parentstate)
          Add a nodestate.
 void addTransition(java.lang.String sourcestate, java.lang.String eventname, java.lang.String targetstate, FSMAction action)
          This method creates a transition between the sourcestate and the target state.
 FSMContext createFSMInstance()
          This method serves as a factory method to create FSMContexts from the FSM.
 NodeState getRoot()
           
 State getStateWithName(java.lang.String name)
          Convenience method.
 void setDefaultState(java.lang.String state)
          Set the default state for the root state.
 void setDefaultState(java.lang.String parent, java.lang.String state)
          Set the default state for a nodestate.
 void setInitAction(FSMAction action)
          Sometimes it's necessary to do some initialization before the FSM can be used.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ROOT

public static java.lang.String ROOT
Constructor Detail

FSM

public FSM()
Initialize the FSM: create a root NodeState.
Method Detail

getRoot

public NodeState getRoot()
Returns:
The root NodeState of the fsm

addLeafState

public void addLeafState(java.lang.String statename,
                         java.lang.String parentstate)
Add a leafstate.
Parameters:
statename - The name of this state
parentstate - The name of the parent state. If left null, the state will be added to the root state.

addLeafState

public void addLeafState(FSMAction entryAction,
                         java.lang.String statename,
                         java.lang.String parentstate)
Add a leafstate.
Parameters:
statename - The name of this state
parentstate - The name of the parent state. If left null, the state will be added to the root state.

addLeafState

public void addLeafState(java.lang.String statename,
                         FSMAction exitAction,
                         java.lang.String parentstate)
Add a leafstate.
Parameters:
statename - The name of this state
exitAction - The action that is executed upon state-exit
parentstate - The name of the parent state. If left null, the state will be added to the root state.

addLeafState

public void addLeafState(FSMAction entryAction,
                         java.lang.String statename,
                         FSMAction exitAction,
                         java.lang.String parentstate)
Add a leafstate. FSM uses the State class to create a new State object
Parameters:
entryAction - The action that is executed upon state-entry
statename - The name of the state
exitAction - The action that is executed upon state-exit
parentstate - The name of the parent state. If left null, the state will be added to the root state.

addNodeState

public void addNodeState(java.lang.String statename,
                         java.lang.String parentstate)
Add a nodestate.
Parameters:
statename - The name of the state
parentstate - The name of the parent state. If left null, the state will be added to the root state.

addEvent

public void addEvent(java.lang.String name)
This method can be used to add an event to the FSM. FSM uses the Event class to create a new Event object
Parameters:
name - This is the name of the event.

addTransition

public void addTransition(java.lang.String sourcestate,
                          java.lang.String eventname,
                          java.lang.String targetstate,
                          FSMAction action)
This method creates a transition between the sourcestate and the target state. The method checks whether the given states and the event exist before it creates the transition. If they don't exist a RuntimeException is thrown.
Parameters:
sourcestate - The name of the sourcestate
eventname - The name of the event that triggers the transition
targetstate - the name of the targetstate
action - The action that will be executed when the transition is triggered.

setDefaultState

public void setDefaultState(java.lang.String state)
Set the default state for the root state.

setDefaultState

public void setDefaultState(java.lang.String parent,
                            java.lang.String state)
Set the default state for a nodestate.
Parameters:
parent - The nodestate
state - The default state

getStateWithName

public State getStateWithName(java.lang.String name)
Convenience method.
Parameters:
name - The name of the state
Returns:
a state object for name

setInitAction

public void setInitAction(FSMAction action)
Sometimes it's necessary to do some initialization before the FSM can be used. For this purpos a initial action can be set. This action is executed when the FSMContext is created.
Parameters:
action - The initial action.

createFSMInstance

public FSMContext createFSMInstance()
This method serves as a factory method to create FSMContexts from the FSM. Also the init action is run (if available).
Returns:
A new FSMContext for the FSM.