1 11 package org.eclipse.equinox.internal.jsp.jasper.registry; 12 13 import org.osgi.framework.Bundle; 14 import org.osgi.framework.BundleActivator; 15 import org.osgi.framework.BundleContext; 16 import org.osgi.framework.ServiceReference; 17 import org.osgi.service.packageadmin.PackageAdmin; 18 import org.osgi.util.tracker.ServiceTracker; 19 import org.osgi.util.tracker.ServiceTrackerCustomizer; 20 21 public class Activator implements BundleActivator, ServiceTrackerCustomizer { 22 23 private ServiceTracker packageAdminTracker; 24 private static PackageAdmin packageAdmin; 25 private BundleContext context; 26 27 public void start(BundleContext context) throws Exception { 28 this.context = context; 29 packageAdminTracker = new ServiceTracker(context, PackageAdmin.class.getName(), this); 30 packageAdminTracker.open(); 31 } 32 33 public void stop(BundleContext context) throws Exception { 34 packageAdminTracker.close(); 35 packageAdminTracker = null; 36 this.context = null; 37 } 38 39 public static synchronized Bundle getBundle(String symbolicName) { 40 if (packageAdmin == null) 41 throw new IllegalStateException ("Not started"); 43 Bundle[] bundles = packageAdmin.getBundles(symbolicName, null); 44 if (bundles == null) 45 return null; 46 for (int i = 0; i < bundles.length; i++) { 48 if ((bundles[i].getState() & (Bundle.INSTALLED | Bundle.UNINSTALLED)) == 0) { 49 return bundles[i]; 50 } 51 } 52 return null; 53 } 54 55 public Object addingService(ServiceReference reference) { 56 synchronized (Activator.class) { 57 packageAdmin = (PackageAdmin) context.getService(reference); 58 } 59 return packageAdmin; 60 } 61 62 public void modifiedService(ServiceReference reference, Object service) { 63 } 64 65 public void removedService(ServiceReference reference, Object service) { 66 synchronized (Activator.class) { 67 context.ungetService(reference); 68 packageAdmin = null; 69 } 70 } 71 } 72 | Popular Tags |