geronimo-xbean-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xuhaih...@apache.org
Subject svn commit: r1126325 - /geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/BundleUtils.java
Date Mon, 23 May 2011 06:02:29 GMT
Author: xuhaihong
Date: Mon May 23 06:02:29 2011
New Revision: 1126325

URL: http://svn.apache.org/viewvc?rev=1126325&view=rev
Log:
Add a getBundle method in the BundleUtils, which is used to get the reference bundle from
the classLoader parameter

Modified:
    geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/BundleUtils.java

Modified: geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/BundleUtils.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/BundleUtils.java?rev=1126325&r1=1126324&r2=1126325&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/BundleUtils.java
(original)
+++ geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/BundleUtils.java
Mon May 23 06:02:29 2011
@@ -102,16 +102,24 @@ public class BundleUtils {
 
     /**
      * Returns bundle (if any) associated with current thread's context classloader.
-     *
+     * Invoking this method is equivalent to getBundle(Thread.currentThread().getContextClassLoader(),
unwrap)
+     */
+    public static Bundle getContextBundle(boolean unwrap) {
+        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+        return classLoader == null ? null : getBundle(classLoader, unwrap);
+    }
+
+    /**
+     *  Returns bundle (if any) associated with the classloader.
+     * @param 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 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.
+     * @return The bundle associated with the classloader. Might be null.
      */
-    public static Bundle getContextBundle(boolean unwrap) {
-        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+    public static Bundle getBundle(ClassLoader classLoader, boolean unwrap) {
         if (classLoader instanceof DelegatingBundleReference) {
             return ((DelegatingBundleReference) classLoader).getBundle(unwrap);
         } else if (classLoader instanceof BundleReference) {



Mime
View raw message