KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > protocol > http > control > Cookie


1 // $Header: /home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/control/Cookie.java,v 1.10.2.1 2004/10/23 19:41:08 sebb Exp $
2
/*
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17 */

18
19 package org.apache.jmeter.protocol.http.control;
20
21 import java.io.Serializable JavaDoc;
22
23 import org.apache.jmeter.config.ConfigElement;
24 import org.apache.jmeter.testelement.AbstractTestElement;
25 import org.apache.jmeter.testelement.property.BooleanProperty;
26 import org.apache.jmeter.testelement.property.LongProperty;
27 import org.apache.jorphan.util.JOrphanUtils;
28
29 /**
30  * This class is a Cookie encapsulator.
31  *
32  * @author <a HREF="mailto:sdowd@arcmail.com">Sean Dowd</a>
33  */

34 public class Cookie extends AbstractTestElement implements Serializable JavaDoc
35 {
36     private static String JavaDoc VALUE = "Cookie.value";
37     private static String JavaDoc DOMAIN = "Cookie.domain";
38     private static String JavaDoc EXPIRES = "Cookie.expires";
39     private static String JavaDoc SECURE = "Cookie.secure";
40     private static String JavaDoc PATH = "Cookie.path";
41
42     /**
43      * create the coookie
44      */

45     public Cookie()
46     {
47         this.setName("");
48         this.setValue("");
49         this.setDomain("");
50         this.setPath("");
51         this.setSecure(false);
52         this.setExpires(0);
53     }
54
55     /**
56      * create the coookie
57      */

58     public Cookie(
59         String JavaDoc name,
60         String JavaDoc value,
61         String JavaDoc domain,
62         String JavaDoc path,
63         boolean secure,
64         long expires)
65     {
66         this.setName(name);
67         this.setValue(value);
68         this.setDomain(domain);
69         this.setPath(path);
70         this.setSecure(secure);
71         this.setExpires(expires);
72     }
73
74     public void addConfigElement(ConfigElement config)
75     {
76     }
77
78     public boolean expectsModification()
79     {
80         return false;
81     }
82
83     public String JavaDoc getClassLabel()
84     {
85         return "Cookie";
86     }
87
88     /**
89      * get the value for this object.
90      */

91     public synchronized String JavaDoc getValue()
92     {
93         return getPropertyAsString(VALUE);
94     }
95
96     /**
97      * set the value for this object.
98      */

99     public synchronized void setValue(String JavaDoc value)
100     {
101         this.setProperty(VALUE, value);
102     }
103
104     /**
105      * get the domain for this object.
106      */

107     public synchronized String JavaDoc getDomain()
108     {
109         return getPropertyAsString(DOMAIN);
110     }
111
112     /**
113      * set the domain for this object.
114      */

115     public synchronized void setDomain(String JavaDoc domain)
116     {
117         setProperty(DOMAIN, domain);
118     }
119
120     /**
121      * get the expires for this object.
122      */

123     public synchronized long getExpires()
124     {
125         return getPropertyAsLong(EXPIRES);
126     }
127
128     /**
129      * set the expires for this object.
130      */

131     public synchronized void setExpires(long expires)
132     {
133         setProperty(new LongProperty(EXPIRES, expires));
134     }
135
136     /**
137      * get the secure for this object.
138      */

139     public synchronized boolean getSecure()
140     {
141         return getPropertyAsBoolean(SECURE);
142     }
143
144     /**
145      * set the secure for this object.
146      */

147     public synchronized void setSecure(boolean secure)
148     {
149         setProperty(new BooleanProperty(SECURE, secure));
150     }
151
152     /**
153      * get the path for this object.
154      */

155     public synchronized String JavaDoc getPath()
156     {
157         return getPropertyAsString(PATH);
158     }
159
160     /**
161      * set the path for this object.
162      */

163     public synchronized void setPath(String JavaDoc path)
164     {
165         setProperty(PATH, path);
166     }
167
168     /**
169      * creates a string representation of this cookie
170      */

171     public String JavaDoc toString()
172     {
173         return getDomain()
174             + "\tTRUE\t"
175             + getPath()
176             + "\t"
177             + JOrphanUtils.booleanToSTRING(getSecure())
178             + "\t"
179             + getExpires()
180             + "\t"
181             + getName()
182             + "\t"
183             + getValue();
184     }
185 }
186
Popular Tags