From 8ca484af3571b01feac6fd9b07a9ef409b78a956 Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Fri, 7 Mar 2008 14:50:02 +0000 Subject: [PATCH] transition with no target bugfixes --- .../webflow/engine/TargetStateResolver.java | 2 +- .../webflow/engine/Transition.java | 34 ++++++++++--------- .../support/DefaultTargetStateResolver.java | 6 +++- .../webflow/engine/TransitionTests.java | 24 +++++++++++++ 4 files changed, 48 insertions(+), 18 deletions(-) diff --git a/spring-webflow/src/main/java/org/springframework/webflow/engine/TargetStateResolver.java b/spring-webflow/src/main/java/org/springframework/webflow/engine/TargetStateResolver.java index ce28ebe2..5b8de38a 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/engine/TargetStateResolver.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/engine/TargetStateResolver.java @@ -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); } \ No newline at end of file diff --git a/spring-webflow/src/main/java/org/springframework/webflow/engine/Transition.java b/spring-webflow/src/main/java/org/springframework/webflow/engine/Transition.java index c5788a33..9a13c4e5 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/engine/Transition.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/engine/Transition.java @@ -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; diff --git a/spring-webflow/src/main/java/org/springframework/webflow/engine/support/DefaultTargetStateResolver.java b/spring-webflow/src/main/java/org/springframework/webflow/engine/support/DefaultTargetStateResolver.java index 000910eb..bcf8035a 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/engine/support/DefaultTargetStateResolver.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/engine/support/DefaultTargetStateResolver.java @@ -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() { diff --git a/spring-webflow/src/test/java/org/springframework/webflow/engine/TransitionTests.java b/spring-webflow/src/test/java/org/springframework/webflow/engine/TransitionTests.java index 6b1a7a57..c2b5e25f 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/engine/TransitionTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/engine/TransitionTests.java @@ -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") {