lastEvent -> currentEvent

lastTransition -> currentTransition
This commit is contained in:
Keith Donald
2008-03-31 19:31:28 +00:00
parent d82d4fb77e
commit de66dd5720
18 changed files with 83 additions and 100 deletions

View File

@@ -129,7 +129,7 @@ public class ActionState extends TransitionableState {
public Transition getRequiredTransition(RequestContext context) throws NoMatchingTransitionException {
Transition transition = getTransitionSet().getTransition(context);
if (transition == null) {
throw new NoMatchingActionResultTransitionException(this, context.getLastEvent());
throw new NoMatchingActionResultTransitionException(this, context.getCurrentEvent());
}
return transition;
}
@@ -182,7 +182,7 @@ public class ActionState extends TransitionableState {
executionCount++;
}
if (executionCount > 0) {
throw new NoMatchingTransitionException(getFlow().getId(), getId(), context.getLastEvent(),
throw new NoMatchingTransitionException(getFlow().getId(), getId(), context.getCurrentEvent(),
"No transition was matched on the event(s) signaled by the [" + executionCount
+ "] action(s) that executed in this action state '" + getId() + "' of flow '"
+ getFlow().getId() + "'; transitions must be defined to handle action result outcomes -- "

View File

@@ -54,12 +54,12 @@ public interface RequestControlContext extends RequestContext {
public void setCurrentState(State state);
/**
* Record the last transition that executed in the executing flow. This method will be called as part of executing a
* transition from one state to another.
* @param lastTransition the last transition that executed
* Record the transition executing in the flow. This method will be called as part of executing a transition from
* one state to another.
* @param transition the transition being executed
* @see Transition#execute(State, RequestControlContext)
*/
public void setLastTransition(Transition lastTransition);
public void setCurrentTransition(Transition transition);
/**
* Assign the ongoing flow execution its flow execution key. This method will be called before a state is about to

View File

@@ -107,7 +107,7 @@ public class SubflowState extends TransitionableState {
*/
public boolean handleEvent(RequestControlContext context) {
if (subflowAttributeMapper != null) {
AttributeMap subflowOutput = context.getLastEvent().getAttributes();
AttributeMap subflowOutput = context.getCurrentEvent().getAttributes();
if (logger.isDebugEnabled()) {
logger.debug("Mapping subflow output " + subflowOutput);
}

View File

@@ -207,7 +207,7 @@ public class Transition extends AnnotatedObject implements TransitionDefinition
if (logger.isDebugEnabled()) {
logger.debug("Executing " + this);
}
context.setLastTransition(this);
context.setCurrentTransition(this);
if (targetStateResolver != null) {
State targetState = targetStateResolver.resolveTargetState(this, sourceState, context);
if (targetState != null) {

View File

@@ -90,8 +90,8 @@ public abstract class TransitionableState extends State implements Transitionabl
public Transition getRequiredTransition(RequestContext context) throws NoMatchingTransitionException {
Transition transition = getTransitionSet().getTransition(context);
if (transition == null) {
throw new NoMatchingTransitionException(getFlow().getId(), getId(), context.getLastEvent(),
"No transition found on occurence of event '" + context.getLastEvent() + "' in state '" + getId()
throw new NoMatchingTransitionException(getFlow().getId(), getId(), context.getCurrentEvent(),
"No transition found on occurence of event '" + context.getCurrentEvent() + "' in state '" + getId()
+ "' of flow '" + getFlow().getId() + "' -- valid transitional criteria are "
+ StylerUtils.style(getTransitionSet().getTransitionCriterias())
+ " -- likely programmer error, check the set of TransitionCriteria for this state");
@@ -111,7 +111,7 @@ public abstract class TransitionableState extends State implements Transitionabl
/**
* Inform this state definition that an event was signaled in it. The signaled event is the last event available in
* given request context ({@link RequestContext#getLastEvent()}).
* given request context ({@link RequestContext#getCurrentEvent()}).
* @param context the flow execution control context
* @throws NoMatchingTransitionException when a matching transition cannot be found
*/

View File

@@ -75,14 +75,14 @@ class RequestControlContextImpl implements RequestControlContext {
private AttributeMap attributes = CollectionUtils.EMPTY_ATTRIBUTE_MAP;
/**
* The last event that occurred in this request context; initially null.
* The current event being processed by this flow; initially null.
*/
private Event lastEvent;
private Event currentEvent;
/**
* The last transition that executed in this request context; initially null.
*/
private Transition lastTransition;
private Transition currentTransition;
/**
* Create a new request context.
@@ -148,12 +148,12 @@ class RequestControlContextImpl implements RequestControlContext {
return flowExecution;
}
public Event getLastEvent() {
return lastEvent;
public Event getCurrentEvent() {
return currentEvent;
}
public TransitionDefinition getLastTransition() {
return lastTransition;
public TransitionDefinition getCurrentTransition() {
return currentTransition;
}
public AttributeMap getAttributes() {
@@ -187,8 +187,8 @@ class RequestControlContextImpl implements RequestControlContext {
flowExecution.setCurrentState(state, this);
}
public void setLastTransition(Transition lastTransition) {
this.lastTransition = lastTransition;
public void setCurrentTransition(Transition transition) {
this.currentTransition = transition;
}
public FlowExecutionKey assignFlowExecutionKey() {
@@ -205,7 +205,7 @@ class RequestControlContextImpl implements RequestControlContext {
}
public boolean handleEvent(Event event) throws FlowExecutionException {
this.lastEvent = event;
this.currentEvent = event;
return flowExecution.handleEvent(event, this);
}

View File

@@ -52,7 +52,7 @@ public class DefaultTransitionCriteria implements TransitionCriteria {
return ((Boolean) result).booleanValue();
} else {
String eventId = String.valueOf(result);
return context.getLastEvent().getId().equals(eventId);
return context.getCurrentEvent().getId().equals(eventId);
}
}

View File

@@ -26,7 +26,7 @@ import org.springframework.webflow.execution.RequestContext;
* Simple transition criteria that matches on an eventId and nothing else. Specifically, if the id of the last event
* that occurred equals {@link #getEventId()} this criteria will return true.
*
* @see RequestContext#getLastEvent()
* @see RequestContext#getCurrentEvent()
*
* @author Erwin Vervaet
* @author Keith Donald
@@ -67,7 +67,7 @@ public class EventIdTransitionCriteria implements TransitionCriteria, Serializab
}
public boolean test(RequestContext context) {
Event lastEvent = context.getLastEvent();
Event lastEvent = context.getCurrentEvent();
if (lastEvent == null) {
return false;
}

View File

@@ -75,6 +75,14 @@ public interface RequestContext {
*/
public StateDefinition getCurrentState() throws IllegalStateException;
/**
* Returns true if the flow is currently active and in a view state. When in a view state {@link #getViewScope()},
* can be safely called.
* @see #getViewScope()
* @return true if in a view state, false if not
*/
public boolean inViewState();
/**
* Returns a mutable map for accessing and/or setting attributes in request scope. <b>Request scoped attributes
* exist for the duration of this request only.</b>
@@ -89,18 +97,11 @@ public interface RequestContext {
*/
public MutableAttributeMap getFlashScope();
/**
* Returns true if the flow is currently active and in a view state. When in a view state {@link #getViewScope()},
* can be safely called.
* @see #getViewScope()
* @return true if in a view state, false if not
*/
public boolean inViewState();
/**
* Returns a mutable map for accessing and/or setting attributes in view scope. <b>View scoped attributes exist for
* the life of the current view state.</b>
* @return the view scope
* @see #inViewState()
* @throws IllegalStateException this flow is not in a view-state
*/
public MutableAttributeMap getViewScope() throws IllegalStateException;
@@ -161,17 +162,17 @@ public interface RequestContext {
public FlowExecutionContext getFlowExecutionContext();
/**
* Returns the last event signaled during this request. The event may or may not have caused a state transition to
* happen.
* @return the last signaled event, or null if no event has been signaled yet
* Returns the current event being processed by this flow. The event may or may not have caused a state transition
* to happen.
* @return the current event, or null if no event has been signaled yet
*/
public Event getLastEvent();
public Event getCurrentEvent();
/**
* Returns the last state transition that executed in this request.
* @return the last transition, or <code>null</code> if no transition has occurred yet
*/
public TransitionDefinition getLastTransition();
public TransitionDefinition getCurrentTransition();
/**
* Returns a context map for accessing arbitrary attributes about the state of the current request. These attributes

View File

@@ -143,7 +143,7 @@ public class ImplicitFlowVariableELResolver extends ELResolver {
private static final PropertyResolver currentEventResolver = new PropertyResolver() {
protected Object doResolve(ELContext elContext, RequestContext requestContext, Object property) {
return requestContext.getLastEvent();
return requestContext.getCurrentEvent();
}
};

View File

@@ -28,7 +28,7 @@ import org.springframework.webflow.execution.RequestContextHolder;
/**
* Custom EL resolver that resolves the current RequestContext under the variable {@link #REQUEST_CONTEXT_VARIABLE_NAME}.
* Allows for accessing any propert of the RequestContext instance. For example:
* Allows for accessing any property of the RequestContext instance. For example:
* "#{flowRequestContext.conversationScope.myProperty}".
*
* @author Jeremy Grelle

View File

@@ -45,8 +45,6 @@ import org.springframework.webflow.execution.RequestContext;
*/
public class MockRequestContext implements RequestContext {
protected static final String FLOW_VIEW_MAP_ATTRIBUTE = "flowViewMap";
private FlowExecutionContext flowExecutionContext;
private ExternalContext externalContext;
@@ -57,9 +55,9 @@ public class MockRequestContext implements RequestContext {
private MutableAttributeMap attributes = new LocalAttributeMap();
private Event lastEvent;
private Event currentEvent;
private Transition lastTransition;
private Transition currentTransition;
/**
* Convenience constructor that creates a new mock request context with the following defaults:
@@ -120,6 +118,10 @@ public class MockRequestContext implements RequestContext {
return getFlowExecutionContext().getActiveSession().getState();
}
public boolean inViewState() {
return getFlowExecutionContext().isActive() && getCurrentState() != null && getCurrentState().isViewState();
}
public MutableAttributeMap getRequestScope() {
return requestScope;
}
@@ -128,19 +130,8 @@ public class MockRequestContext implements RequestContext {
return getMockFlowExecutionContext().getFlashScope();
}
public boolean inViewState() {
return getFlowExecutionContext().isActive() && getCurrentState() != null && getCurrentState().isViewState();
}
public MutableAttributeMap getViewScope() throws IllegalStateException {
if (!getFlowExecutionContext().isActive()) {
throw new IllegalStateException("This flow is not active");
}
if (!getCurrentState().isViewState()) {
throw new IllegalStateException("The current state '" + getCurrentState().getId() + "' of this flow '"
+ getActiveFlow().getId() + "' is not a view state - view scope not accessible");
}
return (MutableAttributeMap) getFlowScope().get(FLOW_VIEW_MAP_ATTRIBUTE);
return getMockFlowExecutionContext().getActiveSession().getViewScope();
}
public MutableAttributeMap getFlowScope() {
@@ -167,12 +158,12 @@ public class MockRequestContext implements RequestContext {
return flowExecutionContext;
}
public Event getLastEvent() {
return lastEvent;
public Event getCurrentEvent() {
return currentEvent;
}
public TransitionDefinition getLastTransition() {
return lastTransition;
public TransitionDefinition getCurrentTransition() {
return currentTransition;
}
public AttributeMap getAttributes() {
@@ -228,19 +219,19 @@ public class MockRequestContext implements RequestContext {
}
/**
* Set the last event that occured in this request context.
* @param lastEvent the event to set
* Set the current event being processed by this flow.
* @param event the current event
*/
public void setLastEvent(Event lastEvent) {
this.lastEvent = lastEvent;
public void setCurrentEvent(Event event) {
this.currentEvent = event;
}
/**
* Set the last transition that executed in this request context.
* @param lastTransition the last transition to set
* Set the current transition executing in this request context.
* @param transition the current transition to set
*/
public void setLastTransition(Transition lastTransition) {
this.lastTransition = lastTransition;
public void setCurrentTransition(Transition transition) {
this.currentTransition = transition;
}
/**

View File

@@ -15,7 +15,6 @@
*/
package org.springframework.webflow.test;
import org.springframework.webflow.core.collection.LocalAttributeMap;
import org.springframework.webflow.core.collection.MutableAttributeMap;
import org.springframework.webflow.engine.Flow;
import org.springframework.webflow.engine.RequestControlContext;
@@ -74,16 +73,8 @@ public class MockRequestControlContext extends MockRequestContext implements Req
flow.start(this, input);
}
public void initViewScope() {
getFlowScope().put(FLOW_VIEW_MAP_ATTRIBUTE, new LocalAttributeMap());
}
public void destroyViewScope() {
getFlowScope().remove(FLOW_VIEW_MAP_ATTRIBUTE);
}
public boolean handleEvent(Event event) {
setLastEvent(event);
setCurrentEvent(event);
return ((Flow) getActiveFlow()).handleEvent(this);
}
@@ -104,14 +95,14 @@ public class MockRequestControlContext extends MockRequestContext implements Req
return key;
}
public boolean getAlwaysRedirectOnPause() {
return alwaysRedirectOnPause;
}
public boolean getFlowExecutionRedirectSent() {
return this.flowExecutionRedirectSent;
}
public boolean getAlwaysRedirectOnPause() {
return alwaysRedirectOnPause;
}
public void setAlwaysRedirectOnPause(boolean alwaysRedirectOnPause) {
this.alwaysRedirectOnPause = alwaysRedirectOnPause;
}

View File

@@ -342,7 +342,7 @@ public class FormActionTests extends TestCase {
assertSame(formObject, errors.getTarget());
context = new MockRequestContext();
context.setLastEvent(new Event(this, "start"));
context.setCurrentEvent(new Event(this, "start"));
OtherTestBean freshBean = new OtherTestBean();
context.getFlowScope().put("test", freshBean);

View File

@@ -35,7 +35,7 @@ public class DecisionStateTests extends TestCase {
state.getTransitionSet().add(new Transition(new EventIdTransitionCriteria("foo"), to("target")));
new EndState(flow, "target");
MockRequestControlContext context = new MockRequestControlContext(flow);
context.setLastEvent(new Event(this, "foo"));
context.setCurrentEvent(new Event(this, "foo"));
state.enter(context);
assertFalse(context.getFlowExecutionContext().isActive());
}
@@ -47,7 +47,7 @@ public class DecisionStateTests extends TestCase {
state.getTransitionSet().add(new Transition(to("target")));
new EndState(flow, "target");
MockRequestControlContext context = new MockRequestControlContext(flow);
context.setLastEvent(new Event(this, "bogus"));
context.setCurrentEvent(new Event(this, "bogus"));
state.enter(context);
assertFalse(context.getFlowExecutionContext().isActive());
}
@@ -58,7 +58,7 @@ public class DecisionStateTests extends TestCase {
state.getTransitionSet().add(new Transition(new EventIdTransitionCriteria("foo"), to("invalid")));
state.getTransitionSet().add(new Transition(new EventIdTransitionCriteria("bar"), to("invalid")));
MockRequestControlContext context = new MockRequestControlContext(flow);
context.setLastEvent(new Event(this, "bogus"));
context.setCurrentEvent(new Event(this, "bogus"));
try {
state.enter(context);
fail("Expected no matching");

View File

@@ -230,7 +230,7 @@ public class FlowTests extends TestCase {
MockRequestControlContext context = new MockRequestControlContext(flow);
Event event = new Event(this, "foo");
try {
context.setLastEvent(event);
context.setCurrentEvent(event);
flow.handleEvent(context);
} catch (IllegalStateException e) {
@@ -241,9 +241,9 @@ public class FlowTests extends TestCase {
MockRequestControlContext context = new MockRequestControlContext(flow);
context.setCurrentState(flow.getStateInstance("myState2"));
Event event = new Event(this, "submit");
context.setLastEvent(event);
context.setCurrentEvent(event);
try {
context.setLastEvent(event);
context.setCurrentEvent(event);
flow.handleEvent(context);
} catch (IllegalStateException e) {
@@ -254,9 +254,9 @@ public class FlowTests extends TestCase {
MockRequestControlContext context = new MockRequestControlContext(flow);
context.setCurrentState(flow.getStateInstance("myState1"));
Event event = new Event(this, "submit");
context.setLastEvent(event);
context.setCurrentEvent(event);
assertTrue(context.getFlowExecutionContext().isActive());
context.setLastEvent(event);
context.setCurrentEvent(event);
flow.handleEvent(context);
assertTrue(!context.getFlowExecutionContext().isActive());
}
@@ -265,9 +265,9 @@ public class FlowTests extends TestCase {
MockRequestControlContext context = new MockRequestControlContext(flow);
context.setCurrentState(flow.getStateInstance("myState1"));
Event event = new Event(this, "globalEvent");
context.setLastEvent(event);
context.setCurrentEvent(event);
assertTrue(context.getFlowExecutionContext().isActive());
context.setLastEvent(event);
context.setCurrentEvent(event);
flow.handleEvent(context);
assertTrue(!context.getFlowExecutionContext().isActive());
}
@@ -276,9 +276,9 @@ public class FlowTests extends TestCase {
MockRequestControlContext context = new MockRequestControlContext(flow);
context.setCurrentState(flow.getStateInstance("myState1"));
Event event = new Event(this, "bogus");
context.setLastEvent(event);
context.setCurrentEvent(event);
try {
context.setLastEvent(event);
context.setCurrentEvent(event);
flow.handleEvent(context);
} catch (NoMatchingTransitionException e) {

View File

@@ -74,7 +74,7 @@ public class TextToTransitionCriteriaTests extends TestCase {
String expression = "${3 + 4}";
TransitionCriteria criterion = (TransitionCriteria) converter.convert(expression);
MockRequestContext ctx = getRequestContext();
ctx.setLastEvent(new Event(this, "7"));
ctx.setCurrentEvent(new Event(this, "7"));
assertTrue("Criterion should evaluate to true", criterion.test(ctx));
}
@@ -94,7 +94,7 @@ public class TextToTransitionCriteriaTests extends TestCase {
MockRequestContext ctx = new MockRequestContext(flow);
RequestContextHolder.setRequestContext(ctx);
ctx.getFlowScope().put("foo", "bar");
ctx.setLastEvent(new Event(this, "sample"));
ctx.setCurrentEvent(new Event(this, "sample"));
return ctx;
}
}

View File

@@ -24,18 +24,18 @@ public class EventIdTransitionCriteriaTests extends TestCase {
public void testTestCriteria() {
EventIdTransitionCriteria c = new EventIdTransitionCriteria("foo");
MockRequestContext context = new MockRequestContext();
context.setLastEvent(new Event(this, "foo"));
context.setCurrentEvent(new Event(this, "foo"));
assertEquals(true, c.test(context));
context.setLastEvent(new Event(this, "FOO"));
context.setCurrentEvent(new Event(this, "FOO"));
assertEquals(false, c.test(context)); // case sensitive
context.setLastEvent(new Event(this, "bar"));
context.setCurrentEvent(new Event(this, "bar"));
assertEquals(false, c.test(context));
}
public void testNullLastEventId() {
EventIdTransitionCriteria c = new EventIdTransitionCriteria("foo");
MockRequestContext context = new MockRequestContext();
context.setLastEvent(null);
context.setCurrentEvent(null);
assertEquals(false, c.test(context));
}