if (shouldUseSchemaValidation()) {
schema = SCHEMA_DIR + ECLIPSELINK_SCHEMA;
}
// Assume the format is OPM parse the document with OPM validation on.
XMLPlatform xmlPlatform = XMLPlatformFactory.getInstance().getXMLPlatform();
XMLParser parser = createXMLParser(xmlPlatform, true, false, schema);
try {
document = parser.parse(new StringReader(writer.toString()));
} catch (Exception parseException) {
// If the parse fails, it may be because the format was EclipseLink 1.0
try {
if (shouldUseSchemaValidation()) {
schema = SCHEMA_DIR + ECLIPSELINK_1_0_SCHEMA;
}
parser = createXMLParser(xmlPlatform, true, false, schema);
document = parser.parse(new StringReader(writer.toString()));
} catch (Exception parseException2){
// If the parse fails, it may be because the format was 11.1.1
try {
if (shouldUseSchemaValidation()) {
schema = SCHEMA_DIR + TOPLINK_11_SCHEMA;
}
parser = createXMLParser(xmlPlatform, true, false, schema);
document = parser.parse(new StringReader(writer.toString()));
} catch (Exception parseException3){
// If the parse validation fails, it may be because the format was 904 which is
// not support in eclipselink, just not valid, through original exception.
throw parseException;
}