StateMachine Class

com.beasys.commerce.foundation
StateMachine Class

public class StateMachine

    extends Object
    implements Workflow

This is the reference implemenation of a Workflow object. It provides a simple implemenation based on a set of states and transitions.

Related Topics

Workflow


Hierarchy
Object
  StateMachine
All Implemented Interfaces

BusinessSmartComponent, Serializable, Workflow
Direct Known Subclasses

PaymentWorkflow

Field Summary

protected State
currentState
State
protected State
initialState
State
protected TreeSet
states
TreeSet
protected String
TRANSITION_KEY_TOKEN
String
protected TreeMap
transitions
TreeMap
 

Constructor Summary

StateMachine()

Use WorkflowHome.create("com.beasys.commerce.foundation.StateMachine") to instantiate the workflow.
 

Method Summary

protected void
addTransition(Transition t)
public String
doTransition(String transitionName)
Given the name of the transition, perform the transition and return the new state.
public WorkflowContext
getContext()
Get the context of the Workflow.
public String
getCurrentStateName()
Get the name of the current state
public String
getInitialStateName()
Get the name of the initial state
public String[]
getOutgoingTransitions(String state)
Given the name of the state, return all transitions starting from that state
public String[]
getStateNames()
Get all State names in an array of Strings.
public String[]
getTransitionNames()
Get all transition names in an array of Strings.
public String
lookAheadTransition(String transition)
Given the name of the transition, look ahead the transition and return the predicted new state.
public void
reset()
Reset the current workflow state to the initial state
public void
setContext(WorkflowContext workflowContext)
Set the new context for the underlying workflow engine.
 
Methods from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
   
Methods from interface com.beasys.commerce.foundation.Workflow
doTransition, getContext, getCurrentStateName, getInitialStateName, getOutgoingTransitions, getStateNames, getTransitionNames, lookAheadTransition, reset, setContext
 

Field Detail

currentState

protected State currentState


initialState

protected State initialState


states

protected TreeSet states


TRANSITION_KEY_TOKEN

protected String TRANSITION_KEY_TOKEN


transitions

protected TreeMap transitions

 

Constructor Detail

StateMachine

public StateMachine()
Use WorkflowHome.create("com.beasys.commerce.foundation.StateMachine") to instantiate the workflow.
 

Method Detail

addTransition(Transition) Method

protected void addTransition(Transition t)

doTransition(String) Method

public String doTransition(String transitionName)
throws IllegalWorkflowTransitionException
Given the name of the transition, perform the transition and return the new state. If transition is invalid for the current state of the state machine, throw IllegalWorkflowTransitionException

Parameters

transitionName
the name of the transition to be performed

Returns

new state.

Exceptions

IllegalWorkflowTransitionException
if the transition is invalid

getContext() Method

public WorkflowContext getContext()
Get the context of the Workflow. This method should be used only by the classes that implement the Workflow interface.

Returns

WorkflowContext

getCurrentStateName() Method

public String getCurrentStateName()
Get the name of the current state

Returns

current state name

getInitialStateName() Method

public String getInitialStateName()
Get the name of the initial state

Returns

initial state name

getOutgoingTransitions(String) Method

public String[] getOutgoingTransitions(String state)
throws IllegalWorkflowTransitionException
Given the name of the state, return all transitions starting from that state

Parameters

state
the name of the state

Returns

a String[] of transition names.

Exceptions

IllegalWorkflowTransitionException
if the transition is invalid

getStateNames() Method

public String[] getStateNames()
Get all State names in an array of Strings.

Returns

String[] an array of Strings

getTransitionNames() Method

public String[] getTransitionNames()
Get all transition names in an array of Strings.

Returns

String[] an array of Strings

lookAheadTransition(String) Method

public String lookAheadTransition(String transition)
throws IllegalWorkflowTransitionException
Given the name of the transition, look ahead the transition and return the predicted new state. If transition is invalid for the current state of the state machine, throw IllegalWorkflowTransitionException.

Parameters

transition
the name of the transition to be performed

Returns

predicted new state.

Exceptions

IllegalWorkflowTransitionException
if the transition is invalid

reset() Method

public void reset()
Reset the current workflow state to the initial state


setContext(WorkflowContext) Method

public void setContext(WorkflowContext workflowContext)
Set the new context for the underlying workflow engine. This method should be used only by the classes that implement the Workflow interface.

Parameters

workflowContext
the new context for the underlying workflow engine.