From e1eabf08cb956c26dedb875549774960b1052cd1 Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Thu, 8 Dec 2016 15:30:45 +0100 Subject: Reactivating the Java binding tests --- .../org/uscxml/apache/commons/scxml2/Context.java | 7 ++++ .../uscxml/apache/commons/scxml2/Evaluator.java | 7 ++++ .../apache/commons/scxml2/JexlEvaluator.java | 19 +++++++++ .../org/uscxml/apache/commons/scxml2/SCXML.java | 8 ++++ .../apache/commons/scxml2/SCXMLExecutor.java | 49 ++++++++++++++++++++++ .../uscxml/apache/commons/scxml2/SCXMLReader.java | 13 ++++++ .../apache/commons/scxml2/SimpleErrorReporter.java | 5 +++ .../org/uscxml/examples/ApacheCommonsAPI.java | 45 ++++++++++++++++++++ contrib/java/bindings/build.properties | 4 +- contrib/java/bindings/build.xml | 2 + .../org/uscxml/apache/commons/scxml2/Context.java | 7 ---- .../uscxml/apache/commons/scxml2/Evaluator.java | 7 ---- .../apache/commons/scxml2/JexlEvaluator.java | 19 --------- .../org/uscxml/apache/commons/scxml2/SCXML.java | 8 ---- .../apache/commons/scxml2/SCXMLExecutor.java | 49 ---------------------- .../uscxml/apache/commons/scxml2/SCXMLReader.java | 13 ------ .../apache/commons/scxml2/SimpleErrorReporter.java | 5 --- .../org/uscxml/examples/ApacheCommonsAPI.java | 45 -------------------- .../org/uscxml/tests/JexlDataModelTest.java | 14 +++---- .../common/org/uscxml/dm/jexl/JexlDataModel.java | 3 +- 20 files changed, 165 insertions(+), 164 deletions(-) create mode 100644 contrib/java/apache-commons/org/uscxml/apache/commons/scxml2/Context.java create mode 100644 contrib/java/apache-commons/org/uscxml/apache/commons/scxml2/Evaluator.java create mode 100644 contrib/java/apache-commons/org/uscxml/apache/commons/scxml2/JexlEvaluator.java create mode 100644 contrib/java/apache-commons/org/uscxml/apache/commons/scxml2/SCXML.java create mode 100644 contrib/java/apache-commons/org/uscxml/apache/commons/scxml2/SCXMLExecutor.java create mode 100644 contrib/java/apache-commons/org/uscxml/apache/commons/scxml2/SCXMLReader.java create mode 100644 contrib/java/apache-commons/org/uscxml/apache/commons/scxml2/SimpleErrorReporter.java create mode 100644 contrib/java/apache-commons/org/uscxml/examples/ApacheCommonsAPI.java delete mode 100644 contrib/java/bindings/org/uscxml/apache/commons/scxml2/Context.java delete mode 100644 contrib/java/bindings/org/uscxml/apache/commons/scxml2/Evaluator.java delete mode 100644 contrib/java/bindings/org/uscxml/apache/commons/scxml2/JexlEvaluator.java delete mode 100644 contrib/java/bindings/org/uscxml/apache/commons/scxml2/SCXML.java delete mode 100644 contrib/java/bindings/org/uscxml/apache/commons/scxml2/SCXMLExecutor.java delete mode 100644 contrib/java/bindings/org/uscxml/apache/commons/scxml2/SCXMLReader.java delete mode 100644 contrib/java/bindings/org/uscxml/apache/commons/scxml2/SimpleErrorReporter.java delete mode 100644 contrib/java/bindings/org/uscxml/examples/ApacheCommonsAPI.java diff --git a/contrib/java/apache-commons/org/uscxml/apache/commons/scxml2/Context.java b/contrib/java/apache-commons/org/uscxml/apache/commons/scxml2/Context.java new file mode 100644 index 0000000..a0208c9 --- /dev/null +++ b/contrib/java/apache-commons/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/contrib/java/apache-commons/org/uscxml/apache/commons/scxml2/Evaluator.java b/contrib/java/apache-commons/org/uscxml/apache/commons/scxml2/Evaluator.java new file mode 100644 index 0000000..5bd5642 --- /dev/null +++ b/contrib/java/apache-commons/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/contrib/java/apache-commons/org/uscxml/apache/commons/scxml2/JexlEvaluator.java b/contrib/java/apache-commons/org/uscxml/apache/commons/scxml2/JexlEvaluator.java new file mode 100644 index 0000000..127bed3 --- /dev/null +++ b/contrib/java/apache-commons/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/contrib/java/apache-commons/org/uscxml/apache/commons/scxml2/SCXML.java b/contrib/java/apache-commons/org/uscxml/apache/commons/scxml2/SCXML.java new file mode 100644 index 0000000..67e5b1f --- /dev/null +++ b/contrib/java/apache-commons/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/contrib/java/apache-commons/org/uscxml/apache/commons/scxml2/SCXMLExecutor.java b/contrib/java/apache-commons/org/uscxml/apache/commons/scxml2/SCXMLExecutor.java new file mode 100644 index 0000000..704e897 --- /dev/null +++ b/contrib/java/apache-commons/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/contrib/java/apache-commons/org/uscxml/apache/commons/scxml2/SCXMLReader.java b/contrib/java/apache-commons/org/uscxml/apache/commons/scxml2/SCXMLReader.java new file mode 100644 index 0000000..45c2a54 --- /dev/null +++ b/contrib/java/apache-commons/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/contrib/java/apache-commons/org/uscxml/apache/commons/scxml2/SimpleErrorReporter.java b/contrib/java/apache-commons/org/uscxml/apache/commons/scxml2/SimpleErrorReporter.java new file mode 100644 index 0000000..06187f8 --- /dev/null +++ b/contrib/java/apache-commons/org/uscxml/apache/commons/scxml2/SimpleErrorReporter.java @@ -0,0 +1,5 @@ +package org.uscxml.apache.commons.scxml2; + +public class SimpleErrorReporter { + +} diff --git a/contrib/java/apache-commons/org/uscxml/examples/ApacheCommonsAPI.java b/contrib/java/apache-commons/org/uscxml/examples/ApacheCommonsAPI.java new file mode 100644 index 0000000..4cf3de4 --- /dev/null +++ b/contrib/java/apache-commons/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/contrib/java/bindings/build.properties b/contrib/java/bindings/build.properties index dd0fe62..9d23ea4 100644 --- a/contrib/java/bindings/build.properties +++ b/contrib/java/bindings/build.properties @@ -5,5 +5,5 @@ uscxml.library.path=/usr/local/share/uscxml/bindings/java uscxml.jar=/usr/local/share/uscxml/bindings/uscxml.jar -jexl.jar=libs/commons-jexl3-3.0.jar -logging.jar=libs/commons-logging-1.2.jar \ No newline at end of file +jexl.jar=../libs/commons-jexl3-3.0.jar +logging.jar=../libs/commons-logging-1.2.jar \ No newline at end of file diff --git a/contrib/java/bindings/build.xml b/contrib/java/bindings/build.xml index 19d7817..d5c6db7 100644 --- a/contrib/java/bindings/build.xml +++ b/contrib/java/bindings/build.xml @@ -4,6 +4,7 @@ + @@ -21,6 +22,7 @@ + diff --git a/contrib/java/bindings/org/uscxml/apache/commons/scxml2/Context.java b/contrib/java/bindings/org/uscxml/apache/commons/scxml2/Context.java deleted file mode 100644 index a0208c9..0000000 --- a/contrib/java/bindings/org/uscxml/apache/commons/scxml2/Context.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.uscxml.apache.commons.scxml2; - -import org.uscxml.DataModel; - -public class Context { - public DataModel dm = null; -} diff --git a/contrib/java/bindings/org/uscxml/apache/commons/scxml2/Evaluator.java b/contrib/java/bindings/org/uscxml/apache/commons/scxml2/Evaluator.java deleted file mode 100644 index 5bd5642..0000000 --- a/contrib/java/bindings/org/uscxml/apache/commons/scxml2/Evaluator.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.uscxml.apache.commons.scxml2; - -public abstract class Evaluator { - - public abstract Context newContext(Object object); - -} diff --git a/contrib/java/bindings/org/uscxml/apache/commons/scxml2/JexlEvaluator.java b/contrib/java/bindings/org/uscxml/apache/commons/scxml2/JexlEvaluator.java deleted file mode 100644 index 127bed3..0000000 --- a/contrib/java/bindings/org/uscxml/apache/commons/scxml2/JexlEvaluator.java +++ /dev/null @@ -1,19 +0,0 @@ -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/contrib/java/bindings/org/uscxml/apache/commons/scxml2/SCXML.java b/contrib/java/bindings/org/uscxml/apache/commons/scxml2/SCXML.java deleted file mode 100644 index 67e5b1f..0000000 --- a/contrib/java/bindings/org/uscxml/apache/commons/scxml2/SCXML.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.uscxml.apache.commons.scxml2; - -import java.net.URL; - -public class SCXML { - public URL url = null; - -} diff --git a/contrib/java/bindings/org/uscxml/apache/commons/scxml2/SCXMLExecutor.java b/contrib/java/bindings/org/uscxml/apache/commons/scxml2/SCXMLExecutor.java deleted file mode 100644 index 704e897..0000000 --- a/contrib/java/bindings/org/uscxml/apache/commons/scxml2/SCXMLExecutor.java +++ /dev/null @@ -1,49 +0,0 @@ -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/contrib/java/bindings/org/uscxml/apache/commons/scxml2/SCXMLReader.java b/contrib/java/bindings/org/uscxml/apache/commons/scxml2/SCXMLReader.java deleted file mode 100644 index 45c2a54..0000000 --- a/contrib/java/bindings/org/uscxml/apache/commons/scxml2/SCXMLReader.java +++ /dev/null @@ -1,13 +0,0 @@ -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/contrib/java/bindings/org/uscxml/apache/commons/scxml2/SimpleErrorReporter.java b/contrib/java/bindings/org/uscxml/apache/commons/scxml2/SimpleErrorReporter.java deleted file mode 100644 index 06187f8..0000000 --- a/contrib/java/bindings/org/uscxml/apache/commons/scxml2/SimpleErrorReporter.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.uscxml.apache.commons.scxml2; - -public class SimpleErrorReporter { - -} diff --git a/contrib/java/bindings/org/uscxml/examples/ApacheCommonsAPI.java b/contrib/java/bindings/org/uscxml/examples/ApacheCommonsAPI.java deleted file mode 100644 index 4cf3de4..0000000 --- a/contrib/java/bindings/org/uscxml/examples/ApacheCommonsAPI.java +++ /dev/null @@ -1,45 +0,0 @@ -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/contrib/java/bindings/org/uscxml/tests/JexlDataModelTest.java b/contrib/java/bindings/org/uscxml/tests/JexlDataModelTest.java index da79d37..3db5b29 100644 --- a/contrib/java/bindings/org/uscxml/tests/JexlDataModelTest.java +++ b/contrib/java/bindings/org/uscxml/tests/JexlDataModelTest.java @@ -14,14 +14,14 @@ import org.uscxml.helper.TestMonitor; public class JexlDataModelTest { - public static void main(String[] args) { + public static void main(String[] args) throws MalformedURLException { 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); -// String testUri = "/Users/sradomski/Documents/TK/Code/uscxml/test/w3c/jexl/test144.scxml"; + String testUri = "/Users/sradomski/Documents/TK/Code/uscxml/test/w3c/jexl/test144.scxml"; // String testUri = "/Users/sradomski/Desktop/stopwatch.xml"; @@ -31,20 +31,20 @@ public class JexlDataModelTest { { JexlDataModel jdm = new JexlDataModel(); -// Factory.getInstance().registerDataModel(jdm); + //Factory.getInstance().registerDataModel(jdm); TestMonitor tm = new TestMonitor(); try { -// File testFile = new File(testUri); -// String testName = testFile.toURI().toURL().toString(); - String testName = "https://raw.githubusercontent.com/woonsan/commons-scxml-examples/master/stopwatch/src/main/resources/com/github/woonsan/commons/scxml/examples/stopwatch/stopwatch.xml"; + File testFile = new File(testUri); + String testName = testFile.toURI().toURL().toString(); +// String testName = "https://raw.githubusercontent.com/woonsan/commons-scxml-examples/master/stopwatch/src/main/resources/com/github/woonsan/commons/scxml/examples/stopwatch/stopwatch.xml"; System.out.println(testName); Interpreter scxml = Interpreter.fromURL(testName); - jdm.ctx.set("stopWatch", new StopWatch()); + //jdm.ctx.set("stopWatch", new StopWatch()); ActionLanguage al = new ActionLanguage(); al.setDataModel(jdm); diff --git a/contrib/java/common/org/uscxml/dm/jexl/JexlDataModel.java b/contrib/java/common/org/uscxml/dm/jexl/JexlDataModel.java index 731ceaa..0b35c29 100644 --- a/contrib/java/common/org/uscxml/dm/jexl/JexlDataModel.java +++ b/contrib/java/common/org/uscxml/dm/jexl/JexlDataModel.java @@ -76,8 +76,6 @@ public class JexlDataModel extends DataModel { public Data evalAsData(String content) { JexlExpression expr = jexl.createExpression(content); Data d = getJexlObjectAsData(expr.evaluate(ctx)); -// d.setAtom(expr.getParsedText()); -// d.setType(Data.Type.VERBATIM); return d; } @@ -253,6 +251,7 @@ public class JexlDataModel extends DataModel { private static Set> getWrapperTypes() { Set> ret = new HashSet>(); + ret.add(String.class); ret.add(Boolean.class); ret.add(Character.class); ret.add(Byte.class); -- cgit v0.12