in xmlschema-walker/src/main/java/org/apache/ws/commons/schema/docpath/XmlSchemaElementValidator.java [311:498]
private static void validateAtomicType(String name, String value, XmlSchemaTypeInfo typeInfo,
NamespaceContext nsContext) throws ValidationException {
if (!typeInfo.getType().equals(XmlSchemaTypeInfo.Type.ATOMIC)) {
throw new ValidationException(name + " must have a type of ATOMIC, not " + typeInfo.getType());
} else if ((value == null) || (value.length() == 0)) {
throw new ValidationException(name + " cannot have a null or empty value when validating.");
}
final Map<XmlSchemaRestriction.Type, List<XmlSchemaRestriction>> facets = typeInfo.getFacets();
switch (typeInfo.getBaseType()) {
case ANYTYPE:
case ANYSIMPLETYPE:
case ANYURI:
/*
* anyURI has no equivalent type in Java. (from
* http://docs.oracle.com/cd/E19159-01/819-3669/bnazf/index.html)
*/
case STRING:
// Text plus facets.
stringLengthChecks(name, DatatypeConverter.parseString(value), facets);
break;
case DURATION:
try {
getDatatypeFactory().newDuration(value);
} catch (IllegalArgumentException iae) {
throw new ValidationException(name + " value of \"" + value + "\" is not a valid duration.",
iae);
}
break;
case DATETIME:
try {
DatatypeConverter.parseDateTime(value);
} catch (IllegalArgumentException iae) {
throw new ValidationException(name + " value of \"" + value + "\" is not a valid date-time.",
iae);
}
break;
case TIME:
try {
DatatypeConverter.parseTime(value);
} catch (IllegalArgumentException iae) {
throw new ValidationException(name + " value of \"" + value + "\" is not a valid time.", iae);
}
break;
case DATE:
try {
DatatypeConverter.parseDate(value);
} catch (IllegalArgumentException iae) {
throw new ValidationException(name + " value of \"" + value + "\" is not a valid date.", iae);
}
break;
case YEARMONTH:
try {
getDatatypeFactory().newXMLGregorianCalendar(value);
} catch (IllegalArgumentException iae) {
throw new ValidationException(
name + " value of \"" + value + "\" is not a valid Year-Month.",
iae);
}
break;
case YEAR:
try {
getDatatypeFactory().newXMLGregorianCalendar(value);
} catch (IllegalArgumentException iae) {
throw new ValidationException(name + " value of \"" + value + "\" is not a valid year.", iae);
}
break;
case MONTHDAY:
try {
getDatatypeFactory().newXMLGregorianCalendar(value);
} catch (IllegalArgumentException iae) {
throw new ValidationException(name + " value of \"" + value + "\" is not a valid month-day.",
iae);
}
break;
case DAY:
try {
getDatatypeFactory().newXMLGregorianCalendar(value);
} catch (IllegalArgumentException iae) {
throw new ValidationException(name + " value of \"" + value + "\" is not a valid day.", iae);
}
break;
case MONTH:
try {
getDatatypeFactory().newXMLGregorianCalendar(value);
} catch (IllegalArgumentException iae) {
throw new ValidationException(name + " value of \"" + value + "\" is not a valid month.", iae);
}
break;
// Dates
case BOOLEAN:
if (!value.equalsIgnoreCase("true") && !value.equalsIgnoreCase("false")) {
throw new ValidationException(name + " value of \"" + value
+ "\" is not a valid boolean; must be \"true\" or \"false\".");
}
break;
case BIN_BASE64:
try {
DatatypeConverter.parseBase64Binary(value);
} catch (IllegalArgumentException iae) {
throw new ValidationException(name + " value of \"" + value
+ "\" is not valid base-64 binary.", iae);
}
break;
case BIN_HEX:
try {
DatatypeConverter.parseHexBinary(value);
} catch (IllegalArgumentException iae) {
throw new ValidationException(name + " value of \"" + value
+ "\" is not valid hexadecimal binary.", iae);
}
break;
case FLOAT:
try {
rangeChecks(name, BigDecimal.valueOf(DatatypeConverter.parseFloat(value)), facets);
} catch (NumberFormatException iae) {
throw new ValidationException(name + " value of \"" + value + "\" is not a valid float.", iae);
}
break;
case DECIMAL:
try {
final BigDecimal decimal = DatatypeConverter.parseDecimal(value);
rangeChecks(name, decimal, facets);
digitsFacetChecks(name, decimal, facets);
} catch (NumberFormatException iae) {
throw new ValidationException(name + " value of \"" + value + "\" is not a valid decimal.",
iae);
}
break;
case DOUBLE:
try {
rangeChecks(name, BigDecimal.valueOf(DatatypeConverter.parseDouble(value)), facets);
} catch (NumberFormatException iae) {
throw new ValidationException(name + " value of \"" + value + "\" is not a valid double.",
iae);
}
break;
case QNAME:
try {
DatatypeConverter.parseQName(value, nsContext);
} catch (IllegalArgumentException iae) {
throw new ValidationException(name + " value of \"" + value + "\" is not a valid .", iae);
}
break;
case NOTATION:
try {
/*
* The value space of NOTATION is the set of QNames of notations
* declared in the current schema.
*/
final String[] qNames = value.split(" ");
for (String qName : qNames) {
DatatypeConverter.parseQName(qName, nsContext);
}
} catch (IllegalArgumentException iae) {
throw new ValidationException(name + " value of \"" + value
+ "\" is not a valid series of QNames.", iae);
}
break;
default:
throw new ValidationException(name + " has an unrecognized base value type of "
+ typeInfo.getBaseType());
}
checkEnumerationFacet(name, value, facets);
}