final String lexicalForm = getLexicalForm( literal );
try {
final XMLGregorianCalendar c = getDatatypeFactory().newXMLGregorianCalendar(
lexicalForm );
if( !schemaType.equals( c.getXMLSchemaType() ) )
throw new InvalidLiteralException( getName(), lexicalForm );
return c;
} catch( IllegalArgumentException e ) {
/*
* newXMLGregorianCalendar will throw an IllegalArgumentException if
* the lexical form is not one of the XML Schema datetime types
*/
throw new InvalidLiteralException( getName(), lexicalForm );
} catch( IllegalStateException e ) {
/*
* getXMLSchemaType will throw an IllegalStateException if the
* combination of fields set in the calendar object doesn't match
* one of the XML Schema datetime types
*/
throw new InvalidLiteralException( getName(), lexicalForm );
}
}