if (invokers.containsKey(tt)) {
Invoker toCancel = (Invoker) invokers.get(tt);
try {
toCancel.cancel();
} catch (InvokerException ie) {
TriggerEvent te = new TriggerEvent(tt.getId()
+ ".invoke.cancel.failed", TriggerEvent.ERROR_EVENT);
internalEvents.add(te);
}
// done here, don't wait for cancel response
invokers.remove(tt);
}
nr.fireOnExit(tt, tt);
nr.fireOnExit(stateMachine, tt);
TriggerEvent te = new TriggerEvent(tt.getId() + ".exit",
TriggerEvent.CHANGE_EVENT);
internalEvents.add(te);
}
// ExecutePhaseActions / Transitions
for (Iterator i = step.getTransitList().iterator(); i.hasNext();) {
Transition t = (Transition) i.next();
try {
for (Iterator transitIter = t.getActions().iterator();
transitIter.hasNext();) {
((Action) transitIter.next()).execute(evtDispatcher,
errRep, scInstance, appLog, internalEvents);
}
} catch (SCXMLExpressionException e) {
errRep.onError(ErrorConstants.EXPRESSION_ERROR,
e.getMessage(), t);
}
List rtargets = t.getRuntimeTargets();
for (int j = 0; j < rtargets.size(); j++) {
TransitionTarget tt = (TransitionTarget) rtargets.get(j);
nr.fireOnTransition(t, t.getParent(), tt, t);
nr.fireOnTransition(stateMachine, t.getParent(), tt, t);
}
}
// ExecutePhaseActions / OnEntry
for (Iterator i = step.getEntryList().iterator(); i.hasNext();) {
TransitionTarget tt = (TransitionTarget) i.next();
OnEntry oe = tt.getOnEntry();
try {
for (Iterator onEntryIter = oe.getActions().iterator();
onEntryIter.hasNext();) {
((Action) onEntryIter.next()).execute(evtDispatcher,
errRep, scInstance, appLog, internalEvents);
}
} catch (SCXMLExpressionException e) {
errRep.onError(ErrorConstants.EXPRESSION_ERROR, e.getMessage(),
oe);
}
nr.fireOnEntry(tt, tt);
nr.fireOnEntry(stateMachine, tt);
TriggerEvent te = new TriggerEvent(tt.getId() + ".entry",
TriggerEvent.CHANGE_EVENT);
internalEvents.add(te);
// actions in initial transition (if any) and .done events
if (tt instanceof State) {
State ts = (State) tt;
Initial ini = ts.getInitial();
if (ts.isComposite() && ini != null) {
try {
for (Iterator iniIter = ini.getTransition().
getActions().iterator(); iniIter.hasNext();) {
((Action) iniIter.next()).execute(evtDispatcher,
errRep, scInstance, appLog, internalEvents);
}
} catch (SCXMLExpressionException e) {
errRep.onError(ErrorConstants.EXPRESSION_ERROR,
e.getMessage(), ini);
}
}
if (ts.isFinal()) {
State parent = (State) ts.getParent();
String prefix = "";
if (parent != null) {
prefix = parent.getId();
}
te = new TriggerEvent(prefix + ".done",
TriggerEvent.CHANGE_EVENT);
internalEvents.add(te);
if (parent != null) {
scInstance.setDone(parent, true);
}
if (parent != null && parent.isRegion()) {
//3.4 we got a region, which is finalized
//let's check its siblings too
Parallel p = (Parallel) parent.getParent();
int finCount = 0;
int pCount = p.getChildren().size();
for (Iterator regions = p.getChildren().iterator();
regions.hasNext();) {
State reg = (State) regions.next();
if (scInstance.isDone(reg)) {
finCount++;
}
}
if (finCount == pCount) {
te = new TriggerEvent(p.getId() + ".done",
TriggerEvent.CHANGE_EVENT);
internalEvents.add(te);
scInstance.setDone(p, true);
if (stateMachine.isLegacy()) {
te = new TriggerEvent(p.getParent().getId()
+ ".done", TriggerEvent.CHANGE_EVENT);
internalEvents.add(te);
//this is not in the specs, but is makes sense
scInstance.setDone(p.getParentState(), true);
}