1 11 package org.eclipse.pde.internal.core.text.bundle; 12 13 import org.eclipse.osgi.util.ManifestElement; 14 import org.eclipse.pde.internal.core.ibundle.IBundleModel; 15 16 public class PackageObject extends PDEManifestElement { 17 18 private static final long serialVersionUID = 1L; 19 20 private transient String fVersionAttribute; 21 22 public PackageObject(ManifestHeader header, ManifestElement element, String versionAttribute) { 23 super(header, element); 24 fVersionAttribute = versionAttribute; 25 } 26 27 public PackageObject(ManifestHeader header, String name, String version, String versionAttribute) { 28 super(header, name.length() > 0 ? name : "."); fVersionAttribute = versionAttribute; 30 if (version != null) 31 addAttribute(fVersionAttribute, version); 32 } 33 34 public String toString() { 35 StringBuffer buffer = new StringBuffer (getValue()); 36 String version = getVersion(); 37 if (version != null && version.length() > 0) { 38 buffer.append(" "); boolean wrap = Character.isDigit(version.charAt(0)); 40 if (wrap) 41 buffer.append("("); buffer.append(version); 43 if (wrap) 44 buffer.append(")"); } 46 return buffer.toString(); 47 } 48 49 public String getVersion() { 50 String [] version = getAttributes(fVersionAttribute); 51 if (version == null || version.length == 0) 52 return null; 53 if (version.length == 1) 54 return version[0]; 55 return version[0] + ',' + version[1]; 56 } 57 58 public String getName() { 59 return getValue(); 60 } 61 62 public void setName(String name) { 63 setValueComponents(new String [] {name}); 64 } 65 66 public void setVersion(String version) { 67 String old = getVersion(); 68 setAttribute(fVersionAttribute, version); 69 fHeader.update(); 70 firePropertyChanged(this, fVersionAttribute, old, version); 71 } 72 73 public void reconnect(IBundleModel model, ManifestHeader header, 74 String versionAttribute) { 75 super.reconnect(model, header); 76 fVersionAttribute = versionAttribute; 78 } 79 80 } 81 | Popular Tags |