KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.apache.axis.utils.Messages;
19
20 import java.math.BigInteger JavaDoc;
21 import java.util.Random JavaDoc;
22 import java.io.ObjectStreamException JavaDoc;
23
24 /**
25  * Custom class for supporting primitive XSD data type negativeinteger
26  *
27  * negativeInteger is derived from nonPositiveInteger by setting the
28  * value of maxInclusive to be -1. This results in the standard
29  * mathematical concept of the negative integers. The value space of
30  * negativeInteger is the infinite set {...,-2,-1}.
31  * The base type of negativeInteger is nonPositiveInteger.
32  *
33  * @author Chris Haddad <haddadc@apache.org>
34  * @see <a HREF="http://www.w3.org/TR/xmlschema-2/#negativeInteger">XML Schema 3.3.15</a>
35  */

36 public class NegativeInteger extends NonPositiveInteger {
37
38     public NegativeInteger(byte[] val) {
39         super(val);
40         checkValidity();
41     } // ctor
42

43     public NegativeInteger(int signum, byte[] magnitude) {
44         super(signum, magnitude);
45         checkValidity();
46     } // ctor
47

48     public NegativeInteger(int bitLength, int certainty, Random JavaDoc rnd) {
49         super(bitLength, certainty, rnd);
50         checkValidity();
51     } // ctor
52

53     public NegativeInteger(int numBits, Random JavaDoc rnd) {
54         super(numBits, rnd);
55         checkValidity();
56     } // ctor
57

58     public NegativeInteger(String JavaDoc val) {
59         super(val);
60         checkValidity();
61     }
62
63     public NegativeInteger(String JavaDoc val, int radix) {
64         super(val, radix);
65         checkValidity();
66     } // ctor
67

68     /**
69      * validate the value against the xsd definition
70      */

71     private BigInteger JavaDoc zero = new BigInteger JavaDoc("0");
72     private void checkValidity() {
73         if (compareTo(zero) >= 0) {
74             throw new NumberFormatException JavaDoc(
75                     Messages.getMessage("badnegInt00")
76                     + ": " + this);
77         }
78     } // checkValidity
79

80     /**
81      * Work-around for http://developer.java.sun.com/developer/bugParade/bugs/4378370.html
82      * @return BigIntegerRep
83      * @throws java.io.ObjectStreamException
84      */

85     public Object JavaDoc writeReplace() throws ObjectStreamException JavaDoc {
86         return new BigIntegerRep(toByteArray());
87     }
88     
89     protected static class BigIntegerRep implements java.io.Serializable JavaDoc {
90         private byte[] array;
91         protected BigIntegerRep(byte[] array) {
92             this.array = array;
93         }
94         protected Object JavaDoc readResolve() throws java.io.ObjectStreamException JavaDoc {
95             return new NegativeInteger(array);
96         }
97     }
98 } // class NonNegativeInteger
99
Popular Tags