handle(context.getCurrentState(), event);
}
}
private void handle(State state, Event event) {
StateContext context = event.getContext();
for (Transition t : state.getTransitions()) {
if (log.isDebugEnabled()) {
log.debug("Trying transition " + t);
}
try {
if (t.execute(event)) {
if (log.isDebugEnabled()) {
log.debug("Transition " + t + " executed successfully.");
}
setCurrentState(context, t.getNextState());
return;
}
} catch (BreakAndContinueException bace) {
if (log.isDebugEnabled()) {
log.debug("BreakAndContinueException thrown in "
+ "transition " + t
+ ". Continuing with next transition.");
}
} catch (BreakAndGotoException bage) {
State newState = getState(bage.getStateId());
if (bage.isNow()) {
if (log.isDebugEnabled()) {
log.debug("BreakAndGotoException thrown in "
+ "transition " + t + ". Moving to state "
+ newState.getId() + " now.");
}
setCurrentState(context, newState);
handle(newState, event);
} else {
if (log.isDebugEnabled()) {
log.debug("BreakAndGotoException thrown in "
+ "transition " + t + ". Moving to state "
+ newState.getId() + " next.");
}
setCurrentState(context, newState);
}
return;
} catch (BreakAndCallException bace) {
State newState = getState(bace.getStateId());
Stack<State> callStack = getCallStack(context);
State returnTo = bace.getReturnToStateId() != null
? getState(bace.getReturnToStateId())
: context.getCurrentState();
callStack.push(returnTo);
if (bace.isNow()) {
if (log.isDebugEnabled()) {
log.debug("BreakAndCallException thrown in "