KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > framework > server > Sync4jDevice


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package sync4j.framework.server;
20
21 import java.io.Serializable JavaDoc;
22
23 import java.util.Map JavaDoc;
24 import java.util.Iterator JavaDoc;
25
26 import org.apache.commons.lang.builder.ToStringBuilder;
27
28
29 /**
30  * This class represents a Sync4j device.
31  *
32  * @author Luigia Fassina @ Funambol
33  *
34  * @version $Id: Sync4jDevice.java,v 1.11 2005/06/13 17:16:59 nichele Exp $
35  *
36  */

37 public class Sync4jDevice implements Serializable JavaDoc {
38
39     // --------------------------------------------------------------- Constants
40
private static final String JavaDoc DEFAULT_CHARSET = "UTF-8";
41
42     // ------------------------------------------------------------ Private data
43
private String JavaDoc deviceId ;
44     private String JavaDoc description ;
45     private String JavaDoc type ;
46     private byte[] clientNonce ;
47     private byte[] serverNonce ;
48     private String JavaDoc serverPassword ;
49     private String JavaDoc timeZone ;
50     private boolean convertDate ;
51     private Capabilities capabilities;
52     private String JavaDoc charset ;
53
54
55     // ------------------------------------------------------------- Costructors
56
/** Creates a new instance of Sync4jDevice */
57     public Sync4jDevice() {
58         this(null, null, null, null, null, null, null, false, null);
59     }
60
61     /**
62      * Creates a new instance of Sync4jDevice.
63      *
64      * @param deviceId the device identification
65      */

66     public Sync4jDevice(final String JavaDoc deviceId) {
67         this(deviceId, null, null, null, null, null, null, false, null);
68     }
69
70     /**
71      * Creates a new instance of Sync4jDevice.
72      *
73      * @param deviceId the device identification
74      * @param description the device description
75      * @param type the device type
76      *
77      */

78     public Sync4jDevice(final String JavaDoc deviceId ,
79                         final String JavaDoc description,
80                         final String JavaDoc type ) {
81         this(deviceId, description, type, null, null, null, null, false, null);
82
83     }
84
85     /**
86      * Creates a new instance of Sync4jDevice.
87      *
88      * @param deviceId the device identification
89      * @param description the device description
90      * @param type the device type
91      * @param clientNonce the next nonce sent by server for MD5 authentication
92      * @param serverNonce the next nonce sent by client for MD5 authentication
93      */

94     public Sync4jDevice(final String JavaDoc deviceId ,
95                         final String JavaDoc description,
96                         final String JavaDoc type ,
97                         final byte[] clientNonce ,
98                         final byte[] serverNonce) {
99         this(deviceId,
100              description,
101              type,
102              clientNonce,
103              serverNonce,
104              null,
105              null,
106              false,
107              null);
108
109     }
110
111     /**
112      * Creates a new instance of Sync4jDevice.
113      *
114      * @param deviceId the device identification
115      * @param description the device description
116      * @param type the device type
117      * @param clientNonce the next nonce sent by server for MD5 authentication
118      * @param serverNonce the next nonce sent by client for MD5 authentication
119      * @param serverPassword the server password for this device
120      * @param timeZone the timezone for this device
121      * @param convertDate must the date be converted in the device timezone ?
122      */

123     public Sync4jDevice(final String JavaDoc deviceId ,
124                         final String JavaDoc description,
125                         final String JavaDoc type ,
126                         final byte[] clientNonce,
127                         final byte[] serverNonce,
128                         final String JavaDoc serverPassword,
129                         final String JavaDoc timeZone,
130                         final boolean convertDate,
131                         final String JavaDoc charset) {
132         this.deviceId = deviceId;
133         this.description = description;
134         this.type = type;
135         this.clientNonce = clientNonce;
136         this.serverNonce = serverNonce;
137         this.serverPassword = serverPassword;
138         this.timeZone = timeZone;
139         this.convertDate = convertDate;
140         if (charset == null) {
141             this.charset = DEFAULT_CHARSET;
142         } else {
143             this.charset = charset;
144         }
145         
146         //
147
// Default capabilities...
148
//
149
this.capabilities = new Capabilities();
150     }
151
152
153     /** Getter for property deviceId.
154      * @return Value of property deviceId.
155      *
156      */

157     public String JavaDoc getDeviceId() {
158         return deviceId;
159     }
160
161     /** Setter for property deviceId.
162      * @param deviceId New value of property deviceId.
163      *
164      */

165     public void setDeviceId(String JavaDoc deviceId) {
166         this.deviceId = deviceId;
167     }
168
169     /** Getter for property description.
170      * @return Value of property description.
171      *
172      */

173     public String JavaDoc getDescription() {
174         return description;
175     }
176
177     /** Setter for property description.
178      * @param description New value of property description.
179      *
180      */

181     public void setDescription(String JavaDoc description) {
182         this.description = description;
183     }
184
185     /** Getter for property type.
186      * @return Value of property type.
187      *
188      */

189     public String JavaDoc getType() {
190         return type;
191     }
192
193     /** Setter for property type.
194      * @param type New value of property type.
195      *
196      */

197     public void setType(String JavaDoc type) {
198         this.type = type;
199     }
200
201     /**
202      * Gets the client_nonce property
203      *
204      * @return clientNonce the nonce that the server uses in order to authenticate
205      * iteself with the client
206      */

207     public byte[] getClientNonce() {
208         return this.clientNonce;
209     }
210
211     /**
212      * Sets the client_nonce property
213      *
214      * @param clientNonce the nonce that the server uses in order to authenticate
215      * iteself with the client
216      */

217     public void setClientNonce(byte[] clientNonce) {
218         if (clientNonce == null) {
219             clientNonce = new byte[0];
220         }
221         this.clientNonce = clientNonce;
222     }
223
224     /**
225      * Gets the server_nonce property
226      *
227      * @return serverNonce the nonce that the client uses in order to authenticate
228      * iteself with the server
229      */

230     public byte[] getServerNonce() {
231         return this.serverNonce;
232     }
233
234     /**
235      * Sets the server_nonce property
236      *
237      * @param serverNonce the nonce that the client uses in order to authenticate
238      * iteself with the server
239      */

240     public void setServerNonce(byte[] serverNonce) {
241         if (serverNonce == null) {
242             serverNonce = new byte[0];
243         }
244         this.serverNonce = serverNonce;
245     }
246
247     /**
248      * Gets the server password property
249      *
250      * @return serverPassword the server password for this device
251      */

252     public String JavaDoc getServerPassword() {
253         return this.serverPassword;
254     }
255
256     /**
257      * Sets the server password property
258      *
259      * @param serverPassword the server password for this device
260      */

261     public void setServerPassword(String JavaDoc serverPassword) {
262         this.serverPassword = serverPassword;
263     }
264
265     /**
266      * Sets the client device capabilities
267      *
268      * @param capabilities the client device capabilities
269      */

270     public void setCapabilities(Capabilities capabilities) {
271         this.capabilities = capabilities;
272     }
273
274     /**
275      * Gets the client device capabilities
276      *
277      * @return the client device capabilities
278      */

279     public Capabilities getCapabilities() {
280         return capabilities;
281     }
282
283     /**
284      * Sets the client device timeZone
285      *
286      * @param tz the client device timeZone
287      */

288     public void setTimeZone(String JavaDoc tz) {
289         this.timeZone = tz;
290     }
291
292     /**
293      * Gets the client device timeZone
294      *
295      * @return the client device timeZone
296      */

297     public String JavaDoc getTimeZone() {
298         return timeZone;
299     }
300
301     /**
302      * Sets the convertDate
303      *
304      * @param convertDate the convert date
305      */

306     public void setConvertDate(boolean convertDate) {
307         this.convertDate = convertDate;
308     }
309
310     /**
311      * Gets the convertDate
312      *
313      * @return the convertDate
314      */

315     public boolean getConvertDate() {
316         return convertDate;
317     }
318
319     /**
320      * Sets the charset
321      *
322      * @param charset the charset
323      */

324     public void setCharset(String JavaDoc charset) {
325         this.charset = charset;
326     }
327
328     /**
329      * Gets the charset
330      *
331      * @return the charset
332      */

333     public String JavaDoc getCharset() {
334         return charset;
335     }
336
337
338     public String JavaDoc toString() {
339         ToStringBuilder sb = new ToStringBuilder(this);
340
341          sb.append("deviceId", deviceId);
342          sb.append("description", description);
343          sb.append("type", type);
344          if (clientNonce != null) {
345              sb.append("client_nonce", new String JavaDoc(clientNonce));
346          }
347          if (serverNonce != null) {
348              sb.append("server_nonce", new String JavaDoc(serverNonce));
349          }
350          sb.append("serverPassword", serverPassword);
351          sb.append("timeZone", timeZone);
352          sb.append("convertDate", convertDate);
353          sb.append("charset", charset);
354
355          return sb.toString();
356     }
357
358 }
359
Popular Tags