KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > model > bundle > BasePackageHeader


1 /*******************************************************************************
2  * Copyright (c) 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.pde.internal.ui.model.bundle;
12
13 import java.util.Iterator JavaDoc;
14 import java.util.TreeMap JavaDoc;
15 import java.util.Vector JavaDoc;
16
17 import org.eclipse.pde.core.IModelChangedEvent;
18 import org.eclipse.pde.internal.core.ICoreConstants;
19 import org.eclipse.pde.internal.core.bundle.BundlePluginBase;
20 import org.eclipse.pde.internal.core.ibundle.IBundle;
21 import org.osgi.framework.Constants;
22
23 public abstract class BasePackageHeader extends ManifestHeader {
24
25     private static final long serialVersionUID = 1L;
26     
27     protected TreeMap JavaDoc fPackages = new TreeMap JavaDoc();
28     
29     protected String JavaDoc fLineDelimiter;
30
31     public BasePackageHeader(String JavaDoc name, String JavaDoc value, IBundle bundle,
32             String JavaDoc lineDelimiter) {
33         super(name, value, bundle);
34         this.fLineDelimiter = lineDelimiter;
35         processValue();
36     }
37
38     protected String JavaDoc getVersionAttribute() {
39         int manifestVersion = BundlePluginBase.getBundleManifestVersion(getBundle());
40         return (manifestVersion < 2) ? ICoreConstants.PACKAGE_SPECIFICATION_VERSION : Constants.VERSION_ATTRIBUTE;
41     }
42     
43     protected abstract void processValue();
44
45     public void addPackage(PackageObject object) {
46         fPackages.put(object.getName(), object);
47         updateValue();
48         fireStructureChanged(object, IModelChangedEvent.INSERT);
49     }
50     
51     public void removePackage(PackageObject object) {
52         fPackages.remove(object.getName());
53         updateValue();
54         fireStructureChanged(object, IModelChangedEvent.REMOVE);
55     }
56     
57     public Vector JavaDoc getPackageNames() {
58         Vector JavaDoc vector = new Vector JavaDoc(fPackages.size());
59         Iterator JavaDoc iter = fPackages.keySet().iterator();
60         for (int i = 0; iter.hasNext(); i++) {
61             vector.add(iter.next().toString());
62         }
63         return vector;
64     }
65     
66     public boolean hasPackage(String JavaDoc packageName) {
67         return fPackages.containsKey(packageName);
68     }
69     
70     public void updateValue() {
71         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
72         Iterator JavaDoc iter = fPackages.values().iterator();
73         while (iter.hasNext()) {
74             buffer.append(((PackageObject)iter.next()).write());
75             if (iter.hasNext()) {
76                 buffer.append(","); //$NON-NLS-1$
77
buffer.append(fLineDelimiter);
78                 buffer.append(" "); //$NON-NLS-1$
79
}
80         }
81        fValue = buffer.toString();
82     }
83
84
85 }
86
Popular Tags