org.apache.commons.graph.domain.statemachine
Class StateMachine

java.lang.Object
  extended byorg.apache.commons.graph.domain.basic.GraphWrapper
      extended byorg.apache.commons.graph.domain.basic.DirectedGraphWrapper
          extended byorg.apache.commons.graph.decorator.DDirectedGraph
              extended byorg.apache.commons.graph.domain.statemachine.StateMachine
All Implemented Interfaces:
DirectedGraph, Graph, WeightedGraph

public class StateMachine
extends DDirectedGraph

StateMachine - This represents a Finite State Machine. It has a collection of states and transitions which move between them.


Field Summary
private  GraphFactory factory
           
private  java.util.Set finalStates
           
private  MutableDirectedGraph graph
           
private  java.lang.String name
           
private  State startState
           
private  java.util.Map states
           
private  java.util.Map transes
           
 
Fields inherited from class org.apache.commons.graph.decorator.DDirectedGraph
 
Fields inherited from class org.apache.commons.graph.domain.basic.DirectedGraphWrapper
 
Constructor Summary
StateMachine(java.lang.String name)
          Create a new StateMachine given the name.
 
Method Summary
 void addFinalState(State state)
          Adds the state to the set of Final States available.
 void addState(State state)
          Adds a State to the collection of states maintained by the machine.
 void addState(java.lang.String name)
          Creates a new State with name provided.
 void addTransition(java.lang.String name, State source, State target)
          Adds a feature to the Transition attribute of the StateMachine object.
 void addTransition(java.lang.String name, java.lang.String source, java.lang.String target)
          Add a Transition to the diagram with the name provided.
 void addTransition(Transition trans)
          Adds a feature to the Transition attribute of the StateMachine object.
 java.lang.String getName()
          Gets the StateMachines name (or namespace)
 State getState(java.lang.String name)
          Gets the state attribute of the StateMachine object
 Transition getTransition(java.lang.String name)
          Gets the Transition associated with the Name.
 void setStartState(State state)
          Sets the startState attribute of the StateMachine object
 
Methods inherited from class org.apache.commons.graph.decorator.DDirectedGraph
decorateGraph, getWeight, hasConnection, maximumSpanningForest, minimumSpanningForest, setWeight, transpose
 
Methods inherited from class org.apache.commons.graph.domain.basic.DirectedGraphWrapper
getInbound, getOutbound, getSource, getTarget, setDirGraph
 
Methods inherited from class org.apache.commons.graph.domain.basic.GraphWrapper
getEdges, getEdges, getVertices, getVertices, setGraph
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.commons.graph.DirectedGraph
getInbound, getOutbound, getSource, getTarget
 
Methods inherited from interface org.apache.commons.graph.Graph
getEdges, getEdges, getVertices, getVertices
 

Field Detail

states

private java.util.Map states

transes

private java.util.Map transes

finalStates

private java.util.Set finalStates

startState

private State startState

graph

private MutableDirectedGraph graph

name

private java.lang.String name

factory

private GraphFactory factory
Constructor Detail

StateMachine

public StateMachine(java.lang.String name)
Create a new StateMachine given the name.

Parameters:
name - Name (or Namespace) of StateMachine
Method Detail

getName

public java.lang.String getName()
Gets the StateMachines name (or namespace)


addState

public void addState(State state)
              throws GraphException
Adds a State to the collection of states maintained by the machine.

Throws:
GraphException

addState

public void addState(java.lang.String name)
              throws GraphException
Creates a new State with name provided. Adds it to the machine.

Throws:
GraphException

setStartState

public void setStartState(State state)
Sets the startState attribute of the StateMachine object


addFinalState

public void addFinalState(State state)
Adds the state to the set of Final States available.


addTransition

public void addTransition(java.lang.String name,
                          java.lang.String source,
                          java.lang.String target)
                   throws GraphException
Add a Transition to the diagram with the name provided. This transition traverses from the State specified in source and the target.

Parameters:
name - Name of the Transition.
source - Name of the Source State.
target - Name of the Target State.
Throws:
GraphException

addTransition

public void addTransition(java.lang.String name,
                          State source,
                          State target)
                   throws GraphException
Adds a feature to the Transition attribute of the StateMachine object.

Parameters:
name - Name of the Transition
source - Source of the Transition
target - Target of the Transition
Throws:
GraphException

addTransition

public void addTransition(Transition trans)
                   throws GraphException
Adds a feature to the Transition attribute of the StateMachine object. Transition is expected to know its source and target.

Throws:
GraphException

getState

public State getState(java.lang.String name)
Gets the state attribute of the StateMachine object


getTransition

public Transition getTransition(java.lang.String name)
Gets the Transition associated with the Name.