Class
caplin.trading.statemachine

StateMachineFactory

The StateMachineFactory is responsible providing caplin.trading.statemachine.StateMachines, which are constructed from an XML configuration file (provided with #loadModels. A StateMachine instance is required to construct a caplin.trading.trademodel.Trade instance.

The XML configuration file defines the States and Transitions within the trade model. Below is an example XML configuration file for the ESP trading protocol.
<?xml version="1.0" encoding="UTF-8" ?>
<tradeModels> 
  <tradeModel name="ESP" initialState="Initial">
	 <state name="Initial">
	   <transition target="OpenSent" trigger="Open" source="client"/>
	 </state>
	 <state name="OpenSent" timeout="10" timeoutEvent="Timeout">
	   <transition target="Opened" trigger="OpenAck" source="server"/>
	 </state>
	 <state name="Opened">
	   <transition target="TradeConfirmed" trigger="TradeConfirmation"  source="server"/>
	   <transition target="TradePassed" trigger="Pass" source="server"/>
	   <transition target="TradeExpired" trigger="Expired" source="server"/>
	 </state>
	 <state name="TradeConfirmed">
	 </state>
	 <state name="TradePassed">
	 </state>
	 <state name="TradeExpired">
	 </state>
  </tradeModel>
</tradeModels>

The XML configuration file contains all possible routes a trade can traverse on its way to completion, whether or not it is successful. There are a number of states, each containing a number of transitions that cause the trade model to move to other states. A transition defines the message that will cause the change to occur, and the new state the model will move into. Transition events correlate to either server-side or client-side trade messages.

Constructor Summary

Attributes Name and Description
caplin.trading.statemachine.StateMachineFactory()

Constructs a caplin.trading.statemachine.StateMachineFactory.

Method Summary

Attributes Name and Description
caplin.trading.statemachine.StateMachine getStateMachine(String sModelName)

Returns a new StateMachine for the specified model name.

void loadModels(String sFileUrl)

Loads the models into the factory from the given file at the specified url.

void loadModelsFromXml(String sXmlString)

Loads the models into the factory from the specified XML string.

void loadModelsFromXmlElement( XML)

Loads the models into the factory from the specified XML DOM element.

Constructor Detail

caplin.trading.statemachine.StateMachineFactory()

Constructs a caplin.trading.statemachine.StateMachineFactory.

Method Detail

caplin.trading.statemachine.StateMachine getStateMachine(String sModelName)

Returns a new StateMachine for the specified model name.

Parameters
String sModelName The model name for the wanted StateMachine.
Throws
caplin.core.Error
If the specified model does not exist.
Returns
A new state machine for the specified model name, set to the initial state.

void loadModels(String sFileUrl)

Loads the models into the factory from the given file at the specified url.

Parameters
String sFileUrl The URL of the file to load the models from.
Throws
caplin.core.Error
If more than one model with the same name is defined in the XML, or if there was an error parsing the XML.
See
#loadModelsFromXml

void loadModelsFromXml(String sXmlString)

Loads the models into the factory from the specified XML string.

Parameters
String sXmlString The XML to load the models from.
Throws
caplin.core.Error
If more than one model with the same name is defined in the XML, or if there was an error parsing the XML.
See
#loadModels

void loadModelsFromXmlElement( XML)

Loads the models into the factory from the specified XML DOM element.

Parameters
XML DOM element to load the models from.
Throws
caplin.core.Error
If more than one model with the same name is defined in the XML, or if there was an error parsing the XML.
See
#loadModels