01: /*
02: * Copyright 2004-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.springframework.webflow.engine;
17:
18: import org.springframework.webflow.execution.FlowExecutionException;
19: import org.springframework.webflow.execution.RequestContext;
20: import org.springframework.webflow.execution.ViewSelection;
21:
22: /**
23: * A simple transitionable state that when entered will execute the first
24: * transition whose matching criteria evaluates to <code>true</code> in the
25: * {@link RequestContext context} of the current request.
26: * <p>
27: * A decision state is a convenient, simple way to encapsulate reusable state
28: * transition logic in one place.
29: *
30: * @author Keith Donald
31: */
32: public class DecisionState extends TransitionableState {
33:
34: /**
35: * Creates a new decision state.
36: * @param flow the owning flow
37: * @param stateId the state identifier (must be unique to the flow)
38: * @throws IllegalArgumentException when this state cannot be added to given
39: * flow, e.g. because the id is not unique
40: */
41: public DecisionState(Flow flow, String stateId)
42: throws IllegalArgumentException {
43: super (flow, stateId);
44: }
45:
46: /**
47: * Specialization of State's <code>doEnter</code> template method that
48: * executes behaviour specific to this state type in polymorphic fashion.
49: * <p>
50: * Simply looks up the first transition that matches the state of the
51: * context and executes it.
52: * @param context the control context for the currently executing flow, used
53: * by this state to manipulate the flow execution
54: * @return a view selection containing model and view information needed to
55: * render the results of the state execution
56: * @throws FlowExecutionException if an exception occurs in this state
57: */
58: protected ViewSelection doEnter(RequestControlContext context)
59: throws FlowExecutionException {
60: return getRequiredTransition(context).execute(this, context);
61: }
62: }
|