Search code examples
javascxml

How do I verify that my SCXML defines a valid state machine?


I've just started looking at defining state machines and SCXML looks attractive, especially the Apache Commons SCXML for Java. Obviously I can validate the XML (with an appropriate XSD).

However I can't obviously find any way to verify that the defined state machine is valid (no dead-ends, no unreachable states, etc).

But how can I verify a defined state-machine before I execute it? In particular I am interested in tools that can integrated into a build tool-chain (i.e. from the command-line).


Solution

  • The uscxml-analyze tool from the uSCXML distribution will do just that:

    $ uscxml-browser -c ../../test/w3c/ecma/test144.scxml
    

    It checks for a whole bunch of issues:

    • Required attributes
    • Valid parent elements
    • Valid default history configurations
    • Valid initial transition
    • Valid initial attributes
    • Unreachable state hierarchies
    • Uniqueness of state id attribute
    • Valid targets for transitions
    • Redundant / unselectable transitions
    • Superfluous history elements
    • Legal configuration of target sets
    • A bunch of attribute / element combination constraints
    • Valid syntax of data-model expressions

    The uSCXML interpreter will also check for cycles within a macro-step during interpretation.