java - Apache SCXML : add a custom action

标签 java scxml apache-commons-scxml

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

最佳答案

嗯,我想我明白了,我找到了 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 Action ,几乎是一样的:

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);

关于java - Apache SCXML : add a custom action,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35163827/

相关文章:

Qt 5.8 如何使用带有子状态机的 SCXML 框架?

java - 如何模式匹配第一次出现?

java - Java 中的 setRGB()

java - Rocks DB的Java API是否支持前缀扫描?

java - 共享 SCXML 问题

java - Apache Commons SCXML 有什么替代品吗?

java - ` (strs[i].indexOf(prefix) != 0) ` 在查找 LongestCommonPrefix

android - 用于表示多模式用户界面的状态图建模的可视化编程工具

javascript - 在 D3 中选择 DOM 元素而不是它们的子元素