List of usage examples for org.apache.commons.scxml.env SimpleDispatcher SimpleDispatcher
public SimpleDispatcher()
From source file:com.korwe.thecore.scxml.ScxmlMessageProcessor.java
@Override public void initialize(String sessionId) { super.initialize(sessionId); try {// www . jav a 2 s . co m String scxmlPath = CoreConfig.getInstance().getProperty("scxml_path"); if (LOG.isDebugEnabled()) { LOG.debug("SCXML path = " + scxmlPath); } File scfile = new File(scxmlPath); if (LOG.isDebugEnabled()) { LOG.debug("Absolute path: [" + scfile.getAbsolutePath() + "]"); } InputSource source = new InputSource(new BufferedReader(new FileReader(scxmlPath))); scxml = SCXMLParser.parse(source, new SimpleErrorHandler()); exec = new SCXMLExecutor(new JexlEvaluator(), new SimpleDispatcher(), new SimpleErrorReporter()); exec.setStateMachine(scxml); exec.addListener(scxml, new SimpleSCXMLListener()); exec.registerInvokerClass("x-coremessage", SendCoreMessageInvoker.class); Context context = new JexlContext(); context.set("sessionId", sessionId); context.set("lastMsg", null); exec.setRootContext(context); exec.go(); } catch (Exception e) { LOG.error("Failed to parse SCXML", e); } }
From source file:alma.acs.nc.sm.generic.AcsScxmlEngine.java
/** * @param scxmlFileName The qualified xml file name, e.g. "/alma/acs/nc/sm/EventSubscriberStates.xml", * in the form that {@link Class#getResource(String)} can use to load the scxml * definition file from the classpath. * @param logger//ww w . j av a2s .c o m * @param actionDispatcher * @param signalType enum class, needed to convert signal names to enum values. * @throws IllegalArgumentException if any of the args are <code>null</code> or if the <code>actionDispatcher</code> * is not complete for all possible actions. */ public AcsScxmlEngine(String scxmlFileName, Logger logger, AcsScxmlActionDispatcher<A> actionDispatcher, Class<S> signalType) { this.logger = logger; this.actionDispatcher = actionDispatcher; this.signalType = signalType; // TODO decide if we want to insist here, or let the user check this beforehand if (!actionDispatcher.isActionMappingComplete()) { throw new IllegalArgumentException("actionDispatcher is not complete."); } errorTracer = new Tracer(); // create error tracer exprEvaluator = new JexlEvaluator(); // Evaluator evaluator = new ELEvaluator(); eventDispatcher = new SimpleDispatcher(); // create event dispatcher exprContext = new JexlContext(); // set new context // Adding AcsScxmlActionDispatcher to the SM root context // so that the generated action classes can get it from there and can delegate action calls. exprContext.set(AcsScxmlActionDispatcher.class.getName(), actionDispatcher); try { // load the scxml model loadModel(scxmlFileName); startExecution(); } catch (Exception ex) { logger.log(Level.SEVERE, "Failed to load or start the state machine.", ex); // TODO } }
From source file:ch.shaktipat.saraswati.internal.common.AbstractStateMachine.java
/** * Instantiate and initialize the underlying executor instance. * * @param stateMachine The state machine * @param rootCtx The root context/* www . j av a 2 s. c o m*/ * @param evaluator The expression evaluator */ private void initialize(final SCXML stateMachine, final Context rootCtx, final Evaluator evaluator) { engine = new SCXMLExecutor(evaluator, new SimpleDispatcher(), new SimpleErrorReporter()); engine.setStateMachine(stateMachine); engine.setSuperStep(true); engine.setRootContext(rootCtx); engine.addListener(stateMachine, new EntryListener()); try { engine.go(); } catch (ModelException me) { logError(me); } }
From source file:de.dfki.iui.mmds.scxml.engine.impl.SCXMLEngineImpl.java
/** * Primary constructor, object instantiation incurs parsing cost. * /* ww w . j a va2 s . c om*/ * @param scxmlDocument * The URL pointing to the SCXML document that describes the * "lifecycle" of the instances of this class. * @param rootCtx * The root context for this instance. * @param evaluator * The expression evaluator for this instance. * * @see Context * @see Evaluator */ public SCXMLEngineImpl(final URL scxmlDocument, final Context rootCtx, final Evaluator evaluator) { log = LogFactory.getLog(this.getClass()); initialize(load(scxmlDocument), rootCtx, evaluator, new SimpleDispatcher(), new SimpleErrorReporter()); }
From source file:de.dfki.iui.mmds.scxml.engine.impl.SCXMLEngineImpl.java
/** * Primary constructor.//from w ww .j av a 2s .c o m * * @param stateMachine * The parsed SCXML instance that describes the * "lifecycle" of the instances of this class. * @param rootCtx * The root context for this instance. * @param evaluator * The expression evaluator for this instance. * * @see Context * @see Evaluator * * @since 0.7 */ public SCXMLEngineImpl(final SCXML stateMachine, final Context rootCtx, final Evaluator evaluator) { log = LogFactory.getLog(this.getClass()); initialize(stateMachine, rootCtx, evaluator, new SimpleDispatcher(), new SimpleErrorReporter()); }
From source file:de.dfki.iui.mmds.scxml.engine.impl.SCXMLEngineImpl.java
/** * Instantiate and initialize the underlying executor instance with default * evaluator and context./*from www . ja va2s .c om*/ */ @Override public void initialize(URL scxmlDocument) { initialize(load(scxmlDocument), new JSContext(), new JSEvaluator(), new SimpleDispatcher(), new SimpleErrorReporter()); }
From source file:de.dfki.iui.mmds.scxml.engine.impl.SCXMLEngineImpl.java
/** * /*w w w. j av a 2 s . c o m*/ */ @Override public void initialize(URL scxmlDocument, String idSuffix) { initialize(load(scxmlDocument), idSuffix, new JSContext(), new JSEvaluator(), new SimpleDispatcher(), new SimpleErrorReporter()); }
From source file:org.dishevelled.piccolo.identify.StateMachineSupport.java
/** * Create a new state machine support class to be delegated to * by the specified delegator with the specified state machine. * * @param delegator object delegating to this state machine support * class, must not be null//from w ww . j a v a 2 s. co m * @param stateMachine state machine for this support class, must * not be null */ StateMachineSupport(final Object delegator, final SCXML stateMachine) { if (delegator == null) { throw new IllegalArgumentException("delegator must not be null"); } if (stateMachine == null) { throw new IllegalArgumentException("stateMachine must not be null"); } this.delegator = delegator; Evaluator evaluator = new JexlEvaluator(); EventDispatcher dispatcher = new SimpleDispatcher(); ErrorReporter errorReporter = new NoopErrorReporter(); Context rootContext = new JexlContext(); SCXMLListener listener = new SCXMLListener() { @Override public void onEntry(final TransitionTarget entered) { invoke(entered.getId()); } @Override public void onExit(final TransitionTarget exited) { // empty } @Override public void onTransition(final TransitionTarget to, final TransitionTarget from, final Transition transition) { // empty } }; executor = new SCXMLExecutor(evaluator, dispatcher, errorReporter); executor.setStateMachine(stateMachine); executor.setSuperStep(false); executor.setRootContext(rootContext); executor.addListener(stateMachine, listener); try { executor.go(); } catch (ModelException e) { // ignore } }