summaryrefslogtreecommitdiffstats
path: root/embedding/java/src/org/uscxml/tests/datamodel/TestPlatformExtensions.java
blob: 86ba8846651fa072192e38f909f8d5f872f3275d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package org.uscxml.tests.datamodel;

import org.uscxml.Data;
import org.uscxml.DataModelExtension;
import org.uscxml.Interpreter;
import org.uscxml.InterpreterException;
import org.uscxml.InterpreterState;

public class TestPlatformExtensions extends DataModelExtension {

	/* Currently only with ECMAScript via JavaScriptCore! */
	
	@Override
	public String provides() {
		return "_x.platform.pool";
	}

	@Override
	public Data getValueOf(String member) {
		return new Data(true);
	}
	
	@Override
	public void setValueOf(String member, Data data) {
		System.out.println("Setting " + member + " to \n" + data);
	}

	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");

		TestPlatformExtensions ext = new TestPlatformExtensions();
		
		String xml = 
		"<scxml datamodel=\"ecmascript\">" +
		"  <script src=\"http://uscxml.tk.informatik.tu-darmstadt.de/scripts/dump.js\" />" +
		"  <state id=\"s1\">" +
		"    <onentry>" +
        "      <script>_x.platform.pool('member.second', { foo: 12, bar: 34})</script>" +
        "      <log label=\"ext\" expr=\"dump(_x.platform.pool('member.first'))\" />" +
        "    </onentry>" +
		"    <transition target=\"done\" />" +		
		"  </state>" +
		"  <final id=\"done\" />" +
		"</scxml>";

		Interpreter interpreter = Interpreter.fromXML(xml);
		interpreter.addDataModelExtension(ext);

		InterpreterState state;
		
		do {
			state = interpreter.step();			
		} while (state != InterpreterState.USCXML_FINISHED && 
				 state != InterpreterState.USCXML_DESTROYED);

	}

}