StateDelta delta = state.getChanges(); BundleDelta[] addedBundles = delta.getChanges(BundleDelta.ADDED, false); for (int i = 0; i < addedBundles.length; i++) systemState.addBundle(factory.createBundleDescription(addedBundles[i].getBundle())); BundleDelta[] removedBundles = delta.getChanges(BundleDelta.REMOVED, false); for (int i = 0; i < removedBundles.length; i++) systemState.removeBundle(removedBundles[i].getBundle());
UserState userState = (UserState) state; Long[] allAdded = userState.getAllAdded(); for (int i = 0; i < allAdded.length; i++) { BundleDescription added = userState.getBundle(allAdded[i].longValue());  if (added != null) installer.installBundle(added); } Long[] allRemoved = userState.getAllRemoved(); for (int i = 0; i < allRemoved.length; i++) { long removedId = allRemoved[i].longValue(); BundleDescription removedFromUserState = userState.getBundle(removedId);  if (removedFromUserState == null) { BundleDescription existingSystemState = systemState.getBundle(removedId); if (existingSystemState != null) installer.uninstallBundle(existingSystemState); } }
public synchronized void commit(State state) throws BundleException {		if (!(state instanceof StateImpl))			throw new IllegalArgumentException();		if (state.getTimeStamp() != systemState.getTimeStamp())			throw new BundleException(StateMsg.formatter.getString("COMMIT_INVALID_TIMESTAMP")); //$NON-NLS-1$		StateDelta delta = state.getChanges();		BundleDelta[] addedBundles = delta.getChanges(BundleDelta.ADDED, false);		for (int i = 0; i < addedBundles.length; i++)			systemState.addBundle(factory.createBundleDescription(addedBundles[i].getBundle()));		BundleDelta[] removedBundles = delta.getChanges(BundleDelta.REMOVED, false);		for (int i = 0; i < removedBundles.length; i++)			systemState.removeBundle(removedBundles[i].getBundle());			}	