Saturday, August 29, 2009

Using UML2 Tools for SCXML

UML2 Tools from the Eclipse Model Development Tools (MDT) project provides a set of GMF-based (Graphical Modeling Framework) editors for viewing and editing UML models. After a quick install on Galileo, it was time for some experimentation. The diagramming feature-set is certainly more constrained than some of the other proprietary products in the space, particularly in the context of executable content in state machines. The model format used is XMI (XML Metadata Interchange) and there have been a couple of requests on Apache Commons user mailing list to get a stylesheet going to convert to State Chart XML (SCXML). r808257 adds the beginnings of such a stylesheet to the Commons SCXML extras.

A UML2 state machine diagram can actually contain multiple disconnected state machines. Since each needs to be styled to its own SCXML document, that clearly ruled in favor of using the less pervasive XSLT 2.0, for <xsl:result-document>. Which meant support for if-then-else in the XPaths came along, which turned out quite handy.

The transformation itself isn't too bad, once its bootstrapped. At the onset, to get the SCXML ball rolling, the first order of business is to determine whether the state machine has top level orthogonal states (<region>s in XMI). The second is to determine the initial state for each of the orthogonal states, which in XMI turns out to be a subvertex of type pseudostate with no value in the kind attribute i.e. subvertex[@xmi:type='uml:Pseudostate'][empty(@kind)]

And that gives us:






















Once we get down from the region to the subvertex itself, the transformation is a straightforward switch on the type of the state to generate (abridged via ellipsis):












































With increased UML2 Tools capabilities for the state machine diagram editor, many of us may soon have easy access to the model to middleware transformation below:

SCXML development