1 16 package org.apache.axis.types; 17 18 import org.apache.axis.utils.Messages; 19 20 import java.io.ObjectStreamException ; 21 import java.math.BigInteger ; 22 import java.util.Random ; 23 24 30 public class NonNegativeInteger extends BigInteger { 31 32 public NonNegativeInteger(byte[] val) { 33 super(val); 34 checkValidity(); 35 } 37 public NonNegativeInteger(int signum, byte[] magnitude) { 38 super(signum, magnitude); 39 checkValidity(); 40 } 42 public NonNegativeInteger(int bitLength, int certainty, Random rnd) { 43 super(bitLength, certainty, rnd); 44 checkValidity(); 45 } 47 public NonNegativeInteger(int numBits, Random rnd) { 48 super(numBits, rnd); 49 checkValidity(); 50 } 52 public NonNegativeInteger(String val) { 53 super(val); 54 checkValidity(); 55 } 56 57 public NonNegativeInteger(String val, int radix) { 58 super(val, radix); 59 checkValidity(); 60 } 62 65 private BigInteger zero = new BigInteger ("0"); 66 private void checkValidity() { 67 if (compareTo(zero) < 0) { 68 throw new NumberFormatException ( 69 Messages.getMessage("badNonNegInt00") 70 + ": " + this); 71 } 72 } 74 79 public Object writeReplace() throws ObjectStreamException { 80 return new BigIntegerRep(toByteArray()); 81 } 82 83 protected static class BigIntegerRep implements java.io.Serializable { 84 private byte[] array; 85 protected BigIntegerRep(byte[] array) { 86 this.array = array; 87 } 88 protected Object readResolve() throws java.io.ObjectStreamException { 89 return new NonNegativeInteger(array); 90 } 91 } 92 } | Popular Tags |