001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.axis2.databinding.types;
020:
021: import java.io.ObjectStreamException;
022: import java.math.BigInteger;
023: import java.util.Random;
024:
025: /**
026: * Custom class for supporting primitive XSD data type positiveInteger
027: * <p/>
028: * positiveInteger is derived from nonNegativeInteger by setting the value of minInclusive to be 1.
029: * This results in the standard mathematical concept of the positive integer numbers. The value
030: * space of positiveInteger is the infinite set {1,2,...}.
031: *
032: * @see <a href="http://www.w3.org/TR/xmlschema-2/#positiveInteger">XML Schema 3.3.25</a>
033: */
034: public class PositiveInteger extends NonNegativeInteger {
035:
036: private static final long serialVersionUID = -4562301423231920813L;
037:
038: public PositiveInteger(byte[] val) {
039: super (val);
040: checkValidity();
041: } // ctor
042:
043: public PositiveInteger(int signum, byte[] magnitude) {
044: super (signum, magnitude);
045: checkValidity();
046: } // ctor
047:
048: public PositiveInteger(int bitLength, int certainty, Random rnd) {
049: super (bitLength, certainty, rnd);
050: checkValidity();
051: } // ctor
052:
053: public PositiveInteger(int numBits, Random rnd) {
054: super (numBits, rnd);
055: checkValidity();
056: } // ctor
057:
058: public PositiveInteger(String val) {
059: super (val);
060: checkValidity();
061: }
062:
063: public PositiveInteger(String val, int radix) {
064: super (val, radix);
065: checkValidity();
066: } // ctor
067:
068: /** validate the value against the xsd definition */
069: private BigInteger iMinInclusive = new BigInteger("1");
070:
071: private void checkValidity() {
072: if (compareTo(iMinInclusive) < 0) {
073: throw new NumberFormatException(
074: //Messages.getMessage("badposInt00")
075: ": " + this );
076: }
077: } // checkValidity
078:
079: /**
080: * Work-around for http://developer.java.sun.com/developer/bugParade/bugs/4378370.html
081: *
082: * @return BigIntegerRep
083: * @throws java.io.ObjectStreamException
084: */
085: public Object writeReplace() throws ObjectStreamException {
086: return new BigIntegerRep(toByteArray());
087: }
088:
089: protected static class BigIntegerRep implements
090: java.io.Serializable {
091: private static final long serialVersionUID = 1251664160936150499L;
092: private byte[] array;
093:
094: protected BigIntegerRep(byte[] array) {
095: this .array = array;
096: }
097:
098: protected Object readResolve()
099: throws java.io.ObjectStreamException {
100: return new PositiveInteger(array);
101: }
102: }
103: } // class NonNegativeInteger
|