KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > webflow > engine > ViewState


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.core.style.ToStringCreator;
19 import org.springframework.util.Assert;
20 import org.springframework.webflow.execution.FlowExecutionException;
21 import org.springframework.webflow.execution.RequestContext;
22 import org.springframework.webflow.execution.ViewSelection;
23
24 /**
25  * A view state is a state that issues a response to the user, for
26  * example, for soliciting form input.
27  * <p>
28  * To accomplish this, a <code>ViewState</code> makes a {@link ViewSelection},
29  * which contains the necessary information to issue a suitable response.
30  *
31  * @see org.springframework.webflow.engine.ViewSelector
32  *
33  * @author Keith Donald
34  * @author Erwin Vervaet
35  */

36 public class ViewState extends TransitionableState {
37
38     /**
39      * The list of actions to be executed when this state is entered.
40      */

41     private ActionList renderActionList = new ActionList();
42
43     /**
44      * The factory for the view selection to return when this state is entered.
45      */

46     private ViewSelector viewSelector = NullViewSelector.INSTANCE;
47
48     /**
49      * Create a new view state.
50      * @param flow the owning flow
51      * @param id the state identifier (must be unique to the flow)
52      * @throws IllegalArgumentException when this state cannot be added to given
53      * flow, e.g. because the id is not unique
54      */

55     public ViewState(Flow flow, String JavaDoc id) throws IllegalArgumentException JavaDoc {
56         super(flow, id);
57     }
58
59     /**
60      * Returns the strategy used to select the view to render in this view
61      * state.
62      */

63     public ViewSelector getViewSelector() {
64         return viewSelector;
65     }
66
67     /**
68      * Sets the strategy used to select the view to render in this view state.
69      */

70     public void setViewSelector(ViewSelector viewSelector) {
71         Assert.notNull(viewSelector, "The view selector to make view selections is required");
72         this.viewSelector = viewSelector;
73     }
74
75     /**
76      * Returns the list of actions executable by this view state on entry and on
77      * refresh. The returned list is mutable.
78      * @return the state action list
79      */

80     public ActionList getRenderActionList() {
81         return renderActionList;
82     }
83
84     /**
85      * Specialization of State's <code>doEnter</code> template method that
86      * executes behavior specific to this state type in polymorphic fashion.
87      * <p>
88      * Returns a view selection indicating a response to issue. The view
89      * selection typically contains all the data necessary to issue the
90      * response.
91      * @param context the control context for the currently executing flow, used
92      * by this state to manipulate the flow execution
93      * @return a view selection serving as a response instruction
94      * @throws FlowExecutionException if an exception occurs in this state
95      */

96     protected ViewSelection doEnter(RequestControlContext context) throws FlowExecutionException {
97         if (viewSelector.isEntrySelectionRenderable(context)) {
98             // the entry selection will be rendered!
99
renderActionList.execute(context);
100         }
101         return viewSelector.makeEntrySelection(context);
102     }
103
104     /**
105      * Request that the current view selection be reconstituted to support
106      * reissuing the response. This is an idempotent operation that may be
107      * safely called any number of times on a paused execution, used primarily
108      * to support a flow execution redirect.
109      * @param context the request context
110      * @return the view selection
111      * @throws FlowExecutionException if an exception occurs in this state
112      */

113     public ViewSelection refresh(RequestContext context) throws FlowExecutionException {
114         renderActionList.execute(context);
115         return viewSelector.makeRefreshSelection(context);
116     }
117
118     protected void appendToString(ToStringCreator creator) {
119         creator.append("viewSelector", viewSelector);
120         super.appendToString(creator);
121     }
122 }
Popular Tags