001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: *
021: * $Id: SerializableCookie.java,v 1.2 2006-06-15 13:47:00 sinisa Exp $
022: */
023:
024: package com.lutris.http;
025:
026: import java.io.Serializable;
027:
028: import javax.servlet.http.Cookie;
029:
030: /**
031: * This class is a substitute for Cookies, but it is serializable.
032: * It is used to pass cookies back and forth when using RMI.
033: * Rather than pasing or returning a Cookie, which would cause a
034: * marshalling error, the Cookies are turned into SerializabeCookies,
035: * passed through RMI, then turned back into Cookies at the other end. <P>
036: *
037: * There is no reason why Cookies could not be serializable. Sun may well
038: * fix this oversight in version 2 of Java, in which case this class will
039: * no longer be necissary to use RMI with the MultiServer.
040: *
041: * @see javax.servlet.http.Cookie
042: * @see com.lutris.servlet.connectionMethod.RMIConnectionMethodImpl
043: * @see com.lutris.servlet.rmi.http.RMIHttpServletRequestImpl
044: * @see com.lutris.servlet.rmi.http.RMIHttpServletResponseImpl
045: */
046: public class SerializableCookie implements Serializable {
047:
048: private String name;
049: private String value;
050: private String comment;
051: private String domain;
052: private int maxAge;
053: private String path;
054: private boolean secure;
055: private int version;
056:
057: /**
058: * Constructor. Saves all the data about the Cookie, so it can be
059: * reconstructed later.
060: *
061: * @param cookie The cookie to make a copy of.
062: */
063: public SerializableCookie(Cookie cookie) {
064: name = cookie.getName();
065: value = cookie.getValue();
066: comment = cookie.getComment();
067: domain = cookie.getDomain();
068: maxAge = cookie.getMaxAge();
069: path = cookie.getPath();
070: secure = cookie.getSecure();
071: version = cookie.getVersion();
072: }
073:
074: /**
075: * Recreate the cookie that was passed into the constructor.
076: *
077: * @return A Cookie just like the one passed into the constructor.
078: */
079: public Cookie getCookie() {
080: Cookie cookie = new Cookie(name, value);
081: if (comment != null)
082: cookie.setComment(comment);
083: if (domain != null)
084: cookie.setDomain(domain);
085: cookie.setMaxAge(maxAge);
086: if (path != null)
087: cookie.setPath(path);
088: cookie.setSecure(secure);
089: cookie.setVersion(version);
090: return cookie;
091: }
092:
093: /**
094: * Returns a multi-line description of the data stored about
095: * the cookie. Usefull for debugging.
096: *
097: * @return A string description of the cookie.
098: */
099: public String toString() {
100: return "SerializableCookie:" + "\n name = " + name
101: + "\n value = " + value + "\n comment = "
102: + comment + "\n domain = " + domain
103: + "\n maxAge = " + maxAge + "\n path = " + path
104: + "\n secure = " + secure + "\n version = "
105: + version;
106: }
107:
108: }
|