diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-06-25 21:05:44 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-06-25 21:05:44 (GMT) |
commit | e3767be4f9c5874d9c996200f2e9705ce31a5976 (patch) | |
tree | be3d06f550286e23eeb3252277c1a2b7d12554ef /contrib/java | |
parent | 758bda908ded461c9d34d274a18454ffba4b7450 (diff) | |
download | uscxml-e3767be4f9c5874d9c996200f2e9705ce31a5976.zip uscxml-e3767be4f9c5874d9c996200f2e9705ce31a5976.tar.gz uscxml-e3767be4f9c5874d9c996200f2e9705ce31a5976.tar.bz2 |
Work on bindings
- Introduced exceptions into C# and Java
- Moved binding examples to /embedding
- Interpreter will now throw exceptions, beware!
Diffstat (limited to 'contrib/java')
-rw-r--r-- | contrib/java/.classpath | 10 | ||||
-rw-r--r-- | contrib/java/.project | 39 | ||||
-rw-r--r-- | contrib/java/build-java.xml | 91 | ||||
-rw-r--r-- | contrib/java/src/js.jar | bin | 1134765 -> 0 bytes | |||
-rw-r--r-- | contrib/java/src/org/uscxml/datamodel/ecmascript/ECMAData.java | 110 | ||||
-rw-r--r-- | contrib/java/src/org/uscxml/datamodel/ecmascript/ECMAEvent.java | 126 | ||||
-rw-r--r-- | contrib/java/src/org/uscxml/datamodel/ecmascript/ECMAScriptDataModel.java | 396 | ||||
-rw-r--r-- | contrib/java/src/org/uscxml/tests/TestData.java | 23 | ||||
-rw-r--r-- | contrib/java/src/org/uscxml/tests/TestInvoker.java | 66 | ||||
-rw-r--r-- | contrib/java/src/org/uscxml/tests/TestJavaScriptDataModel.java | 26 | ||||
-rw-r--r-- | contrib/java/src/org/uscxml/tests/TestW3CECMA.java | 40 |
11 files changed, 91 insertions, 836 deletions
diff --git a/contrib/java/.classpath b/contrib/java/.classpath deleted file mode 100644 index 0830f8a..0000000 --- a/contrib/java/.classpath +++ /dev/null @@ -1,10 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" path="src"/> - <classpathentry kind="src" path="java"/> - <classpathentry kind="src" path="uscxml"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> - <classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/umundo"/> - <classpathentry kind="lib" path="/Users/sradomski/Documents/TK/Code/rhino1_7R4/build/rhino1_7R4/js.jar" sourcepath="/Users/sradomski/Documents/TK/Code/rhino1_7R4/src"/> - <classpathentry kind="output" path="bin"/> -</classpath> diff --git a/contrib/java/.project b/contrib/java/.project deleted file mode 100644 index bed7874..0000000 --- a/contrib/java/.project +++ /dev/null @@ -1,39 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<projectDescription> - <name>uscxml</name> - <comment></comment> - <projects> - </projects> - <buildSpec> - <buildCommand> - <name>org.eclipse.jdt.core.javabuilder</name> - <arguments> - </arguments> - </buildCommand> - </buildSpec> - <natures> - <nature>org.eclipse.jdt.core.javanature</nature> - </natures> - <linkedResources> - <link> - <name>applications</name> - <type>2</type> - <location>/Users/sradomski/Documents/TK/Code/uscxml/test/samples/uscxml/applications</location> - </link> - <link> - <name>bindings</name> - <type>2</type> - <location>/Users/sradomski/Documents/TK/Code/uscxml/src/bindings/swig/java</location> - </link> - <link> - <name>java</name> - <type>2</type> - <location>/Users/sradomski/Documents/TK/Code/uscxml/src/bindings/swig/java</location> - </link> - <link> - <name>uscxml</name> - <type>2</type> - <location>/Users/sradomski/Documents/TK/Code/uscxml/build/cli/src/bindings/swig/java</location> - </link> - </linkedResources> -</projectDescription> diff --git a/contrib/java/build-java.xml b/contrib/java/build-java.xml new file mode 100644 index 0000000..ca5cc88 --- /dev/null +++ b/contrib/java/build-java.xml @@ -0,0 +1,91 @@ +<!-- This ant build script is called from CMake at configure time --> +<project name="uscxml" default="jar"> + +<!-- taskdef resource="net/sf/antcontrib/antcontrib.properties"> + <classpath> + <pathelement location="lib/ant-contrib-1.0b3.jar"/> + </classpath> +</taskdef --> + +<target name="compile" description="Compile the uscxml java code."> + <echo message="dest: ${build.dir}/src/bindings/swig/java-class/"/> + <echo message="src: ${build.dir}/src/bindings/swig/java/"/> + <echo message="src: ${src.dir}/src/bindings/swig/java/"/> + + <mkdir dir="${build.dir}/src/bindings/swig/java-class/" /> + + <javac destdir="${build.dir}/src/bindings/swig/java-class/" debug="true" includeantruntime="false" target="1.5" source="1.5"> + <src path="${build.dir}/src/bindings/swig/java/" /> + <src path="${src.dir}/src/bindings/swig/java/" /> + <!--classpath> + <pathelement location="${src.dir}/contrib/java/lib/protobuf-java-2.5.0.jar"/> + </classpath --> + </javac> +</target> + +<target name="jar" depends="compile" description="Create a bundle of the source code"> + <echo message="library dir: ${lib.dir}"/> + <echo message="source dir: ${src.dir}"/> + <echo message="build dir: ${build.dir}"/> + <echo message="build type: ${build.type}"/> + <echo message="exclude debug: ${exclude.debug}"/> + <echo message="exclude jni: ${exclude.jni}"/> + + <condition property="exclude.debug.jar"> + <equals arg1="${exclude.debug}" arg2="ON"/> + </condition> + + <condition property="exclude.jni.jar"> + <equals arg1="${exclude.jni}" arg2="ON"/> + </condition> + + <!-- flatten all JNI libraries for inclusion into the fat JAR --> + <fileset id="all.jni" dir="${lib.dir}"> + <include name="**/*NativeJava*.jnilib"/> + <include name="**/*NativeJava*.so"/> + <include name="**/*NativeJava*.dll"/> + <exclude name="cross-compiled/**"/> + <exclude name="linux-armv*/**"/> + <!-- do not include debug builds in release --> + <!--exclude name="**/*undocoreSwigSwig_d*" if="${exclude.debug.jar}"/ --> + <!--exclude name="**/*undocoreSwig64_d*" if="${exclude.debug.jar}"/ --> + </fileset> + + <!-- Copy all JNI libraries as found above into the lib/ directory --> + <mkdir dir="${lib.dir}/jni" /> + <copy todir="${lib.dir}/jni" flatten="true"> + <fileset refid="all.jni" /> + </copy> + + <pathconvert pathsep="${line.separator}| |-- " + property="echo.all.jni" + refid="all.jni"> + </pathconvert> + <echo>${echo.all.jni}</echo> + + <!-- delete an eventual old jar --> + <delete dir="${lib.dir}/uscxml.jar" /> + + <!-- build new jar --> + <jar destfile="${lib.dir}/uscxml.jar"> + <!-- All the class files we compiled --> + <fileset dir="${build.dir}/src/bindings/swig/java-class/" > + <include name="**/*.class" /> + </fileset> + <!-- Include all source files --> + <fileset dir="${build.dir}/src/bindings/swig/java/" > + <include name="**/*.java" /> + </fileset> + <fileset dir="${src.dir}/src/bindings/swig/java/" > + <include name="**/*.java" /> + </fileset> + <!-- The JNI libraries --> + <fileset dir="${lib.dir}/jni" > + <include name="**/*" /> + <exclude name="**/*" if="${exclude.jni.jar}" /> + </fileset> + </jar> + <delete dir="${lib.dir}/jni" /> +</target> + +</project> diff --git a/contrib/java/src/js.jar b/contrib/java/src/js.jar Binary files differdeleted file mode 100644 index 6f0dafb..0000000 --- a/contrib/java/src/js.jar +++ /dev/null diff --git a/contrib/java/src/org/uscxml/datamodel/ecmascript/ECMAData.java b/contrib/java/src/org/uscxml/datamodel/ecmascript/ECMAData.java deleted file mode 100644 index 56d7090..0000000 --- a/contrib/java/src/org/uscxml/datamodel/ecmascript/ECMAData.java +++ /dev/null @@ -1,110 +0,0 @@ -package org.uscxml.datamodel.ecmascript; - -import org.mozilla.javascript.Scriptable; -import org.uscxml.Data; - -public class ECMAData implements Scriptable { - - protected Data data; - protected Scriptable parent; - protected Scriptable prototype; - - public ECMAData(Data data) { - this.data = data; - } - - @Override - public String getClassName() { - return "Data"; - } - - public Object unwrap(Data data) { - if (data.atom.length() > 0) { - return data.atom; - } - return new ECMAData(data); - - } - - @Override - public Object get(String name, Scriptable start) { - if (data.compound.containsKey(name)) - return unwrap(data.compound.get(name)); - return NOT_FOUND; - } - - @Override - public Object get(int index, Scriptable start) { - if (data.array.size() > index) - return unwrap(data.array.get(index)); - return NOT_FOUND; - } - - @Override - public boolean has(String name, Scriptable start) { - return data.compound.containsKey(name); - } - - @Override - public boolean has(int index, Scriptable start) { - return data.array.size() > index; - } - - @Override - public void put(String name, Scriptable start, Object value) { - } - - @Override - public void put(int index, Scriptable start, Object value) { - } - - @Override - public void delete(String name) { - } - - @Override - public void delete(int index) { - } - - @Override - public Scriptable getPrototype() { - return prototype; - } - - @Override - public void setPrototype(Scriptable prototype) { - this.prototype = prototype; - } - - @Override - public Scriptable getParentScope() { - return parent; - } - - @Override - public void setParentScope(Scriptable parent) { - this.parent = parent; - } - - @Override - public Object[] getIds() { - return data.compound.keySet().toArray(); - } - - @Override - public Object getDefaultValue(Class<?> hint) { - return "[object Data]"; - } - - @Override - public boolean hasInstance(Scriptable instance) { - Scriptable proto = instance.getPrototype(); - while (proto != null) { - if (proto.equals(this)) - return true; - proto = proto.getPrototype(); - } - return false; - } - -} diff --git a/contrib/java/src/org/uscxml/datamodel/ecmascript/ECMAEvent.java b/contrib/java/src/org/uscxml/datamodel/ecmascript/ECMAEvent.java deleted file mode 100644 index 58fff72..0000000 --- a/contrib/java/src/org/uscxml/datamodel/ecmascript/ECMAEvent.java +++ /dev/null @@ -1,126 +0,0 @@ -package org.uscxml.datamodel.ecmascript; - -import java.util.HashMap; -import java.util.Map; - -import org.mozilla.javascript.Scriptable; -import org.uscxml.Data; -import org.uscxml.Event; -import org.uscxml.ParamPair; -import org.uscxml.ParamPairVector; - -public class ECMAEvent implements Scriptable { - - protected Event event; - protected Scriptable parent; - protected Scriptable prototype; - - protected Map<String, Object> members = new HashMap<String, Object>(); - - public ECMAEvent(Event event) { - this.event = event; - - Data data = new Data(event.getData()); - - // insert params into event.data - ParamPairVector ppv = event.getParamPairs(); - for (int i = 0; i < ppv.size(); i++) { - ParamPair pp = ppv.get(i); - data.compound.put(pp.getFirst(), new Data(pp.getSecond())); - } - - members.put("type", event.getEventType().toString()); - members.put("data", new ECMAData(data)); - members.put("sendid", event.getSendId()); - members.put("origin", event.getOrigin()); - members.put("originType", event.getOriginType()); - // add others as necessary - - } - - @Override - public String getClassName() { - return "Event"; - } - - @Override - public Object get(String name, Scriptable start) { - if (members.containsKey(name)) - return members.get(name); - return NOT_FOUND; - } - - @Override - public Object get(int index, Scriptable start) { - return NOT_FOUND; - } - - @Override - public boolean has(String name, Scriptable start) { - return (members.containsKey(name)); - } - - @Override - public boolean has(int index, Scriptable start) { - return false; - } - - @Override - public void put(String name, Scriptable start, Object value) { - } - - @Override - public void put(int index, Scriptable start, Object value) { - } - - @Override - public void delete(String name) { - } - - @Override - public void delete(int index) { - } - - @Override - public Scriptable getPrototype() { - return prototype; - } - - @Override - public void setPrototype(Scriptable prototype) { - this.prototype = prototype; - } - - @Override - public Scriptable getParentScope() { - return parent; - } - - @Override - public void setParentScope(Scriptable parent) { - this.parent = parent; - } - - @Override - public Object[] getIds() { - return members.keySet().toArray(); - } - - @Override - public Object getDefaultValue(Class<?> hint) { - return "[object Event]"; - } - - @Override - public boolean hasInstance(Scriptable instance) { - Scriptable proto = instance.getPrototype(); - while (proto != null) { - if (proto.equals(this)) - return true; - proto = proto.getPrototype(); - } - - return false; - } - -} diff --git a/contrib/java/src/org/uscxml/datamodel/ecmascript/ECMAScriptDataModel.java b/contrib/java/src/org/uscxml/datamodel/ecmascript/ECMAScriptDataModel.java deleted file mode 100644 index 3d77dc5..0000000 --- a/contrib/java/src/org/uscxml/datamodel/ecmascript/ECMAScriptDataModel.java +++ /dev/null @@ -1,396 +0,0 @@ -package org.uscxml.datamodel.ecmascript; - -import java.lang.reflect.Method; - -import org.mozilla.javascript.Callable; -import org.mozilla.javascript.Context; -import org.mozilla.javascript.EvaluatorException; -import org.mozilla.javascript.FunctionObject; -import org.mozilla.javascript.NativeJSON; -import org.mozilla.javascript.Scriptable; -import org.mozilla.javascript.ScriptableObject; -import org.mozilla.javascript.Undefined; -import org.uscxml.Data; -import org.uscxml.DataNative; -import org.uscxml.Event; -import org.uscxml.Interpreter; -import org.uscxml.JavaDataModel; -import org.uscxml.StringSet; -import org.uscxml.StringVector; - -public class ECMAScriptDataModel extends JavaDataModel { - - public static boolean debug = true; - - private class NullCallable implements Callable { - @Override - public Object call(Context context, Scriptable scope, - Scriptable holdable, Object[] objects) { - return objects[1]; - } - } - - public Context ctx; - public Scriptable scope; - public Interpreter interpreter; - - public Data getScriptableAsData(Object object) { - Data data = new Data(); - - Scriptable s; - try { - s = (Scriptable) object; - String className = s.getClassName(); // ECMA class name - if (className.toLowerCase().equals("object")) { - ScriptableObject obj = (ScriptableObject) Context.toObject(s, - scope); - for (Object key : obj.getIds()) { - data.compound.put(Context.toString(key), - getScriptableAsData(obj.get(key))); - } - } - } catch (ClassCastException e) { - if (object instanceof Boolean) { - data.atom = (Context.toBoolean(object) ? "true" : "false"); - data.type = Data.Type.INTERPRETED; - } else if (object instanceof String) { - data.atom = (String) object; - data.type = Data.Type.VERBATIM; - } else if (object instanceof Integer) { - data.atom = ((Integer) object).toString(); - data.type = Data.Type.INTERPRETED; - } else { - throw new RuntimeException("Unhandled ECMA type " - + object.getClass().getName()); - } - } - - return data; - } - - public ScriptableObject getDataAsScriptable(Data data) { - throw new UnsupportedOperationException("Not implemented"); - } - - public static boolean jsIn(String stateName) { - return true; - } - - @Override - public JavaDataModel create(Interpreter interpreter) { - /** - * Called when an SCXML interpreter wants an instance of this datamodel - * Be careful to instantiate attributes of instance returned and not - * *this* - */ - - ECMAScriptDataModel newDM = new ECMAScriptDataModel(); - newDM.interpreter = interpreter; - newDM.ctx = Context.enter(); - - try { - newDM.scope = newDM.ctx.initStandardObjects(); - } catch (Exception e) { - System.err.println(e); - } - - newDM.scope.put("_name", newDM.scope, interpreter.getName()); - newDM.scope.put("_sessionid", newDM.scope, interpreter.getSessionId()); - - // ioProcessors - { - Data ioProcs = new Data(); - StringVector keys = interpreter.getIOProcessorKeys(); - for (int i = 0; i < keys.size(); i++) { - ioProcs.compound.put(keys.get(i), new Data(interpreter - .getIOProcessors().get(keys.get(i)) - .getDataModelVariables())); - } - newDM.scope - .put("_ioprocessors", newDM.scope, new ECMAData(ioProcs)); - } - - // invokers - { - Data invokers = new Data(); - StringVector keys = interpreter.getInvokerKeys(); - for (int i = 0; i < keys.size(); i++) { - invokers.compound.put(keys.get(i), new Data(interpreter - .getInvokers().get(keys.get(i)) - .getDataModelVariables())); - } - newDM.scope - .put("_ioprocessors", newDM.scope, new ECMAData(invokers)); - } - - // In predicate (not working as static is required) see: - // http://stackoverflow.com/questions/3441947/how-do-i-call-a-method-of-a-java-instance-from-javascript/16479685#16479685 - try { - Class[] parameters = new Class[] { String.class }; - Method inMethod = ECMAScriptDataModel.class.getMethod("jsIn", - parameters); - FunctionObject inFunc = new FunctionObject("In", inMethod, - newDM.scope); - newDM.scope.put("In", newDM.scope, inFunc); - } catch (SecurityException e) { - System.err.println(e); - } catch (NoSuchMethodException e) { - System.err.println(e); - } - - return newDM; - } - - @Override - public StringSet getNames() { - /** - * Register with the following names for the datamodel attribute at the - * scxml element. <scxml datamodel="one of these"> - */ - StringSet ss = new StringSet(); - ss.insert("ecmascript"); - return ss; - } - - @Override - public boolean validate(String location, String schema) { - /** - * Validate the datamodel. This make more sense for XML datamodels and - * is pretty much unused but required as per draft. - */ - return true; - } - - @Override - public void setEvent(Event event) { - if (debug) { - System.out.println(interpreter.getName() + " setEvent"); - } - - /** - * Make the current event available as the variable _event in the - * datamodel. - */ - ECMAEvent ecmaEvent = new ECMAEvent(event); - scope.put("_event", scope, ecmaEvent); - } - - @Override - public DataNative getStringAsData(String content) { - if (debug) { - System.out.println(interpreter.getName() + " getStringAsData"); - } - - /** - * Evaluate the string as a value expression and transform it into a - * JSON-like Data structure - */ - if (content.length() == 0) { - return Data.toNative(new Data()); - } - - // is it a json expression? - try { - Object json = NativeJSON.parse(ctx, scope, content, - new NullCallable()); - if (json != NativeJSON.NOT_FOUND) { - return Data.toNative(getScriptableAsData(json)); - } - } catch (org.mozilla.javascript.EcmaError e) { - System.err.println(e); - } - - // is it a function call or variable? - Object x = ctx.evaluateString(scope, content, "uscxml", 0, null); - if (x == Undefined.instance) { - // maybe a literal string? - x = ctx.evaluateString(scope, '"' + content + '"', "uscxml", 0, - null); - } - return Data.toNative(getScriptableAsData(x)); - } - - @Override - public long getLength(String expr) { - if (debug) { - System.out.println(interpreter.getName() + " getLength"); - } - - /** - * Return the length of the expression if it were an array, used by - * foreach element. - */ - - Object x = scope.get(expr, scope); - if (x == Undefined.instance) { - return 0; - } - - Scriptable result = Context.toObject(x, scope); - if (result.has("length", result)) { - return (long) Context.toNumber(result.get("length", result)); - } - return 0; - } - - @Override - public void setForeach(String item, String array, String index, - long iteration) { - if (debug) { - System.out.println(interpreter.getName() + " setForeach"); - } - - /** - * Prepare an iteration of the foreach element, by setting the variable - * in index to the current iteration and setting the variable in item to - * the current item from array. - */ - - try { - // get the array object - Scriptable arr = (Scriptable) scope.get(array, scope); - - if (arr.has((int) iteration, arr)) { - ctx.evaluateString(scope, item + '=' + array + '[' + iteration - + ']', "uscxml", 1, null); - if (index.length() > 0) { - ctx.evaluateString(scope, index + '=' + iteration, - "uscxml", 1, null); - } - } else { - handleException(""); - } - - } catch (ClassCastException e) { - System.err.println(e); - } - } - - @Override - public void eval(String scriptElem, String expr) { - if (debug) { - System.out.println(interpreter.getName() + " eval"); - } - - /** - * Evaluate the given expression in the datamodel. This is used foremost - * with script elements. - */ - ctx.evaluateString(scope, expr, "uscxml", 1, null); - - } - - @Override - public String evalAsString(String expr) { - if (debug) { - System.out.println(interpreter.getName() + " evalAsString: " + expr); - } - - /** - * Evaluate the expression as a string e.g. for the log element. - */ - if (!ctx.stringIsCompilableUnit(expr)) { - handleException(""); - return ""; - } - try { - Object result = ctx.evaluateString(scope, expr, "uscxml", 1, null); - return Context.toString(result); - } catch (IllegalStateException e) { - System.err.println(e); - handleException(""); - } catch (EvaluatorException e) { - System.err.println(e); - handleException(""); - } - return ""; - } - - @Override - public boolean evalAsBool(String elem, String expr) { - if (debug) { - System.out.println(interpreter.getName() + " evalAsBool"); - } - - /** - * Evaluate the expression as a boolean for cond attributes in if and - * transition elements. - */ - Object result = ctx.evaluateString(scope, expr, "uscxml", 1, null); - return Context.toBoolean(result); - } - - @Override - public boolean isDeclared(String expr) { - if (debug) { - System.out.println(interpreter.getName() + " isDeclared"); - } - - /** - * The interpreter is supposed to raise an error if we assign to an - * undeclared variable. This method is used to check whether a location - * from assign is declared. - */ - Object x = scope.get(expr, scope); - return x != Scriptable.NOT_FOUND; - } - - @Override - public void init(String dataElem, String location, String content) { - if (debug) { - System.out.println(interpreter.getName() + " init"); - } - - /** - * Called when we pass data elements. - */ - if (("null").equals(location)) - return; - - if (("null").equals(content) || content.length() == 0) { - scope.put(location, scope, Context.getUndefinedValue()); - return; - } - - try { - Object json = NativeJSON.parse(ctx, scope, content, - new NullCallable()); - if (json != NativeJSON.NOT_FOUND) { - scope.put(location, scope, json); - } else { - scope.put(location, scope, content); - } - } catch (org.mozilla.javascript.EcmaError e) { - scope.put(location, scope, content); - } - } - - @Override - public void assign(String assignElem, String location, String content) { - if (debug) { - System.out.println(interpreter.getName() + " assign"); - } - - /** - * Called when we evaluate assign elements - */ - if (("null").equals(location)) - return; - - if (("null").equals(content) || content.length() == 0) { - scope.put(location, scope, Context.getUndefinedValue()); - return; - } - - String expr = location + "=" + content; - ctx.evaluateString(scope, expr, "uscxml", 1, null); - } - - public void handleException(String cause) { - Event exceptionEvent = new Event(); - exceptionEvent.setName("error.execution"); - exceptionEvent.setEventType(Event.Type.PLATFORM); - - interpreter.receiveInternal(exceptionEvent); - } -} diff --git a/contrib/java/src/org/uscxml/tests/TestData.java b/contrib/java/src/org/uscxml/tests/TestData.java deleted file mode 100644 index 44f1ce0..0000000 --- a/contrib/java/src/org/uscxml/tests/TestData.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.uscxml.tests; - -import org.uscxml.Data; -import org.uscxml.DataNative; - -public class TestData { - - public static void main(String[] args) { - System.load("/Users/sradomski/Documents/TK/Code/uscxml/build/cli/lib/libuscxmlNativeJava64.jnilib"); - { - Data data = Data.fromJSON("[1,2,3,4,5]"); - DataNative nData2 = Data.toNative(data); - Data data2 = new Data(nData2); - System.out.println(data2); - } - { - Data data = Data.fromJSON("{ \"foo\": \"bar\", \"faz\": 12 }"); - DataNative nData2 = Data.toNative(data); - Data data2 = new Data(nData2); - System.out.println(data2); - } - } -} diff --git a/contrib/java/src/org/uscxml/tests/TestInvoker.java b/contrib/java/src/org/uscxml/tests/TestInvoker.java deleted file mode 100644 index 7807cda..0000000 --- a/contrib/java/src/org/uscxml/tests/TestInvoker.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.uscxml.tests; - -import org.uscxml.Data; -import org.uscxml.DataNative; -import org.uscxml.Event; -import org.uscxml.Factory; -import org.uscxml.Interpreter; -import org.uscxml.InvokeRequest; -import org.uscxml.JavaInvoker; -import org.uscxml.SendRequest; -import org.uscxml.StringSet; - -public class TestInvoker extends JavaInvoker { - - @Override - public StringSet getNames() { - StringSet ss = new StringSet(); - ss.insert("java"); - return ss; - } - - @Override - public DataNative getDataModelVariables() { - Data data = new Data(); - data.array.add(new Data("foo", Data.Type.VERBATIM)); - return Data.toNative(data); - } - - @Override - public void send(SendRequest req) { - System.out.println("send"); - } - - @Override - public void invoke(InvokeRequest req) { - System.out.println("invoke"); - - System.out.println(req.getData()); - System.out.println(req.getXML()); - - Event ev = new Event(); - ev.setName("foo"); - returnEvent(ev); - } - - @Override - public JavaInvoker create(Interpreter interpreter) { - return new TestInvoker(); - } - - /** - * @param args - */ - public static void main(String[] args) { - System.load("/Users/sradomski/Documents/TK/Code/uscxml/build/cli/lib/libuscxmlNativeJava64_d.jnilib"); - - TestInvoker invoker = new TestInvoker(); - Factory.getInstance().registerInvoker(invoker); - - Interpreter interpreter = Interpreter - .fromURI("/Users/sradomski/Documents/TK/Code/uscxml/test/samples/uscxml/test-java-invoker.scxml"); - while (true) - interpreter.interpret(); - } - -} diff --git a/contrib/java/src/org/uscxml/tests/TestJavaScriptDataModel.java b/contrib/java/src/org/uscxml/tests/TestJavaScriptDataModel.java deleted file mode 100644 index 7399c94..0000000 --- a/contrib/java/src/org/uscxml/tests/TestJavaScriptDataModel.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.uscxml.tests; - -import org.uscxml.Factory; -import org.uscxml.Interpreter; -import org.uscxml.datamodel.ecmascript.ECMAScriptDataModel; - -public class TestJavaScriptDataModel { - - public static void main(String[] args) { - // load JNI library from build directory - System.load("/Users/sradomski/Documents/TK/Code/uscxml/build/cli/lib/libuscxmlNativeJava64.jnilib"); - - // register java datamodel at factory - ECMAScriptDataModel datamodel = new ECMAScriptDataModel(); - Factory.getInstance().registerDataModel(datamodel); - - // instantiate interpreter with document from file - Interpreter interpreter = Interpreter - .fromURI("/Users/sradomski/Documents/TK/Code/uscxml/test/uscxml/java/test-ecmascript-datamodel.scxml"); - - // wait until interpreter has finished - while (true) - interpreter.interpret(); - } - -} diff --git a/contrib/java/src/org/uscxml/tests/TestW3CECMA.java b/contrib/java/src/org/uscxml/tests/TestW3CECMA.java deleted file mode 100644 index 0949701..0000000 --- a/contrib/java/src/org/uscxml/tests/TestW3CECMA.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.uscxml.tests; - -import java.io.File; - -import org.uscxml.Capabilities; -import org.uscxml.Factory; -import org.uscxml.Interpreter; -import org.uscxml.InterpreterOptions; -import org.uscxml.datamodel.ecmascript.ECMAScriptDataModel; - -public class TestW3CECMA { - - public static String testDir = "/Users/sradomski/Documents/TK/Code/uscxml/test/w3c/ecma"; - - public static void main(String[] args) { - System.load("/Users/sradomski/Documents/TK/Code/uscxml/build/cli/lib/libuscxmlNativeJava64.jnilib"); - - ECMAScriptDataModel datamodel = new ECMAScriptDataModel(); - Factory.getInstance().registerDataModel(datamodel); - -// while(true) { -// System.out.println("### test235 #####"); -// Interpreter interpreter = Interpreter.fromURI("/Users/sradomski/Documents/TK/Code/uscxml/test/w3c/ecma/test144.scxml"); -// interpreter.interpret(); -// } - - File dir = new File(testDir); - File[] filesList = dir.listFiles(); - for (File file : filesList) { - if (file.isFile() && file.getName().endsWith(".scxml")) { - System.out.println("### " + file.getName() + " #####"); - Interpreter interpreter = Interpreter.fromURI(file.getAbsolutePath()); - interpreter.setCapabilities(1); - interpreter.interpret(); - } - } - - } - -} |