简体   繁体   中英

Apache SCXML: add a custom action

I'm working with Apache Commons SCXML 0.9 and I can't find how to add a CustomAction. I've found examples using v2.0-SNAPSHOT (which by the way I don't know where to get it), but it seems that doesn't work on v0.9, so far I got something like this:

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


For v2.0-SNAPSHOT I could write:

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

and after that, get a SCXMLExecutor and call the SCXMLExecutor.go method, but I can't find any option for v0.9, please I need your help here.
Best regards

Well, I think I got it, I've found this post where there is a full example (in spanish) using SCXML v0.9.
Here is the code I've wrote to add a custom action 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);

and if you want to register an onEntry action, is almost the same:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM