KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > osgi > internal > resolver > UserState


1 /*******************************************************************************
2  * Copyright (c) 2003, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.osgi.internal.resolver;
12
13 import java.util.HashSet JavaDoc;
14 import java.util.Set JavaDoc;
15 import org.eclipse.osgi.service.resolver.*;
16 import org.osgi.framework.BundleException;
17
18 /**
19  * This implementation of State does a bookkeeping of all added/removed
20  */

21 public class UserState extends StateImpl {
22     // TODO this is not an accurate way to record updates
23
private Set JavaDoc updated = new HashSet JavaDoc();
24
25     public synchronized boolean removeBundle(BundleDescription description) {
26         if (description.getLocation() != null)
27             updated.remove(description.getLocation());
28         if (!super.removeBundle(description))
29             return false;
30         return true;
31     }
32
33     public boolean updateBundle(BundleDescription newDescription) {
34         if (!super.updateBundle(newDescription))
35             return false;
36         updated.add(newDescription.getLocation());
37         return true;
38     }
39
40     public StateDelta compare(State baseState) throws BundleException {
41         BundleDescription[] current = this.getBundles();
42         StateDeltaImpl delta = new StateDeltaImpl(this);
43         // process additions and updates
44
for (int i = 0; i < current.length; i++) {
45             BundleDescription existing = baseState.getBundleByLocation(current[i].getLocation());
46             if (existing == null)
47                 delta.recordBundleAdded((BundleDescriptionImpl) current[i]);
48             else if (updated.contains(current[i].getLocation()))
49                 delta.recordBundleUpdated((BundleDescriptionImpl) current[i]);
50         }
51         // process removals
52
BundleDescription[] existing = baseState.getBundles();
53         for (int i = 0; i < existing.length; i++) {
54             BundleDescription local = getBundleByLocation(existing[i].getLocation());
55             if (local == null)
56                 delta.recordBundleRemoved((BundleDescriptionImpl) existing[i]);
57         }
58         return delta;
59     }
60 }
61
Popular Tags