transition with no target bugfixes
This commit is contained in:
@@ -31,7 +31,7 @@ public interface TargetStateResolver {
|
||||
* @param transition the transition
|
||||
* @param sourceState the source state of the transition, could be null
|
||||
* @param context the current request context
|
||||
* @return the transition's target state
|
||||
* @return the transition's target state - may be null if no state change should occur
|
||||
*/
|
||||
public State resolveTargetState(Transition transition, State sourceState, RequestContext context);
|
||||
}
|
||||
@@ -200,25 +200,27 @@ public class Transition extends AnnotatedObject implements TransitionDefinition
|
||||
context.setLastTransition(this);
|
||||
if (targetStateResolver != null) {
|
||||
State targetState = targetStateResolver.resolveTargetState(this, sourceState, context);
|
||||
if (sourceState != null) {
|
||||
if (targetState != null) {
|
||||
if (sourceState != null) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Exiting state '" + sourceState.getId() + "'");
|
||||
}
|
||||
if (sourceState instanceof TransitionableState) {
|
||||
((TransitionableState) sourceState).exit(context);
|
||||
}
|
||||
}
|
||||
targetState.enter(context);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Exiting state '" + sourceState.getId() + "'");
|
||||
}
|
||||
if (sourceState instanceof TransitionableState) {
|
||||
((TransitionableState) sourceState).exit(context);
|
||||
if (context.getFlowExecutionContext().isActive()) {
|
||||
logger.debug("Completed transition execution. As a result, the new state is '"
|
||||
+ context.getCurrentState().getId() + "' in flow '"
|
||||
+ context.getActiveFlow().getId() + "'");
|
||||
} else {
|
||||
logger.debug("Completed transition execution. As a result, the flow execution has ended");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
targetState.enter(context);
|
||||
if (logger.isDebugEnabled()) {
|
||||
if (context.getFlowExecutionContext().isActive()) {
|
||||
logger.debug("Completed transition execution. As a result, the new state is '"
|
||||
+ context.getCurrentState().getId() + "' in flow '" + context.getActiveFlow().getId()
|
||||
+ "'");
|
||||
} else {
|
||||
logger.debug("Completed transition execution. As a result, the flow execution has ended");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -56,7 +56,11 @@ public class DefaultTargetStateResolver implements TargetStateResolver {
|
||||
|
||||
public State resolveTargetState(Transition transition, State sourceState, RequestContext context) {
|
||||
String stateId = String.valueOf(targetStateIdExpression.getValue(context));
|
||||
return ((Flow) context.getActiveFlow()).getStateInstance(stateId);
|
||||
if (stateId != null) {
|
||||
return ((Flow) context.getActiveFlow()).getStateInstance(stateId);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
||||
@@ -74,6 +74,30 @@ public class TransitionTests extends TestCase {
|
||||
assertSame(target, context.getCurrentState());
|
||||
}
|
||||
|
||||
public void testExecuteTransitionNullTargetState() {
|
||||
Flow flow = new Flow("flow");
|
||||
final TransitionableState source = new TransitionableState(flow, "state 1") {
|
||||
public void exit(RequestControlContext context) {
|
||||
exitCalled = true;
|
||||
}
|
||||
|
||||
protected void doEnter(RequestControlContext context) throws FlowExecutionException {
|
||||
}
|
||||
};
|
||||
TargetStateResolver targetResolver = new TargetStateResolver() {
|
||||
public State resolveTargetState(Transition transition, State sourceState, RequestContext context) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
MockRequestControlContext context = new MockRequestControlContext(flow);
|
||||
context.setCurrentState(source);
|
||||
Transition t = new Transition(targetResolver);
|
||||
boolean stateExited = t.execute(source, context);
|
||||
assertFalse(stateExited);
|
||||
assertFalse(exitCalled);
|
||||
assertSame(source, context.getCurrentState());
|
||||
}
|
||||
|
||||
public void testTransitionExecutionRefused() {
|
||||
Flow flow = new Flow("flow");
|
||||
final TransitionableState source = new TransitionableState(flow, "state 1") {
|
||||
|
||||
Reference in New Issue
Block a user