Package org.apache.commons.scxml

Examples of org.apache.commons.scxml.SCXMLExecutor


     * @param rootCtx The root context
     * @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());
View Full Code Here


                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) {
View Full Code Here

            throw new InvokerException(ioe.getMessage(), ioe.getCause());
        } catch (SAXException se) {
            throw new InvokerException(se.getMessage(), se.getCause());
        }
        Evaluator eval = parentSCInstance.getEvaluator();
        executor = new SCXMLExecutor(eval,
            new SimpleDispatcher(), new SimpleErrorReporter());
        Context rootCtx = eval.newContext(null);
        for (Iterator iter = params.entrySet().iterator(); iter.hasNext();) {
            Map.Entry entry = (Map.Entry) iter.next();
            rootCtx.setLocal((String) entry.getKey(), entry.getValue());
View Full Code Here

     */
    public void testInvoke01Sample() {
        try {
            SCXML scxml = SCXMLParser.parse(invoke01,
                new SimpleErrorHandler());
            exec = new SCXMLExecutor(new JexlEvaluator(), new SimpleDispatcher(),
                new SimpleErrorReporter());
            assertNotNull(exec);
            exec.setRootContext(new JexlContext());
            exec.setStateMachine(scxml);
            exec.registerInvokerClass("scxml", SimpleSCXMLInvoker.class);
View Full Code Here

    public void testInvoke02Sample() {
        try {
            SCXML scxml = SCXMLParser.parse(invoke02,
                new SimpleErrorHandler());
            exec = new SCXMLExecutor(new JexlEvaluator(), new SimpleDispatcher(),
                new SimpleErrorReporter());
            assertNotNull(exec);
            exec.setRootContext(new JexlContext());
            exec.setStateMachine(scxml);
            exec.registerInvokerClass("scxml", SimpleSCXMLInvoker.class);
View Full Code Here

    public void testInvoke03Sample() {
        try {
            SCXML scxml = SCXMLParser.parse(invoke03,
                new SimpleErrorHandler());
            exec = new SCXMLExecutor(new JexlEvaluator(), new SimpleDispatcher(),
                new SimpleErrorReporter());
            assertNotNull(exec);
            exec.setRootContext(new JexlContext());
            exec.setStateMachine(scxml);
            exec.registerInvokerClass("scxml", SimpleSCXMLInvoker.class);
View Full Code Here

    }

    public void testJexlStaticMethodInvocation() {
        Context jc = new JexlContext();
        jc.set("System", System.class);
        SCXMLExecutor exec = SCXMLTestHelper.getExecutor(staticmethod,
                jc, new JexlEvaluator());
        Set currentStates = exec.getCurrentStatus().getStates();
        assertEquals(1, currentStates.size());
        assertEquals("static", ((State)currentStates.iterator().
            next()).getId());
    }
View Full Code Here

                      context.getViewRoot().getViewId() +
                      ",fromAction=" + fromAction +
                      ",outcome=" + outcome + ")");
        }

        SCXMLExecutor exec = getDialogExecutor(context);
        String viewId = null;
       
        if (exec == null && outcome != null && outcome.startsWith(PREFIX)) {
         
          /**** DIALOG ENTRY ****/
          // dialog is a state machine, parse & obtain an executor
          exec = initDialogExecutor(context, outcome.substring(PREFIX.
              length()));

          if (exec != null) {
            // cache executor in session scope
            // TODO: Shale caches Dialog instances. SCXMLExecutor
            // knows what state(s) the dialog is in, so Dialog#findState()
            // is not needed.
            setDialogExecutor(context, exec);
            // obtain our initial view
            viewId = getCurrentViewId(exec);
          }
          // else delegate
         
        } else if (exec != null) {
         
          /**** SUBSEQUENT TURNS OF DIALOG ****/
          // pass a handle to the current ctx (for evaluating binding exprs)
          updateEvaluator(context, outcome);
          // fire a "faces.outcome" event on the dialog's state machine
          TriggerEvent[] te = { new TriggerEvent("faces.outcome",
              TriggerEvent.SIGNAL_EVENT) };
          try {
            exec.triggerEvents(te);
          } catch (ModelException me) {
            log.error(me.getMessage(), me);
          }
          // obtain next view
          viewId = getCurrentViewId(exec);
View Full Code Here

        if (scxml == null) {
          log.warn("Could not parse SCXML document at: " + dialogIdentifier);
          return null;
        }
       
        SCXMLExecutor exec = null;
        try {
            exec = new SCXMLExecutor(evaluator, new SimpleDispatcher(),
                new SimpleErrorReporter());
            scxml.addListener(new SimpleSCXMLListener());
            exec.setSuperStep(true);
            exec.setStateMachine(scxml);
        } catch (ModelException me) {
          log.warn(me.getMessage(), me);
          return null;
        }
       
View Full Code Here

                      context.getViewRoot().getViewId() +
                      ",fromAction=" + fromAction +
                      ",outcome=" + outcome + ")");
        }

        SCXMLExecutor exec = getDialogExecutor(context);
        String viewId = null;
       
        if (exec == null && outcome != null && outcome.startsWith(PREFIX)) {
         
          /**** DIALOG ENTRY ****/
          // dialog is a state machine, parse & obtain an executor
          exec = initDialogExecutor(context, outcome.substring(PREFIX.
              length()));

          if (exec != null) {
            // cache executor in session scope
            // TODO: Shale caches Dialog instances. SCXMLExecutor
            // knows what state(s) the dialog is in, so Dialog#findState()
            // is not needed.
            setDialogExecutor(context, exec);
            // obtain our initial view
            viewId = getCurrentViewId(exec);
          }
          // else delegate
         
        } else if (exec != null) {
         
          /**** SUBSEQUENT TURNS OF DIALOG ****/
          // pass a handle to the current ctx (for evaluating binding exprs)
          updateEvaluator(context, outcome);
          // fire a "faces.outcome" event on the dialog's state machine
          TriggerEvent[] te = { new TriggerEvent("faces.outcome",
              TriggerEvent.SIGNAL_EVENT) };
          try {
            exec.triggerEvents(te);
          } catch (ModelException me) {
            log.error(me.getMessage(), me);
          }
          // obtain next view
          viewId = getCurrentViewId(exec);
View Full Code Here

TOP

Related Classes of org.apache.commons.scxml.SCXMLExecutor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.