我正在使用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的任何选项,请在这里需要您的帮助。
祝您好!
答案 0 :(得分:0)
嗯,我想我明白了,我发现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);