diff options
author | Stefan Radomski <github@mintwerk.de> | 2016-08-22 14:53:14 (GMT) |
---|---|---|
committer | Stefan Radomski <github@mintwerk.de> | 2016-08-22 14:53:14 (GMT) |
commit | e5782b214d839fe5d8b2f527ae331a246c6e012f (patch) | |
tree | 246e5bf1143b72267791e682b1ac37991d26adbe /test/bindings | |
parent | db8418fb9f733ca0147cc225ce0988d7866f15cd (diff) | |
download | uscxml-e5782b214d839fe5d8b2f527ae331a246c6e012f.zip uscxml-e5782b214d839fe5d8b2f527ae331a246c6e012f.tar.gz uscxml-e5782b214d839fe5d8b2f527ae331a246c6e012f.tar.bz2 |
Progress on the apache-commons wrapper
Diffstat (limited to 'test/bindings')
10 files changed, 184 insertions, 1 deletions
diff --git a/test/bindings/java/org/uscxml/apache/commons/scxml2/Context.java b/test/bindings/java/org/uscxml/apache/commons/scxml2/Context.java new file mode 100644 index 0000000..a0208c9 --- /dev/null +++ b/test/bindings/java/org/uscxml/apache/commons/scxml2/Context.java @@ -0,0 +1,7 @@ +package org.uscxml.apache.commons.scxml2; + +import org.uscxml.DataModel; + +public class Context { + public DataModel dm = null; +} diff --git a/test/bindings/java/org/uscxml/apache/commons/scxml2/Evaluator.java b/test/bindings/java/org/uscxml/apache/commons/scxml2/Evaluator.java new file mode 100644 index 0000000..5bd5642 --- /dev/null +++ b/test/bindings/java/org/uscxml/apache/commons/scxml2/Evaluator.java @@ -0,0 +1,7 @@ +package org.uscxml.apache.commons.scxml2; + +public abstract class Evaluator { + + public abstract Context newContext(Object object); + +} diff --git a/test/bindings/java/org/uscxml/apache/commons/scxml2/JexlEvaluator.java b/test/bindings/java/org/uscxml/apache/commons/scxml2/JexlEvaluator.java new file mode 100644 index 0000000..e50a259 --- /dev/null +++ b/test/bindings/java/org/uscxml/apache/commons/scxml2/JexlEvaluator.java @@ -0,0 +1,19 @@ +package org.uscxml.apache.commons.scxml2; + +import org.uscxml.Factory; +import org.uscxml.dm.jexl.JEXLDataModel; + +public class JexlEvaluator extends Evaluator { + + public JexlEvaluator() { + + } + + @Override + public Context newContext(Object object) { + // TODO Auto-generated method stub + Context ctx = new Context(); + ctx.dm = new JEXLDataModel(); + return ctx; + } +} diff --git a/test/bindings/java/org/uscxml/apache/commons/scxml2/SCXML.java b/test/bindings/java/org/uscxml/apache/commons/scxml2/SCXML.java new file mode 100644 index 0000000..67e5b1f --- /dev/null +++ b/test/bindings/java/org/uscxml/apache/commons/scxml2/SCXML.java @@ -0,0 +1,8 @@ +package org.uscxml.apache.commons.scxml2; + +import java.net.URL; + +public class SCXML { + public URL url = null; + +} diff --git a/test/bindings/java/org/uscxml/apache/commons/scxml2/SCXMLExecutor.java b/test/bindings/java/org/uscxml/apache/commons/scxml2/SCXMLExecutor.java new file mode 100644 index 0000000..704e897 --- /dev/null +++ b/test/bindings/java/org/uscxml/apache/commons/scxml2/SCXMLExecutor.java @@ -0,0 +1,49 @@ +package org.uscxml.apache.commons.scxml2; + +import java.net.URL; + +import org.uscxml.ActionLanguage; +import org.uscxml.Factory; +import org.uscxml.Interpreter; +import org.uscxml.InterpreterException; +import org.uscxml.InterpreterState; +import org.uscxml.helper.TestMonitor; + +public class SCXMLExecutor { + + public Interpreter interpreter = null; + public URL sourceURL = null; + public ActionLanguage al = new ActionLanguage(); + + public SCXMLExecutor(Evaluator evaluator, Object object, SimpleErrorReporter simpleErrorReporter) { + // TODO Auto-generated constructor stub + } + + public void setStateMachine(SCXML scxml) { + sourceURL = scxml.url; + } + + public void setRootContext(Context rootContext) { + al.setDataModel(rootContext.dm); + } + + public void go() { + try { + interpreter = Interpreter.fromURL(sourceURL.toString()); + interpreter.setActionLanguage(al); + + TestMonitor tm = new TestMonitor(); + interpreter.addMonitor(tm); + + InterpreterState state = InterpreterState.USCXML_UNDEF; + while(state != InterpreterState.USCXML_FINISHED) { + interpreter.step(); + } + + } catch (InterpreterException e) { + e.printStackTrace(); + } + + } + +} diff --git a/test/bindings/java/org/uscxml/apache/commons/scxml2/SCXMLReader.java b/test/bindings/java/org/uscxml/apache/commons/scxml2/SCXMLReader.java new file mode 100644 index 0000000..45c2a54 --- /dev/null +++ b/test/bindings/java/org/uscxml/apache/commons/scxml2/SCXMLReader.java @@ -0,0 +1,13 @@ +package org.uscxml.apache.commons.scxml2; + +import java.net.URL; + +public class SCXMLReader { + + public static SCXML read(URL scxml) { + SCXML foo = new SCXML(); + foo.url = scxml; + return foo; + } + +} diff --git a/test/bindings/java/org/uscxml/apache/commons/scxml2/SimpleErrorReporter.java b/test/bindings/java/org/uscxml/apache/commons/scxml2/SimpleErrorReporter.java new file mode 100644 index 0000000..06187f8 --- /dev/null +++ b/test/bindings/java/org/uscxml/apache/commons/scxml2/SimpleErrorReporter.java @@ -0,0 +1,5 @@ +package org.uscxml.apache.commons.scxml2; + +public class SimpleErrorReporter { + +} diff --git a/test/bindings/java/org/uscxml/dm/jexl/JEXLDataModel.java b/test/bindings/java/org/uscxml/dm/jexl/JEXLDataModel.java index 33da96c..5564d63 100644 --- a/test/bindings/java/org/uscxml/dm/jexl/JEXLDataModel.java +++ b/test/bindings/java/org/uscxml/dm/jexl/JEXLDataModel.java @@ -72,7 +72,12 @@ public class JEXLDataModel extends DataModel { @Override public Data evalAsData(String content) { - return new Data(); + JexlExpression expr = jexl.createExpression(content); + System.out.println(); + Data d = new Data(); + d.setAtom(expr.getParsedText()); + d.setType(Data.Type.VERBATIM); + return d; } @Override 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 |