}
if (myFacets[SchemaType.FACET_MIN_LENGTH] != null)
{
// An error for 'length' and 'minLength' to be specified at the same time
// except if the base type had the same value for 'minLength' also
XmlAnySimpleType baseMinLength = baseImpl.getFacet(SchemaType.FACET_MIN_LENGTH);
if (!(baseMinLength != null &&
baseMinLength.valueEquals(myFacets[SchemaType.FACET_MIN_LENGTH]) &&
baseMinLength.compareValue(len) <= 0))
{
state.error(XmlErrorCodes.DATATYPE_LENGTH, null, facet);
continue;
}
}
if (myFacets[SchemaType.FACET_MAX_LENGTH] != null)
{
// An error for 'length' and 'maxLength' to be specified at the same time
// except if the base type had the same value for 'maxLength' also
XmlAnySimpleType baseMaxLength = baseImpl.getFacet(SchemaType.FACET_MAX_LENGTH);
if (!(baseMaxLength != null &&
baseMaxLength.valueEquals(myFacets[SchemaType.FACET_MAX_LENGTH]) &&
baseMaxLength.compareValue(len) >= 0))
{
state.error(XmlErrorCodes.DATATYPE_LENGTH, null, facet);
continue;
}
}
myFacets[code] = len;
break;
case SchemaType.FACET_MIN_LENGTH:
case SchemaType.FACET_MAX_LENGTH:
XmlInteger mlen = StscTranslator.buildNnInteger(facet.getValue());
if (mlen == null)
{
state.error("Must be a nonnegative integer", XmlErrorCodes.FACET_VALUE_MALFORMED, facet);
continue;
}
if (fixedFacets[code] && !myFacets[code].valueEquals(mlen))
{
state.error(XmlErrorCodes.FACET_FIXED, new Object[] { facetName }, facet);
continue;
}
if (myFacets[SchemaType.FACET_LENGTH] != null)
{
// It's an error for 'length' and 'minLength'/'maxLength' to be
// specified at the same time, except for the case when
// the base type had the same value for 'minLength'/'maxLength'
// and the two values are consistent
XmlAnySimpleType baseMinMaxLength = baseImpl.getFacet(code);
if (!(baseMinMaxLength != null &&
baseMinMaxLength.valueEquals(mlen) &&
(code == SchemaType.FACET_MIN_LENGTH ?
baseMinMaxLength.compareTo(myFacets[SchemaType.FACET_LENGTH]) <= 0 :
baseMinMaxLength.compareTo(myFacets[SchemaType.FACET_LENGTH]) >= 0)))
{
state.error(XmlErrorCodes.DATATYPE_LENGTH, null, facet);
continue;
}
}
if (myFacets[SchemaType.FACET_MAX_LENGTH] != null)
{
if (mlen.compareValue(myFacets[SchemaType.FACET_MAX_LENGTH]) > 0)
{
state.error(XmlErrorCodes.DATATYPE_MAX_LENGTH_RESTRICTION, null, facet);
continue;
}
}
if (myFacets[SchemaType.FACET_MIN_LENGTH] != null)
{
if (mlen.compareValue(myFacets[SchemaType.FACET_MIN_LENGTH]) < 0)
{
state.error(XmlErrorCodes.DATATYPE_MIN_LENGTH_RESTRICTION, null, facet);
continue;
}
}
myFacets[code] = mlen;
break;
case SchemaType.FACET_TOTAL_DIGITS:
XmlPositiveInteger dig = StscTranslator.buildPosInteger(facet.getValue());
if (dig == null)
{
state.error("Must be a positive integer", XmlErrorCodes.FACET_VALUE_MALFORMED, facet);
break;
}
if (fixedFacets[code] && !myFacets[code].valueEquals(dig))
{
state.error(XmlErrorCodes.FACET_FIXED, new Object[] { facetName }, facet);
continue;
}
if (myFacets[SchemaType.FACET_TOTAL_DIGITS] != null)
{
if (dig.compareValue(myFacets[SchemaType.FACET_TOTAL_DIGITS]) > 0)
state.error(XmlErrorCodes.DATATYPE_TOTAL_DIGITS_RESTRICTION, null, facet);
}
myFacets[code] = dig;
break;
case SchemaType.FACET_FRACTION_DIGITS:
XmlNonNegativeInteger fdig = StscTranslator.buildNnInteger(facet.getValue());
if (fdig == null)
{
state.error("Must be a nonnegative integer", XmlErrorCodes.FACET_VALUE_MALFORMED, facet);
break;
}
if (fixedFacets[code] && !myFacets[code].valueEquals(fdig))
{
state.error(XmlErrorCodes.FACET_FIXED, new Object[] { facetName }, facet);
continue;
}
if (myFacets[SchemaType.FACET_FRACTION_DIGITS] != null)
{
if (fdig.compareValue(myFacets[SchemaType.FACET_FRACTION_DIGITS]) > 0)
state.error(XmlErrorCodes.DATATYPE_FRACTION_DIGITS_RESTRICTION, null, facet);
}
if (myFacets[SchemaType.FACET_TOTAL_DIGITS] != null)
{
if (fdig.compareValue(myFacets[SchemaType.FACET_TOTAL_DIGITS]) > 0)
state.error(XmlErrorCodes.DATATYPE_FRACTION_DIGITS_LE_TOTAL_DIGITS, null, facet);
}
myFacets[code] = fdig;
break;
case SchemaType.FACET_MIN_EXCLUSIVE:
case SchemaType.FACET_MIN_INCLUSIVE:
case SchemaType.FACET_MAX_INCLUSIVE:
case SchemaType.FACET_MAX_EXCLUSIVE:
if (seenFacet[other_similar_limit(code)])
{
state.error("Cannot define both inclusive and exclusive limit in the same restriciton", XmlErrorCodes.FACET_DUPLICATED, facet);
continue;
}
boolean ismin = (code == SchemaType.FACET_MIN_EXCLUSIVE || code == SchemaType.FACET_MIN_INCLUSIVE);
boolean isexclusive = (code == SchemaType.FACET_MIN_EXCLUSIVE || code == SchemaType.FACET_MAX_EXCLUSIVE);
XmlAnySimpleType limit;
try
{
limit = baseImpl.newValue(facet.getValue(), true);
}
catch (XmlValueOutOfRangeException e)
{
// note: this guarantees that the limit is a valid number in the
// base data type!!
switch (code)
{
case SchemaType.FACET_MIN_EXCLUSIVE:
state.error(XmlErrorCodes.DATATYPE_MIN_EXCLUSIVE_RESTRICTION,
new Object[] {e.getMessage()}, facet);
break;
case SchemaType.FACET_MIN_INCLUSIVE:
state.error(XmlErrorCodes.DATATYPE_MIN_INCLUSIVE_RESTRICTION,
new Object[] {e.getMessage()}, facet);
break;
case SchemaType.FACET_MAX_INCLUSIVE:
state.error(XmlErrorCodes.DATATYPE_MAX_INCLUSIVE_RESTRICTION,
new Object[] {e.getMessage()}, facet);
break;
case SchemaType.FACET_MAX_EXCLUSIVE:
state.error(XmlErrorCodes.DATATYPE_MAX_EXCLUSIVE_RESTRICTION,
new Object[] {e.getMessage()}, facet);
break;
}
// BUGBUG: if there are actual schemas that redefine min/maxExclusive,
// they will need this rule relaxed for them!!
continue;
}
if (fixedFacets[code] && !myFacets[code].valueEquals(limit))
{
state.error(XmlErrorCodes.FACET_FIXED, new Object[] { facetName }, facet);
continue;
}
if (myFacets[code] != null)
{
int comparison = limit.compareValue(myFacets[code]);
if (comparison == 2 || comparison == (ismin ? -1 : 1))
{
state.error(ismin ?
(isexclusive ?
"Must be greater than or equal to previous minExclusive" :