1 11 package org.eclipse.pde.internal.ui.model.bundle; 12 13 import java.util.Iterator ; 14 import java.util.TreeMap ; 15 import java.util.Vector ; 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 fPackages = new TreeMap (); 28 29 protected String fLineDelimiter; 30 31 public BasePackageHeader(String name, String value, IBundle bundle, 32 String lineDelimiter) { 33 super(name, value, bundle); 34 this.fLineDelimiter = lineDelimiter; 35 processValue(); 36 } 37 38 protected String 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 getPackageNames() { 58 Vector vector = new Vector (fPackages.size()); 59 Iterator 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 packageName) { 67 return fPackages.containsKey(packageName); 68 } 69 70 public void updateValue() { 71 StringBuffer buffer = new StringBuffer (); 72 Iterator iter = fPackages.values().iterator(); 73 while (iter.hasNext()) { 74 buffer.append(((PackageObject)iter.next()).write()); 75 if (iter.hasNext()) { 76 buffer.append(","); buffer.append(fLineDelimiter); 78 buffer.append(" "); } 80 } 81 fValue = buffer.toString(); 82 } 83 84 85 } 86 | Popular Tags |