geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r1346483 - /geronimo/server/branches/3.0-beta/framework/modules/geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/BundleUtils.java
Date Tue, 05 Jun 2012 17:27:32 GMT
Author: gawor
Date: Tue Jun  5 17:27:32 2012
New Revision: 1346483

URL: http://svn.apache.org/viewvc?rev=1346483&view=rev
Log:
use BundleWiring API instead of PackageAdmin to get wired bundles

Modified:
    geronimo/server/branches/3.0-beta/framework/modules/geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/BundleUtils.java

Modified: geronimo/server/branches/3.0-beta/framework/modules/geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/BundleUtils.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-beta/framework/modules/geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/BundleUtils.java?rev=1346483&r1=1346482&r2=1346483&view=diff
==============================================================================
--- geronimo/server/branches/3.0-beta/framework/modules/geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/BundleUtils.java
(original)
+++ geronimo/server/branches/3.0-beta/framework/modules/geronimo-hook/src/main/java/org/apache/geronimo/hook/equinox/BundleUtils.java
Tue Jun  5 17:27:32 2012
@@ -16,96 +16,35 @@
  */
 package org.apache.geronimo.hook.equinox;
 
-import java.util.ArrayList;
 import java.util.LinkedHashSet;
 import java.util.List;
 
-import org.eclipse.osgi.framework.internal.core.Constants;
-import org.eclipse.osgi.util.ManifestElement;
 import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.packageadmin.ExportedPackage;
-import org.osgi.service.packageadmin.PackageAdmin;
+import org.osgi.framework.wiring.BundleRevision;
+import org.osgi.framework.wiring.BundleWire;
+import org.osgi.framework.wiring.BundleWiring;
 
 public class BundleUtils {
 
     public static LinkedHashSet<Bundle> getWiredBundles(Bundle bundle) {
-        BundleContext bundleContext = bundle.getBundleContext();
-        if (bundleContext == null) {
-            return new LinkedHashSet<Bundle>(0);
-        } else {
-            ServiceReference reference = bundleContext.getServiceReference(PackageAdmin.class.getName());
-            PackageAdmin packageAdmin = (PackageAdmin) bundle.getBundleContext().getService(reference);
-            try {
-                return getWiredBundles(packageAdmin, bundle);
-            } finally {
-                bundle.getBundleContext().ungetService(reference);
+        LinkedHashSet<Bundle> wiredBundles = null;
+        BundleWiring wiring = bundle.adapt(BundleWiring.class);
+        if (wiring != null) {
+            wiredBundles = new LinkedHashSet<Bundle>();
+            List<BundleWire> wires;
+            wires = wiring.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE);
+            for (BundleWire wire : wires) {
+                wiredBundles.add(wire.getProviderWiring().getBundle());
             }
-        }
-    }
-    
-    public static LinkedHashSet<Bundle> getWiredBundles(PackageAdmin packageAdmin,
Bundle bundle) {
-        // handle static wire via Import-Package
-        List<String> imports = getExternalImports(bundle);
-        LinkedHashSet<Bundle> wiredBundles = new LinkedHashSet<Bundle>();
-        for (String packageImport : imports) {
-            ExportedPackage[] exports = packageAdmin.getExportedPackages(packageImport);
-            Bundle wiredBundle = getWiredBundle(bundle, exports);
-            if (wiredBundle != null) {
-                wiredBundles.add(wiredBundle);
+            wires = wiring.getRequiredWires(BundleRevision.BUNDLE_NAMESPACE);
+            for (BundleWire wire : wires) {
+                wiredBundles.add(wire.getProviderWiring().getBundle());
             }
+            wiredBundles.remove(bundle);
+        } else {
+            wiredBundles = new LinkedHashSet<Bundle>(0);
         }
         return wiredBundles;
     }
-
-    private static Bundle getWiredBundle(Bundle bundle, ExportedPackage[] exports) {
-        if (exports != null) {
-            for (ExportedPackage exportedPackage : exports) {
-                Bundle[] importingBundles = exportedPackage.getImportingBundles();
-                if (importingBundles != null) {
-                    for (Bundle importingBundle : importingBundles) {
-                        if (importingBundle == bundle) {
-                            return exportedPackage.getExportingBundle();
-                        }
-                    }
-                }
-            }
-        }
-        return null;
-    }
-    
-    public static List<String> getExternalImports(Bundle bundle) {
-        List<String> imports = new ArrayList<String>();
-        
-        String importPackages = (String) bundle.getHeaders().get(Constants.IMPORT_PACKAGE);
-        String exportPackages = (String) bundle.getHeaders().get(Constants.EXPORT_PACKAGE);
-        try {
-            ManifestElement[] importElements = ManifestElement.parseHeader(Constants.IMPORT_PACKAGE,
importPackages);
-            ManifestElement[] exportElements = ManifestElement.parseHeader(Constants.EXPORT_PACKAGE,
exportPackages);
-            
-            if (importElements != null) {
-                for (ManifestElement importElement : importElements) {
-                    if (exportElements == null || !isExported(exportElements, importElement))
{
-                        imports.add(importElement.getValue());
-                    }
-                }
-            }
-        } catch (BundleException e) {
-            // ignore
-        }
-        
-        return imports;
-    }
-    
-    private static boolean isExported(ManifestElement[] exportElements, ManifestElement importElement)
{
-        for (ManifestElement exportElement : exportElements) {
-            if (exportElement.getValue().equals(importElement.getValue())) {
-                return true;
-            }
-        }
-        return false;
-    }
     
 }



Mime
View raw message