home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / esc.jar / com / extensibility / validation / IntegralLeafValidator.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-06-30  |  2.6 KB  |  69 lines

  1. package com.extensibility.validation;
  2.  
  3. import com.extensibility.xml.SchemaIntf;
  4. import com.extensibility.xml.dt.DataType;
  5. import com.extensibility.xml.dt.DataTypeIntf;
  6. import java.math.BigInteger;
  7.  
  8. class IntegralLeafValidator extends DataValidator {
  9.    BigInteger min;
  10.    BigInteger max;
  11.    BigInteger zero = new BigInteger("0");
  12.    BigInteger minS1 = new BigInteger("-80", 16);
  13.    BigInteger maxS1 = new BigInteger("7F", 16);
  14.    BigInteger maxU1 = new BigInteger("FF", 16);
  15.    BigInteger minS2 = new BigInteger("-8000", 16);
  16.    BigInteger maxS2 = new BigInteger("7FFF", 16);
  17.    BigInteger maxU2 = new BigInteger("FFFF", 16);
  18.    BigInteger minS4 = new BigInteger("-80000000", 16);
  19.    BigInteger maxS4 = new BigInteger("7FFFFFFF", 16);
  20.    BigInteger maxU4 = new BigInteger("FFFFFFFF", 16);
  21.    BigInteger minS8 = new BigInteger("-8000000000000000", 16);
  22.    BigInteger maxS8 = new BigInteger("7FFFFFFFFFFFFFFF", 16);
  23.    BigInteger maxU8 = new BigInteger("FFFFFFFFFFFFFFFF", 16);
  24.  
  25.    String validate(SchemaIntf var1, DataType var2, String var3) {
  26.       if (var3.startsWith("+") && !var3.startsWith("+-")) {
  27.          var3 = var3.substring(1);
  28.       }
  29.  
  30.       BigInteger var4;
  31.       try {
  32.          var4 = new BigInteger(var3);
  33.       } catch (NumberFormatException var7) {
  34.          String var6 = "invalid integer";
  35.          return var6;
  36.       }
  37.  
  38.       this.min = null;
  39.       this.max = null;
  40.       if (var2.getTypeName() == DataTypeIntf.I1) {
  41.          this.min = this.minS1;
  42.          this.max = this.maxS1;
  43.       } else if (var2.getTypeName() == DataTypeIntf.UI1) {
  44.          this.min = this.zero;
  45.          this.max = this.maxU1;
  46.       } else if (var2.getTypeName() == DataTypeIntf.I2) {
  47.          this.min = this.minS2;
  48.          this.max = this.maxS2;
  49.       } else if (var2.getTypeName() == DataTypeIntf.UI2) {
  50.          this.min = this.zero;
  51.          this.max = this.maxU2;
  52.       } else if (var2.getTypeName() == DataTypeIntf.I4) {
  53.          this.min = this.minS4;
  54.          this.max = this.maxS4;
  55.       } else if (var2.getTypeName() == DataTypeIntf.UI4) {
  56.          this.min = this.zero;
  57.          this.max = this.maxU4;
  58.       } else if (var2.getTypeName() == DataTypeIntf.I8) {
  59.          this.min = this.minS8;
  60.          this.max = this.maxS8;
  61.       } else if (var2.getTypeName() == DataTypeIntf.UI8) {
  62.          this.min = this.zero;
  63.          this.max = this.maxU8;
  64.       }
  65.  
  66.       return this.min == null || var4.compareTo(this.min) >= 0 && var4.compareTo(this.max) <= 0 ? ((DataValidator)this).applyIntegralFacets(var1, var2, var4) : String.valueOf("value out of range for type ").concat(String.valueOf(var2.getTypeName()));
  67.    }
  68. }
  69.