PrecisionDecimalDV.java revision 286
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Validator for <precisionDecimal> datatype (W3C Schema 1.1)
*
* @xerces.experimental
*
* @author Ankit Pasricha, IBM
*
*/
class PrecisionDecimalDV extends TypeValidator {
static class XPrecisionDecimal {
// sign: 0 for absent; 1 for positive values; -1 for negative values (except in case of INF, -INF)
int sign = 1;
// total digits. >= 1
int totalDigits = 0;
// integer digits when sign != 0
int intDigits = 0;
// fraction digits when sign != 0
int fracDigits = 0;
//precision
//int precision = 0;
// the string representing the integer part
// the string representing the fraction part
int pvalue = 0;
sign = 0;
}
return;
}
}
if (len == 0)
throw new NumberFormatException();
// Deal with leading sign symbol if present
// skip '+', so intStart should be 1
intStart = 1;
}
intStart = 1;
sign = -1;
}
// skip leading zeroes in integer part
int actualIntStart = intStart;
}
// Find the ending position of the integer part
for (intEnd = actualIntStart; intEnd < len && TypeValidator.isDigit(content.charAt(intEnd)); intEnd++);
// Not reached the end yet
// the remaining part is not ".DDD" or "EDDD" or "eDDD", error
if (content.charAt(intEnd) != '.' && content.charAt(intEnd) != 'E' && content.charAt(intEnd) != 'e')
throw new NumberFormatException();
// fraction part starts after '.', and ends at the end of the input
// find location of E or e (if present)
// Find the ending position of the fracion part
fracEnd++);
}
else {
}
}
// no integer part, no fraction part, error.
throw new NumberFormatException();
// ignore trailing zeroes in fraction part
/*while (fracEnd > fracStart && content.charAt(fracEnd-1) == '0') {
fracEnd--;
}*/
// check whether there is non-digit characters in the fraction part
throw new NumberFormatException();
}
if (intDigits > 0) {
}
if (fracDigits > 0) {
}
}
}
if (val == this)
return true;
if (!(val instanceof XPrecisionDecimal))
return false;
}
/**
* @return
*/
return EQUAL;
}
fValue.deleteCharAt(i);
else
break;
else
break;
}
// seen NaN
if(sign == 0)
return INDETERMINATE;
//INF is greater than everything and equal to itself
return EQUAL;
return GREATER_THAN;
return LESS_THAN;
}
//-INF is smaller than everything and equal itself
return EQUAL;
return LESS_THAN;
return GREATER_THAN;
}
}
// To enable comparison - the exponent part of the decimal will be limited
// to the max value of int.
else {
//otherwise the 2 combined values are the same
for(int i = 0;i < expDiff; i++) {
if(i < fracDigits) {
fbuffer.deleteCharAt(i);
}
else
}
}
else {
for(int i = 0;i < expDiff; i++) {
if(i < val.fracDigits) {
fbuffer.deleteCharAt(i);
}
else
}
}
}
}
else {
}
}
/**
* @param val
* @return
*/
}
/**
* @param val
* @return
*/
if (ret != 0)
return EQUAL;
}
}
return canonical;
}
private void makeCanonical() {
// REVISIT: to be determined by working group
canonical = "TBD by Working Group";
}
/**
* @param decimal
* @return
*/
if(ivalue.equals(decimal.ivalue) && (ivalue.equals("INF") || ivalue.equals("-INF") || ivalue.equals("NaN")))
return true;
if(sign == decimal.sign && intDigits == decimal.intDigits && fracDigits == decimal.fracDigits && pvalue == decimal.pvalue
return true;
return false;
}
}
/* (non-Javadoc)
* @see com.sun.org.apache.xerces.internal.impl.dv.xs.TypeValidator#getAllowedFacets()
*/
public short getAllowedFacets() {
return ( XSSimpleTypeDecl.FACET_PATTERN | XSSimpleTypeDecl.FACET_WHITESPACE | XSSimpleTypeDecl.FACET_ENUMERATION |XSSimpleTypeDecl.FACET_MAXINCLUSIVE |XSSimpleTypeDecl.FACET_MININCLUSIVE | XSSimpleTypeDecl.FACET_MAXEXCLUSIVE | XSSimpleTypeDecl.FACET_MINEXCLUSIVE | XSSimpleTypeDecl.FACET_TOTALDIGITS | XSSimpleTypeDecl.FACET_FRACTIONDIGITS);
}
/* (non-Javadoc)
* @see com.sun.org.apache.xerces.internal.impl.dv.xs.TypeValidator#getActualValue(java.lang.String, com.sun.org.apache.xerces.internal.impl.dv.ValidationContext)
*/
throws InvalidDatatypeValueException {
try {
return new XPrecisionDecimal(content);
} catch (NumberFormatException nfe) {
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "precisionDecimal"});
}
}
}
}
}
return false;
}
}