KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > framework > core > VerProto


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
20 package sync4j.framework.core;
21
22 /**
23  * This class represents the <VerProto> tag as defined by the SyncML r
24  * epresentation specifications.
25  *
26  * @author Stefano Fornari @ Funambol
27  *
28  * @version $Id: VerProto.java,v 1.3 2005/03/02 20:57:37 harrie Exp $
29  *
30  */

31 public final class VerProto
32 implements java.io.Serializable JavaDoc {
33     
34     // ------------------------------------------------------------ Private data
35

36     private String JavaDoc version;
37     
38     // ------------------------------------------------------------ Constructors
39

40     /**
41      * For serialization purposes
42      */

43     protected VerProto() {}
44     
45     /**
46      * Creates a new VerProto object from its version.
47      *
48      * @param version the protocol version - NOT NULL
49      *
50      */

51     public VerProto(final String JavaDoc version) {
52         setVersion(version);
53     }
54     
55     // ---------------------------------------------------------- Public methods
56

57     /**
58      * Returns the protocol version.
59      *
60      * @return the protocol version - NOT NULL
61      *
62      */

63     public String JavaDoc getVersion() {
64         return version;
65     }
66     
67     /**
68      * Sets the protol version.
69      *
70      * @param version the protocol version - NOT NULL
71      *
72      * @throws IllegalArgumentException if version is null
73      */

74     public void setVersion(String JavaDoc version) {
75         if (version == null) {
76             throw new IllegalArgumentException JavaDoc("version cannot be null");
77         }
78         this.version = version;
79     }
80     
81     /**
82      * Compares this VerProto with a given object. If obj is a VerProto,
83      * versions are compared as stored internally. if obj is null, false is
84      * returned. If obj is a String, the string representation of this VerProto
85      * is used for the comparison. If obj is neither a VerProto nor a String,
86      * String.valueOf(obj) is used for the comparison
87      *
88      * @param obj the obect to be compared
89      *
90      * @return true if the two object represent the same information
91      */

92     public boolean equals(Object JavaDoc obj) {
93         if (obj == null) {
94             return false;
95         }
96         
97         String JavaDoc s = null;
98         if (obj instanceof VerProto) {
99             s = ((VerProto)obj).getVersion();
100         } else if (obj instanceof String JavaDoc) {
101             s = (String JavaDoc)obj;
102         } else {
103             s = String.valueOf(obj);
104         }
105         
106         return (s.equals(version));
107     }
108 }
109
Popular Tags