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