1 2 58 59 package org.enhydra.apache.xerces.validators.datatype; 60 61 62 import java.util.Hashtable ; 63 import java.util.Vector ; 64 65 72 73 public abstract class AbstractNumericValidator extends AbstractNumericFacetValidator { 74 75 public AbstractNumericValidator () throws InvalidDatatypeFacetException { 76 super( null, null, false ); } 78 79 public AbstractNumericValidator ( DatatypeValidator base, 80 Hashtable facets, 81 boolean derivedByList) throws InvalidDatatypeFacetException { 82 super (base, facets, derivedByList); 83 } 84 85 86 96 public Object validate(String content, Object state) throws InvalidDatatypeValueException { 97 checkContent(content, state, null, false); 99 return null; 100 } 101 102 public Object clone() throws CloneNotSupportedException { 103 throw new CloneNotSupportedException ("clone() is not supported in "+this.getClass().getName()); 104 } 105 106 116 protected void checkContentEnum(String content, Object state, Vector enumeration) 117 throws InvalidDatatypeValueException { 118 checkContent(content, state, enumeration, false); 119 } 120 121 122 abstract protected void checkContent( String content, Object State, Vector enumer, boolean asBase) 126 throws InvalidDatatypeValueException; 127 128 129 132 protected void boundsCheck(Object d) throws InvalidDatatypeValueException { 133 134 boolean minOk = true; 135 boolean maxOk = true; 136 String upperBound=""; 137 138 String lowerBound=""; 139 String lowerBoundIndicator = ""; 140 String upperBoundIndicator = ""; 141 int compare; 142 if ( (fFacetsDefined & DatatypeValidator.FACET_MAXINCLUSIVE) != 0 ) { 143 compare = compareValues(d, fMaxInclusive); 144 maxOk=(compare==1)?false:true; 145 upperBound = getMaxInclusive(false); 146 if ( upperBound != null ) { 147 upperBoundIndicator = "<="; 148 } 149 else { 150 upperBound=""; 151 } 152 } 153 if ( (fFacetsDefined & DatatypeValidator.FACET_MAXEXCLUSIVE) != 0 ) { 154 compare = compareValues(d, fMaxExclusive ); 155 maxOk = (compare==-1)?true:false; 156 upperBound = getMaxExclusive (false); 157 if ( upperBound != null ) { 158 upperBoundIndicator = "<"; 159 } 160 else { 161 upperBound = ""; 162 } 163 } 164 165 if ( (fFacetsDefined & DatatypeValidator.FACET_MININCLUSIVE) != 0 ) { 166 compare = compareValues(d, fMinInclusive); 167 minOk = (compare==-1)?false:true; 168 lowerBound = getMinInclusive (false); 169 if ( lowerBound != null ) { 170 lowerBoundIndicator = "<="; 171 } 172 else { 173 lowerBound = ""; 174 } 175 } 176 if ( (fFacetsDefined & DatatypeValidator.FACET_MINEXCLUSIVE) != 0 ) { 177 compare = compareValues(d, fMinExclusive); 178 minOk = (compare==1)?true:false; 179 lowerBound = getMinExclusive (false ); 180 if ( lowerBound != null ) { 181 lowerBoundIndicator = "<"; 182 } 183 else { 184 lowerBound = ""; 185 } 186 } 187 188 if ( !(minOk && maxOk) ) 189 throw new InvalidDatatypeValueException ( 190 getErrorString(DatatypeMessageProvider.OUT_OF_BOUNDS, 191 DatatypeMessageProvider.MSG_NONE, 192 new Object [] { d.toString() , lowerBound , 193 upperBound, lowerBoundIndicator, upperBoundIndicator})); 194 195 196 } 197 198 199 200 } 201 | Popular Tags |