Thursday, April 28, 2011

XML for UML State diagrams

W3C again...


"..Harel State Tables are a state machine notation that was developed by the mathematician David Harel [Harel and Politi] and is included in UML [UML 2.3]. They offer a clean and well-thought out semantics for sophisticated constructs such as a parallel states. They have been defined as a graphical specification language, however, and hence do not have an XML representation. The goal of this document is to combine Harel semantics with an XML syntax that is a logical extension of CCXML's state and event notation.."
State Chart XML (SCXML): State Machine Notation for Control Abstraction

I like the microwave example:
<scxml datamodel="ecmascript" initial="off" version="1.0" xmlns="http://www.w3.org/2005/07/scxml">

  
  <datamodel>
    <data expr="5" id="cook_time">
    <data expr="true" id="door_closed">
    <data expr="0" id="timer">
  </data></data></data></datamodel>

  <state id="off">
    
    <transition event="turn.on" target="on">
  </transition></state>

  <state id="on">
    <initial>
        <transition target="idle">
    </transition></initial>
    

    <transition event="turn.off" target="off">
    <transition cond="timer >= cook_time" target="off">

    <state id="idle">
      
      <transition cond="door_closed" target="cooking">
      <transition event="door.close" target="cooking">
        <assign expr="true" location="door_closed">
        
      </assign></transition>
    </transition></state>

    <state id="cooking">
      <transition event="door.open" target="idle">
        <assign expr="false" location="door_closed">
      </assign></transition>

      
      <transition event="time">
        <assign expr="timer + 1" location="timer">
      </assign></transition>
    </state>

  </transition></transition></state>

</scxml>

No comments: