You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@locus.apache.org on 2000/09/24 21:22:36 UTC
cvs commit: jakarta-tomcat/src/facade22/org/apache/tomcat/facade CookieFacade.java HttpSessionFacade.java
costin 00/09/24 12:22:35
Modified: src/facade22/org/apache/tomcat/facade HttpSessionFacade.java
Added: src/facade22/org/apache/tomcat/facade CookieFacade.java
Log:
Checked in CookieFacade - present a javax.servlet.Cookie view for the
internal representation of Cookie.
Revision Changes Path
1.2 +89 -12 jakarta-tomcat/src/facade22/org/apache/tomcat/facade/HttpSessionFacade.java
Index: HttpSessionFacade.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/HttpSessionFacade.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- HttpSessionFacade.java 2000/08/23 05:39:20 1.1
+++ HttpSessionFacade.java 2000/09/24 19:22:34 1.2
@@ -91,14 +91,16 @@
* @author costin@eng.sun.com
*/
final class HttpSessionFacade implements HttpSession {
- HttpSession realSession;
+ private static StringManager sm =
+ StringManager.getManager("org.apache.tomcat.resources");
+ ServerSession realSession;
HttpSessionFacade() {
}
/** Package-level method - accessible only by core
*/
- void setRealSession(HttpSession s) {
+ void setRealSession(ServerSession s) {
realSession=s;
}
@@ -111,11 +113,19 @@
// -------------------- public facade --------------------
public String getId() {
- return realSession.getId();
+ return realSession.getId().toString();
}
+ /**
+ * Return the time when this session was created, in milliseconds since
+ * midnight, January 1, 1970 GMT.
+ *
+ * @exception IllegalStateException if this method is called on an
+ * invalidated session
+ */
public long getCreationTime() {
- return realSession.getCreationTime();
+ checkValid();
+ return realSession.getTimeStamp().getCreationTime();
}
/**
@@ -129,25 +139,51 @@
}
public long getLastAccessedTime() {
- return realSession.getLastAccessedTime();
+ checkValid();
+ return realSession.getTimeStamp().getLastAccessedTime();
}
+ /**
+ * Invalidates this session and unbinds any objects bound to it.
+ *
+ * @exception IllegalStateException if this method is called on
+ * an invalidated session
+ */
public void invalidate() {
- realSession.invalidate();
+ checkValid();
+ realSession.expire();
}
+ /**
+ * Return <code>true</code> if the client does not yet know about the
+ * session, or if the client chooses not to join the session. For
+ * example, if the server used only cookie-based sessions, and the client
+ * has disabled the use of cookies, then a session would be new on each
+ * request.
+ *
+ * @exception IllegalStateException if this method is called on an
+ * invalidated session
+ */
public boolean isNew() {
- return realSession.isNew();
+ checkValid();
+ return realSession.getTimeStamp().isNew();
}
/**
* @deprecated
*/
public void putValue(String name, Object value) {
- realSession.putValue(name, value);
+ setAttribute(name, value);
}
public void setAttribute(String name, Object value) {
+ checkValid();
+
+ if (realSession.isDistributable() &&
+ !(value instanceof Serializable))
+ throw new IllegalArgumentException
+ (sm.getString("standardSession.setAttribute.iae"));
+
realSession.setAttribute( name, value );
}
@@ -155,10 +191,11 @@
* @deprecated
*/
public Object getValue(String name) {
- return realSession.getValue(name);
+ return getAttribute(name);
}
public Object getAttribute(String name) {
+ checkValid();
return realSession.getAttribute(name);
}
@@ -166,10 +203,24 @@
* @deprecated
*/
public String[] getValueNames() {
- return realSession.getValueNames();
+ checkValid();
+
+ Enumeration attrs = getAttributeNames();
+ String names[] = new String[realSession.getAttributeCount()];
+ for (int i = 0; i < names.length; i++)
+ names[i] = (String)attrs.nextElement();
+ return names;
}
+ /**
+ * Return an <code>Enumeration</code> of <code>String</code> objects
+ * containing the names of the objects bound to this session.
+ *
+ * @exception IllegalStateException if this method is called on an
+ * invalidated session
+ */
public Enumeration getAttributeNames() {
+ checkValid();
return realSession.getAttributeNames();
}
@@ -180,15 +231,41 @@
realSession.removeAttribute(name);
}
+ /**
+ * Remove the object bound with the specified name from this session. If
+ * the session does not have an object bound with this name, this method
+ * does nothing.
+ * <p>
+ * After this method executes, and if the object implements
+ * <code>HttpSessionBindingListener</code>, the container calls
+ * <code>valueUnbound()</code> on the object.
+ *
+ * @param name Name of the object to remove from this session.
+ *
+ * @exception IllegalStateException if this method is called on an
+ * invalidated session
+ */
public void removeAttribute(String name) {
+ checkValid();
realSession.removeAttribute(name);
}
public void setMaxInactiveInterval(int interval) {
- realSession.setMaxInactiveInterval( interval );
+ checkValid();
+ realSession.getTimeStamp().setMaxInactiveInterval( interval );
}
public int getMaxInactiveInterval() {
- return realSession.getMaxInactiveInterval();
+ checkValid();
+ return realSession.getTimeStamp().getMaxInactiveInterval();
}
+
+ // duplicated code, private
+ private void checkValid() {
+ if (!realSession.isValid()) {
+ throw new IllegalStateException
+ (sm.getString("standardSession.getAttributeNames.ise"));
+ }
+ }
+
}
1.1 jakarta-tomcat/src/facade22/org/apache/tomcat/facade/CookieFacade.java
Index: CookieFacade.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.tomcat.facade;
import org.apache.tomcat.util.*;
import org.apache.tomcat.helper.RequestUtil;
import org.apache.tomcat.core.*;
import org.apache.tomcat.facade.*;
import java.io.*;
import java.net.*;
import java.security.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.tomcat.core.Constants;
/**
* Facade for a ServerCookie object. The ServerCookie is a recyclable
* and efficient Cookie implementation. The Facades makes sure the
* user "sees" only what's permited by the servlet spec.
*
* @author Costin Manolache
*/
final class CookieFacade extends Cookie {
ServerCookie sC;
CookieFacade( ServerCookie sC ) {
// we can't reuse super anyway
super(null, null);
this.sC=sC;
}
public void setComment(String purpose) {
sC.getComment().setString( purpose);
}
public String getComment() {
return sC.getComment().toString();
}
public void setDomain(String pattern) {
sC.getDomain().setString( pattern.toLowerCase());
// IE allegedly needs this
}
public String getDomain() {
return sC.getDomain().toString();
}
public void setMaxAge(int expiry) {
sC.setMaxAge(expiry);
}
public int getMaxAge() {
return sC.getMaxAge();
}
public void setPath(String uri) {
sC.getPath().setString( uri );
}
public String getPath() {
return sC.getPath().toString();
}
public void setSecure(boolean flag) {
sC.setSecure( flag );
}
public boolean getSecure() {
return sC.getSecure();
}
public String getName() {
return sC.getName().toString();
}
public void setValue(String newValue) {
sC.getValue().setString(newValue);
}
public String getValue() {
return sC.getValue().toString();
}
public int getVersion() {
return sC.getVersion();
}
public void setVersion(int v) {
sC.setVersion(v);
}
}