/** * Return a list of Archives representing the root of the persistence descriptor. It is the * caller's responsibility to close all the archives. * * @param loader the class loader to get the class path from */ public static Set<Archive> findPersistenceArchives( ClassLoader loader, String descriptorPath, List<URL> jarFileUrls) { Archive archive = null; Set<Archive> archives = new HashSet<Archive>(); // See if we are talking about an embedded descriptor // If not embedded descriptor then just use the regular descriptor path int splitPosition = descriptorPath.indexOf("!/"); if (splitPosition != -1) { // It is an embedded archive, so split up the parts descriptorPath = descriptorPath.substring(splitPosition + 2); } try { for (int i = 0; i < jarFileUrls.size(); i++) { URL puRootUrl = jarFileUrls.get(i); archive = PersistenceUnitProcessor.getArchiveFactory(loader) .createArchive(puRootUrl, descriptorPath, null); // archive = new BundleArchive(puRootUrl, descUrl); if (archive != null) { archives.add(archive); } } } catch (Exception ex) { // clean up first for (Archive a : archives) { a.close(); } throw PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(loader, ex); } return archives; }
/** * Return a list of Archives representing the root of the persistence descriptor. It is the * caller's responsibility to close all the archives. * * @param loader the class loader to get the class path from */ public static Set<Archive> findPersistenceArchives(ClassLoader loader, String descriptorPath) { Archive archive = null; Set<Archive> archives = new HashSet<Archive>(); // See if we are talking about an embedded descriptor int splitPosition = descriptorPath.indexOf("!/"); try { // If not embedded descriptor then just use the regular descriptor path if (splitPosition == -1) { Enumeration<URL> resources = loader.getResources(descriptorPath); while (resources.hasMoreElements()) { URL descUrl = resources.nextElement(); if (descUrl != null) { URL puRootUrl = computePURootURL(descUrl, descriptorPath); archive = PersistenceUnitProcessor.getArchiveFactory(loader) .createArchive(puRootUrl, descriptorPath, null); // archive = new BundleArchive(puRootUrl, descUrl); if (archive != null) { archives.add(archive); } } } } else { // It is an embedded archive, so split up the parts String jarPrefixPath = descriptorPath.substring(0, splitPosition); String descPath = descriptorPath.substring(splitPosition + 2); // TODO This causes the bundle to be resolved (not what we want)! URL prefixUrl = loader.getResource(jarPrefixPath); archive = PersistenceUnitProcessor.getArchiveFactory(loader) .createArchive(prefixUrl, descPath, null); if (archive != null) { archives.add(archive); } } } catch (Exception ex) { // clean up first for (Archive a : archives) { a.close(); } throw PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(loader, ex); } return archives; }