BundleDescription description = adaptor.getPlatformAdmin().getFactory().createBundleDescription(manifest, Constants.SYSTEM_BUNDLE_LOCATION, 0); if (description == null) throw new BundleException("Unable to construct System Bundle description"); adaptor.getState().addBundle(description);  adaptor.getState().resolve();
BundleDescription newSystemBundle = adaptor.getPlatformAdmin().getFactory().createBundleDescription(manifest, Constants.SYSTEM_BUNDLE_LOCATION, 0); if (newSystemBundle == null) throw new BundleException(Msg.formatter.getString("OSGI_SYSTEMBUNDLE_DESCRIPTION_ERROR"));  State state = adaptor.getState(); BundleDescription oldSystemBundle = state.getBundle(0); if (oldSystemBundle != null) {   PackageSpecification[] oldPackages = oldSystemBundle.getPackages(); PackageSpecification[] newPackages = newSystemBundle.getPackages();  boolean different = false; if (oldPackages.length == newPackages.length) { for (int i=0; i<oldPackages.length; i++) { if (oldPackages[i].getName().equals(newPackages[i].getName())) { Object oldVersion = oldPackages[i].getVersionSpecification(); Object newVersion = newPackages[i].getVersionSpecification(); if (oldVersion == null) { if ( newVersion != null) { different = true; break; } } else if (!oldVersion.equals(newVersion)) { different = true; break; } } else { different = true; break; } } } else { different = true; }  if (different) { state.removeBundle(0); state.addBundle(newSystemBundle);  state.resolve(false); } } else { state.addBundle(newSystemBundle);  state.resolve(false); }
	private void createSystemBundle() {		try {			String resource = Constants.OSGI_SYSTEMBUNDLE_MANIFEST;			InputStream in = getClass().getResourceAsStream(resource);			if (Debug.DEBUG && Debug.DEBUG_GENERAL) {				if (in == null) {					Debug.println(						"Unable to find system bundle manifest " + resource);				}			}			// now get any extra packages and services that the adaptor wants to export			// and merge this into the system bundle's manifest			String exportPackages = adaptor.getExportPackages();			String exportServices = adaptor.getExportServices(); 												Headers manifest = Headers.parseManifest(in);			if (exportPackages != null) {				String value = (String) manifest.get(Constants.EXPORT_PACKAGE);				if (value == null) {					value = exportPackages;				}				else {					value += "," + exportPackages;				}				manifest.set(Constants.EXPORT_PACKAGE,null);				manifest.set(Constants.EXPORT_PACKAGE,value);			}			if (exportServices != null) {				String value = (String) manifest.get(Constants.EXPORT_SERVICE);				if (value == null) {					value = exportServices;				}				else {					value += "," + exportServices;				}				manifest.set(Constants.EXPORT_SERVICE,null);				manifest.set(Constants.EXPORT_SERVICE,value);			}			BundleDescription description = adaptor.getPlatformAdmin().getFactory().createBundleDescription(manifest, Constants.SYSTEM_BUNDLE_LOCATION, 0);			if (description == null) 				throw new BundleException("Unable to construct System Bundle description");			adaptor.getState().addBundle(description);			// force resolution so packages are properly linked 			adaptor.getState().resolve();			systemBundle = createSystemBundle(manifest);			SystemBundleLoader.clearSystemPackages();			PackageSpecification[] packages = description.getPackages();			if (packages != null) {				String[] systemPackages = new String[packages.length];				for (int i = 0; i < packages.length; i++) {					PackageSpecification spec = packages[i];					if (spec.getName().equals(Constants.OSGI_FRAMEWORK_PACKAGE)) {						String version = spec.getVersionSpecification().toString();						if (version != null) 							properties.put(Constants.FRAMEWORK_VERSION, version);					}					systemPackages[i] = spec.getName();				}				// remember the system packages.				if (System.getProperty("osgi.autoExportSystemPackages") != null) 					SystemBundleLoader.setSystemPackages(systemPackages);			}		} catch (BundleException e) /* fatal error */ {			e.printStackTrace();			throw new RuntimeException(Msg.formatter.getString("OSGI_SYSTEMBUNDLE_CREATE_EXCEPTION", e.getMessage()));		}	}