diff options
author | Stefan Radomski <github@mintwerk.de> | 2016-11-28 18:21:13 (GMT) |
---|---|---|
committer | Stefan Radomski <github@mintwerk.de> | 2016-11-28 18:21:13 (GMT) |
commit | 044fefae99320aa575523eab90032f9e9d8b498c (patch) | |
tree | 6cf9abc9828265a7ca293a56c9593fca485fdad5 /contrib/java/bindings/org/uscxml/examples/ApacheCommonsAPI.java | |
parent | 5c09b82c85430839afbd7d89f00ff697aec9ff77 (diff) | |
download | uscxml-044fefae99320aa575523eab90032f9e9d8b498c.zip uscxml-044fefae99320aa575523eab90032f9e9d8b498c.tar.gz uscxml-044fefae99320aa575523eab90032f9e9d8b498c.tar.bz2 |
Moved java binding
Diffstat (limited to 'contrib/java/bindings/org/uscxml/examples/ApacheCommonsAPI.java')
-rw-r--r-- | contrib/java/bindings/org/uscxml/examples/ApacheCommonsAPI.java | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/contrib/java/bindings/org/uscxml/examples/ApacheCommonsAPI.java b/contrib/java/bindings/org/uscxml/examples/ApacheCommonsAPI.java new file mode 100644 index 0000000..4cf3de4 --- /dev/null +++ b/contrib/java/bindings/org/uscxml/examples/ApacheCommonsAPI.java @@ -0,0 +1,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(); + } + +} |