stateManager.update(newData.getManifest(),newData.getLocation(),newData.getBundleID());
long bundleId = newData.getBundleID(); State systemState = stateManager.getSystemState(); systemState.removeBundle(bundleId); BundleDescription newDescription = stateManager.getFactory().createBundleDescription(newData.getManifest(), newData.getLocation(),bundleId); systemState.addBundle(newDescription);
	public BundleOperation updateBundle(		final org.eclipse.osgi.framework.adaptor.BundleData bundledata,		final URLConnection source)	{		return (new BundleOperation()		{			private DefaultBundleData data;			private DefaultBundleData newData;			/**			 * Perform the change to persistent storage.			 *			 * @return Bundle object for the target bundle.			 */			public org.eclipse.osgi.framework.adaptor.BundleData begin() throws BundleException			{				this.data = (DefaultBundleData) bundledata;				try				{					InputStream in = source.getInputStream();					try					{						if (in instanceof ReferenceInputStream)						{							URL reference = ((ReferenceInputStream) in).getReference();							if (!"file".equals(reference.getProtocol()))							{								throw new BundleException(									AdaptorMsg.formatter.getString("ADAPTOR_URL_CREATE_EXCEPTION", reference));							}							// check to make sure we are not just trying to update to the same							// directory reference.  This would be a no-op.							String path = reference.getPath();							if (path.equals(data.getName())){								throw new BundleException(									AdaptorMsg.formatter.getString("ADAPTOR_SAME_REF_UPDATE",reference));							}							try							{								newData = data.nextGeneration(reference.getPath());							}							catch (IOException e)							{								throw new BundleException(									AdaptorMsg.formatter.getString("ADAPTOR_STORAGE_EXCEPTION"),									e);							}							File bundleGenerationDir = newData.getGenerationDir();							if (!bundleGenerationDir.exists())							{								throw new BundleException(									AdaptorMsg.formatter.getString(										"ADAPTOR_DIRECTORY_CREATE_EXCEPTION",										bundleGenerationDir.getPath()));							}							newData.bundleFile = BundleFile.createBundleFile(newData.file, newData);						}						else						{							try							{								newData = data.nextGeneration();							}							catch (IOException e)							{								throw new BundleException(									AdaptorMsg.formatter.getString("ADAPTOR_STORAGE_EXCEPTION"),									e);							}							File bundleGenerationDir = newData.getGenerationDir();							if (!bundleGenerationDir.exists())							{								throw new BundleException(									AdaptorMsg.formatter.getString(										"ADAPTOR_DIRECTORY_CREATE_EXCEPTION",										bundleGenerationDir.getPath()));							}							File file = newData.getBundleFile();							readFile(in, file);							newData.bundleFile = BundleFile.createBundleFile(file, newData);						}					}					finally					{						try						{							in.close();						}						catch (IOException ee)						{						}					}					newData.loadFromManifest();				}				catch (IOException e)				{					throw new BundleException(AdaptorMsg.formatter.getString("BUNDLE_READ_EXCEPTION"), e);				}				return (newData);			}			/**			 * Commit the change to persistent storage.			 *			 * @param postpone If true, the bundle's persistent			 * storage cannot be immediately reclaimed.			 * @throws BundleException If a failure occured modifiying peristent storage.			 */			public void commit(boolean postpone) throws BundleException			{				try				{					newData.save();				}				catch (IOException e)				{					throw new BundleException(AdaptorMsg.formatter.getString("ADAPTOR_STORAGE_EXCEPTION"), e);				}				stateManager.update(newData.getManifest(),newData.getLocation(),newData.getBundleID());				File originalGenerationDir = data.getGenerationDir();				if (postpone || !rm(originalGenerationDir))				{					/* mark this bundle to be deleted to ensure it is fully cleaned up					 * on next restart.					 */					File delete = new File(originalGenerationDir, ".delete");					if (!delete.exists())					{						try						{							/* create .delete */							FileOutputStream out = new FileOutputStream(delete);							out.close();						}						catch (IOException e)						{							if (Debug.DEBUG && Debug.DEBUG_GENERAL)							{								Debug.println("Unable to write " + delete.getPath() + ": " + e.getMessage());							}							eventPublisher.publishFrameworkEvent(FrameworkEvent.ERROR, data.getBundle(), e);						}					}				}			}			/**			 * Undo the change to persistent storage.			 *			 * @throws BundleException If a failure occured modifiying peristent storage.			 */			public void undo() throws BundleException			{				/*if (bundleFile != null)				{					bundleFile.close();				} */				if (newData != null)				{					File nextGenerationDir = newData.getGenerationDir();					if (!rm(nextGenerationDir)) /* delete downloaded bundle */					{						/* mark this bundle to be deleted to ensure it is fully cleaned up						 * on next restart.						 */						File delete = new File(nextGenerationDir, ".delete");						if (!delete.exists())						{							try							{								/* create .delete */								FileOutputStream out = new FileOutputStream(delete);								out.close();							}							catch (IOException e)							{								if (Debug.DEBUG && Debug.DEBUG_GENERAL)								{									Debug.println("Unable to write " + delete.getPath() + ": " + e.getMessage());								}							}						}					}				}			}		});	}