Exemplo n.º 1
0
  @Override
  public void execute(ActionExecutionContext exctx)
      throws ModelException, SCXMLExpressionException {

    // 得到资源文件路径
    final URL url = this.getClass().getClassLoader().getResource(getSrc());
    SCXML scxml = null;
    // 根据src的值,启动状态机
    try {
      scxml = SCXMLReader.read(url);
    } catch (Exception e) {
      System.out.println("couldn't find :" + getSrc());
      e.printStackTrace();
    }

    for (int i = 0; i < getInstances(); i++) {

      Evaluator evaluator = EvaluatorFactory.getEvaluator(scxml);

      SCXMLExecutionContext currentExecutionContext =
          (SCXMLExecutionContext) exctx.getInternalIOProcessor();

      SCXMLInstanceTree instanceTree = currentExecutionContext.getInstanceTree();
      SCXMLExecutor executor =
          new SCXMLExecutor(evaluator, null, new SimpleErrorReporter(), null, instanceTree);
      executor.setStateMachine(scxml);

      // 设置引擎执行的根上下文
      Context rootContext = evaluator.newContext(null);
      executor.setRootContext(rootContext);

      // 开始启动流程
      executor.go();

      // 维护关系
      String currentSessionId =
          (String)
              currentExecutionContext
                  .getScInstance()
                  .getSystemContext()
                  .get(SCXMLSystemContext.SESSIONID_KEY);

      String subStateMachineSessionId =
          (String)
              executor.getGlobalContext().getSystemContext().get(SCXMLSystemContext.SESSIONID_KEY);

      instanceTree.insert(
          currentSessionId, subStateMachineSessionId, executor.getStateMachine().getName());

      // 将当前的Executor加入到  实例管理器里面

      SCXMLInstanceManager.setSCXMLInstance(executor);
    }
  }
 /** @return Returns the SCXML Execution Logger for the application */
 public Log getAppLog() {
   return exctx.getAppLog();
 }
 /** @return Returns the event dispatcher */
 public EventDispatcher getEventDispatcher() {
   return exctx.getEventDispatcher();
 }
 /** @return Returns the error reporter */
 public ErrorReporter getErrorReporter() {
   return exctx.getErrorReporter();
 }
 /** @return Returns The evaluator. */
 public Evaluator getEvaluator() {
   return exctx.getEvaluator();
 }
 /**
  * @param state an EnterableState
  * @return Returns the context for an EnterableState
  */
 public Context getContext(EnterableState state) {
   return exctx.getScInstance().getContext(state);
 }
 /** @return Returns the global context */
 public Context getGlobalContext() {
   return exctx.getScInstance().getGlobalContext();
 }
 /** @return Returns the state machine */
 public SCXML getStateMachine() {
   return exctx.getStateMachine();
 }