blob: fcad1861957dad23d938885e4470c6580c54d460 (
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
|
package org.uscxml.tests.datamodel;
import org.uscxml.Interpreter;
import org.uscxml.InterpreterException;
import org.uscxml.InterpreterState;
public class TestDataModelAccess {
public static void main(String[] args) throws InterpreterException {
// load JNI library from build directory
System.load("/Users/sradomski/Documents/TK/Code/uscxml/build/cli/lib/libuscxmlNativeJava64.jnilib");
{
// initializing and accessing complex data
String xml =
"<scxml datamodel=\"ecmascript\">" +
" <script src=\"http://uscxml.tk.informatik.tu-darmstadt.de/scripts/dump.js\" />" +
" <datamodel>" +
" <data id=\"cmplx1\"><![CDATA[" +
" { foo: \"bar\", baz: 12 }" +
" ]]></data>" +
" </datamodel>" +
" <state id=\"s1\">" +
" <onentry>" +
" <log label=\"cmplx1\" expr=\"cmplx1.foo\" />" +
" <log label=\"cmplx1\" expr=\"cmplx1.baz\" />" +
" <script>dump(cmplx1)</script>" +
" </onentry>" +
" <transition target=\"done\" />" +
" </state>" +
" <final id=\"done\" />" +
"</scxml>";
Interpreter interpreter = Interpreter.fromXML(xml);
InterpreterState state;
do {
state = interpreter.step();
// after first microstep, data model is initialized and we can access cmplx1
if (state == InterpreterState.USCXML_MICROSTEPPED)
System.out.println(interpreter.getDataModel().getStringAsData("cmplx1").toString());
} while (state != InterpreterState.USCXML_FINISHED &&
state != InterpreterState.USCXML_DESTROYED);
}
{
// initializing and accessing complex data via data.src
String xml =
"<scxml datamodel=\"ecmascript\">" +
" <script src=\"http://uscxml.tk.informatik.tu-darmstadt.de/scripts/dump.js\" />" +
" <datamodel>" +
" <data id=\"cmplx1\" src=\"TestData.json\" />" +
" <data id=\"cmplx2\" src=\"TestData.xml\" />" +
" </datamodel>" +
" <state id=\"s1\">" +
" <onentry>" +
" <!-- BUG script>" +
" var node = document.evaluate('//to', cmplx2);" +
" dump(node);" +
" </script -->" +
" <log label=\"cmplx1\" expr=\"cmplx1.name\" />" +
" <log label=\"cmplx1\" expr=\"cmplx1.price\" />" +
" <script>dump(cmplx1)</script>" +
" </onentry>" +
" <transition target=\"done\" />" +
" </state>" +
" <final id=\"done\" />" +
"</scxml>";
Interpreter interpreter = Interpreter.fromXML(xml);
interpreter.setSourceURI(TestDataModelAccess.class.getResource("").toString());
InterpreterState state;
do {
state = interpreter.step();
// after first microstep, data model is initialized and we can access cmplx1
if (state == InterpreterState.USCXML_MICROSTEPPED)
System.out.println(interpreter.getDataModel().getStringAsData("cmplx1").toString());
} while (state != InterpreterState.USCXML_FINISHED &&
state != InterpreterState.USCXML_DESTROYED);
}
}
}
|