Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6018d7d17487cec0c8a546b4b6582cc8dde5e4b7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*******************************************************************************
 * Copyright (c) 2003, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.osgi.internal.resolver;

import java.util.ArrayList;
import java.util.List;
import org.eclipse.osgi.service.resolver.*;
import org.osgi.framework.BundleException;

/**
 * This implementation of State does a bookkeeping of all added/removed 
 */
public class UserState extends StateImpl {
	private List added = new ArrayList();
	private List removed = new ArrayList();
	private List updated = new ArrayList();

	public synchronized boolean addBundle(BundleDescription description) {
		if (!super.addBundle(description))
			return false;
		added.add(description.getLocation());
		return true;
	}

	public synchronized boolean removeBundle(BundleDescription description) {
		if (!super.removeBundle(description))
			return false;
		removed.add(description.getLocation());
		return true;
	}

	public boolean updateBundle(BundleDescription newDescription) {
		if (!super.updateBundle(newDescription))
			return false;
		updated.add(newDescription.getLocation());
		return true;
	}

	public String[] getAllAdded() {
		return (String[]) added.toArray(new String[added.size()]);
	}

	public String[] getAllRemoved() {
		return (String[]) removed.toArray(new String[removed.size()]);
	}

	public String[] getAllUpdated() {
		return (String[]) updated.toArray(new String[updated.size()]);
	}

	public StateDelta compare(State baseState) throws BundleException {
		BundleDescription[] current = this.getBundles();
		StateDeltaImpl delta = new StateDeltaImpl(this);
		// process additions and updates
		for (int i = 0; i < current.length; i++) {
			BundleDescription existing = baseState.getBundleByLocation(current[i].getLocation());
			if (existing == null)
				delta.recordBundleAdded((BundleDescriptionImpl) current[i]);
			else if (updated.contains(current[i].getLocation()))
				delta.recordBundleUpdated((BundleDescriptionImpl) current[i]);
		}
		// process removals
		BundleDescription[] existing = baseState.getBundles();
		for (int i = 0; i < existing.length; i++) {
			BundleDescription local = getBundleByLocation(existing[i].getLocation());
			if (local == null)
				delta.recordBundleRemoved((BundleDescriptionImpl) existing[i]);
		}
		return delta;
	}
}

Back to the top