SCXML domain

YAKINDU Statechart Tools Professional Edition comes with an SCXML domain which allows to generate SCXML code from your statechart, as well as to simulate and test it in a way that is compliant to the SCXML execution semantics.

SCXML, short for State Chart XML, is a statechart interchange format. It is based on XML and has been standardized by the W3C. This standardization makes statecharts highly portable and independent of a particular implementation. The prerequisite is of course that the respective execution environment corresponds to the SCXML specification.

The current version of the specification was released by the W3C in September 2015. A “hello world” in SCXML looks like this:

<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" initial="hello">
  <final id="hello">
    <onentry>
      <log expr="'hello world'" />
    </onentry>
  </final>
</scxml>

The XML defines all the states, transitions, events and variables used in the state machine. Besides the state machine’s structural elements, the SCXML standard also defines the execution semantics of that state machine. And this is one of the biggest advantages of SCXML – the same statechart model can run on different SCXML engines on different platforms and it always behaves in exactly the same way – as long as the engines conform to the specified execution semantics.

SCXML is supported on nearly all platforms. For Java, Apache Commons SCXML is the most popular SCXML Engine. There are even SCXML engines written in JavaScript to be used in web applications, like SCION. Another very popular platform that uses SCXML for Human Machine Interfaces is the SCXML Interpreter for Qt.

To use the SCXML domain, just select it on the domain selection page when creating a new statechart. Alternatively, you can select it in the statechart’s property view. When using the SCXML domain, everything will by fully compliant with the SCXML standard. We adapted the built-in simulation engine to reflect the SCXML execution semantics, and of course the SCTUnit framework also supports the SCXML standard. Thus, you can be sure that your SCTUnit test results exactly reflect the behavior of the SCXML engine of your choice.

SCXML code generation

Generating SCXML code works like with any other code generator. You need to create a generator model and select the SCXML code generator. Please note, that your statechart must have the SCXML domain enabled.

In the generator model, you need to specify the target folder for the generated XML file. For this, you can use the Outlet feature like for any other code generator in YAKINDU Statechart Tools:

GeneratorModel for yakindu::scxml {

    statechart example {

        feature Outlet {
            targetProject = "scxml.example"
            targetFolder = "gen"
        }
    }
}

This example will generate the XML file into the „gen” folder of your „scxml.example” project.

You can also omit the targetProject attribute and specify a path on your file system. The path can be absolute or relative to the generator model location.

Simulating and testing SCXML statecharts

Statecharts with the SCXML domain can also be simulated in the same way standard statecharts are simulated. The only difference is that the YAKINDU simulation engine will use the Apache Commons SCXML engine under the hood. This ensures that the simulation shows the same behavior as when using the SCXML model in other contexts. The same holds for using our test framework SCTUnit with an SCXML statechart.