KickJava   Java API By Example, From Geeks To Geeks.

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


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 nonPositiveInteger
26  *
27  * nonPositiveInteger is derived from integer by setting the value of
28  * maxInclusive to be 0. This results in the standard mathematical
29  * concept of the non-positive integers. The value space of
30  * nonPositiveInteger is the infinite set {...,-2,-1,0}.
31  *
32  * @author Chris Haddad <haddadc@apache.org
33  * @see <a HREF="http://www.w3.org/TR/xmlschema-2/#nonPositiveInteger">XML Schema 3.3.14</a>
34  */

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

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

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

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

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

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

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

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

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