UnsignedInt.java
上传用户:zsjinxin
上传日期:2013-04-21
资源大小:18236k
文件大小:4k
源码类别:

Web服务器

开发平台:

Java

  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. import org.apache.axis.utils.Messages;
  18. /**
  19.  * Custom class for supporting primitive XSD data type UnsignedInt
  20.  *
  21.  * @author Chris Haddad <chaddad@cobia.net>
  22.  * @see <a href="http://www.w3.org/TR/xmlschema-2/#unsignedInt">XML Schema 3.3.22</a>
  23.  */
  24. public class UnsignedInt extends java.lang.Number implements java.lang.Comparable {
  25.     protected Long lValue = new Long(0);
  26.     public UnsignedInt() {
  27.     }
  28.     /**
  29.      * ctor for UnsignedInt
  30.      * @exception NumberFormatException will be thrown if validation fails
  31.      */
  32.     public UnsignedInt(long iValue) throws NumberFormatException {
  33.       setValue(iValue);
  34.     }
  35.     public UnsignedInt(String stValue) throws NumberFormatException {
  36.       setValue(Long.parseLong(stValue));
  37.     }
  38.     /**
  39.      *
  40.      * validates the data and sets the value for the object.
  41.      *
  42.      * @param iValue value
  43.      */
  44.     public void setValue(long iValue) throws NumberFormatException {
  45.       if (UnsignedInt.isValid(iValue) == false)
  46.             throw new NumberFormatException(
  47.                     Messages.getMessage("badUnsignedInt00") +
  48.                     String.valueOf(iValue) + "]");
  49.       lValue = new Long(iValue);
  50.     }
  51.     public String toString(){
  52.       if (lValue != null)
  53.         return lValue.toString();
  54.       else
  55.         return null;
  56.     }
  57.     public int hashCode(){
  58.       if (lValue != null)
  59.         return lValue.hashCode();
  60.       else
  61.         return 0;
  62.     }
  63.     /**
  64.      *
  65.      * validate the value against the xsd definition
  66.      *
  67.      */
  68.     public static boolean isValid(long iValue) {
  69.       if ( (iValue < 0L)  || (iValue > 4294967295L))
  70.         return false;
  71.       else
  72.         return true;
  73.     }
  74.     private Object __equalsCalc = null;
  75.     public synchronized boolean equals(Object obj) {
  76.         if (!(obj instanceof UnsignedInt)) return false;
  77.         UnsignedInt other = (UnsignedInt) obj;
  78.         if (obj == null) return false;
  79.         if (this == obj) return true;
  80.         if (__equalsCalc != null) {
  81.             return (__equalsCalc == obj);
  82.         }
  83.         __equalsCalc = obj;
  84.         boolean _equals;
  85.         _equals = true &&
  86.             ((lValue ==null && other.lValue ==null) ||
  87.              (lValue !=null &&
  88.               lValue.equals(other.lValue)));
  89.         __equalsCalc = null;
  90.         return _equals;
  91.     }
  92.     // implement java.lang.comparable interface
  93.     public int compareTo(Object obj) {
  94.       if (lValue != null)
  95.         return lValue.compareTo(obj);
  96.       else
  97.         if (equals(obj) == true)
  98.             return 0;  // null == null
  99.         else
  100.             return 1;  // object is greater
  101.     }
  102.     // Implement java.lang.Number interface
  103.     public byte byteValue() { return lValue.byteValue(); }
  104.     public short shortValue() { return lValue.shortValue(); }
  105.     public int intValue() { return lValue.intValue(); }
  106.     public long longValue() { return lValue.longValue(); }
  107.     public double doubleValue() { return lValue.doubleValue(); }
  108.     public float floatValue() { return lValue.floatValue(); }
  109. }