KickJava   Java API By Example, From Geeks To Geeks.

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


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

34 public class PositiveInteger extends NonNegativeInteger {
35
36     public PositiveInteger(byte[] val) {
37         super(val);
38         checkValidity();
39     } // ctor
40

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

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

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

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

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

69     private BigInteger JavaDoc iMinInclusive = new BigInteger JavaDoc("1");
70     private void checkValidity() {
71         if (compareTo(iMinInclusive) < 0) {
72             throw new NumberFormatException JavaDoc(
73                     Messages.getMessage("badposInt00")
74                     + ": " + this);
75         }
76     } // checkValidity
77

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

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