SMC
6_0_1

statemap
Class FSMContext

java.lang.Object
  extended by statemap.FSMContext
All Implemented Interfaces:
java.io.Serializable

public abstract class FSMContext
extends java.lang.Object
implements java.io.Serializable

Base class for all SMC-generated application context classes. This class stores the FSM name, current and previous states, the state stack, debugging information and state change listeners.

See Also:
Serialized Form

Field Summary
protected  boolean _debugFlag
          When this flag is set to true, this class will print out debug messages.
protected  java.io.PrintStream _debugStream
          Write debug output to this stream.
protected  java.lang.String _name
          The FSM name.
protected  State _previousState
          Stores which state a transition left.
protected  State _state
          The current state.
protected  java.util.Stack<State> _stateStack
          This stack is used to store the current state when a push transition is taken.
protected  java.lang.String _transition
          The current transition name.
 
Constructor Summary
protected FSMContext(State initState)
          Creates a finite state machine context for the given initial state.
 
Method Summary
 void addStateChangeListener(java.beans.PropertyChangeListener listener)
          Adds a PropertyChangeListener to the listener list.
 void clearState()
          Places the current state into the previous state sets the current state to null.
 void emptyStateStack()
          Empties the state stack.
abstract  void enterStartState()
          Starts the finite state machine running by executing the initial state's entry actions.
 boolean getDebugFlag()
          When debug is set to true, the state machine will print messages to the console.
 java.io.PrintStream getDebugStream()
          Writes the debug output to this stream.
 java.lang.String getName()
          Returns the FSM name.
 State getPreviousState()
          If this FSM is in transition, then returns the previous state which the last transition left.
 java.lang.String getTransition()
          If this FSM is in transition, then returns the transition name.
 boolean isInTransition()
          Returns true if this FSM is in a transition and false otherwise.
 void popState()
          Sets the previous state to the current state and pops the top state off the stack and places it into the current state.
 void pushState(State state)
          Pushes the current state on top of the state stack and sets the current state to state.
 void removeStateChangeListener(java.beans.PropertyChangeListener listener)
          Removes a PropertyChangeListener for the state change property.
 void setDebugFlag(boolean flag)
          Turns debug output on if flag is true and off if flag is false.
 void setDebugStream(java.io.PrintStream stream)
          Sets the debug output stream to the given value.
 void setName(java.lang.String name)
          Sets the FSM name.
 void setState(State state)
          Sets the current state to the given value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_name

protected transient java.lang.String _name
The FSM name.


_state

protected transient State _state
The current state. Will be null while in transition.


_transition

protected transient java.lang.String _transition
The current transition name. Used for debugging purposes. Will be en empty string when not in transition.


_previousState

protected transient State _previousState
Stores which state a transition left. May be null.


_stateStack

protected transient java.util.Stack<State> _stateStack
This stack is used to store the current state when a push transition is taken.


_debugFlag

protected transient boolean _debugFlag
When this flag is set to true, this class will print out debug messages.


_debugStream

protected transient java.io.PrintStream _debugStream
Write debug output to this stream.

Constructor Detail

FSMContext

protected FSMContext(State initState)
Creates a finite state machine context for the given initial state.

Parameters:
initState - the finite state machine's start state.
Method Detail

enterStartState

public abstract void enterStartState()
Starts the finite state machine running by executing the initial state's entry actions.


getName

public java.lang.String getName()
Returns the FSM name.

Returns:
the FSM name.

getDebugFlag

public boolean getDebugFlag()
When debug is set to true, the state machine will print messages to the console.

Returns:
true if debug output is generated.

getDebugStream

public java.io.PrintStream getDebugStream()
Writes the debug output to this stream.

Returns:
the debug output stream.

isInTransition

public boolean isInTransition()
Returns true if this FSM is in a transition and false otherwise.

Returns:
true if this FSM is in a transition and false otherwise.

getPreviousState

public State getPreviousState()
                       throws java.lang.NullPointerException
If this FSM is in transition, then returns the previous state which the last transition left.

Returns:
the previous state which the current transition left. May return null.
Throws:
java.lang.NullPointerException

getTransition

public java.lang.String getTransition()
If this FSM is in transition, then returns the transition name. If not in trnasition, then returns an empty string.

Returns:
the current transition name.

setName

public void setName(java.lang.String name)
Sets the FSM name.

Parameters:
name - The finite state machine name.

setDebugFlag

public void setDebugFlag(boolean flag)
Turns debug output on if flag is true and off if flag is false.

Parameters:
flag - true to turn debuggin on and false to turn debugging off.

setDebugStream

public void setDebugStream(java.io.PrintStream stream)
Sets the debug output stream to the given value.

Parameters:
stream - The debug output stream.

setState

public void setState(State state)
Sets the current state to the given value.

Parameters:
state - The current state.

clearState

public void clearState()
Places the current state into the previous state sets the current state to null.


pushState

public void pushState(State state)
Pushes the current state on top of the state stack and sets the current state to state.

Parameters:
state - The new current state.
Throws:
java.lang.NullPointerException - if state is null.

popState

public void popState()
              throws java.util.EmptyStackException
Sets the previous state to the current state and pops the top state off the stack and places it into the current state.

Throws:
java.util.EmptyStackException - if the state stack is empty.

emptyStateStack

public void emptyStateStack()
Empties the state stack.


addStateChangeListener

public void addStateChangeListener(java.beans.PropertyChangeListener listener)
Adds a PropertyChangeListener to the listener list. The listener is registered for state property changes only. The same listener may be added more than once. For each state change, the listener will be invoked the number of times it was added. If listener is null, no exception is thrown and no action is taken.

Parameters:
listener - The PropertyChangeListener to be added.

removeStateChangeListener

public void removeStateChangeListener(java.beans.PropertyChangeListener listener)
Removes a PropertyChangeListener for the state change property. If listener was added more than once to the same event source, it will be notified one less time after being removed. If listener is null or was never added, no exception is thrown and no action is taken.

Parameters:
listener - The PropertyChangeListener to be removed.

SMC
6_0_1

Copyright © 2009. Charles W. Rapp. All Rights Reserved. Use is subject to license terms.