KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > types > UnsignedInt


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

16 package org.apache.axis.types;
17
18
19
20 import org.apache.axis.utils.Messages;
21
22 /**
23  * Custom class for supporting primitive XSD data type UnsignedInt
24  *
25  * @author Chris Haddad <chaddad@cobia.net>
26  * @see <a HREF="http://www.w3.org/TR/xmlschema-2/#unsignedInt">XML Schema 3.3.22</a>
27  */

28 public class UnsignedInt extends java.lang.Number JavaDoc implements java.lang.Comparable JavaDoc {
29
30     protected Long JavaDoc lValue = new Long JavaDoc(0);
31
32     public UnsignedInt() {
33     }
34
35     /**
36      * ctor for UnsignedInt
37      * @exception NumberFormatException will be thrown if validation fails
38      */

39     public UnsignedInt(long iValue) throws NumberFormatException JavaDoc {
40       setValue(iValue);
41     }
42
43     public UnsignedInt(String JavaDoc stValue) throws NumberFormatException JavaDoc {
44       setValue(Long.parseLong(stValue));
45     }
46
47
48     /**
49      *
50      * validates the data and sets the value for the object.
51      *
52      * @param iValue value
53      */

54     public void setValue(long iValue) throws NumberFormatException JavaDoc {
55       if (UnsignedInt.isValid(iValue) == false)
56             throw new NumberFormatException JavaDoc(
57                     Messages.getMessage("badUnsignedInt00") +
58                     String.valueOf(iValue) + "]");
59       lValue = new Long JavaDoc(iValue);
60     }
61
62     public String JavaDoc toString(){
63       if (lValue != null)
64         return lValue.toString();
65       else
66         return null;
67     }
68
69     public int hashCode(){
70       if (lValue != null)
71         return lValue.hashCode();
72       else
73         return 0;
74     }
75
76     /**
77      *
78      * validate the value against the xsd definition
79      *
80      */

81     public static boolean isValid(long iValue) {
82       if ( (iValue < 0L) || (iValue > 4294967295L))
83         return false;
84       else
85         return true;
86     }
87
88     private Object JavaDoc __equalsCalc = null;
89     public synchronized boolean equals(Object JavaDoc obj) {
90         if (!(obj instanceof UnsignedInt)) return false;
91         UnsignedInt other = (UnsignedInt) obj;
92         if (obj == null) return false;
93         if (this == obj) return true;
94         if (__equalsCalc != null) {
95             return (__equalsCalc == obj);
96         }
97         __equalsCalc = obj;
98         boolean _equals;
99         _equals = true &&
100             ((lValue ==null && other.lValue ==null) ||
101              (lValue !=null &&
102               lValue.equals(other.lValue)));
103         __equalsCalc = null;
104         return _equals;
105     }
106
107     // implement java.lang.comparable interface
108
public int compareTo(Object JavaDoc obj) {
109       if (lValue != null)
110         return lValue.compareTo(obj);
111       else
112         if (equals(obj) == true)
113             return 0; // null == null
114
else
115             return 1; // object is greater
116
}
117
118     // Implement java.lang.Number interface
119
public byte byteValue() { return lValue.byteValue(); }
120     public short shortValue() { return lValue.shortValue(); }
121     public int intValue() { return lValue.intValue(); }
122     public long longValue() { return lValue.longValue(); }
123     public double doubleValue() { return lValue.doubleValue(); }
124     public float floatValue() { return lValue.floatValue(); }
125
126
127 }
128
Popular Tags