summaryrefslogtreecommitdiffstats
path: root/test/samples/apache/datamodel-01.xml
blob: cc874fb8308627bdd12b3a0fdc455f40679f2ab6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?xml version="1.0"?>
<!--
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
-->
<!-- A fictitious state machine used by test cases.
     Meant to illustrate the usage of SCXML <datamodel> element
     and the Commons SCXML Data() function -->
<scxml xmlns="http://www.w3.org/2005/07/scxml"
       version="1.0"
       initialstate="main">

    <!-- Root or document datamodel -->
    <datamodel>
        <data id="docdata">
            <root xmlns="">
                <foo>foo</foo>
            </root>
        </data>
    </datamodel>

    <state id="main">

        <initial>
            <transition target="ten"/>
        </initial>

        <!-- datamodel scoped to state "main" -->
        <datamodel>
            <data id="mainvar" expr="${0}" />
            <data id="maindata">
                <root xmlns="">
                    <foo>
                        <bar>bar</bar>
                    </foo>
                </root>
            </data>
        </datamodel>

        <state id="ten">
            <onentry>
                <!-- Assign Usage 1: name is previously defined
                      <var> or degenerate <data> (as in this case) -->
                <assign name="mainvar" expr="${10}" />
            </onentry>
            <!-- Commons SCXML defines a Data() function to use in conjunction
                 with the Commons EL expression language. The
                 first argument is the named XML data tree and the second is
                 the XPath expression to a node whose value is to be
                 examined  -->
            <transition event="ten.done"
             cond="${mainvar eq 10 and Data(maindata,'root/foo/bar') eq 'bar'}"
             target="twenty" />
            <onexit>
                <!-- Assign Usage 2: location must point to an existing
                      node  -->
                <assign location="${Data(maindata,'root/foo/bar')}" expr="baz" />
            </onexit>
        </state>

        <state id="twenty">
            <onentry>
                <assign name="mainvar" expr="${20}" />
            </onentry>
            <transition event="twenty.done"
             cond="${Data(maindata,'root/foo/bar') eq 'baz' and mainvar eq 20}"
             target="thirty" />
            <onexit>
                <!-- Assign Usage 3: location points to an existing
                      node, and expr points to an existing node.
                      In this case, location adopts expr's child nodes.  -->
                <assign location="${Data(docdata,'root/foo')}"
                        expr="${Data(maindata,'root/foo')}" />
                <assign location="${Data(docdata,'root/foo/bar')}"
                        expr="${10}" />
            </onexit>
        </state>

        <state id="thirty">
            <!-- Arithmetic operations are possible with results from
                 the Data() function. Note that data "docdata"
                 did not have a node at 'root/foo/bar' to begin with,
                 the XML tree was manipulated by the <assign> above -->
            <transition event="thirty.done"
             cond="${Data(docdata,'root/foo/bar') gt 5}"
             target="forty" />
        </state>

        <state id="forty" final="true" />

    </state>

</scxml>