KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > webflow > execution > ScopeType


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.execution;
17
18 import org.springframework.core.enums.StaticLabeledEnum;
19 import org.springframework.webflow.core.collection.MutableAttributeMap;
20 import org.springframework.webflow.definition.FlowDefinition;
21
22 /**
23  * An enumeration of the core scope types of Spring Web Flow. Provides easy
24  * access to each scope by <i>type</i> using
25  * {@link #getScope(RequestContext)}.
26  * <p>
27  * A "scope" defines a data structure for storing custom user attributes within
28  * a flow execution. Different scope types have different semantics in terms of
29  * how long attributes placed in those scope maps remain valid.
30  *
31  * @author Keith Donald
32  * @author Erwin Vervaet
33  */

34 public abstract class ScopeType extends StaticLabeledEnum {
35
36     /**
37      * The "request" scope type. Attributes placed in request scope exist for
38      * the life of the current request into the flow execution. When the request
39      * ends any attributes in request scope go out of scope.
40      */

41     public static final ScopeType REQUEST = new ScopeType(0, "Request") {
42         public MutableAttributeMap getScope(RequestContext context) {
43             return context.getRequestScope();
44         }
45     };
46
47     /**
48      * The "flash" scope type. Attributes placed in flash scope exist through
49      * the life of the current request <i>and until the next user event is
50      * signaled in a subsequent request</i>. When the next external user event
51      * is signaled flash scope is cleared.
52      * <p>
53      * Flash scope is typically used to store messages that should be preserved
54      * across refreshes of the next view state (for example, on a redirect and
55      * any browser refreshes).
56      */

57     public static final ScopeType FLASH = new ScopeType(1, "Flash") {
58         public MutableAttributeMap getScope(RequestContext context) {
59             return context.getFlashScope();
60         }
61     };
62
63     /**
64      * The "flow" scope type. Attributes placed in flow scope exist through the
65      * life of an executing flow session, representing an instance a single
66      * {@link FlowDefinition flow definition}. When the flow session ends any
67      * data in flow scope goes out of scope.
68      */

69     public static final ScopeType FLOW = new ScopeType(2, "Flow") {
70         public MutableAttributeMap getScope(RequestContext context) {
71             return context.getFlowScope();
72         }
73     };
74
75     /**
76      * The "conversation" scope type. Attributes placed in conversation scope
77      * are shared by all flow sessions started within a flow execution and live
78      * for the life of the entire flow execution (representing a single logical
79      * user conversation). When the governing execution ends, any data in
80      * conversation scope goes out of scope.
81      */

82     public static final ScopeType CONVERSATION = new ScopeType(3, "Conversation") {
83         public MutableAttributeMap getScope(RequestContext context) {
84             return context.getConversationScope();
85         }
86     };
87
88     /**
89      * Private constructor because this is a typesafe enum!
90      */

91     private ScopeType(int code, String JavaDoc label) {
92         super(code, label);
93     }
94
95     public Class JavaDoc getType() {
96         // force ScopeType as type
97
return ScopeType.class;
98     }
99
100     /**
101      * Accessor that returns the mutable attribute map for this scope type for a
102      * given flow execution request context.
103      * @param context the context representing an executing request
104      * @return the scope map of this type for that request, allowing attributes
105      * to be accessed and set
106      */

107     public abstract MutableAttributeMap getScope(RequestContext context);
108 }
Popular Tags