Package org.uscxml

Examples of org.uscxml.Interpreter


    System.load("/Users/sradomski/Documents/TK/Code/uscxml/build/cli/lib/libuscxmlNativeJava64.jnilib");

    // syntactic xml parse error -> throws
    try {
      String xml = "<invalid";
      Interpreter interpreter = Interpreter.fromXML(xml);
      throw new RuntimeException("");
    } catch (InterpreterException e) {
      System.err.println(e);
    }

    // semantic xml parse error -> throws
    try {
      String xml = "<invalid />";
      Interpreter interpreter = Interpreter.fromXML(xml);
      if (interpreter.getState() != InterpreterState.USCXML_INSTANTIATED) throw new RuntimeException("");
      interpreter.step();
      throw new RuntimeException("");
    } catch (InterpreterException e) {
      System.err.println(e);
    }

    // request unknown datamodel -> throws
    try {
      String xml =
      "<scxml datamodel=\"invalid\">" +
      "  <state id=\"start\">" +
      "    <transition target=\"done\" />" +
      " </state>" +
      " <final id=\"done\" />" +
      "</scxml>";
      Interpreter interpreter = Interpreter.fromXML(xml);
      if (interpreter.getState() != InterpreterState.USCXML_INSTANTIATEDthrow new RuntimeException("");
      interpreter.step();
      throw new RuntimeException("");
     
    } catch (InterpreterException e) {
      System.err.println(e);
    }

    try {
      // two microsteps
      String xml =
      "<scxml>" +
      "  <state id=\"start\">" +
      "    <transition target=\"s2\" />" +
      "   </state>" +
      "  <state id=\"s2\">" +
      "    <transition target=\"done\" />" +
      " </state>" +
      " <final id=\"done\" />" +
      "</scxml>";
     
      Interpreter interpreter = Interpreter.fromXML(xml);

      if (interpreter.getState() != InterpreterState.USCXML_INSTANTIATED) throw new RuntimeException("");
      if (interpreter.step() != InterpreterState.USCXML_MICROSTEPPED) throw new RuntimeException("");
      if (interpreter.step() != InterpreterState.USCXML_MICROSTEPPED) throw new RuntimeException("");
      if (interpreter.step() != InterpreterState.USCXML_FINISHED) throw new RuntimeException("");

    } catch (InterpreterException e) {
      System.err.println(e);
    }
 
    try {
      // single macrostep, multiple runs
      String xml =
      "<scxml>" +
      "  <state id=\"start\">" +
      "    <transition target=\"done\" />" +
      " </state>" +
      " <final id=\"done\" />" +
      "</scxml>";
     
      Interpreter interpreter = Interpreter.fromXML(xml);
      if (interpreter.getState() != InterpreterState.USCXML_INSTANTIATED) throw new RuntimeException("");
      if (interpreter.step() != InterpreterState.USCXML_MICROSTEPPED) throw new RuntimeException("");
      if (interpreter.step() != InterpreterState.USCXML_FINISHED) throw new RuntimeException("");
      interpreter.reset();

      if (interpreter.getState() != InterpreterState.USCXML_INSTANTIATED) throw new RuntimeException("");
      if (interpreter.step() != InterpreterState.USCXML_MICROSTEPPED) throw new RuntimeException("");
      if (interpreter.step() != InterpreterState.USCXML_FINISHED) throw new RuntimeException("");

    } catch (InterpreterException e) {
      System.err.println(e);
    }
   
    try {
      // macrostep in between
      String xml =
      "<scxml>" +
      "  <state id=\"start\">" +
      "    <onentry>" +
      "      <send event=\"continue\" delay=\"2s\"/>" +
      "    </onentry>" +
      "    <transition target=\"s2\" event=\"continue\" />" +
      " </state>" +
      "  <state id=\"s2\">" +
      "    <transition target=\"done\" />" +
      " </state>" +
      " <final id=\"done\" />" +
      "</scxml>";
     
      Interpreter interpreter = Interpreter.fromXML(xml);
      if (interpreter.getState() != InterpreterState.USCXML_INSTANTIATED) throw new RuntimeException("");
      if (interpreter.step() != InterpreterState.USCXML_IDLE) throw new RuntimeException("");
      if (interpreter.step(true) != InterpreterState.USCXML_MACROSTEPPED) throw new RuntimeException("");
      if (interpreter.step() != InterpreterState.USCXML_MICROSTEPPED) throw new RuntimeException("");
      if (interpreter.step() != InterpreterState.USCXML_FINISHED) throw new RuntimeException("");

    } catch (InterpreterException e) {
      System.err.println(e);
    }
  }
View Full Code Here


      "  <state id=\"start\">" +
      "    <transition target=\"don\" cond=\"%sf\" />" +
      " </state>" +
      " <final />" +
      "</scxml>";
      Interpreter interpreter = Interpreter.fromXML(xml);
      IssueList issues = interpreter.validate();
      for (int i = 0; i < issues.size(); i++) {
        System.out.println(issues.get(i));
      }
           
    } catch (InterpreterException e) {
View Full Code Here

    "</scxml>";

    TestAdhocIOProc ioProc = new TestAdhocIOProc();

    // parse and interpret
    Interpreter interpreter = Interpreter.fromXML(xml);
    interpreter.addIOProcessor(ioProc);
    interpreter.interpret();
  }
View Full Code Here

    p.add(label);
    add(p);
    setSize(200, 100);

    // instantiate SCXML interpreter
    final Interpreter interpreter = Interpreter.fromXML(
        "<scxml datamodel=\"ecmascript\">"
            + "  <script src=\"http://uscxml.tk.informatik.tu-darmstadt.de/scripts/dump.js\" />"
            + " <script>var charSeq = \"\";</script>"
            + "  <state id=\"idle\">"
            + "   <transition event=\"error\" target=\"quit\">"
            + "     <log label=\"error\" expr=\"dump(_event)\" />"
            + "   </transition>"
            + "   <transition event=\"key.released\" cond=\"_event.data.keyChar == 10\">"
            + "     <send type=\"console\">"
            + "       <param name=\"foo\" expr=\"charSeq\" />"
            + "     </send>"
            + "     <script>"
            + "       charSeq = \"\"; // reset string"
            + "     </script>"
            + "   </transition>"
            + "   <transition event=\"*\">"
            + "     <log label=\"event\" expr=\"dump(_event.data)\" />"
            + "     <script>charSeq += String.fromCharCode(_event.data.keyChar);</script>"
            + "   </transition>"
            + "  </state>"
            + " <final id=\"quit\" />"
            + "</scxml>");

    /**
     *  ConsoleIOProc will register as a keyboard listener and send events to the interpreter.
     * 
     *   This circumvents the factory and registers instances directly. You will have to promise
     *   that the ioProc instance exists for the complete lifetime of the interpreter, otherwise
     *   finalize() will call the C++ destructor and SegFaults will occur.
     */
    ioProc = new ConsoleIOProc(this);
    interpreter.addIOProcessor(ioProc);

    // Start the interpreter in a separate thread
    Thread intrerpreterThread = new Thread(new Runnable() {
      @Override
      public void run() {
        try {
          interpreter.interpret();
        } catch (InterpreterException e) {
          e.printStackTrace();
        }       
      }
    });
View Full Code Here

    "  </state>" +
    "  <final id=\"done\" />" +
    "</scxml>";

    // parse and interpret
    Interpreter interpreter = Interpreter.fromXML(xml);
    interpreter.interpret();
  }
View Full Code Here

    System.load("/Users/sradomski/Documents/TK/Code/uscxml/build/cli/lib/libuscxmlNativeJava64.jnilib");

    HTTPServer http = HTTPServer.getInstance(5080, 5081);
   
    URL jVoiceXMLDoc = new URL(new URL("file:"), "../../test/uscxml/test-jvoicexml.scxml");
    Interpreter interpreter = Interpreter.fromURI(jVoiceXMLDoc);
    interpreter.interpret();
  }
View Full Code Here

    "  </state>" +
    "  <final id=\"done\" />" +
    "</scxml>";

    // parse and interpret
    Interpreter interpreter = Interpreter.fromXML(xml);
   
    TestCustomMonitor monitor = new TestCustomMonitor();
    interpreter.addMonitor(monitor);
   
    interpreter.interpret();
  }
View Full Code Here

    " <final id=\"done\" />" +
    "</scxml>";

    if (false) {
      // datamodel not available before first step -> dies with segfault
      Interpreter interpreter = Interpreter.fromXML(xml);
      System.out.println(interpreter.getDataModel().evalAsString("'FOO'"));
    }

    if (false) {
      // datamodel is available but syntactic ecmascript exception is not propagated
      Interpreter interpreter = Interpreter.fromXML(xml);
      interpreter.step();
      System.out.println(interpreter.getDataModel().evalAsString("'FOO' / qwer"));
    }

   
   
  }
View Full Code Here

    // register java datamodel at factory
    ECMAScriptDataModel datamodel = new ECMAScriptDataModel();
    Factory.getInstance().registerDataModel(datamodel);

    // instantiate interpreter with document from file
    Interpreter interpreter = Interpreter
        .fromURI("/Users/sradomski/Documents/TK/Code/uscxml/test/uscxml/java/test-ecmascript-datamodel.scxml");

    // wait until interpreter has finished
    while (true)
      interpreter.interpret();
  }
View Full Code Here

    File dir = new File(testDir);
    File[] filesList = dir.listFiles();
    for (File file : filesList) {
        if (file.isFile() && file.getName().endsWith(".scxml")) {
          System.out.println("### " + file.getName() + " #####");
          Interpreter interpreter = Interpreter.fromURI(file.getAbsolutePath());
          interpreter.setCapabilities(1);
          interpreter.interpret();
        }
    }

  }
View Full Code Here

TOP

Related Classes of org.uscxml.Interpreter

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.