1

我正在使用 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 的任何选项,请在这里需要您的帮助。
最好的祝福

4

1 回答 1

1

好吧,我想我明白了,我发现这篇文章有一个使用 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);
于 2016-02-03T13:48:11.237 回答