【问题标题】:Apache SCXML: add a custom actionApache SCXML:添加自定义操作
【发布时间】:2016-02-02 21:07:57
【问题描述】:

我正在使用 Apache Commons SCXML 0.9,但我找不到如何添加 CustomAction。我找到了使用 v2.0-SNAPSHOT 的示例(顺便说一句,我不知道从哪里得到它),但似乎在 v0.9 上不起作用,到目前为止我得到了这样的东西:

CustomAction customAction = new CustomAction("http://my.custom-actions.domain/CUSTOM", "my", MyCustomAction.class);
List<CustomAction> customActions = new ArrayList<CustomAction>();
customActions.add(customAction);


对于 v2.0-SNAPSHOT,我可以写:

SCXML scxml = SCXMLTestHelper.parse("path/to/my/sm.xml", customActions);

然后,获取SCXMLExecutor 并调用SCXMLExecutor.go 方法,但我找不到v0.9 的任何选项,请在这里我需要你的帮助。
最好的问候

【问题讨论】:

    标签: java scxml apache-commons-scxml


    【解决方案1】:

    好吧,我想我明白了,我找到了this post,其中有一个使用 SCXML v0.9 的完整示例(西班牙语)。
    这是我为添加自定义操作而编写的代码onExit:

    MyCustomAction mca = new MyCustomAction();//MyCustomAction extends org.apache.commons.scxml.model.Action
    State state = (State) getEngine().getStateMachine().getTargets().get("yourstate");
    OnExit oex = state.getOnExit();
    oex.addAction(mca);
    state.setOnExit(oex);
    

    如果你想注册一个onEntry 动作,几乎是一样的:

    MyCustomAction mca = new MyCustomAction();//MyCustomAction extends org.apache.commons.scxml.model.Action
    MyCustomAction2 mca2 = new MyCustomAction2();//MyCustomAction2 extends org.apache.commons.scxml.model.Action
    State state = (State) getEngine().getStateMachine().getTargets().get("yourstate");
    OnEntry oe = state.getOnEntry();
    oe.addAction(mca);
    oe.addAction(mca2);
    state.setOnEntry(oe);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-26
      • 2011-05-22
      • 1970-01-01
      • 1970-01-01
      • 2012-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多