spf.setNamespaceAware(true);
spf.setValidating(true);
XMLReader xmlReader = null;
SAXParser sp = null;
XMLExceptionHandler xmlErrorHandler = new XMLExceptionHandler();
// create a SAX parser
try {
sp = spf.newSAXParser();
sp.setProperty(XMLConstants.SCHEMA_LANGUAGE, XMLConstants.XML_SCHEMA);
} catch (javax.xml.parsers.ParserConfigurationException exc){
throw XMLParseException.exceptionCreatingSAXParser(baseURL, exc);
} catch (org.xml.sax.SAXException exc){
throw XMLParseException.exceptionCreatingSAXParser(baseURL, exc);
}
// create an XMLReader
try {
xmlReader = sp.getXMLReader();
xmlReader.setErrorHandler(xmlErrorHandler);
} catch (org.xml.sax.SAXException exc){
throw XMLParseException.exceptionCreatingXMLReader(baseURL, exc);
}
// attempt to load the schema from the classpath
URL schemaURL = loader.getResource(XMLConstants.PERSISTENCE_SCHEMA_NAME);
if (schemaURL != null) {
try {
sp.setProperty(XMLConstants.JAXP_SCHEMA_SOURCE, schemaURL.toString());
} catch (org.xml.sax.SAXException exc){
throw XMLParseException.exceptionSettingSchemaSource(baseURL, schemaURL, exc);
}
}
PersistenceContentHandler myContentHandler = new PersistenceContentHandler();
xmlReader.setContentHandler(myContentHandler);
InputSource inputSource = new InputSource(input);
try{
xmlReader.parse(inputSource);
} catch (IOException exc){
throw PersistenceUnitLoadingException.exceptionProcessingPersistenceXML(baseURL, exc);
} catch (org.xml.sax.SAXException exc){
// XMLErrorHandler will handle SAX exceptions
}
// handle any parse exceptions
XMLException xmlError = xmlErrorHandler.getXMLException();
if (xmlError != null) {
throw PersistenceUnitLoadingException.exceptionProcessingPersistenceXML(baseURL, xmlError);
}
Iterator<SEPersistenceUnitInfo> persistenceInfos = myContentHandler.getPersistenceUnits().iterator();