List of usage examples for org.apache.commons.scxml2.env.jexl JexlEvaluator JexlEvaluator
public JexlEvaluator()
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);/*from w w w. java 2s . c om*/ // 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 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);/*from ww w .j a va 2s. com*/ // 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(); new StopWatchFrame(executor); }
From source file:StandaloneJexlExpressions.java
/** * Launcher.//from w w w. j ava2 s . co m * @param args The arguments, one expected, the URI or filename of the * SCXML document */ public static void main(final String[] args) { if (args.length < 1) { System.out.println("USAGE: java " + StandaloneJexlExpressions.class.getName() + "<url|filename>"); System.exit(-1); } Evaluator evaluator = new JexlEvaluator(); StandaloneUtils.execute(args[0], evaluator); }
From source file:it.polito.elite.dog.drivers.appliances.base.ApplianceDriverInstance.java
private void initializeDeviceStateMachine() { // check if all needed elements are initialized if ((this.deviceSerial != null) && (!this.deviceSerial.isEmpty()) && (this.stateMachineLocator != null)) { // get the device-specific state machine URL, if any available URL stateMachineURL = this.stateMachineLocator.getStateMachine(this.deviceSerial); // check not null if (stateMachineURL != null) { try { // get the SCXML state machine (SCXML root element) this.stateMachine = SCXMLReader.read(stateMachineURL); // build a new executor this.executor = new SCXMLExecutor(new JexlEvaluator(), new SimpleDispatcher(), new SimpleErrorReporter()); //set a scheduler dispatcher to handle delayed events this.executor.setEventdispatcher(new SimpleScheduler(this.executor)); // set the state machine this.executor.setStateMachine(this.stateMachine); // set the root context JexlContext context = new JexlContext(); // set the executor context this.executor.setRootContext(context); // add this class as listener of the state machine changes this.executor.addListener(this.stateMachine, this); // start the engine this.executor.go(); } catch (IOException | ModelException | XMLStreamException e) { // log the error and continue if possible this.logger.log(LogService.LOG_ERROR, "Error while creating the state machine executor associated to this driver instance", e);/*from w w w . j a v a 2 s .c o m*/ } } } }