geronimo-xbean-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r1133254 - in /geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util: BundleUtils.java DelegatingBundle.java
Date Wed, 08 Jun 2011 05:59:12 GMT
Author: gawor
Date: Wed Jun  8 05:59:12 2011
New Revision: 1133254

URL: http://svn.apache.org/viewvc?rev=1133254&view=rev
Log:
XBEAN-177: No need to delegate classloading if a wire is established

Modified:
    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/DelegatingBundle.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=1133254&r1=1133253&r2=1133254&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
Wed Jun  8 05:59:12 2011
@@ -238,7 +238,7 @@ public class BundleUtils {
         return wiredBundles;
     }
 
-    private static Bundle getWiredBundle(Bundle bundle, ExportedPackage[] exports) {
+    static Bundle getWiredBundle(Bundle bundle, ExportedPackage[] exports) {
         if (exports != null) {
             for (ExportedPackage exportedPackage : exports) {
                 Bundle[] importingBundles = exportedPackage.getImportingBundles();

Modified: geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/DelegatingBundle.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/DelegatingBundle.java?rev=1133254&r1=1133253&r2=1133254&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/DelegatingBundle.java
(original)
+++ geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/DelegatingBundle.java
Wed Jun  8 05:59:12 2011
@@ -35,6 +35,8 @@ import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.Version;
+import org.osgi.service.packageadmin.ExportedPackage;
+import org.osgi.service.packageadmin.PackageAdmin;
 
 /**
  * Bundle that delegates ClassLoader operations to a collection of {@link Bundle} objects.

@@ -66,12 +68,40 @@ public class DelegatingBundle implements
             try {
                 return bundle.loadClass(name);
             } catch (ClassNotFoundException ex) {
-                // ignore
+                int index = name.lastIndexOf('.');
+                if (index > 0) {
+                    /*
+                     * We got CNFE and if we are wired to a bundle that exports the 
+                     * given package then there is no hope of loading the class.
+                     */
+                    String packageName = name.substring(0, index);
+                    if (isWired(bundle, packageName)) {
+                        throw ex;
+                    } else {
+                        // ignore - try to load with next bundle
+                    }
+                } else {
+                    // no package name
+                    throw ex;
+                }                
             }
         }
         throw new ClassNotFoundException(name);
     }
 
+    private boolean isWired(Bundle importingBundle, String packageName) {
+        BundleContext context = bundle.getBundleContext();
+        ServiceReference reference = context.getServiceReference(PackageAdmin.class.getName());
+        PackageAdmin packageAdmin = (PackageAdmin) context.getService(reference);
+        try {
+            ExportedPackage[] packages = packageAdmin.getExportedPackages(packageName);
+            Bundle exportingBundle = BundleUtils.getWiredBundle(importingBundle, packages);
+            return (exportingBundle != null);
+        } finally {
+            context.ungetService(reference);
+        }
+    }
+    
     public URL getResource(String name) {
         URL resource = null;
         for (Bundle bundle : bundles) {



Mime
View raw message