processExtension(newData, EXTENSION_INSTALLED);
processExtension(newData, EXTENSION_UPDATED);
	public BundleOperation updateBundle(final org.eclipse.osgi.framework.adaptor.BundleData bundledata, final URLConnection source) {		return (new BundleOperation() {			private AbstractBundleData data;			private AbstractBundleData 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 = (AbstractBundleData) bundledata;				try {					InputStream in = source.getInputStream();					URL sourceURL = source.getURL();					String protocol = sourceURL == null ? null : sourceURL.getProtocol();					try {						if (in instanceof ReferenceInputStream) {							ReferenceInputStream refIn = (ReferenceInputStream) in;							URL reference = (refIn).getReference();							if (!"file".equals(reference.getProtocol())) { //$NON-NLS-1$								throw new BundleException(AdaptorMsg.formatter.getString("ADAPTOR_URL_CREATE_EXCEPTION", reference)); //$NON-NLS-1$							}							// 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.getFileName())) {								throw new BundleException(AdaptorMsg.formatter.getString("ADAPTOR_SAME_REF_UPDATE", reference)); //$NON-NLS-1$							}							try {								newData = data.nextGeneration(reference.getPath());							} catch (IOException e) {								throw new BundleException(AdaptorMsg.formatter.getString("ADAPTOR_STORAGE_EXCEPTION"), e); //$NON-NLS-1$							}							File bundleGenerationDir = newData.createGenerationDir();							if (!bundleGenerationDir.exists()) {								throw new BundleException(AdaptorMsg.formatter.getString("ADAPTOR_DIRECTORY_CREATE_EXCEPTION", bundleGenerationDir.getPath())); //$NON-NLS-1$							}							newData.createBaseBundleFile();						} else {							try {								newData = data.nextGeneration(null);							} catch (IOException e) {								throw new BundleException(AdaptorMsg.formatter.getString("ADAPTOR_STORAGE_EXCEPTION"), e); //$NON-NLS-1$							}							File bundleGenerationDir = newData.createGenerationDir();							if (!bundleGenerationDir.exists()) {								throw new BundleException(AdaptorMsg.formatter.getString("ADAPTOR_DIRECTORY_CREATE_EXCEPTION", bundleGenerationDir.getPath())); //$NON-NLS-1$							}							File outFile = newData.getBaseFile();							if ("file".equals(protocol)) { //$NON-NLS-1$								File inFile = new File(source.getURL().getPath());								if (inFile.isDirectory()) {									copyDir(inFile, outFile);								} else {									readFile(in, outFile);								}							} else {								readFile(in, outFile);							}							newData.createBaseBundleFile();						}					} finally {						try {							in.close();						} catch (IOException ee) {						}					}					newData.loadFromManifest();				} catch (IOException e) {					throw new BundleException(AdaptorMsg.formatter.getString("BUNDLE_READ_EXCEPTION"), e); //$NON-NLS-1$				}				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 {				processExtension(data, EXTENSION_UNINSTALLED); // remove the old extension				processExtension(newData, EXTENSION_INSTALLED); // add the new one				try {					newData.setLastModified(System.currentTimeMillis());					newData.save();				} catch (IOException e) {					throw new BundleException(AdaptorMsg.formatter.getString("ADAPTOR_STORAGE_EXCEPTION"), e); //$NON-NLS-1$				}				updateState(newData, BundleEvent.UPDATED);				File originalGenerationDir = data.createGenerationDir();				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"); //$NON-NLS-1$					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()); //$NON-NLS-1$ //$NON-NLS-2$							}							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.createGenerationDir();					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"); //$NON-NLS-1$						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()); //$NON-NLS-1$ //$NON-NLS-2$								}							}						}					}				}			}		});	}