KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > environment > http > HttpSession


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
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.apache.cocoon.environment.http;
17
18 import org.apache.cocoon.environment.Session;
19
20 import java.util.Enumeration JavaDoc;
21
22 /**
23  *
24  * Provides a way to identify a user across more than one page
25  * request or visit to a Web site and to store information about that user.
26  *
27  * <p>Cocoon uses this interface to create a session
28  * between a client and the "cocoon server". The session persists
29  * for a specified time period, across more than one connection or
30  * page request from the user. A session usually corresponds to one
31  * user, who may visit a site many times. The server can maintain a
32  * session in many ways such as using cookies or rewriting URLs.
33  *
34  * <p>This interface allows Cocoon to
35  * <ul>
36  * <li>View and manipulate information about a session, such as
37  * the session identifier, creation time, and last accessed time
38  * <li>Bind objects to sessions, allowing user information to persist
39  * across multiple user connections
40  * </ul>
41  *
42  * <p>Session information is scoped only to the current context
43  * (<code>Context</code>), so information stored in one context
44  * will not be directly visible in another.
45  *
46  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
47  * @version CVS $Id: HttpSession.java 30932 2004-07-29 17:35:38Z vgritsenko $
48  *
49  */

50
51 public final class HttpSession
52 implements Session {
53
54     javax.servlet.http.HttpSession JavaDoc wrappedSession;
55
56     /**
57      * Construct a new session from an HttpSession
58      */

59     public HttpSession(javax.servlet.http.HttpSession JavaDoc session) {
60         this.wrappedSession = session;
61     }
62
63     /**
64      *
65      * Returns the time when this session was created, measured
66      * in milliseconds since midnight January 1, 1970 GMT.
67      *
68      * @return a <code>long</code> specifying
69      * when this session was created,
70      * expressed in
71      * milliseconds since 1/1/1970 GMT
72      *
73      * @exception IllegalStateException if this method is called on an
74      * invalidated session
75      *
76      */

77     public long getCreationTime() {
78         return this.wrappedSession.getCreationTime();
79     }
80
81     /**
82      *
83      * Returns a string containing the unique identifier assigned
84      * to this session. The identifier is assigned
85      * by the context container and is implementation dependent.
86      *
87      * @return a string specifying the identifier
88      * assigned to this session
89      *
90      * @exception IllegalStateException if this method is called on an
91      * invalidated session
92      *
93      */

94     public String JavaDoc getId() {
95         return this.wrappedSession.getId();
96     }
97
98     /**
99      *
100      * Returns the last time the client sent a request associated with
101      * this session, as the number of milliseconds since midnight
102      * January 1, 1970 GMT.
103      *
104      * <p>Actions that your application takes, such as getting or setting
105      * a value associated with the session, do not affect the access
106      * time.
107      *
108      * @return a <code>long</code>
109      * representing the last time
110      * the client sent a request associated
111      * with this session, expressed in
112      * milliseconds since 1/1/1970 GMT
113      *
114      * @exception IllegalStateException if this method is called on an
115      * invalidated session
116      *
117      */

118
119     public long getLastAccessedTime() {
120         return this.wrappedSession.getLastAccessedTime();
121     }
122
123     /**
124      *
125      * Specifies the time, in seconds, between client requests before the
126      * contextcontainer will invalidate this session. A negative time
127      * indicates the session should never timeout.
128      *
129      * @param interval An integer specifying the number
130      * of seconds
131      *
132      */

133     public void setMaxInactiveInterval(int interval) {
134         this.wrappedSession.setMaxInactiveInterval(interval);
135     }
136
137    /**
138     * Returns the maximum time interval, in seconds, that
139     * the context container will keep this session open between
140     * client accesses. After this interval, the context container
141     * will invalidate the session. The maximum time interval can be set
142     * with the <code>setMaxInactiveInterval</code> method.
143     * A negative time indicates the session should never timeout.
144     *
145     *
146     * @return an integer specifying the number of
147     * seconds this session remains open
148     * between client requests
149     *
150     * @see #setMaxInactiveInterval(int)
151     *
152     *
153     */

154     public int getMaxInactiveInterval() {
155         return this.wrappedSession.getMaxInactiveInterval();
156     }
157
158     /**
159      *
160      * Returns the object bound with the specified name in this session, or
161      * <code>null</code> if no object is bound under the name.
162      *
163      * @param name a string specifying the name of the object
164      *
165      * @return the object with the specified name
166      *
167      * @exception IllegalStateException if this method is called on an
168      * invalidated session
169      *
170      */

171     public Object JavaDoc getAttribute(String JavaDoc name) {
172         return this.wrappedSession.getAttribute(name);
173     }
174
175     /**
176      *
177      * Returns an <code>Enumeration</code> of <code>String</code> objects
178      * containing the names of all the objects bound to this session.
179      *
180      * @return an <code>Enumeration</code> of
181      * <code>String</code> objects specifying the
182      * names of all the objects bound to
183      * this session
184      *
185      * @exception IllegalStateException if this method is called on an
186      * invalidated session
187      *
188      */

189     public Enumeration JavaDoc getAttributeNames() {
190         return this.wrappedSession.getAttributeNames();
191     }
192
193     /**
194      * Binds an object to this session, using the name specified.
195      * If an object of the same name is already bound to the session,
196      * the object is replaced.
197      *
198      *
199      * @param name the name to which the object is bound;
200      * cannot be null
201      *
202      * @param value the object to be bound; cannot be null
203      *
204      * @exception IllegalStateException if this method is called on an
205      * invalidated session
206      *
207      */

208     public void setAttribute(String JavaDoc name, Object JavaDoc value) {
209         this.wrappedSession.setAttribute(name, value);
210     }
211
212     /**
213      *
214      * Removes the object bound with the specified name from
215      * this session. If the session does not have an object
216      * bound with the specified name, this method does nothing.
217      *
218      *
219      * @param name the name of the object to
220      * remove from this session
221      *
222      * @exception IllegalStateException if this method is called on an
223      * invalidated session
224      */

225     public void removeAttribute(String JavaDoc name) {
226         this.wrappedSession.removeAttribute(name);
227     }
228
229     /**
230      *
231      * Invalidates this session
232      * to it.
233      *
234      * @exception IllegalStateException if this method is called on an
235      * already invalidated session
236      *
237      */

238     public void invalidate() {
239         this.wrappedSession.invalidate();
240     }
241
242     /**
243      *
244      * Returns <code>true</code> if the client does not yet know about the
245      * session or if the client chooses not to join the session. For
246      * example, if the server used only cookie-based sessions, and
247      * the client had disabled the use of cookies, then a session would
248      * be new on each request.
249      *
250      * @return <code>true</code> if the
251      * server has created a session,
252      * but the client has not yet joined
253      *
254      * @exception IllegalStateException if this method is called on an
255      * already invalidated session
256      *
257      */

258     public boolean isNew() {
259         return this.wrappedSession.isNew();
260     }
261
262 }
263
264
Popular Tags