blob: 4cf3de4841e982ee57b39d98e51fec7684c1e860 (
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
|
package org.uscxml.examples;
import java.net.URL;
//import org.uscxml.apache.commons.scxml2.*;
import org.apache.commons.scxml2.*;
import org.apache.commons.scxml2.env.SimpleErrorReporter;
import org.apache.commons.scxml2.env.jexl.JexlEvaluator;
import org.apache.commons.scxml2.io.SCXMLReader;
import org.apache.commons.scxml2.model.SCXML;
public class ApacheCommonsAPI {
// SCXML model source URL
private static final URL SCXML = ApacheCommonsAPI.class.getResource("hello-world.xml");
public static void main(String [] args) throws Exception {
String uSCXMLLibPath = "/Users/sradomski/Documents/TK/Code/uscxml/build/cli/lib/libuscxmlNativeJava.jnilib";
if (System.getenv().containsKey("USCXML_JAVA_LIB")) {
uSCXMLLibPath = System.getenv("USCXML_JAVA_LIB");
}
System.load(uSCXMLLibPath);
// evaluator instance which is used by SCXML engine to evaluate expressions in SCXML
Evaluator evaluator = new JexlEvaluator();
// engine to execute the scxml instance
SCXMLExecutor executor = new SCXMLExecutor(evaluator, null, new SimpleErrorReporter());
// parse SCXML URL into SCXML model
SCXML scxml = SCXMLReader.read(SCXML);
// set state machine (scxml instance) to execute
executor.setStateMachine(scxml);
// create root context storing variables and being used by evaluator
Context rootContext = evaluator.newContext(null);
// set the root context for the engine
executor.setRootContext(rootContext);
// initiate the execution of the state machine
executor.go();
}
}
|