001: /*
002: * Copyright 2004-2007 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.springframework.webflow.execution;
017:
018: import org.springframework.core.enums.StaticLabeledEnum;
019: import org.springframework.webflow.core.collection.MutableAttributeMap;
020: import org.springframework.webflow.definition.FlowDefinition;
021:
022: /**
023: * An enumeration of the core scope types of Spring Web Flow. Provides easy
024: * access to each scope by <i>type</i> using
025: * {@link #getScope(RequestContext)}.
026: * <p>
027: * A "scope" defines a data structure for storing custom user attributes within
028: * a flow execution. Different scope types have different semantics in terms of
029: * how long attributes placed in those scope maps remain valid.
030: *
031: * @author Keith Donald
032: * @author Erwin Vervaet
033: */
034: public abstract class ScopeType extends StaticLabeledEnum {
035:
036: /**
037: * The "request" scope type. Attributes placed in request scope exist for
038: * the life of the current request into the flow execution. When the request
039: * ends any attributes in request scope go out of scope.
040: */
041: public static final ScopeType REQUEST = new ScopeType(0, "Request") {
042: public MutableAttributeMap getScope(RequestContext context) {
043: return context.getRequestScope();
044: }
045: };
046:
047: /**
048: * The "flash" scope type. Attributes placed in flash scope exist through
049: * the life of the current request <i>and until the next user event is
050: * signaled in a subsequent request</i>. When the next external user event
051: * is signaled flash scope is cleared.
052: * <p>
053: * Flash scope is typically used to store messages that should be preserved
054: * across refreshes of the next view state (for example, on a redirect and
055: * any browser refreshes).
056: */
057: public static final ScopeType FLASH = new ScopeType(1, "Flash") {
058: public MutableAttributeMap getScope(RequestContext context) {
059: return context.getFlashScope();
060: }
061: };
062:
063: /**
064: * The "flow" scope type. Attributes placed in flow scope exist through the
065: * life of an executing flow session, representing an instance a single
066: * {@link FlowDefinition flow definition}. When the flow session ends any
067: * data in flow scope goes out of scope.
068: */
069: public static final ScopeType FLOW = new ScopeType(2, "Flow") {
070: public MutableAttributeMap getScope(RequestContext context) {
071: return context.getFlowScope();
072: }
073: };
074:
075: /**
076: * The "conversation" scope type. Attributes placed in conversation scope
077: * are shared by all flow sessions started within a flow execution and live
078: * for the life of the entire flow execution (representing a single logical
079: * user conversation). When the governing execution ends, any data in
080: * conversation scope goes out of scope.
081: */
082: public static final ScopeType CONVERSATION = new ScopeType(3,
083: "Conversation") {
084: public MutableAttributeMap getScope(RequestContext context) {
085: return context.getConversationScope();
086: }
087: };
088:
089: /**
090: * Private constructor because this is a typesafe enum!
091: */
092: private ScopeType(int code, String label) {
093: super (code, label);
094: }
095:
096: public Class getType() {
097: // force ScopeType as type
098: return ScopeType.class;
099: }
100:
101: /**
102: * Accessor that returns the mutable attribute map for this scope type for a
103: * given flow execution request context.
104: * @param context the context representing an executing request
105: * @return the scope map of this type for that request, allowing attributes
106: * to be accessed and set
107: */
108: public abstract MutableAttributeMap getScope(RequestContext context);
109: }
|