incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r794537 - in /sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader: DynamicClassLoaderProvider.java impl/ClassLoaderFacade.java impl/DynamicClassLoaderManagerImpl.java
Date Thu, 16 Jul 2009 05:31:50 GMT
Author: cziegeler
Date: Thu Jul 16 05:31:50 2009
New Revision: 794537

URL: http://svn.apache.org/viewvc?rev=794537&view=rev
Log:
Provide parent class loader to dynamic class loader providers; check for null reference.

Modified:
    sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/DynamicClassLoaderProvider.java
    sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/ClassLoaderFacade.java
    sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/DynamicClassLoaderManagerImpl.java

Modified: sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/DynamicClassLoaderProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/DynamicClassLoaderProvider.java?rev=794537&r1=794536&r2=794537&view=diff
==============================================================================
--- sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/DynamicClassLoaderProvider.java
(original)
+++ sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/DynamicClassLoaderProvider.java
Thu Jul 16 05:31:50 2009
@@ -29,7 +29,12 @@
 
     /**
      * Return the class loader used for dynamic class loading.
+     * The returned class loader should use the provided parent class loader
+     * as one of its parent class loaders. This ensures that the returned
+     * class loader has access to all dynamically loaded classes that
+     * are not part of this class loader.
+     * @param parent The parent class loader for this dynamic class loader.
      * @return The class loader.
      */
-    ClassLoader getClassLoader();
+    ClassLoader getClassLoader(ClassLoader parent);
 }

Modified: sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/ClassLoaderFacade.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/ClassLoaderFacade.java?rev=794537&r1=794536&r2=794537&view=diff
==============================================================================
--- sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/ClassLoaderFacade.java
(original)
+++ sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/ClassLoaderFacade.java
Thu Jul 16 05:31:50 2009
@@ -42,9 +42,11 @@
     public URL getResource(String name) {
         final ClassLoader[] loaders = manager.getDynamicClassLoaders();
         for(final ClassLoader cl : loaders) {
-            final URL u = cl.getResource(name);
-            if ( u != null ) {
-                return u;
+            if ( cl != null ) {
+                final URL u = cl.getResource(name);
+                if ( u != null ) {
+                    return u;
+                }
             }
         }
         return null;
@@ -56,9 +58,11 @@
     public InputStream getResourceAsStream(String name) {
         final ClassLoader[] loaders = manager.getDynamicClassLoaders();
         for(final ClassLoader cl : loaders) {
-            final InputStream i = cl.getResourceAsStream(name);
-            if ( i != null ) {
-                return i;
+            if ( cl != null ) {
+                final InputStream i = cl.getResourceAsStream(name);
+                if ( i != null ) {
+                    return i;
+                }
             }
         }
         return null;
@@ -70,9 +74,11 @@
     public Enumeration<URL> getResources(String name) throws IOException {
         final ClassLoader[] loaders = manager.getDynamicClassLoaders();
         for(final ClassLoader cl : loaders) {
-            final Enumeration<URL> e = cl.getResources(name);
-            if ( e != null && e.hasMoreElements() ) {
-                return e;
+            if ( cl != null ) {
+                final Enumeration<URL> e = cl.getResources(name);
+                if ( e != null && e.hasMoreElements() ) {
+                    return e;
+                }
             }
         }
         return null;
@@ -84,11 +90,13 @@
     public Class<?> loadClass(String name) throws ClassNotFoundException {
         final ClassLoader[] loaders = manager.getDynamicClassLoaders();
         for(final ClassLoader cl : loaders) {
-            try {
-                final Class<?> c = cl.loadClass(name);
-                return c;
-            } catch (Exception cnfe) {
-                // we just ignore this and try the next class loader
+            if ( cl != null ) {
+                try {
+                    final Class<?> c = cl.loadClass(name);
+                    return c;
+                } catch (Exception cnfe) {
+                    // we just ignore this and try the next class loader
+                }
             }
         }
         throw new ClassNotFoundException("Class not found: " + name);

Modified: sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/DynamicClassLoaderManagerImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/DynamicClassLoaderManagerImpl.java?rev=794537&r1=794536&r2=794537&view=diff
==============================================================================
--- sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/DynamicClassLoaderManagerImpl.java
(original)
+++ sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/DynamicClassLoaderManagerImpl.java
Thu Jul 16 05:31:50 2009
@@ -89,7 +89,9 @@
             int index = 1;
             for(final ServiceReference ref : refs) {
                 final DynamicClassLoaderProvider provider = (DynamicClassLoaderProvider)this.getService(ref);
-                loaders[index] = provider.getClassLoader();
+                if ( provider != null ) {
+                    loaders[index] = provider.getClassLoader(this.pckAdminCL);
+                }
                 index++;
             }
             // and now use new array



Mime
View raw message