geronimo-xbean-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r1095778 - in /geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util: BundleClassLoader.java BundleUtils.java DelegatingBundleReference.java equinox/EquinoxBundleClassLoader.java
Date Thu, 21 Apr 2011 17:09:04 GMT
Author: gawor
Date: Thu Apr 21 17:09:04 2011
New Revision: 1095778

URL: http://svn.apache.org/viewvc?rev=1095778&view=rev
Log:
ensure BundleUtils.getContextBundle() works correctly with any type of bundle classloader
implementation

Added:
    geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/DelegatingBundleReference.java
  (with props)
Modified:
    geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/BundleClassLoader.java
    geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/BundleUtils.java
    geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/equinox/EquinoxBundleClassLoader.java

Modified: geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/BundleClassLoader.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/BundleClassLoader.java?rev=1095778&r1=1095777&r2=1095778&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/BundleClassLoader.java
(original)
+++ geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/BundleClassLoader.java
Thu Apr 21 17:09:04 2011
@@ -43,7 +43,7 @@ import org.osgi.framework.BundleReferenc
  * 
  * @version $Rev$ $Date$
  */
-public class BundleClassLoader extends ClassLoader implements BundleReference {
+public class BundleClassLoader extends ClassLoader implements DelegatingBundleReference {
 
     protected final Bundle bundle;
     protected final BundleResourceHelper resourceHelper;

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=1095778&r1=1095777&r2=1095778&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
Thu Apr 21 17:09:04 2011
@@ -112,8 +112,8 @@ public class BundleUtils {
      */
     public static Bundle getContextBundle(boolean unwrap) {
         ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
-        if (classLoader instanceof BundleClassLoader) {
-            return ((BundleClassLoader) classLoader).getBundle(unwrap);
+        if (classLoader instanceof DelegatingBundleReference) {
+            return ((DelegatingBundleReference) classLoader).getBundle(unwrap);
         } else if (classLoader instanceof BundleReference) {
             return ((BundleReference) classLoader).getBundle();
         } else {

Added: geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/DelegatingBundleReference.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/DelegatingBundleReference.java?rev=1095778&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/DelegatingBundleReference.java
(added)
+++ geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/DelegatingBundleReference.java
Thu Apr 21 17:09:04 2011
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.xbean.osgi.bundle.util;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleReference;
+
+/**
+ * DelegatingBundleReference is based on {@link BundleReference} and provides
+ * access to {@link DelegatingBundle}.  
+ */
+public interface DelegatingBundleReference extends BundleReference {
+
+    /**
+     * Returns 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);
+
+}

Propchange: geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/DelegatingBundleReference.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/DelegatingBundleReference.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/DelegatingBundleReference.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/equinox/EquinoxBundleClassLoader.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/equinox/EquinoxBundleClassLoader.java?rev=1095778&r1=1095777&r2=1095778&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/equinox/EquinoxBundleClassLoader.java
(original)
+++ geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/equinox/EquinoxBundleClassLoader.java
Thu Apr 21 17:09:04 2011
@@ -26,6 +26,7 @@ import java.util.Enumeration;
 
 import org.apache.xbean.osgi.bundle.util.BundleResourceHelper;
 import org.apache.xbean.osgi.bundle.util.DelegatingBundle;
+import org.apache.xbean.osgi.bundle.util.DelegatingBundleReference;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleReference;
 
@@ -38,7 +39,7 @@ import org.osgi.framework.BundleReferenc
  * 
  * @version $Rev$ $Date$
  */
-public class EquinoxBundleClassLoader extends URLClassLoader implements BundleReference {
+public class EquinoxBundleClassLoader extends URLClassLoader implements DelegatingBundleReference
{
 
     private final Bundle bundle;
     private final BundleResourceHelper resourceHelper;



Mime
View raw message