try {
inStream1 = getInputStream(filename, true);
// If the persistence.xml was not found, then there is nothing to do.
if (inStream1 != null) {
PersistenceXML persistenceXML;
try {
// Try a 2.1 context first.
persistenceXML = (PersistenceXML) PersistenceXMLMappings.createXML2_1Context().createUnmarshaller().unmarshal(inStream1);
} catch (Exception e) {
// Catch all exceptions and try a 2.0 context second with a new input stream.
inStream2 = getInputStream(filename, true);
persistenceXML = (PersistenceXML) PersistenceXMLMappings.createXML2_0Context().createUnmarshaller().unmarshal(inStream2);
}
for (SEPersistenceUnitInfo puInfo : persistenceXML.getPersistenceUnitInfos()) {
// If no persistence unit list has been specified or one
// has been specified and this persistence unit info's name
// appears in that list then add it.
if (persistenceUnitList == null || persistenceUnitList.contains(puInfo.getPersistenceUnitName())) {
factory.addPersistenceUnit(puInfo, new PersistenceUnit(puInfo, factory, this));