KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > context > request > RequestAttributes


1 /*
2  * Copyright 2002-2007 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
17 package org.springframework.web.context.request;
18
19 /**
20  * Abstraction for accessing attribute objects associated with a request.
21  * Supports access to request-scoped attributes as well as to session-scoped
22  * attributes, with the optional notion of a "global session".
23  *
24  * <p>Can be implemented for any kind of request/session mechanism,
25  * in particular for servlet requests and portlet requests.
26  *
27  * @author Juergen Hoeller
28  * @since 2.0
29  * @see ServletRequestAttributes
30  * @see org.springframework.web.portlet.context.PortletRequestAttributes
31  */

32 public interface RequestAttributes {
33
34     /**
35      * Constant that indicates request scope.
36      */

37     int SCOPE_REQUEST = 0;
38
39     /**
40      * Constant that indicates session scope.
41      * <p>This preferably refers to a locally isolated session, if such
42      * a distinction is available (for example, in a Portlet environment).
43      * Else, it simply refers to the common session.
44      */

45     int SCOPE_SESSION = 1;
46
47     /**
48      * Constant that indicates global session scope.
49      * <p>This explicitly refers to a globally shared session, if such
50      * a distinction is available (for example, in a Portlet environment).
51      * Else, it simply refers to the common session.
52      */

53     int SCOPE_GLOBAL_SESSION = 2;
54
55
56     /**
57      * Return the value for the scoped attribute of the given name, if any.
58      * @param name the name of the attribute
59      * @param scope the scope identifier
60      * @return the current attribute value, or <code>null</code> if not found
61      */

62     Object JavaDoc getAttribute(String JavaDoc name, int scope);
63
64     /**
65      * Set the value for the scoped attribute of the given name,
66      * replacing an existing value (if any).
67      * @param name the name of the attribute
68      * @param scope the scope identifier
69      * @param value the value for the attribute
70      */

71     void setAttribute(String JavaDoc name, Object JavaDoc value, int scope);
72
73     /**
74      * Remove the scoped attribute of the given name, if it exists.
75      * <p>Note that an implementation should also remove a registered destruction
76      * callback for the specified attribute, if any. It does, however, <i>not</i>
77      * need to <i>execute</i> a registered destruction callback in this case,
78      * since the object will be destroyed by the caller (if appropriate).
79      * @param name the name of the attribute
80      * @param scope the scope identifier
81      */

82     void removeAttribute(String JavaDoc name, int scope);
83
84     /**
85      * Register a callback to be executed on destruction of the
86      * specified attribute in the given scope.
87      * <p>Implementations should do their best to execute the callback
88      * at the appropriate time: that is, at request completion or session
89      * termination, respectively. If such a callback is not supported by the
90      * underlying runtime environment, the callback <i>must be ignored</i>
91      * and a corresponding warning should be logged.
92      * <p>Note that 'destruction' usually corresponds to destruction of the
93      * entire scope, not to the individual attribute having been explicitly
94      * removed by the application. If an attribute gets removed via this
95      * facade's {@link #removeAttribute(String, int)} method, any registered
96      * destruction callback should be disabled as well, assuming that the
97      * removed object will be reused or manually destroyed.
98      * @param name the name of the attribute to register the callback for
99      * @param callback the destruction callback to be executed
100      * @param scope the scope identifier
101      */

102     void registerDestructionCallback(String JavaDoc name, Runnable JavaDoc callback, int scope);
103
104     /**
105      * Return an id for the current underlying session.
106      * @return the session id as String (never <code>null</code>
107      */

108     String JavaDoc getSessionId();
109
110     /**
111      * Expose the best available mutex for the underlying session:
112      * that is, an object to synchronize on for the underlying session.
113      * @return the session mutex to use (never <code>null</code>
114      */

115     Object JavaDoc getSessionMutex();
116
117 }
118
Popular Tags