/** * Returns the de-serialized id indicating the current state of this session. */ String getStateId() { if (state == null) { return stateId; } else { return state.getId(); } }
/** * Is a state with the provided id present in this flow? * @param stateId the state id * @return true if yes, false otherwise */ public boolean containsState(String stateId) { for (State state : states) { if (state.getId().equals(stateId)) { return true; } } return false; }
public String[] getPossibleOutcomes() { List<String> possibleOutcomes = new ArrayList<>(); for (State state : states) { if (state instanceof EndState) { possibleOutcomes.add(state.getId()); } } return possibleOutcomes.toArray(new String[possibleOutcomes.size()]); }
public void writeExternal(ObjectOutput out) throws IOException { out.writeObject(flow.getId()); out.writeObject(state != null ? state.getId() : null); out.writeObject(scope); out.writeObject(parent); }
/** * Set the owning flow. * @throws IllegalArgumentException if this state cannot be added to the flow */ private void setFlow(Flow flow) throws IllegalArgumentException { Assert.hasText(getId(), "The id of the state should be set before adding the state to a flow"); Assert.notNull(flow, "The owning flow is required"); this.flow = flow; flow.add(this); }
/** * Convenience accessor that returns an ordered array of the String <code>ids</code> for the state definitions * associated with this flow definition. * @return the state ids */ public String[] getStateIds() { String[] stateIds = new String[getStateCount()]; int i = 0; for (State state : states) { stateIds[i++] = state.getId(); } return stateIds; }
/** * Lookup the identified state instance of this flow. * @param stateId the state id * @return the state * @throws IllegalArgumentException if the identified state cannot be found */ public State getStateInstance(String stateId) throws IllegalArgumentException { if (!StringUtils.hasText(stateId)) { throw new IllegalArgumentException("The specified stateId is invalid: state identifiers must be non-blank"); } for (State state : states) { if (state.getId().equals(stateId)) { return state; } } throw new IllegalArgumentException("Cannot find state with id '" + stateId + "' in flow '" + getId() + "' -- " + "Known state ids are '" + StylerUtils.style(getStateIds()) + "'"); }
@SuppressWarnings("unchecked") public MutableAttributeMap<Object> getViewScope() throws IllegalStateException { if (state == null) { throw new IllegalStateException("The current state of this flow '" + flow.getId() + "' is [null] - cannot access view scope"); } if (!state.isViewState()) { throw new IllegalStateException("The current state '" + state.getId() + "' of this flow '" + flow.getId() + "' is not a view state - view scope not accessible"); } return (MutableAttributeMap<Object>) scope.get(VIEW_SCOPE_ATTRIBUTE); }
@SuppressWarnings("unchecked") public MutableAttributeMap<Object> getViewScope() throws IllegalStateException { if (state == null) { throw new IllegalStateException("The current state of this flow '" + definition.getId() + "' is [null] - cannot access view scope"); } if (!state.isViewState()) { throw new IllegalStateException("The current state '" + state.getId() + "' of this flow '" + definition.getId() + "' is not a view state - view scope not accessible"); } return (MutableAttributeMap<Object>) scope.get(VIEW_MAP_ATTRIBUTE); }
/** * Add given state definition to this flow definition. Marked protected, as this method is to be called by the * (privileged) state definition classes themselves during state construction as part of a FlowBuilder invocation. * @param state the state to add * @throws IllegalArgumentException when the state cannot be added to the flow; for instance if another state shares * the same id as the one provided or if given state already belongs to another flow */ protected void add(State state) throws IllegalArgumentException { if (this != state.getFlow() && state.getFlow() != null) { throw new IllegalArgumentException("State " + state + " cannot be added to this flow '" + getId() + "' -- it already belongs to a different flow: '" + state.getFlow().getId() + "'"); } if (this.states.contains(state) || this.containsState(state.getId())) { throw new IllegalArgumentException("This flow '" + getId() + "' already contains a state with id '" + state.getId() + "' -- state ids must be locally unique to the flow definition; " + "existing state-ids of this flow include: " + StylerUtils.style(getStateIds())); } boolean firstAdd = states.isEmpty(); states.add(state); if (firstAdd) { setStartState(state); } }
/** * Enter this state in the provided flow control context. This implementation just calls the * {@link #doEnter(RequestControlContext)} hook method, which should be implemented by subclasses, after executing * the entry actions. * @param context the control context for the currently executing flow, used by this state to manipulate the flow * execution * @throws FlowExecutionException if an exception occurs in this state */ public final void enter(RequestControlContext context) throws FlowExecutionException { if (logger.isDebugEnabled()) { logger.debug("Entering state '" + getId() + "' of flow '" + getFlow().getId() + "'"); } context.setCurrentState(this); doPreEntryActions(context); entryActionList.execute(context); doEnter(context); }
if (sourceState != null) { if (logger.isDebugEnabled()) { logger.debug("Exiting state '" + sourceState.getId() + "'");
public String toString() { ToStringCreator creator = new ToStringCreator(this).append("id", getId()).append("flow", flow.getId()) .append("entryActionList", entryActionList).append("exceptionHandlerSet", exceptionHandlerSet); appendToString(creator); return creator.toString(); }
/** * Returns the de-serialized id indicating the current state of this session. */ String getStateId() { if (state == null) { return stateId; } else { return state.getId(); } }
public String[] getPossibleOutcomes() { List<String> possibleOutcomes = new ArrayList<>(); for (State state : states) { if (state instanceof EndState) { possibleOutcomes.add(state.getId()); } } return possibleOutcomes.toArray(new String[possibleOutcomes.size()]); }
@SuppressWarnings("unchecked") public MutableAttributeMap<Object> getViewScope() throws IllegalStateException { if (state == null) { throw new IllegalStateException("The current state of this flow '" + definition.getId() + "' is [null] - cannot access view scope"); } if (!state.isViewState()) { throw new IllegalStateException("The current state '" + state.getId() + "' of this flow '" + definition.getId() + "' is not a view state - view scope not accessible"); } return (MutableAttributeMap<Object>) scope.get(VIEW_MAP_ATTRIBUTE); }
public void testStatic() throws Exception { String expression = "mockState"; TargetStateResolver resolver = (TargetStateResolver) converter.convertSourceToTargetClass(expression, TargetStateResolver.class); MockRequestContext context = new MockRequestContext(); Transition transition = new Transition(); assertEquals("mockState", resolver.resolveTargetState(transition, null, context).getId()); }
public void testResolveState() { DefaultTargetStateResolver resolver = new DefaultTargetStateResolver("mockState"); MockRequestContext context = new MockRequestContext(); Transition transition = new Transition(); assertEquals("mockState", resolver.resolveTargetState(transition, null, context).getId()); }
public void testCouldNotHandleException() { FlowExecutionException e = new FlowExecutionException(flow.getId(), state.getId(), "Whatev"); MockRequestControlContext context = new MockRequestControlContext(flow); assertFalse(state.handleException(e, context)); }
public void testResolveStateExpression() { DefaultTargetStateResolver resolver = new DefaultTargetStateResolver(new StaticExpression("mockState")); MockRequestContext context = new MockRequestContext(); Transition transition = new Transition(); assertEquals("mockState", resolver.resolveTargetState(transition, null, context).getId()); }