KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.eclipse.osgi.service.resolver.BundleDelta;
14 import org.eclipse.osgi.service.resolver.BundleDescription;
15
16 public class BundleDeltaImpl implements BundleDelta {
17
18     private BundleDescription bundleDescription;
19     private int type;
20
21     public BundleDeltaImpl(BundleDescription bundleDescription) {
22         this(bundleDescription, 0);
23     }
24
25     public BundleDeltaImpl(BundleDescription bundleDescription, int type) {
26         this.bundleDescription = bundleDescription;
27         this.type = type;
28     }
29
30     public BundleDescription getBundle() {
31         return bundleDescription;
32     }
33
34     public int getType() {
35         return type;
36     }
37
38     protected void setBundle(BundleDescription bundleDescription) {
39         this.bundleDescription = bundleDescription;
40     }
41
42     protected void setType(int type) {
43         this.type = type;
44     }
45
46     public String JavaDoc toString() {
47         return bundleDescription.getSymbolicName() + '_' + bundleDescription.getVersion() + " (" + toTypeString(type) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
48
}
49
50     private static String JavaDoc toTypeString(int type) {
51         StringBuffer JavaDoc typeStr = new StringBuffer JavaDoc();
52         if ((type & BundleDelta.ADDED) != 0)
53             typeStr.append("ADDED,"); //$NON-NLS-1$
54
if ((type & BundleDelta.REMOVED) != 0)
55             typeStr.append("REMOVED,"); //$NON-NLS-1$
56
if ((type & BundleDelta.RESOLVED) != 0)
57             typeStr.append("RESOLVED,"); //$NON-NLS-1$
58
if ((type & BundleDelta.UNRESOLVED) != 0)
59             typeStr.append("UNRESOLVED,"); //$NON-NLS-1$
60
if ((type & BundleDelta.LINKAGE_CHANGED) != 0)
61             typeStr.append("LINKAGE_CHANGED,"); //$NON-NLS-1$
62
if ((type & BundleDelta.UPDATED) != 0)
63             typeStr.append("UPDATED,"); //$NON-NLS-1$
64
if ((type & BundleDelta.REMOVAL_PENDING) != 0)
65             typeStr.append("REMOVAL_PENDING,"); //$NON-NLS-1$
66
if ((type & BundleDelta.REMOVAL_COMPLETE) != 0)
67             typeStr.append("REMOVAL_COMPLETE,"); //$NON-NLS-1$
68
if (typeStr.length() > 0)
69             typeStr.deleteCharAt(typeStr.length() - 1);
70         return typeStr.toString();
71     }
72
73     public int compareTo(Object JavaDoc obj) {
74         long idcomp = getBundle().getBundleId() - ((BundleDelta) obj).getBundle().getBundleId();
75         return (idcomp < 0L) ? -1 : ((idcomp > 0L) ? 1 : 0);
76     }
77 }
78
Popular Tags