mirror of https://github.com/apache/openjpa.git
OPENJPA-9 Use the same criteria for resolving the configuration file for the purposes of listing all the anchors as we do for actually parsing the file itself. Fixes the problem where specifing the property "persistence.xml" was not actually resolving /META-INF/persistence.xml in order to obtain the list of anchors.
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@604300 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
485372b3f6
commit
787b57a486
|
@ -228,7 +228,14 @@ public class PersistenceProductDerivation
|
||||||
public List getAnchorsInResource(String resource) throws Exception {
|
public List getAnchorsInResource(String resource) throws Exception {
|
||||||
ConfigurationParser parser = new ConfigurationParser(null);
|
ConfigurationParser parser = new ConfigurationParser(null);
|
||||||
try {
|
try {
|
||||||
parser.parse(resource);
|
ClassLoader loader = (ClassLoader) AccessController.doPrivileged(
|
||||||
|
J2DoPrivHelper.getContextClassLoaderAction());
|
||||||
|
List<URL> urls = getResourceURLs(resource, loader);
|
||||||
|
if (urls != null) {
|
||||||
|
for (URL url : urls) {
|
||||||
|
parser.parse(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
return getUnitNames(parser);
|
return getUnitNames(parser);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// not all configuration files are XML; return null if unparsable
|
// not all configuration files are XML; return null if unparsable
|
||||||
|
@ -273,6 +280,27 @@ public class PersistenceProductDerivation
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static List<URL> getResourceURLs(String rsrc, ClassLoader loader)
|
||||||
|
throws IOException {
|
||||||
|
Enumeration<URL> urls = null;
|
||||||
|
try {
|
||||||
|
urls = (Enumeration) AccessController.doPrivileged(
|
||||||
|
J2DoPrivHelper.getResourcesAction(loader, rsrc));
|
||||||
|
if (!urls.hasMoreElements()) {
|
||||||
|
if (!rsrc.startsWith("META-INF"))
|
||||||
|
urls = (Enumeration) AccessController.doPrivileged(
|
||||||
|
J2DoPrivHelper.getResourcesAction(
|
||||||
|
loader, "META-INF/" + rsrc));
|
||||||
|
if (!urls.hasMoreElements())
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} catch (PrivilegedActionException pae) {
|
||||||
|
throw (IOException) pae.getException();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Collections.list(urls);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Looks through the resources at <code>rsrc</code> for a configuration
|
* Looks through the resources at <code>rsrc</code> for a configuration
|
||||||
* file that matches <code>name</code> (or an unnamed one if
|
* file that matches <code>name</code> (or an unnamed one if
|
||||||
|
@ -290,21 +318,9 @@ public class PersistenceProductDerivation
|
||||||
loader = (ClassLoader) AccessController.doPrivileged(
|
loader = (ClassLoader) AccessController.doPrivileged(
|
||||||
J2DoPrivHelper.getContextClassLoaderAction());
|
J2DoPrivHelper.getContextClassLoaderAction());
|
||||||
|
|
||||||
Enumeration<URL> urls = null;
|
List<URL> urls = getResourceURLs(rsrc, loader);
|
||||||
try {
|
if (urls == null || urls.size() == 0)
|
||||||
urls = (Enumeration) AccessController.doPrivileged(
|
|
||||||
J2DoPrivHelper.getResourcesAction(loader, rsrc));
|
|
||||||
if (!urls.hasMoreElements()) {
|
|
||||||
if (!rsrc.startsWith("META-INF"))
|
|
||||||
urls = (Enumeration) AccessController.doPrivileged(
|
|
||||||
J2DoPrivHelper.getResourcesAction(
|
|
||||||
loader, "META-INF/" + rsrc));
|
|
||||||
if (!urls.hasMoreElements())
|
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
} catch (PrivilegedActionException pae) {
|
|
||||||
throw (IOException) pae.getException();
|
|
||||||
}
|
|
||||||
|
|
||||||
ConfigurationParser parser = new ConfigurationParser(m);
|
ConfigurationParser parser = new ConfigurationParser(m);
|
||||||
PersistenceUnitInfoImpl pinfo = parseResources(parser, urls, name,
|
PersistenceUnitInfoImpl pinfo = parseResources(parser, urls, name,
|
||||||
|
@ -335,11 +351,11 @@ public class PersistenceProductDerivation
|
||||||
* no name given (preferring an unnamed OpenJPA unit to a named one).
|
* no name given (preferring an unnamed OpenJPA unit to a named one).
|
||||||
*/
|
*/
|
||||||
private PersistenceUnitInfoImpl parseResources(ConfigurationParser parser,
|
private PersistenceUnitInfoImpl parseResources(ConfigurationParser parser,
|
||||||
Enumeration<URL> urls, String name, ClassLoader loader)
|
List<URL> urls, String name, ClassLoader loader)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
List<PersistenceUnitInfoImpl> pinfos =
|
List<PersistenceUnitInfoImpl> pinfos =
|
||||||
new ArrayList<PersistenceUnitInfoImpl>();
|
new ArrayList<PersistenceUnitInfoImpl>();
|
||||||
for (URL url : Collections.list(urls)) {
|
for (URL url : urls) {
|
||||||
parser.parse(url);
|
parser.parse(url);
|
||||||
pinfos.addAll((List<PersistenceUnitInfoImpl>) parser.getResults());
|
pinfos.addAll((List<PersistenceUnitInfoImpl>) parser.getResults());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue