tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1491742 - /tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/QuickContextXmlParser.java
Date Tue, 11 Jun 2013 11:17:25 GMT
Author: rmannibucau
Date: Tue Jun 11 11:17:24 2013
New Revision: 1491742

URL: http://svn.apache.org/r1491742
Log:
TOMEE-970 trying to get urls for custom loaders too

Modified:
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/QuickContextXmlParser.java

Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/QuickContextXmlParser.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/QuickContextXmlParser.java?rev=1491742&r1=1491741&r2=1491742&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/QuickContextXmlParser.java
(original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/QuickContextXmlParser.java
Tue Jun 11 11:17:24 2013
@@ -16,7 +16,9 @@
  */
 package org.apache.openejb.config;
 
+import org.apache.openejb.core.ParentClassLoaderFinder;
 import org.apache.openejb.loader.Files;
+import org.apache.xbean.finder.ClassLoaders;
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.DefaultHandler;
@@ -24,8 +26,10 @@ import org.xml.sax.helpers.DefaultHandle
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
 import java.io.File;
+import java.lang.reflect.Constructor;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.net.URLClassLoader;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashSet;
@@ -42,30 +46,59 @@ public class QuickContextXmlParser exten
     }
 
     private String virtualClasspath = "";
+    private Collection<URL> urls = null;
 
     @Override
     public void startElement(final String uri, final String localName,
                              final String qName, final Attributes attributes) throws SAXException
{
         if ("Loader".equalsIgnoreCase(localName)) {
             final String className = attributes.getValue("className");
-            if ("org.apache.catalina.loader.VirtualWebappLoader".equals(className)
-                    || "org.apache.tomee.catalina.ProvisioningWebappLoader".equals(className))
{
-                virtualClasspath = attributes.getValue("virtualClasspath");
-            } // else ?
+            if (className != null) {
+                if ("org.apache.catalina.loader.VirtualWebappLoader".equals(className)
+                        || "org.apache.tomee.catalina.ProvisioningWebappLoader".equals(className))
{
+                    virtualClasspath = attributes.getValue("virtualClasspath");
+                } else {
+                    try {
+                        final ClassLoader parent = ParentClassLoaderFinder.Helper.get();
+                        final Class<?> clazz = parent.loadClass(className);
+                        ClassLoader instance = null;
+                        try {
+                            final Constructor<?> constructor = clazz.getConstructor(ClassLoader.class);
+                            instance = ClassLoader.class.cast(constructor.newInstance(parent));
+                        } catch (final NoSuchMethodException nsme) {
+                            instance = ClassLoader.class.cast(clazz.newInstance());
+                        }
+
+                        if (instance != null) {
+                            urls = ClassLoaders.findUrls(instance);
+                        }
+                    } catch (final Exception e) {
+                        // no-op
+                    }
+                }
+            }
         }
     }
 
     public Collection<URL> getAdditionalURLs() {
-        final StringTokenizer tkn = new StringTokenizer(virtualClasspath, ";");
         final Set<URL> set = new LinkedHashSet<URL>();
-        while (tkn.hasMoreTokens()) {
-            String token = tkn.nextToken().trim();
-            if (token.isEmpty()) {
-                continue;
+
+        if (virtualClasspath != null) {
+            final StringTokenizer tkn = new StringTokenizer(virtualClasspath, ";");
+            while (tkn.hasMoreTokens()) {
+                String token = tkn.nextToken().trim();
+                if (token.isEmpty()) {
+                    continue;
+                }
+
+                set.addAll(Files.listJars(token));
             }
+        }
 
-            set.addAll(Files.listJars(token));
+        if (urls != null) {
+            set.addAll(urls);
         }
+
         return set;
     }
 



Mime
View raw message