KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > web > session > SessionCookieConfig


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.web.session;
25
26 import java.net.URLEncoder JavaDoc;
27 import org.apache.catalina.Globals;
28
29
30 /**
31  * Representation of the session cookie configuration element for a web
32  * application.
33  *
34  * This configuration is not specified as part of the standard deployment
35  * descriptor but as part of the iAS 7.0's "extended" web application
36  * deployment descriptor - ias-web.xml.
37  */

38
39 public final class SessionCookieConfig {
40
41     // ----------------------------------------------------- Manifest Constants
42

43     /**
44      * The default value for the session tracking cookie's comment.
45      */

46     public static final String JavaDoc SESSION_COOKIE_DEFAULT_COMMENT =
47         URLEncoder.encode("Sun ONE Application Server Session Tracking Cookie");
48
49     // ----------------------------------------------------------- Constructors
50

51     /**
52      * Construct a new SessionCookieConfig with default properties.
53      */

54     public SessionCookieConfig() {
55         super();
56     }
57
58     // ----------------------------------------------------- Instance Variables
59

60     /**
61      * The name of the cookie used for session tracking.
62      *
63      * Default value is JSESSIONID
64      */

65     private String JavaDoc _name = Globals.SESSION_COOKIE_NAME;
66
67     /**
68      * The pathname that is set when the cookie is created.
69      *
70      * The default value is the context path at which the web application
71      * is installed. The browser will send the cookie if the pathname for the
72      * request contains this pathname. If set to / (slash), the browser will
73      * send the cookie to all URLs.
74      */

75     private String JavaDoc _path = null;
76
77     /**
78      * The expiration time in seconds after which the browser expires
79      * the cookie.
80      *
81      * The default value is -1 (never expire).
82      */

83     private int _maxAge = -1;
84
85     /**
86      * The domain for which the cookie is valid.
87      */

88     private String JavaDoc _domain = null;
89
90     /**
91      * The comment that identifies the session tracking cookie in the
92      * browser's cookie file. Applications may choose to provide a more
93      * specific name for this cookie.
94      */

95     private String JavaDoc _comment = SESSION_COOKIE_DEFAULT_COMMENT;
96
97     /**
98      * Construct a new SessionCookieConfig with the specified properties.
99      *
100      * @param name The name of the cookie used for session tracking
101      * @param path The pathname that is set when the cookie is created
102      * @param maxAge The expiration time (in seconds) of the session cookie
103      * (-1 indicates 'never expire')
104      * @param domain The domain for which the cookie is valid
105      * @param comment The comment that identifies the session tracking cookie
106      * in the cookie file.
107      */

108     public SessionCookieConfig(String JavaDoc name, String JavaDoc path, int maxAge,
109                                String JavaDoc domain, String JavaDoc comment) {
110         super();
111         setName(name);
112         setPath(path);
113         setMaxAge(maxAge);
114         setDomain(domain);
115         setComment(comment);
116     }
117
118     // ------------------------------------------------------------- Properties
119

120     /**
121      * Set the name of the session tracking cookie (currently not supported).
122      */

123     public void setName(String JavaDoc name) {
124         _name = name;
125     }
126
127     /**
128      * Return the name of the session tracking cookie.
129      */

130     public String JavaDoc getName() {
131         return _name;
132     }
133
134     /**
135      * Set the path to use when creating the session tracking cookie.
136      */

137     public void setPath(String JavaDoc path) {
138         _path = path;
139     }
140
141     /**
142      * Return the path that is set when the session tracking cookie is
143      * created.
144      */

145     public String JavaDoc getPath() {
146         return _path;
147     }
148
149     /**
150      * Set the expiration time for the session cookie.
151      */

152     public void setMaxAge(int maxAge) {
153         _maxAge = maxAge;
154     }
155
156     /**
157      * Return the expiration time for the session cookie.
158      */

159     public int getMaxAge() {
160         return _maxAge;
161     }
162
163     /**
164      * Set the domain for which the cookie is valid.
165      */

166     public void setDomain(String JavaDoc domain) {
167         _domain = domain;
168     }
169
170     /**
171      * Return the domain for which the cookie is valid.
172      */

173     public String JavaDoc getDomain() {
174         return _domain;
175     }
176
177     /**
178      * Set the comment that identifies the session cookie.
179      */

180     public void setComment(String JavaDoc comment) {
181         _comment = URLEncoder.encode(comment);
182     }
183
184     /**
185      * Return the URLEncoded form of the comment that identifies the session
186      * cookie.
187      */

188     public String JavaDoc getComment() {
189         return _comment;
190     }
191
192     // --------------------------------------------------------- Public Methods
193

194     /**
195      * Return a String representation of this object.
196      */

197     public String JavaDoc toString() {
198
199         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("SessionCookieConfig[");
200         sb.append("name=");
201         sb.append(_name);
202         if (_path != null) {
203             sb.append(", path=");
204             sb.append(_path);
205         }
206         sb.append(", maxAge=");
207         sb.append(_maxAge);
208         if (_domain != null) {
209             sb.append(", domain=");
210             sb.append(_domain);
211         }
212         if (_comment != null) {
213             sb.append(", comment=");
214             sb.append(_comment);
215         }
216         sb.append("]");
217         return (sb.toString());
218
219     }
220 }
221
Popular Tags