001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.environment.http;
018:
019: import org.apache.cocoon.environment.Session;
020:
021: import java.util.Enumeration;
022:
023: /**
024: *
025: * Provides a way to identify a user across more than one page
026: * request or visit to a Web site and to store information about that user.
027: *
028: * <p>Cocoon uses this interface to create a session
029: * between a client and the "cocoon server". The session persists
030: * for a specified time period, across more than one connection or
031: * page request from the user. A session usually corresponds to one
032: * user, who may visit a site many times. The server can maintain a
033: * session in many ways such as using cookies or rewriting URLs.
034: *
035: * <p>This interface allows Cocoon to
036: * <ul>
037: * <li>View and manipulate information about a session, such as
038: * the session identifier, creation time, and last accessed time
039: * <li>Bind objects to sessions, allowing user information to persist
040: * across multiple user connections
041: * </ul>
042: *
043: * <p>Session information is scoped only to the current context
044: * (<code>Context</code>), so information stored in one context
045: * will not be directly visible in another.
046: *
047: * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
048: * @version CVS $Id: HttpSession.java 433543 2006-08-22 06:22:54Z crossley $
049: *
050: */
051:
052: public final class HttpSession implements Session {
053:
054: javax.servlet.http.HttpSession wrappedSession;
055:
056: /**
057: * Construct a new session from an HttpSession
058: */
059: public HttpSession(javax.servlet.http.HttpSession session) {
060: this .wrappedSession = session;
061: }
062:
063: /**
064: *
065: * Returns the time when this session was created, measured
066: * in milliseconds since midnight January 1, 1970 GMT.
067: *
068: * @return a <code>long</code> specifying
069: * when this session was created,
070: * expressed in
071: * milliseconds since 1/1/1970 GMT
072: *
073: * @exception IllegalStateException if this method is called on an
074: * invalidated session
075: *
076: */
077: public long getCreationTime() {
078: return this .wrappedSession.getCreationTime();
079: }
080:
081: /**
082: *
083: * Returns a string containing the unique identifier assigned
084: * to this session. The identifier is assigned
085: * by the context container and is implementation dependent.
086: *
087: * @return a string specifying the identifier
088: * assigned to this session
089: *
090: * @exception IllegalStateException if this method is called on an
091: * invalidated session
092: *
093: */
094: public String getId() {
095: return this .wrappedSession.getId();
096: }
097:
098: /**
099: *
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 getAttribute(String 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 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 name, Object 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 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: }
|