diff options
Diffstat (limited to 'test/bindings/java')
5 files changed, 63 insertions, 27 deletions
diff --git a/test/bindings/java/org/uscxml/apache/commons/scxml2/JexlEvaluator.java b/test/bindings/java/org/uscxml/apache/commons/scxml2/JexlEvaluator.java index e50a259..127bed3 100644 --- a/test/bindings/java/org/uscxml/apache/commons/scxml2/JexlEvaluator.java +++ b/test/bindings/java/org/uscxml/apache/commons/scxml2/JexlEvaluator.java @@ -1,7 +1,7 @@ package org.uscxml.apache.commons.scxml2; import org.uscxml.Factory; -import org.uscxml.dm.jexl.JEXLDataModel; +import org.uscxml.dm.jexl.JexlDataModel; public class JexlEvaluator extends Evaluator { @@ -13,7 +13,7 @@ public class JexlEvaluator extends Evaluator { public Context newContext(Object object) { // TODO Auto-generated method stub Context ctx = new Context(); - ctx.dm = new JEXLDataModel(); + ctx.dm = new JexlDataModel(); return ctx; } } diff --git a/test/bindings/java/org/uscxml/dm/jexl/JEXLDataModel.java b/test/bindings/java/org/uscxml/dm/jexl/JEXLDataModel.java index 5564d63..cd9d175 100644 --- a/test/bindings/java/org/uscxml/dm/jexl/JEXLDataModel.java +++ b/test/bindings/java/org/uscxml/dm/jexl/JEXLDataModel.java @@ -10,7 +10,6 @@ import java.util.Map; import java.util.Set; import org.apache.commons.jexl3.JexlBuilder; -import org.apache.commons.jexl3.JexlContext; import org.apache.commons.jexl3.JexlEngine; import org.apache.commons.jexl3.JexlException; import org.apache.commons.jexl3.JexlExpression; @@ -19,18 +18,22 @@ import org.uscxml.Data; import org.uscxml.DataList; import org.uscxml.DataMap; import org.uscxml.DataModel; +import org.uscxml.DataModelExtension; import org.uscxml.ErrorEvent; import org.uscxml.Event; import org.uscxml.StringList; import org.uscxml.StringVector; -public class JEXLDataModel extends DataModel { +public class JexlDataModel extends DataModel { protected static final JexlEngine jexl = new JexlBuilder().cache(512).strict(true).silent(false).create(); - protected JexlContext ctx; - - - + public MapContext ctx = new MapContext(); + + @Override + public void addExtension(DataModelExtension ext) { + throw new UnsupportedOperationException("Cannot add extensions to the jexl datamodel"); + } + @Override public StringList getNames() { StringList names = new StringList(); @@ -40,8 +43,7 @@ public class JEXLDataModel extends DataModel { @Override public DataModel create() { - JEXLDataModel dm = new JEXLDataModel(); - dm.ctx = new MapContext(); + JexlDataModel dm = new JexlDataModel(); return dm; } @@ -73,10 +75,9 @@ public class JEXLDataModel extends DataModel { @Override public Data evalAsData(String content) { JexlExpression expr = jexl.createExpression(content); - System.out.println(); - Data d = new Data(); - d.setAtom(expr.getParsedText()); - d.setType(Data.Type.VERBATIM); + Data d = getJexlObjectAsData(expr.evaluate(ctx)); +// d.setAtom(expr.getParsedText()); +// d.setType(Data.Type.VERBATIM); return d; } diff --git a/test/bindings/java/org/uscxml/examples/DataModelExample.java b/test/bindings/java/org/uscxml/examples/DataModelExample.java index e6ad619..bba64eb 100644 --- a/test/bindings/java/org/uscxml/examples/DataModelExample.java +++ b/test/bindings/java/org/uscxml/examples/DataModelExample.java @@ -7,7 +7,7 @@ import org.uscxml.Factory; import org.uscxml.Interpreter; import org.uscxml.InterpreterException; import org.uscxml.InterpreterState; -import org.uscxml.dm.jexl.JEXLDataModel; +import org.uscxml.dm.jexl.JexlDataModel; import org.uscxml.helper.TestMonitor; public class DataModelExample { @@ -20,7 +20,7 @@ public class DataModelExample { System.load(uSCXMLLibPath); - JEXLDataModel jdm = new JEXLDataModel(); + JexlDataModel jdm = new JexlDataModel(); Factory.getInstance().registerDataModel(jdm);; TestMonitor tm = new TestMonitor(); diff --git a/test/bindings/java/org/uscxml/helper/StopWatch.java b/test/bindings/java/org/uscxml/helper/StopWatch.java new file mode 100644 index 0000000..4123ba1 --- /dev/null +++ b/test/bindings/java/org/uscxml/helper/StopWatch.java @@ -0,0 +1,22 @@ +package org.uscxml.helper; + +import org.uscxml.Data; +import org.uscxml.DataModelExtension; + +public class StopWatch { + + public StopWatch() { + } + + public void reset() { + System.out.println("RESET"); + } + + public void start() { + System.out.println("START"); + } + public void stop() { + System.out.println("STOP"); + } + +} diff --git a/test/bindings/java/org/uscxml/tests/JexlDataModelTest.java b/test/bindings/java/org/uscxml/tests/JexlDataModelTest.java index 876feb2..da79d37 100644 --- a/test/bindings/java/org/uscxml/tests/JexlDataModelTest.java +++ b/test/bindings/java/org/uscxml/tests/JexlDataModelTest.java @@ -3,11 +3,13 @@ package org.uscxml.tests; import java.io.File; import java.net.MalformedURLException; +import org.uscxml.ActionLanguage; import org.uscxml.Factory; import org.uscxml.Interpreter; import org.uscxml.InterpreterException; import org.uscxml.InterpreterState; -import org.uscxml.dm.jexl.JEXLDataModel; +import org.uscxml.dm.jexl.JexlDataModel; +import org.uscxml.helper.StopWatch; import org.uscxml.helper.TestMonitor; public class JexlDataModelTest { @@ -19,26 +21,37 @@ public class JexlDataModelTest { } 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"; - if (args.length > 0) { - testUri = args[0]; - } + +// if (args.length > 0) { +// testUri = args[0]; +// } { - JEXLDataModel jdm = new JEXLDataModel(); - Factory.getInstance().registerDataModel(jdm); + JexlDataModel jdm = new JexlDataModel(); +// Factory.getInstance().registerDataModel(jdm); + TestMonitor tm = new TestMonitor(); try { - File testFile = new File(testUri); - String testName = testFile.toURI().toURL().toString(); +// 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()); + + ActionLanguage al = new ActionLanguage(); + al.setDataModel(jdm); + scxml.setActionLanguage(al); + scxml.addMonitor(tm); - + while (scxml.step() != InterpreterState.USCXML_FINISHED) { } @@ -48,7 +61,7 @@ public class JexlDataModelTest { } System.out.println("SUCCESS"); - } catch (InterpreterException | MalformedURLException e) { + } catch (InterpreterException e) { e.printStackTrace(); System.exit(-1); } |