1 11 package org.eclipse.core.internal.registry; 12 13 import org.eclipse.core.internal.registry.osgi.Activator; 14 import org.osgi.framework.Bundle; 15 import org.osgi.service.packageadmin.PackageAdmin; 16 import org.osgi.util.tracker.ServiceTracker; 17 18 public class BundleHelper { 19 20 private ServiceTracker bundleTracker = null; 21 22 private static final BundleHelper singleton = new BundleHelper(); 23 24 public static BundleHelper getDefault() { 25 return singleton; 26 } 27 28 31 private BundleHelper() { 32 super(); 33 } 34 35 private PackageAdmin getPackageAdmin() { 36 if (bundleTracker == null) { 37 bundleTracker = new ServiceTracker(Activator.getContext(), PackageAdmin.class.getName(), null); 38 bundleTracker.open(); 39 } 40 return (PackageAdmin) bundleTracker.getService(); 41 } 42 43 public Bundle getBundle(String symbolicName) { 44 PackageAdmin packageAdmin = getPackageAdmin(); 45 if (packageAdmin == null) 46 return null; 47 Bundle[] bundles = packageAdmin.getBundles(symbolicName, null); 48 if (bundles == null) 49 return null; 50 for (int i = 0; i < bundles.length; i++) { 52 if ((bundles[i].getState() & (Bundle.INSTALLED | Bundle.UNINSTALLED)) == 0) { 53 return bundles[i]; 54 } 55 } 56 return null; 57 } 58 59 public Bundle[] getHosts(Bundle bundle) { 60 PackageAdmin packageAdmin = getPackageAdmin(); 61 if (packageAdmin == null) 62 return null; 63 return packageAdmin.getHosts(bundle); 64 } 65 66 } 67 | Popular Tags |