summaryrefslogtreecommitdiffstats
path: root/embedding/java/src/org/uscxml/tests/execContent/TestCustomExecContent.java
blob: 7a97ab4010379b3be395461bc79030b79c6c9744 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package org.uscxml.tests.execContent;

import org.uscxml.ExecutableContent;
import org.uscxml.Factory;
import org.uscxml.Interpreter;
import org.uscxml.InterpreterException;

public class TestCustomExecContent extends ExecutableContent {

	static int instanceId = 0;
	public int id = 0;
	
	public TestCustomExecContent() {
		id = instanceId++;
	} 

	@Override
	public String getLocalName() {
		return "custom";
	}

	@Override
	public String getNamespace() {
		return "http://www.w3.org/2005/07/scxml";
	}


	@Override
	public void enterElement(String node) {
		System.out.println(id + " entering:" + node);
	}

	@Override
	public void exitElement(String node) {
		System.out.println(id + " exiting:" + node);
	}

	@Override
	public boolean processChildren() {
		return false;
	}

	@Override
	public ExecutableContent create(Interpreter interpreter) {
		return new TestCustomExecContent();
	}

	/**
	 * @param args
	 * @throws InterruptedException 
	 * @throws InterpreterException 
	 */
	public static void main(String[] args) throws InterruptedException, InterpreterException {
		System.load("/Users/sradomski/Documents/TK/Code/uscxml/build/cli/lib/libuscxmlNativeJava64.jnilib");

		TestCustomExecContent execContent = new TestCustomExecContent();
		Factory.getInstance().registerExecutableContent(execContent);

		Interpreter interpreter = Interpreter.fromXML(
						"<scxml>\n" +
						"  <state id=\"s0\">\n" +
						"    <onentry>\n" +
						"      <custom foo=\"bar\">\n" +
						"        <something></something>\n" +
						"      </custom>\n" +
						"      <custom foo=\"bar\">\n" +
						"        <something></something>\n" +
						"      </custom>\n" +
						"    </onentry>\n" +
						"    <transition target=\"exit\" />" +
						"  </state>\n" +
						"  <final id=\"exit\" />" +
						"</scxml>\n"
				);
		interpreter.interpret();
		Thread.sleep(1000);
	}

}