KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > Components > CookieImpl


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2002 USTL - LIFL - GOAL
5 Contact: openccm-team@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Mathieu Vadet, Philippe Merle.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.Components;
28
29 /**
30  * This class implements the Components::Cookie valuetype.
31  *
32  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
33  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
34  *
35  * @version 0.3
36  */

37
38 public class CookieImpl
39        extends org.omg.Components.Cookie
40 {
41     // ==================================================================
42
//
43
// Internal state.
44
//
45
// ==================================================================
46

47     /**
48      ** TODO
49      **/

50     private String JavaDoc random_ = "RANDOM NOT COMPUTED";
51
52     // ==================================================================
53
//
54
// Constructor.
55
//
56
// ==================================================================
57

58     /**
59      ** The default constructor.
60      **/

61     public
62     CookieImpl()
63     {
64     }
65
66     /**
67      ** The constructor.
68      **
69      ** @param random The generated random.
70      **/

71     public
72     CookieImpl(String JavaDoc random)
73     {
74         random_ = random;
75     // Set the cookieValue.
76
cookieValue = random.getBytes();
77     }
78
79     // ==================================================================
80
//
81
// Internal methods.
82
//
83
// ==================================================================
84

85     /**
86      ** Init after read from CORBA stream.
87      **/

88     protected void
89     initAfterRead()
90     {
91     random_ = new String JavaDoc(cookieValue);
92     }
93
94     // ==================================================================
95
//
96
// Public methods.
97
//
98
// ==================================================================
99

100     /**
101      ** Generate a cookie.
102      **
103      ** @return The generated cookie.
104      **/

105     public static CookieImpl
106     generate()
107     {
108     // Compute a random.
109
String JavaDoc random = java.lang.Double.toString(java.lang.Math.random());
110
111     // Create a cookie.
112
CookieImpl result = new CookieImpl(random);
113
114     // Return the generated cookie.
115
return result;
116     }
117
118     // ==================================================================
119
//
120
// Methods for the java.lang.Object class.
121
//
122
// ==================================================================
123

124     /**
125      ** Obtain a string representation.
126      **
127      ** @return A string representation.
128      **/

129     public String JavaDoc
130     toString()
131     {
132         return random_;
133     }
134
135     /**
136      ** Compute a hash code.
137      **
138      ** @return The hash code for the random.
139      **/

140     public int
141     hashCode()
142     {
143         return random_.hashCode();
144     }
145
146     /**
147      ** Test equality with another object.
148      **/

149     public boolean
150     equals(Object JavaDoc o)
151     {
152     // Compare random attributes.
153
return random_.equals(((CookieImpl)o).random_);
154     }
155 }
156
Popular Tags