Apache SCXML: add a custom action

364 views Asked by At

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

1

There are 1 answers

0
maxivis On BEST ANSWER

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