1 11 12 package org.eclipse.osgi.framework.internal.core; 13 14 import java.util.Dictionary ; 15 import java.util.Hashtable ; 16 import org.eclipse.osgi.framework.debug.FrameworkDebugOptions; 17 import org.osgi.framework.*; 18 import org.osgi.service.condpermadmin.ConditionalPermissionAdmin; 19 20 23 24 public class SystemBundleActivator implements BundleActivator { 25 protected BundleContext context; 26 protected SystemBundle bundle; 27 protected Framework framework; 28 protected ServiceRegistration packageAdmin; 29 protected ServiceRegistration permissionAdmin; 30 protected ServiceRegistration condPermAdmin; 31 protected ServiceRegistration startLevel; 32 protected ServiceRegistration debugOptions; 33 34 public SystemBundleActivator() { 35 } 36 37 public void start(BundleContext context) throws Exception { 38 this.context = context; 39 bundle = (SystemBundle) context.getBundle(); 40 framework = bundle.framework; 41 42 if (framework.packageAdmin != null) 43 packageAdmin = register(Constants.OSGI_PACKAGEADMIN_NAME, framework.packageAdmin); 44 if (framework.permissionAdmin != null) 45 permissionAdmin = register(Constants.OSGI_PERMISSIONADMIN_NAME, framework.permissionAdmin); 46 if (framework.startLevelManager != null) 47 startLevel = register(Constants.OSGI_STARTLEVEL_NAME, framework.startLevelManager); 48 if (framework.condPermAdmin != null) 49 condPermAdmin = register(ConditionalPermissionAdmin.class.getName(), framework.condPermAdmin); 50 FrameworkDebugOptions dbgOptions = null; 51 if ((dbgOptions = FrameworkDebugOptions.getDefault()) != null) 52 debugOptions = register(org.eclipse.osgi.service.debug.DebugOptions.class.getName(), dbgOptions); 53 54 framework.adaptor.frameworkStart(context); 56 framework.packageAdmin.setResolvedBundles(bundle); 60 } 61 62 public void stop(BundleContext context) throws Exception { 63 framework.adaptor.frameworkStop(context); 65 66 if (packageAdmin != null) 67 packageAdmin.unregister(); 68 if (permissionAdmin != null) 69 permissionAdmin.unregister(); 70 if (condPermAdmin != null) 71 condPermAdmin.unregister(); 72 if (startLevel != null) 73 startLevel.unregister(); 74 if (debugOptions != null) 75 debugOptions.unregister(); 76 77 framework = null; 78 bundle = null; 79 this.context = null; 80 } 81 82 86 protected ServiceRegistration register(String name, Object service) { 87 Hashtable properties = new Hashtable (7); 88 Dictionary headers = bundle.getHeaders(); 89 properties.put(Constants.SERVICE_VENDOR, headers.get(Constants.BUNDLE_VENDOR)); 90 properties.put(Constants.SERVICE_RANKING, new Integer (Integer.MAX_VALUE)); 91 properties.put(Constants.SERVICE_PID, bundle.getBundleId() + "." + service.getClass().getName()); return context.registerService(name, service, properties); 93 } 94 95 } 96 | Popular Tags |