summaryrefslogtreecommitdiffstats
path: root/test/bindings/java/org/uscxml/examples
diff options
context:
space:
mode:
authorStefan Radomski <github@mintwerk.de>2016-08-22 14:53:14 (GMT)
committerStefan Radomski <github@mintwerk.de>2016-08-22 14:53:14 (GMT)
commite5782b214d839fe5d8b2f527ae331a246c6e012f (patch)
tree246e5bf1143b72267791e682b1ac37991d26adbe /test/bindings/java/org/uscxml/examples
parentdb8418fb9f733ca0147cc225ce0988d7866f15cd (diff)
downloaduscxml-e5782b214d839fe5d8b2f527ae331a246c6e012f.zip
uscxml-e5782b214d839fe5d8b2f527ae331a246c6e012f.tar.gz
uscxml-e5782b214d839fe5d8b2f527ae331a246c6e012f.tar.bz2
Progress on the apache-commons wrapper
Diffstat (limited to 'test/bindings/java/org/uscxml/examples')
-rw-r--r--test/bindings/java/org/uscxml/examples/ApacheCommonsAPI.java45
-rw-r--r--test/bindings/java/org/uscxml/examples/hello-world.xml25
2 files changed, 70 insertions, 0 deletions
diff --git a/test/bindings/java/org/uscxml/examples/ApacheCommonsAPI.java b/test/bindings/java/org/uscxml/examples/ApacheCommonsAPI.java
new file mode 100644
index 0000000..4cf3de4
--- /dev/null
+++ b/test/bindings/java/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();
+ }
+
+}
diff --git a/test/bindings/java/org/uscxml/examples/hello-world.xml b/test/bindings/java/org/uscxml/examples/hello-world.xml
new file mode 100644
index 0000000..3ac168c
--- /dev/null
+++ b/test/bindings/java/org/uscxml/examples/hello-world.xml
@@ -0,0 +1,25 @@
+<?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.
+-->
+<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0"
+ initial="hello">
+
+ <final id="hello">
+ <onentry>
+ <log expr="'Hello, World!'" />
+ </onentry>
+ </final>
+
+</scxml> \ No newline at end of file