private static Document getDocument ( URL pathToPersistenceXml ) throws InvalidConfigurationException { InputStream is = null ; Document xmlRootNode = null ; try { if ( pathToPersistenceXml != null ) { URLConnection conn = pathToPersistenceXml . openConnection ( ) ; conn . setUseCaches ( false ) ; // avoid JAR locking on Windows and // Tomcat. is = conn . getInputStream ( ) ; } if ( is == null ) { throw new IOException ( "Failed to obtain InputStream from url: " + pathToPersistenceXml ) ; } xmlRootNode = parseDocument ( is ) ; validateDocumentAgainstSchema ( xmlRootNode ) ; } catch ( IOException e ) { throw new InvalidConfigurationException ( e ) ; } finally { if ( is != null ) { try { is . close ( ) ; } catch ( IOException ex ) { log . warn ( "Input stream could not be closed after parsing persistence.xml, caused by: {}" , ex ) ; } } } return xmlRootNode ; }
Reads the persistence xml content into an object graph and validates it against the related xsd schema .