Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
794 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Default path on Windows (maybe with an '(x86)' in there for good measure) | ||
#umundo.jar=C:\\Program Files\\uMundo\\share\\umundo\\lib\\umundo.jar | ||
|
||
# Default path on MacOSX and Linux | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<project name="java-tests" default="test-w3c"> | ||
|
||
<property environment="env"/> | ||
|
||
<property file="build.properties" /> | ||
<property name="src" value="." /> | ||
<property name="bin" value="bin" /> | ||
<!-- <property name="test.file" value="..." /> --> | ||
|
||
<!-- Allow to override actual value with environment .. yes ant sucks --> | ||
<condition property="real.uscxml.jar" value="${env.USCXML_JAVA_JAR}" else="${uscxml.jar}"> | ||
<isset property="env.USCXML_JAVA_JAR" /> | ||
</condition> | ||
|
||
<target name="clean"> | ||
<delete dir="${bin}" /> | ||
</target> | ||
|
||
<target name="compile"> | ||
<mkdir dir="${bin}" /> | ||
<javac destdir="${bin}" debuglevel="lines,vars,source" debug="on" | ||
encoding="utf-8" includeantruntime="false"> | ||
<src path="${src}" /> | ||
<classpath> | ||
<pathelement location="${real.uscxml.jar}" /> | ||
<pathelement location="${jexl.jar}" /> | ||
<pathelement location="${logging.jar}" /> | ||
</classpath> | ||
<include name="**/*.java" /> | ||
</javac> | ||
</target> | ||
|
||
<target name="test-w3c"> | ||
<antcall target="test-w3c-jexl" /> | ||
</target> | ||
|
||
<target name="test-w3c-jexl" depends="compile"> | ||
<java classpath="${real.uscxml.jar}:${jexl.jar}:${logging.jar}:${bin}" classname="org.uscxml.tests.JexlDataModelTest"> | ||
<arg value="${test.file}"/> | ||
</java> | ||
</target> | ||
</project> |
7 changes: 7 additions & 0 deletions
7
contrib/java/bindings/org/uscxml/apache/commons/scxml2/Context.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.uscxml.apache.commons.scxml2; | ||
|
||
import org.uscxml.DataModel; | ||
|
||
public class Context { | ||
public DataModel dm = null; | ||
} |
7 changes: 7 additions & 0 deletions
7
contrib/java/bindings/org/uscxml/apache/commons/scxml2/Evaluator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.uscxml.apache.commons.scxml2; | ||
|
||
public abstract class Evaluator { | ||
|
||
public abstract Context newContext(Object object); | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
contrib/java/bindings/org/uscxml/apache/commons/scxml2/JexlEvaluator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
contrib/java/bindings/org/uscxml/apache/commons/scxml2/SCXML.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.uscxml.apache.commons.scxml2; | ||
|
||
import java.net.URL; | ||
|
||
public class SCXML { | ||
public URL url = null; | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
contrib/java/bindings/org/uscxml/apache/commons/scxml2/SCXMLExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
contrib/java/bindings/org/uscxml/apache/commons/scxml2/SCXMLReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
contrib/java/bindings/org/uscxml/apache/commons/scxml2/SimpleErrorReporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.uscxml.apache.commons.scxml2; | ||
|
||
public class SimpleErrorReporter { | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
contrib/java/bindings/org/uscxml/examples/ApacheCommonsAPI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
contrib/java/bindings/org/uscxml/examples/BasicExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.uscxml.examples; | ||
|
||
import org.uscxml.Interpreter; | ||
import org.uscxml.InterpreterException; | ||
import org.uscxml.InterpreterState; | ||
|
||
public class BasicExample { | ||
|
||
public static void main(String[] args) { | ||
|
||
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); | ||
|
||
try { | ||
Interpreter scxml = Interpreter.fromURL("https://raw.githubusercontent.com/tklab-tud/uscxml/master/test/w3c/null/test436.scxml"); | ||
InterpreterState state = InterpreterState.USCXML_UNDEF; | ||
while((state = scxml.step()) != InterpreterState.USCXML_FINISHED) { | ||
switch (state) { | ||
case USCXML_FINISHED: | ||
case USCXML_UNDEF: | ||
case USCXML_IDLE: | ||
case USCXML_INITIALIZED: | ||
case USCXML_INSTANTIATED: | ||
case USCXML_MICROSTEPPED: | ||
case USCXML_MACROSTEPPED: | ||
case USCXML_CANCELLED: | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
System.out.println("Machine finished"); | ||
|
||
} catch (InterpreterException e) { | ||
e.printStackTrace(); | ||
System.exit(-1); | ||
} | ||
System.exit(0); | ||
|
||
} | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
contrib/java/bindings/org/uscxml/examples/DataModelExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.uscxml.examples; | ||
|
||
import java.io.File; | ||
import java.net.MalformedURLException; | ||
|
||
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.helper.TestMonitor; | ||
|
||
public class DataModelExample { | ||
|
||
public static void main(String[] args) { | ||
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); | ||
|
||
JexlDataModel jdm = new JexlDataModel(); | ||
Factory.getInstance().registerDataModel(jdm);; | ||
|
||
TestMonitor tm = new TestMonitor(); | ||
|
||
File folder = new File("/Users/sradomski/Documents/TK/Code/uscxml/test/w3c/jexl"); | ||
File[] listOfFiles = folder.listFiles(); | ||
|
||
try { | ||
for (File file : listOfFiles) { | ||
if (!file.getName().endsWith(".scxml")) | ||
continue; | ||
String testName = file.toURI().toURL().toString(); | ||
System.out.println(testName); | ||
|
||
Interpreter scxml = Interpreter.fromURL(testName); | ||
// scxml.setMonitor(tm); | ||
|
||
while(scxml.step() != InterpreterState.USCXML_FINISHED) {} | ||
|
||
if (!scxml.isInState("pass")) { | ||
System.out.println("FAIL: " + testName); | ||
|
||
throw new RuntimeException(); | ||
} | ||
System.out.println("SUCCESS"); | ||
|
||
} | ||
|
||
} catch (InterpreterException | MalformedURLException e) { | ||
e.printStackTrace(); | ||
System.exit(-1); | ||
} | ||
System.exit(0); | ||
|
||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
contrib/java/bindings/org/uscxml/examples/MonitorExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package org.uscxml.examples; | ||
|
||
import org.uscxml.Interpreter; | ||
import org.uscxml.InterpreterException; | ||
import org.uscxml.InterpreterState; | ||
import org.uscxml.StringVector; | ||
import org.uscxml.helper.TestMonitor; | ||
|
||
|
||
public class MonitorExample { | ||
|
||
public static void main(String[] args) { | ||
|
||
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); | ||
|
||
try { | ||
TestMonitor tm = new TestMonitor(); | ||
Interpreter scxml = Interpreter.fromURL("https://raw.githubusercontent.com/tklab-tud/uscxml/master/test/w3c/null/test436.scxml"); | ||
scxml.addMonitor(tm); | ||
InterpreterState state = InterpreterState.USCXML_UNDEF; | ||
while((state = scxml.step()) != InterpreterState.USCXML_FINISHED) { | ||
switch (state) { | ||
case USCXML_FINISHED: | ||
case USCXML_UNDEF: | ||
case USCXML_IDLE: | ||
case USCXML_INITIALIZED: | ||
case USCXML_INSTANTIATED: | ||
break; | ||
case USCXML_MICROSTEPPED: | ||
case USCXML_MACROSTEPPED: | ||
StringVector states = scxml.getConfiguration(); | ||
for (int i = 0; i < states.size(); i++) { | ||
System.out.print(states.get(i) + " "); | ||
} | ||
System.out.println(); | ||
case USCXML_CANCELLED: | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
} catch (InterpreterException e) { | ||
e.printStackTrace(); | ||
System.exit(-1); | ||
} | ||
System.exit(0); | ||
} | ||
|
||
} |
Oops, something went wrong.