001: /*
002: * Copyright 2002-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:
017: package org.springframework.web.context.request;
018:
019: /**
020: * Abstraction for accessing attribute objects associated with a request.
021: * Supports access to request-scoped attributes as well as to session-scoped
022: * attributes, with the optional notion of a "global session".
023: *
024: * <p>Can be implemented for any kind of request/session mechanism,
025: * in particular for servlet requests and portlet requests.
026: *
027: * @author Juergen Hoeller
028: * @since 2.0
029: * @see ServletRequestAttributes
030: * @see org.springframework.web.portlet.context.PortletRequestAttributes
031: */
032: public interface RequestAttributes {
033:
034: /**
035: * Constant that indicates request scope.
036: */
037: int SCOPE_REQUEST = 0;
038:
039: /**
040: * Constant that indicates session scope.
041: * <p>This preferably refers to a locally isolated session, if such
042: * a distinction is available (for example, in a Portlet environment).
043: * Else, it simply refers to the common session.
044: */
045: int SCOPE_SESSION = 1;
046:
047: /**
048: * Constant that indicates global session scope.
049: * <p>This explicitly refers to a globally shared session, if such
050: * a distinction is available (for example, in a Portlet environment).
051: * Else, it simply refers to the common session.
052: */
053: int SCOPE_GLOBAL_SESSION = 2;
054:
055: /**
056: * Return the value for the scoped attribute of the given name, if any.
057: * @param name the name of the attribute
058: * @param scope the scope identifier
059: * @return the current attribute value, or <code>null</code> if not found
060: */
061: Object getAttribute(String name, int scope);
062:
063: /**
064: * Set the value for the scoped attribute of the given name,
065: * replacing an existing value (if any).
066: * @param name the name of the attribute
067: * @param scope the scope identifier
068: * @param value the value for the attribute
069: */
070: void setAttribute(String name, Object value, int scope);
071:
072: /**
073: * Remove the scoped attribute of the given name, if it exists.
074: * <p>Note that an implementation should also remove a registered destruction
075: * callback for the specified attribute, if any. It does, however, <i>not</i>
076: * need to <i>execute</i> a registered destruction callback in this case,
077: * since the object will be destroyed by the caller (if appropriate).
078: * @param name the name of the attribute
079: * @param scope the scope identifier
080: */
081: void removeAttribute(String name, int scope);
082:
083: /**
084: * Retrieve the names of all attributes in the scope.
085: * @param scope the scope identifier
086: * @return the attribute names as String array
087: */
088: String[] getAttributeNames(int scope);
089:
090: /**
091: * Register a callback to be executed on destruction of the
092: * specified attribute in the given scope.
093: * <p>Implementations should do their best to execute the callback
094: * at the appropriate time: that is, at request completion or session
095: * termination, respectively. If such a callback is not supported by the
096: * underlying runtime environment, the callback <i>must be ignored</i>
097: * and a corresponding warning should be logged.
098: * <p>Note that 'destruction' usually corresponds to destruction of the
099: * entire scope, not to the individual attribute having been explicitly
100: * removed by the application. If an attribute gets removed via this
101: * facade's {@link #removeAttribute(String, int)} method, any registered
102: * destruction callback should be disabled as well, assuming that the
103: * removed object will be reused or manually destroyed.
104: * @param name the name of the attribute to register the callback for
105: * @param callback the destruction callback to be executed
106: * @param scope the scope identifier
107: */
108: void registerDestructionCallback(String name, Runnable callback,
109: int scope);
110:
111: /**
112: * Return an id for the current underlying session.
113: * @return the session id as String (never <code>null</code>
114: */
115: String getSessionId();
116:
117: /**
118: * Expose the best available mutex for the underlying session:
119: * that is, an object to synchronize on for the underlying session.
120: * @return the session mutex to use (never <code>null</code>
121: */
122: Object getSessionMutex();
123:
124: }
|