for (int i = removalPending.size() - 1; i >= 0; i--) { BundleLoaderProxy loaderProxy = (BundleLoaderProxy) removalPending.elementAt(i);
synchronized (framework.bundles) { for (int i = removalPending.size() - 1; i >= 0; i--) { BundleLoaderProxy loaderProxy = (BundleLoaderProxy) removalPending.elementAt(i);
	private void processDelta(Vector graph) {		AbstractBundle[] refresh = new AbstractBundle[graph.size()];		boolean[] previouslyResolved = new boolean[graph.size()];		graph.copyInto(refresh);		Util.sort(refresh, 0, graph.size());		Vector notify = new Vector();		try {			try {				/*				 * Suspend each bundle and grab its state change lock.				 */				if (Debug.DEBUG && Debug.DEBUG_PACKAGEADMIN) {					Debug.println("refreshPackages: Suspend each bundle and acquire its state change lock"); //$NON-NLS-1$				}				for (int i = refresh.length - 1; i >= 0; i--) {					AbstractBundle changedBundle = refresh[i];					previouslyResolved[i] = changedBundle.isResolved();					if (changedBundle.isActive() && !changedBundle.isFragment()) {						boolean suspended = framework.suspendBundle(changedBundle, true);						if (!suspended) {							throw new BundleException(Msg.formatter.getString("BUNDLE_STATE_CHANGE_EXCEPTION")); //$NON-NLS-1$						}					} else {						changedBundle.beginStateChange();					}					if (Debug.DEBUG && Debug.DEBUG_PACKAGEADMIN) {						if (changedBundle.stateChanging == null) {							Debug.println("Bundle state change lock is clear! " + changedBundle); //$NON-NLS-1$							Debug.printStackTrace(new Exception("Stack trace")); //$NON-NLS-1$						}					}				}				/*				 * Refresh the bundles which will unexport the packages.				 * This will move RESOLVED bundles to the INSTALLED state.				 */				if (Debug.DEBUG && Debug.DEBUG_PACKAGEADMIN) {					Debug.println("refreshPackages: refresh the bundles"); //$NON-NLS-1$				}				/*				 * Unimport detached BundleLoaders for bundles in the graph.				 */				for (int i = removalPending.size() - 1; i >= 0; i--) {					BundleLoaderProxy loaderProxy = (BundleLoaderProxy) removalPending.elementAt(i);					if (graph.contains(loaderProxy.getBundleHost())) {						framework.bundles.unMarkDependancies(loaderProxy);					}				}				for (int i = 0; i < refresh.length; i++) {					AbstractBundle changedBundle = refresh[i];					changedBundle.refresh();					// send out unresolved events					if (previouslyResolved[i])						framework.publishBundleEvent(BundleEvent.UNRESOLVED, changedBundle);				}				/*				 * Cleanup detached BundleLoaders for bundles in the graph.				 */				if (Debug.DEBUG && Debug.DEBUG_PACKAGEADMIN) {					Debug.println("refreshPackages: unexport the removal pending packages"); //$NON-NLS-1$				}				for (int i = removalPending.size() - 1; i >= 0; i--) {					BundleLoaderProxy loaderProxy = (BundleLoaderProxy) removalPending.elementAt(i);					AbstractBundle removedBundle = loaderProxy.getBundleHost();					if (graph.contains(removedBundle)) {						deleteRemovalPending(loaderProxy);					}				}				// set the resolved bundles state				List allBundles = framework.bundles.getBundles();				int size = allBundles.size();				for (int i = 0; i < size; i++) {					AbstractBundle bundle = (AbstractBundle) allBundles.get(i);					if (bundle.isResolved())						continue;					BundleDescription bundleDes = bundle.getBundleDescription();					if (bundleDes != null) {						if (bundleDes.isResolved()) {							if (bundle.isFragment()) {								BundleHost host = (BundleHost) framework.getBundle(bundleDes.getHost().getSupplier().getBundleId());								if (((BundleFragment) bundle).setHost(host)) {									bundle.resolve(bundleDes.isSingleton());								}							} else {								bundle.resolve(bundleDes.isSingleton());							}							if (bundle.isResolved()) {								notify.addElement(bundle);							}						}					}				}				// update the exported package and bundle lists.				exportedPackages = getExportedPackages(exportedPackages);				exportedBundles = getExportedBundles(exportedBundles);			} finally {				/*				 * Release the state change locks.				 */				if (Debug.DEBUG && Debug.DEBUG_PACKAGEADMIN) {					Debug.println("refreshPackages: release the state change locks"); //$NON-NLS-1$				}				for (int i = 0; i < refresh.length; i++) {					AbstractBundle changedBundle = refresh[i];					changedBundle.completeStateChange();				}			}			/*			 * Take this opportunity to clean up the adaptor storage.			 */			if (Debug.DEBUG && Debug.DEBUG_PACKAGEADMIN) {				Debug.println("refreshPackages: clean up adaptor storage"); //$NON-NLS-1$			}			try {				framework.adaptor.compactStorage();			} catch (IOException e) {				if (Debug.DEBUG && Debug.DEBUG_PACKAGEADMIN) {					Debug.println("refreshPackages exception: " + e.getMessage()); //$NON-NLS-1$					Debug.printStackTrace(e);				}				framework.publishFrameworkEvent(FrameworkEvent.ERROR, framework.systemBundle, new BundleException(Msg.formatter.getString("BUNDLE_REFRESH_FAILURE"), e)); //$NON-NLS-1$			}		} catch (BundleException e) {			if (Debug.DEBUG && Debug.DEBUG_PACKAGEADMIN) {				Debug.println("refreshPackages exception: " + e.getMessage()); //$NON-NLS-1$				Debug.printStackTrace(e.getNestedException());			}			framework.publishFrameworkEvent(FrameworkEvent.ERROR, framework.systemBundle, new BundleException(Msg.formatter.getString("BUNDLE_REFRESH_FAILURE"), e)); //$NON-NLS-1$		}		// send out any resolved/unresolved events		for (int i = 0; i < notify.size(); i++) {			AbstractBundle changedBundle = (AbstractBundle) notify.elementAt(i);			framework.publishBundleEvent(changedBundle.isResolved() ? BundleEvent.RESOLVED : BundleEvent.UNRESOLVED, changedBundle);		}	}