public StateDefinition getState(String stateId) { return getStateInstance(stateId); }
/** * Set the start state for this flow to the state with the provided <code>stateId</code>; a state must exist by the * provided <code>stateId</code>. * @param stateId the id of the new start state * @throws IllegalArgumentException when no state exists with the id you provided */ public void setStartState(String stateId) throws IllegalArgumentException { setStartState(getStateInstance(stateId)); }
/** * Return the <code>TransitionableState</code> with given <code>stateId</code>. * @param stateId id of the state to look up * @return the transitionable state * @throws IllegalArgumentException if the identified state cannot be found * @throws ClassCastException when the identified state is not transitionable */ public TransitionableState getTransitionableState(String stateId) throws IllegalArgumentException, ClassCastException { State state = getStateInstance(stateId); if (state != null && !(state instanceof TransitionableState)) { throw new ClassCastException("The state '" + stateId + "' of flow '" + getId() + "' must be transitionable"); } return (TransitionableState) state; }
public State resolveTargetState(Transition transition, State sourceState, RequestContext context) { String targetStateId = (String) targetStateIdExpression.getValue(context); if (targetStateId != null) { return ((Flow) context.getActiveFlow()).getStateInstance(targetStateId); } else { return null; } }
/** * Jump to a state of the currently active flow. If this execution has not been started, a new session will be * activated and its current state will be set. This is a implementation-internal method that bypasses the * {@link #start(MutableAttributeMap, ExternalContext)} operation and allows for jumping to an arbitrary flow state. * Useful for testing. * @param stateId the identifier of the state to jump to */ public void setCurrentState(String stateId) { FlowSessionImpl session; if (status == FlowExecutionStatus.NOT_STARTED) { session = activateSession(flow); status = FlowExecutionStatus.ACTIVE; } else { session = getActiveSessionInternal(); } State state = session.getFlow().getStateInstance(stateId); session.setCurrentState(state); }
/** * Try to handle given exception using execution exception handlers registered at the state level. Returns null if * no handler handled the exception. * @return true if the exception was handled */ private boolean tryStateHandlers(FlowExecutionException exception, RequestControlContext context) { if (exception.getStateId() != null) { State state = getActiveSessionInternal().getFlow().getStateInstance(exception.getStateId()); return state.handleException(exception, context); } else { return false; } }
FlowSessionImpl rootSession = execution.getRootSession(); rootSession.setFlow(flow); rootSession.setState(flow.getStateInstance(rootSession.getStateId())); if (execution.hasSubflowSessions()) { for (Iterator<FlowSessionImpl> it = execution.getSubflowSessionIterator(); it.hasNext();) { Flow subflowDef = (Flow) subflowDefinitionLocator.getFlowDefinition(subflowSession.getFlowId()); subflowSession.setFlow(subflowDef); subflowSession.setState(subflowDef.getStateInstance(subflowSession.getStateId()));
/** * Set the start state for this flow to the state with the provided <code>stateId</code>; a state must exist by the * provided <code>stateId</code>. * @param stateId the id of the new start state * @throws IllegalArgumentException when no state exists with the id you provided */ public void setStartState(String stateId) throws IllegalArgumentException { setStartState(getStateInstance(stateId)); }
/** * Set the start state for this flow to the state with the provided <code>stateId</code>; a state must exist by the * provided <code>stateId</code>. * @param stateId the id of the new start state * @throws IllegalArgumentException when no state exists with the id you provided */ public void setStartState(String stateId) throws IllegalArgumentException { setStartState(getStateInstance(stateId)); }
public State resolveTargetState(Transition transition, State sourceState, RequestContext context) { String targetStateId = (String) targetStateIdExpression.getValue(context); if (targetStateId != null) { return ((Flow) context.getActiveFlow()).getStateInstance(targetStateId); } else { return null; } }
/** * Try to handle given exception using execution exception handlers registered at the state level. Returns null if * no handler handled the exception. */ private ViewSelection tryStateHandlers(FlowExecutionException exception, RequestControlContext context) { if (isActive() && exception.getStateId() != null) { return getActiveFlow().getStateInstance(exception.getStateId()).handleException(exception, context); } else { return null; } }
public void testOnEventInvalidCurrentState() { MockRequestControlContext context = new MockRequestControlContext(flow); context.setCurrentState(flow.getStateInstance("myState2")); Event event = new Event(this, "submit"); context.setCurrentEvent(event); try { context.setCurrentEvent(event); flow.handleEvent(context); } catch (IllegalStateException e) { } }
public void testOnEventNoTransition() { MockRequestControlContext context = new MockRequestControlContext(flow); context.setCurrentState(flow.getStateInstance("myState1")); Event event = new Event(this, "bogus"); context.setCurrentEvent(event); try { context.setCurrentEvent(event); flow.handleEvent(context); } catch (NoMatchingTransitionException e) { } }
public void testViewStateRedirect() { ViewStateModel view = new ViewStateModel("view"); view.setRedirect("true"); model.setStates(asList(view)); Flow flow = getFlow(model); assertTrue(((ViewState) flow.getStateInstance("view")).getRedirect()); }
public void testViewStateExternalRedirect() { ViewStateModel state = new ViewStateModel("view"); state.setView("externalRedirect:http://www.paypal.com?_callbackUrl=#{flowExecutionUri}"); model.setStates(asList(state)); Flow flow = getFlow(model); ViewFactory vf = ((ViewState) flow.getStateInstance("view")).getViewFactory(); assertTrue(vf instanceof ActionExecutingViewFactory); ActionExecutingViewFactory avf = (ActionExecutingViewFactory) vf; assertTrue(avf.getAction() instanceof ExternalRedirectAction); }
public void testViewStateVariable() { ViewStateModel view = new ViewStateModel("view"); view.setVars(asList(new VarModel("foo", "org.springframework.webflow.TestBean"))); model.setStates(asList(view)); Flow flow = getFlow(model); assertNotNull(((ViewState) flow.getStateInstance("view")).getVariable("foo")); }
public void testViewStateFlowRedirect() { ViewStateModel state = new ViewStateModel("view"); state.setView("flowRedirect:myFlow?input=#{flowScope.foo}"); model.setStates(asList(state)); Flow flow = getFlow(model); ViewFactory vf = ((ViewState) flow.getStateInstance("view")).getViewFactory(); assertTrue(vf instanceof ActionExecutingViewFactory); ActionExecutingViewFactory avf = (ActionExecutingViewFactory) vf; assertTrue(avf.getAction() instanceof FlowDefinitionRedirectAction); }
public void testOnEvent() { MockRequestControlContext context = new MockRequestControlContext(flow); context.setCurrentState(flow.getStateInstance("myState1")); Event event = new Event(this, "submit"); context.setCurrentEvent(event); assertTrue(context.getFlowExecutionContext().isActive()); context.setCurrentEvent(event); flow.handleEvent(context); assertTrue(!context.getFlowExecutionContext().isActive()); }
public void testOnEventGlobalTransition() { MockRequestControlContext context = new MockRequestControlContext(flow); context.setCurrentState(flow.getStateInstance("myState1")); Event event = new Event(this, "globalEvent"); context.setCurrentEvent(event); assertTrue(context.getFlowExecutionContext().isActive()); context.setCurrentEvent(event); flow.handleEvent(context); assertTrue(!context.getFlowExecutionContext().isActive()); }
public void testHandleException() { flow.getExceptionHandlerSet().add( new TransitionExecutingFlowExecutionExceptionHandler().add(TestException.class, "myState2")); MockRequestControlContext context = new MockRequestControlContext(flow); context.setCurrentState(flow.getStateInstance("myState1")); FlowExecutionException e = new FlowExecutionException(flow.getId(), flow.getStartState().getId(), "Oops!", new TestException()); flow.handleException(e, context); assertFalse(context.getFlowExecutionContext().isActive()); }