System.err.println("The SCXML document " + uri
+ " can not be parsed!");
System.exit(-1);
}
System.out.println(SCXMLSerializer.serialize(doc));
SCXMLExecutor exec = new SCXMLExecutor(evaluator, null, trc);
EventDispatcher ed = new SimpleScheduler(exec);
exec.setEventdispatcher(ed);
exec.setStateMachine(doc);
exec.addListener(doc, trc);
exec.registerInvokerClass("scxml", SimpleSCXMLInvoker.class);
exec.setRootContext(rootCtx);
exec.go();
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
String event = null;
while ((event = br.readLine()) != null) {
event = event.trim();
if (event.equalsIgnoreCase("help") || event.equals("?")) {
System.out.println("Enter a space-separated list of "
+ "events");
System.out.println("To populate a variable in the "
+ "current context, type \"name=value\"");
System.out.println("To quit, enter \"quit\"");
System.out.println("To reset state machine, enter "
+ "\"reset\"");
} else if (event.equalsIgnoreCase("quit")) {
break;
} else if (event.equalsIgnoreCase("reset")) {
exec.reset();
} else if (event.indexOf('=') != -1) {
int marker = event.indexOf('=');
String name = event.substring(0, marker);
String value = event.substring(marker + 1);
rootCtx.setLocal(name, value);
System.out.println("Set variable " + name + " to "
+ value);
} else if (SCXMLHelper.isStringEmpty(event)
|| event.equalsIgnoreCase("null")) {
TriggerEvent[] evts = {new TriggerEvent(null,
TriggerEvent.SIGNAL_EVENT, null)};
exec.triggerEvents(evts);
if (exec.getCurrentStatus().isFinal()) {
System.out.println("A final configuration reached.");
}
} else {
StringTokenizer st = new StringTokenizer(event);
int tkns = st.countTokens();
TriggerEvent[] evts = new TriggerEvent[tkns];
for (int i = 0; i < tkns; i++) {
evts[i] = new TriggerEvent(st.nextToken(),
TriggerEvent.SIGNAL_EVENT, null);
}
exec.triggerEvents(evts);
if (exec.getCurrentStatus().isFinal()) {
System.out.println("A final configuration reached.");
}
}
}
} catch (IOException e) {