openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mprud...@apache.org
Subject svn commit: r604300 - /openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
Date Fri, 14 Dec 2007 21:26:07 GMT
Author: mprudhom
Date: Fri Dec 14 13:26:02 2007
New Revision: 604300

URL: http://svn.apache.org/viewvc?rev=604300&view=rev
Log:
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.

Modified:
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java?rev=604300&r1=604299&r2=604300&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
Fri Dec 14 13:26:02 2007
@@ -228,7 +228,14 @@
     public List getAnchorsInResource(String resource) throws Exception {
         ConfigurationParser parser = new ConfigurationParser(null);
         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);
         } catch (IOException e) {
             // not all configuration files are XML; return null if unparsable
@@ -273,6 +280,27 @@
         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
      * file that matches <code>name</code> (or an unnamed one if
@@ -290,21 +318,9 @@
             loader = (ClassLoader) AccessController.doPrivileged(
                 J2DoPrivHelper.getContextClassLoaderAction());
 
-        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();
-        }
+        List<URL> urls = getResourceURLs(rsrc, loader);
+        if (urls == null || urls.size() == 0)
+            return null;
 
         ConfigurationParser parser = new ConfigurationParser(m);
         PersistenceUnitInfoImpl pinfo = parseResources(parser, urls, name, 
@@ -335,11 +351,11 @@
      * no name given (preferring an unnamed OpenJPA unit to a named one).
      */
     private PersistenceUnitInfoImpl parseResources(ConfigurationParser parser,
-        Enumeration<URL> urls, String name, ClassLoader loader)
+        List<URL> urls, String name, ClassLoader loader)
         throws IOException {
         List<PersistenceUnitInfoImpl> pinfos = 
             new ArrayList<PersistenceUnitInfoImpl>();
-        for (URL url : Collections.list(urls)) {
+        for (URL url : urls) {
             parser.parse(url);
             pinfos.addAll((List<PersistenceUnitInfoImpl>) parser.getResults());
         }



Mime
View raw message