geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r928839 - in /geronimo/server/trunk: framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/ plugins/jasper/geronimo-jasper/src/main/java/org/apache/geronimo/jasper/ plugins/myfaces/geronimo-myfaces/src/main/java/or...
Date Mon, 29 Mar 2010 17:24:12 GMT
Author: gawor
Date: Mon Mar 29 17:24:11 2010
New Revision: 928839

URL: http://svn.apache.org/viewvc?rev=928839&view=rev
Log:
make sure BundleClassLoader.getBundle() does not return DelegatingBundle

Modified:
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleClassLoader.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleUtils.java
    geronimo/server/trunk/plugins/jasper/geronimo-jasper/src/main/java/org/apache/geronimo/jasper/GeronimoTldLocationsCache.java
    geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/ApplicationIndexedLifecycleProviderFactory.java

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleClassLoader.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleClassLoader.java?rev=928839&r1=928838&r2=928839&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleClassLoader.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleClassLoader.java
Mon Mar 29 17:24:11 2010
@@ -132,13 +132,41 @@ public class BundleClassLoader extends C
             }
         }
     }
+        
+    /**
+     * Return the bundle associated with this classloader.
+     * 
+     * In most cases the bundle associated with the classloader is a regular framework bundle.

+     * However, in some cases the bundle associated with the classloader is a {@link DelegatingBundle}.
+     * In such cases, the <tt>unwrap</tt> parameter controls whether this function
returns the
+     * {@link DelegatingBundle} instance or the main application bundle backing with the
{@link DelegatingBundle}.
+     *
+     * @param unwrap If true and if the bundle associated with this classloader is a {@link
DelegatingBundle}, 
+     *        this function will return the main application bundle backing with the {@link
DelegatingBundle}. 
+     *        Otherwise, the bundle associated with this classloader is returned as is.
+     * @return The bundle associated with this classloader.
+     */
+    public Bundle getBundle(boolean unwrap) {
+        if (unwrap && bundle instanceof DelegatingBundle) {
+            return ((DelegatingBundle) bundle).getMainBundle();
+        }
+        return bundle;
+    }
     
     /**
-     * Return the bundle instance backing this classloader.
+     * Return the bundle associated with this classloader.
+     * 
+     * This method calls {@link #getBundle(boolean) getBundle(true)} and therefore always
returns a regular 
+     * framework bundle.  
+     * <br><br>
+     * Note: Some libraries use {@link BundleReference#getBundle()} to obtain a bundle for
the given 
+     * classloader and expect the returned bundle instance to be work with any OSGi API.
Some of these API might
+     * not work if {@link DelegatingBundle} is returned. That is why this function will always
return
+     * a regular framework bundle. See {@link #getBundle(boolean)} for more information.
      *
-     * @return The bundle used to source the classloader.
+     * @return The bundle associated with this classloader.
      */
     public Bundle getBundle() {
-        return bundle;
+        return getBundle(true);
     }
 }

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleUtils.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleUtils.java?rev=928839&r1=928838&r2=928839&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleUtils.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleUtils.java
Mon Mar 29 17:24:11 2010
@@ -48,11 +48,20 @@ public class BundleUtils {
     }
     
     /**
-     * Returns Bundle (if any) associated with current thread's context ClassLoader.
+     * Returns bundle (if any) associated with current thread's context classloader.
+     * 
+     * @param unwrap if true and if the bundle associated with the context classloader is
a 
+     *        {@link DelegatingBundle}, this function will return the main application bundle

+     *        backing with the {@link DelegatingBundle}. Otherwise, the bundle associated
with 
+     *        the context classloader is returned as is. See {@link BundleClassLoader#getBundle(boolean)}
+     *        for more information.
+     * @return The bundle associated with the current thread's context classloader. Might
be null.
      */
-    public static Bundle getContextBundle() {
+    public static Bundle getContextBundle(boolean unwrap) {
         ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
-        if (classLoader instanceof BundleReference) {
+        if (classLoader instanceof BundleClassLoader) {
+            return ((BundleClassLoader) classLoader).getBundle(unwrap);        
+        } else if (classLoader instanceof BundleReference) {
             return ((BundleReference) classLoader).getBundle();
         } else {
             return null;

Modified: geronimo/server/trunk/plugins/jasper/geronimo-jasper/src/main/java/org/apache/geronimo/jasper/GeronimoTldLocationsCache.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/jasper/geronimo-jasper/src/main/java/org/apache/geronimo/jasper/GeronimoTldLocationsCache.java?rev=928839&r1=928838&r2=928839&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/jasper/geronimo-jasper/src/main/java/org/apache/geronimo/jasper/GeronimoTldLocationsCache.java
(original)
+++ geronimo/server/trunk/plugins/jasper/geronimo-jasper/src/main/java/org/apache/geronimo/jasper/GeronimoTldLocationsCache.java
Mon Mar 29 17:24:11 2010
@@ -29,7 +29,7 @@ import java.util.zip.ZipEntry;
 import javax.servlet.ServletContext;
 
 import org.apache.geronimo.kernel.osgi.BundleResourceFinder;
-import org.apache.geronimo.kernel.osgi.DelegatingBundle;
+import org.apache.geronimo.kernel.osgi.BundleUtils;
 import org.apache.geronimo.kernel.osgi.BundleResourceFinder.ResourceFinderCallback;
 import org.apache.geronimo.kernel.osgi.jar.BundleJarFile;
 import org.apache.jasper.JasperException;
@@ -41,7 +41,6 @@ import org.apache.jasper.xmlparser.Parse
 import org.apache.jasper.xmlparser.TreeNode;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleReference;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.packageadmin.PackageAdmin;
@@ -157,7 +156,7 @@ public class GeronimoTldLocationsCache e
             tldScanWebXml();
             tldScanResourcePaths(WEB_INF);
 
-            Bundle bundle = getBundle();
+            Bundle bundle = BundleUtils.getContextBundle(true);
             if (bundle != null) {
                 tldScanClassPath(bundle);
                 tldScanGlobal(bundle);
@@ -167,19 +166,6 @@ public class GeronimoTldLocationsCache e
             throw new JasperException(ex);
         }
     }
-
-    private Bundle getBundle() {
-        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
-        if (classLoader instanceof BundleReference) {
-            Bundle bundle = ((BundleReference) classLoader).getBundle();
-            if (bundle instanceof DelegatingBundle) {
-                return ((DelegatingBundle) bundle).getMainBundle();
-            } else {
-                return bundle;
-            }
-        }
-        return null;
-    }
     
     /*
      * Populates taglib map described in web.xml.

Modified: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/ApplicationIndexedLifecycleProviderFactory.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/ApplicationIndexedLifecycleProviderFactory.java?rev=928839&r1=928838&r2=928839&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/ApplicationIndexedLifecycleProviderFactory.java
(original)
+++ geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/ApplicationIndexedLifecycleProviderFactory.java
Mon Mar 29 17:24:11 2010
@@ -46,7 +46,7 @@ public class ApplicationIndexedLifecycle
     }
 
     private Bundle getBundle() {
-        Bundle bundle = BundleUtils.getContextBundle();
+        Bundle bundle = BundleUtils.getContextBundle(false);
         if (bundle == null) {
             throw new IllegalStateException("Unable to get Bundle object associated with
the context classloader");
         }



Mime
View raw message