metadata.setLong(METADATA_ADAPTOR_NEXTID, id);
	public BundleOperation installBundle(final String location, final URLConnection source)	{		return (new BundleOperation()		{			private DefaultBundleData data;			/**			 * Begin the operation on the bundle (install, update, uninstall).			 *			 * @return BundleData object for the target bundle.			 * @throws BundleException If a failure occured modifiying peristent storage.			 */			public org.eclipse.osgi.framework.adaptor.BundleData begin() throws BundleException			{				long id;				try				{					/*					 * Open InputStream first to trigger prereq installs, if any,					 * before allocating bundle id.					 */					InputStream in = source.getInputStream();					try					{						try						{							id = getNextBundleId();							metadata.setLong(METADATA_ADAPTOR_NEXTID, id);							metadata.save();						}						catch (IOException e)						{							throw new BundleException(AdaptorMsg.formatter.getString("ADAPTOR_STORAGE_EXCEPTION"), e);						}						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));							}							data = (DefaultBundleData)getElementFactory().getBundleData(DefaultAdaptor.this);							data.initializeReferencedBundle(id, location, reference.getPath());						}						else						{							data = (DefaultBundleData)getElementFactory().getBundleData(DefaultAdaptor.this);							data.initializeNewBundle(id, location, in);						}					}					finally					{						try						{							in.close();						}						catch (IOException e)						{						}					}				}				catch (IOException ioe)				{					throw new BundleException(AdaptorMsg.formatter.getString("BUNDLE_READ_EXCEPTION"), ioe);				}				return (data);			}			public void undo()			{				if (data != null)				{					try					{						data.close();					}					catch (IOException e)					{						if (Debug.DEBUG && Debug.DEBUG_GENERAL)						{							Debug.println("Unable to close " + data + ": " + e.getMessage());						}					}				}				if (data != null)				{					File bundleDir = data.getBundleDir();					if (!rm(bundleDir))					{						/* mark this bundle to be deleted to ensure it is fully cleaned up						 * on next restart.						 */						File delete = new File(bundleDir, ".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());								}							}						}					}				}			}			public void commit(boolean postpone) throws BundleException			{				try				{					data.save();				}				catch (IOException e)				{					throw new BundleException(AdaptorMsg.formatter.getString("ADAPTOR_STORAGE_EXCEPTION"), e);				}				BundleDescription bundleDescription = stateManager.getFactory().createBundleDescription(data.getManifest(), data.getLocation(),data.getBundleID());				stateManager.getSystemState().addBundle(bundleDescription);			}		});	}