Пример #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);
    }
  }
 /**
  * @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();
 }