The java state machine context

The context class is the fundamental class generated and directly used by your code. The following documentation explains how the context class is named, what are the constructor parameters, how to perform the second phase initialization with enterInitialState(), and finally, how to find out that the context has ended.

Context name

By default the context class name is based on the filename without extension, then it is suffixed by "Context":

MyStateMachine.fsmjava => MyStateMachineContext

It is also possible to set the context class name with the context element:

Context contructor

The constructor parameters are defined by the object tag in the settings element:

Here is the java code that shows how to create an instance of the context:


After the creation of an instance of the context, one may invoke the method enterInitialState() to call the onEntry() methods the from root state to the initial state.

Consider the Led state machine example:

In this case, enterInitialState() will call led.doOff() to make sure the led is switched off.

Context ending and final state

Final states are states which have the attribute kind set to final:

To find out when the context ends, call the context member function setEndHandler and create an anonymous class that implements the interface IContextEnd