State current = position.getState();
String fromStateId = current.getName();
// Select the next state based on the specified outcome
Transition transition = current.findTransition(outcome);
if (transition == null) {
transition = position.getDialog().findTransition(outcome);
}
if (transition == null) {
throw new IllegalStateException
("Cannot find transition '" + outcome
+ "' for state '" + fromStateId
+ "' of dialog '" + position.getDialog().getName() + "'");
}
State next = position.getDialog().findState(transition.getTarget());
if (next == null) {
throw new IllegalStateException
("Cannot find state '" + transition.getTarget()
+ "' for dialog '" + position.getDialog().getName() + "'");
}
String toStateId = next.getName();
position.setState(next);