newstate
Class FSM

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

public class FSM
extends java.lang.Object
implements java.io.Serializable

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.

See Also:
Serialized Form

Constructor Summary
FSM()
           
 
Method Summary
 void addEvent(java.lang.String name)
          This method can be used to add an event to the FSM.
 void addState(FSMAction entryAction, java.lang.String statename)
          This method can be used to add a state to the FSM.
 void addState(FSMAction entryAction, java.lang.String statename, FSMAction exitAction)
          This method can be used to add a state to the FSM.
 void addState(java.lang.String statename)
          This method can be used to add a state to the FSM.
 void addState(java.lang.String statename, FSMAction exitAction)
          This method can be used to add a state to the FSM.
 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.
 void setFirstState(java.lang.String statename)
          This method is used to set the default state for the FSM.
 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
 

Constructor Detail

FSM

public FSM()
Method Detail

addState

public void addState(java.lang.String statename)
This method can be used to add a state to the FSM. FSM uses the State class to create a new State object
Parameters:
statename - The name of the state

addState

public void addState(FSMAction entryAction,
                     java.lang.String statename)
This method can be used to add a state to the FSM. 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

addState

public void addState(java.lang.String statename,
                     FSMAction exitAction)
This method can be used to add a state to the FSM. FSM uses the State class to create a new State object
Parameters:
statename - The name of the state
exitAction - The action that is executed upon state-exit

addState

public void addState(FSMAction entryAction,
                     java.lang.String statename,
                     FSMAction exitAction)
This method can be used to add a state to the FSM. 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

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.

setFirstState

public void setFirstState(java.lang.String statename)
This method is used to set the default state for the FSM. If a FSMContext is created, this state is set as the current state.
Parameters:
statename - The name of the first action.

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.