KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > http > SerializableCookie


1
2 /*
3  * Enhydra Java Application Server Project
4  *
5  * The contents of this file are subject to the Enhydra Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License on
8  * the Enhydra web site ( http://www.enhydra.org/ ).
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific terms governing rights and limitations
13  * under the License.
14  *
15  * The Initial Developer of the Enhydra Application Server is Lutris
16  * Technologies, Inc. The Enhydra Application Server and portions created
17  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
18  * All Rights Reserved.
19  *
20  * Contributor(s):
21  *
22  * $Id: SerializableCookie.java,v 1.2 2005/03/24 10:51:20 slobodan Exp $
23  */

24
25
26
27
28
29 package com.lutris.http;
30
31 import java.io.Serializable JavaDoc;
32
33 import javax.servlet.http.Cookie JavaDoc;
34
35
36 /**
37  * This class is a substitute for Cookies, but it is serializable.
38  * It is used to pass cookies back and forth when using RMI.
39  * Rather than pasing or returning a Cookie, which would cause a
40  * marshalling error, the Cookies are turned into SerializabeCookies,
41  * passed through RMI, then turned back into Cookies at the other end. <P>
42  *
43  * There is no reason why Cookies could not be serializable. Sun may well
44  * fix this oversight in version 2 of Java, in which case this class will
45  * no longer be necissary to use RMI with the MultiServer.
46  *
47  * @see javax.servlet.http.Cookie
48  * @see com.lutris.servlet.connectionMethod.RMIConnectionMethodImpl
49  * @see com.lutris.servlet.rmi.http.RMIHttpServletRequestImpl
50  * @see com.lutris.servlet.rmi.http.RMIHttpServletResponseImpl
51  */

52 public class SerializableCookie implements Serializable JavaDoc {
53
54     private String JavaDoc name;
55     private String JavaDoc value;
56     private String JavaDoc comment;
57     private String JavaDoc domain;
58     private int maxAge;
59     private String JavaDoc path;
60     private boolean secure;
61     private int version;
62
63     /**
64      * Constructor. Saves all the data about the Cookie, so it can be
65      * reconstructed later.
66      *
67      * @param cookie The cookie to make a copy of.
68      */

69     public SerializableCookie(Cookie JavaDoc cookie) {
70         name = cookie.getName();
71         value = cookie.getValue();
72         comment = cookie.getComment();
73         domain = cookie.getDomain();
74         maxAge = cookie.getMaxAge();
75         path = cookie.getPath();
76         secure = cookie.getSecure();
77         version = cookie.getVersion();
78     }
79
80
81     /**
82      * Recreate the cookie that was passed into the constructor.
83      *
84      * @return A Cookie just like the one passed into the constructor.
85      */

86     public Cookie JavaDoc getCookie() {
87         Cookie JavaDoc cookie = new Cookie JavaDoc(name, value);
88         if (comment != null)
89             cookie.setComment(comment);
90         if (domain != null)
91             cookie.setDomain(domain);
92         cookie.setMaxAge(maxAge);
93         if (path != null)
94             cookie.setPath(path);
95         cookie.setSecure(secure);
96         cookie.setVersion(version);
97         return cookie;
98     }
99
100
101     /**
102      * Returns a multi-line description of the data stored about
103      * the cookie. Usefull for debugging.
104      *
105      * @return A string description of the cookie.
106      */

107     public String JavaDoc toString() {
108         return "SerializableCookie:" +
109                "\n name = " + name +
110                "\n value = " + value +
111                "\n comment = " + comment +
112                "\n domain = " + domain +
113                "\n maxAge = " + maxAge +
114                "\n path = " + path +
115                "\n secure = " + secure +
116                "\n version = " + version;
117     }
118
119 }
120
121
122
Popular Tags