List of usage examples for org.apache.commons.scxml2 SCXMLExecutor setStateMachine
public void setStateMachine(final SCXML stateMachine) throws ModelException
If the state machine instance has been initialized before, it will be initialized again, destroying all existing state!
From source file:com.github.woonsan.commons.scxml.examples.helloworld.Main.java
public static void main(String[] args) throws Exception { // 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();//from w w w.j a va2 s. co m }
From source file:com.github.woonsan.commons.scxml.examples.stopwatch.Main.java
public static void main(String[] args) throws Exception { // 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); // create stopWatch object and add it to rootContext // to be able to script with that in SCXML. StopWatch stopWatch = new StopWatch(); rootContext.set("stopWatch", stopWatch); // set the root context for the engine executor.setRootContext(rootContext); // initiate the execution of the state machine executor.go();// w w w .j av a2 s . c o m new StopWatchFrame(executor); }
From source file:org.onehippo.repository.scxml.RepositorySCXMLExecutorFactory.java
@Override public SCXMLExecutor createSCXMLExecutor(SCXMLDefinition scxmlDef) throws SCXMLException { SCXMLExecutor executor = new SCXMLExecutor(scxmlDef.getEvaluator(), new SimpleDispatcher(), new SCXMLStrictErrorReporter(scxmlDef)); executor.setRootContext(scxmlDef.getEvaluator().newContext(null)); try {//from www.ja v a2 s.co m executor.setStateMachine(scxmlDef.getSCXML()); } catch (ModelException me) { throw new SCXMLException(me); } return executor; }