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 negativeinteger
027: * <p/>
028: * negativeInteger is derived from nonPositiveInteger by setting the value of maxInclusive to be -1.
029: * This results in the standard mathematical concept of the negative integers. The value space of
030: * negativeInteger is the infinite set {...,-2,-1}. The base type of negativeInteger is
031: * nonPositiveInteger.
032: *
033: * @see <a href="http://www.w3.org/TR/xmlschema-2/#negativeInteger">XML Schema 3.3.15</a>
034: */
035: public class NegativeInteger extends NonPositiveInteger {
036:
037: private static final long serialVersionUID = -2295928715693639427L;
038:
039: public NegativeInteger(byte[] val) {
040: super (val);
041: checkValidity();
042: } // ctor
043:
044: public NegativeInteger(int signum, byte[] magnitude) {
045: super (signum, magnitude);
046: checkValidity();
047: } // ctor
048:
049: public NegativeInteger(int bitLength, int certainty, Random rnd) {
050: super (bitLength, certainty, rnd);
051: checkValidity();
052: } // ctor
053:
054: public NegativeInteger(int numBits, Random rnd) {
055: super (numBits, rnd);
056: checkValidity();
057: } // ctor
058:
059: public NegativeInteger(String val) {
060: super (val);
061: checkValidity();
062: }
063:
064: public NegativeInteger(String val, int radix) {
065: super (val, radix);
066: checkValidity();
067: } // ctor
068:
069: /** validate the value against the xsd definition */
070: private BigInteger zero = new BigInteger("0");
071:
072: private void checkValidity() {
073: if (compareTo(zero) >= 0) {
074: throw new NumberFormatException(
075: // Messages.getMessage("badnegInt00") +
076: ": " + this );
077: }
078: } // checkValidity
079:
080: /**
081: * Work-around for http://developer.java.sun.com/developer/bugParade/bugs/4378370.html
082: *
083: * @return BigIntegerRep
084: * @throws java.io.ObjectStreamException
085: */
086: public Object writeReplace() throws ObjectStreamException {
087: return new BigIntegerRep(toByteArray());
088: }
089:
090: protected static class BigIntegerRep implements
091: java.io.Serializable {
092: private static final long serialVersionUID = 1209618487031404110L;
093: private byte[] array;
094:
095: protected BigIntegerRep(byte[] array) {
096: this .array = array;
097: }
098:
099: protected Object readResolve()
100: throws java.io.ObjectStreamException {
101: return new NegativeInteger(array);
102: }
103: }
104: } // class NonNegativeInteger
|