From c95be52b02e921d4ba8b3e707cd2f6239ce9c99e Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Wed, 12 Nov 2014 19:56:38 +0100 Subject: Data model access example in Java --- .../src/org/uscxml/tests/datamodel/TestData.json | 10 +++ .../src/org/uscxml/tests/datamodel/TestData.xml | 7 ++ .../tests/datamodel/TestDataModelAccess.java | 84 ++++++++++++++++++++++ test/uscxml/dom/TestData.json | 10 +++ test/uscxml/dom/TestData.xml | 7 ++ test/uscxml/dom/test-xml-access.scxml | 23 ++++++ 6 files changed, 141 insertions(+) create mode 100644 embedding/java/src/org/uscxml/tests/datamodel/TestData.json create mode 100644 embedding/java/src/org/uscxml/tests/datamodel/TestData.xml create mode 100644 embedding/java/src/org/uscxml/tests/datamodel/TestDataModelAccess.java create mode 100644 test/uscxml/dom/TestData.json create mode 100644 test/uscxml/dom/TestData.xml create mode 100644 test/uscxml/dom/test-xml-access.scxml diff --git a/embedding/java/src/org/uscxml/tests/datamodel/TestData.json b/embedding/java/src/org/uscxml/tests/datamodel/TestData.json new file mode 100644 index 0000000..a07a5d9 --- /dev/null +++ b/embedding/java/src/org/uscxml/tests/datamodel/TestData.json @@ -0,0 +1,10 @@ +{ + "id": 1, + "name": "Foo", + "price": 123, + "tags": [ "Bar", "Eek" ], + "stock": { + "warehouse": 300, + "retail": 20, + } +} diff --git a/embedding/java/src/org/uscxml/tests/datamodel/TestData.xml b/embedding/java/src/org/uscxml/tests/datamodel/TestData.xml new file mode 100644 index 0000000..882cd95 --- /dev/null +++ b/embedding/java/src/org/uscxml/tests/datamodel/TestData.xml @@ -0,0 +1,7 @@ + + + Tove + Jani + Reminder + Don't forget me this weekend! + \ No newline at end of file diff --git a/embedding/java/src/org/uscxml/tests/datamodel/TestDataModelAccess.java b/embedding/java/src/org/uscxml/tests/datamodel/TestDataModelAccess.java new file mode 100644 index 0000000..fcad186 --- /dev/null +++ b/embedding/java/src/org/uscxml/tests/datamodel/TestDataModelAccess.java @@ -0,0 +1,84 @@ +package org.uscxml.tests.datamodel; + +import org.uscxml.Interpreter; +import org.uscxml.InterpreterException; +import org.uscxml.InterpreterState; + +public class TestDataModelAccess { + public static void main(String[] args) throws InterpreterException { + // load JNI library from build directory + System.load("/Users/sradomski/Documents/TK/Code/uscxml/build/cli/lib/libuscxmlNativeJava64.jnilib"); + + { + // initializing and accessing complex data + String xml = + "" + + " " + + " " + + " " + + " " + + " " + + ""; + + Interpreter interpreter = Interpreter.fromXML(xml); + InterpreterState state; + do { + state = interpreter.step(); + // after first microstep, data model is initialized and we can access cmplx1 + if (state == InterpreterState.USCXML_MICROSTEPPED) + System.out.println(interpreter.getDataModel().getStringAsData("cmplx1").toString()); + + } while (state != InterpreterState.USCXML_FINISHED && + state != InterpreterState.USCXML_DESTROYED); + } + + { + // initializing and accessing complex data via data.src + String xml = + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + Interpreter interpreter = Interpreter.fromXML(xml); + interpreter.setSourceURI(TestDataModelAccess.class.getResource("").toString()); + InterpreterState state; + do { + state = interpreter.step(); + // after first microstep, data model is initialized and we can access cmplx1 + if (state == InterpreterState.USCXML_MICROSTEPPED) + System.out.println(interpreter.getDataModel().getStringAsData("cmplx1").toString()); + + } while (state != InterpreterState.USCXML_FINISHED && + state != InterpreterState.USCXML_DESTROYED); + + } + } + +} diff --git a/test/uscxml/dom/TestData.json b/test/uscxml/dom/TestData.json new file mode 100644 index 0000000..a07a5d9 --- /dev/null +++ b/test/uscxml/dom/TestData.json @@ -0,0 +1,10 @@ +{ + "id": 1, + "name": "Foo", + "price": 123, + "tags": [ "Bar", "Eek" ], + "stock": { + "warehouse": 300, + "retail": 20, + } +} diff --git a/test/uscxml/dom/TestData.xml b/test/uscxml/dom/TestData.xml new file mode 100644 index 0000000..3160cfd --- /dev/null +++ b/test/uscxml/dom/TestData.xml @@ -0,0 +1,7 @@ + + + Tove + Jani + Reminder + Don't forget me this weekend! + \ No newline at end of file diff --git a/test/uscxml/dom/test-xml-access.scxml b/test/uscxml/dom/test-xml-access.scxml new file mode 100644 index 0000000..a637c00 --- /dev/null +++ b/test/uscxml/dom/test-xml-access.scxml @@ -0,0 +1,23 @@ + + + + + + + + + + + -- cgit v0.12