1 11 package org.eclipse.pde.internal.core.text.bundle; 12 13 import java.io.PrintWriter ; 14 15 import org.eclipse.osgi.service.resolver.ExportPackageDescription; 16 import org.eclipse.osgi.util.ManifestElement; 17 import org.eclipse.pde.internal.core.ICoreConstants; 18 import org.eclipse.pde.internal.core.bundle.BundlePluginBase; 19 import org.eclipse.pde.internal.core.ibundle.IBundleModel; 20 import org.osgi.framework.Constants; 21 import org.osgi.framework.Version; 22 23 public class ImportPackageObject extends PackageObject { 24 25 private static final long serialVersionUID = 1L; 26 27 private static String getVersion(ExportPackageDescription desc) { 28 String version = desc.getVersion().toString(); 29 if (!version.equals(Version.emptyVersion.toString())) 30 return desc.getVersion().toString(); 31 return null; 32 } 33 34 public ImportPackageObject(ManifestHeader header, ManifestElement element, String versionAttribute) { 35 super(header, element, versionAttribute); 36 } 37 38 public ImportPackageObject(ManifestHeader header, ExportPackageDescription desc, String versionAttribute) { 39 super(header, desc.getName(), getVersion(desc), versionAttribute); 40 } 41 42 public ImportPackageObject(ManifestHeader header, String id, String version, String versionAttribute) { 43 super(header, id, version, versionAttribute); 44 } 45 46 public boolean isOptional() { 47 int manifestVersion = BundlePluginBase.getBundleManifestVersion(getHeader().getBundle()); 48 if (manifestVersion > 1) 49 return Constants.RESOLUTION_OPTIONAL.equals(getDirective(Constants.RESOLUTION_DIRECTIVE)); 50 return "true".equals(getAttribute(ICoreConstants.OPTIONAL_ATTRIBUTE)); } 52 53 public void setOptional(boolean optional) { 54 boolean old = isOptional(); 55 int manifestVersion = BundlePluginBase.getBundleManifestVersion(getHeader().getBundle()); 56 if (optional) { 57 if (manifestVersion > 1) 58 setDirective(Constants.RESOLUTION_DIRECTIVE, Constants.RESOLUTION_OPTIONAL); 59 else 60 setAttribute(ICoreConstants.OPTIONAL_ATTRIBUTE, "true"); } else { 62 setDirective(Constants.RESOLUTION_DIRECTIVE, null); 63 setAttribute(ICoreConstants.OPTIONAL_ATTRIBUTE, null); 64 } 65 fHeader.update(); 66 firePropertyChanged(this, Constants.RESOLUTION_DIRECTIVE, Boolean.toString(old), Boolean.toString(optional)); 67 } 68 69 74 public void reconnect(IBundleModel model, ImportPackageHeader header, 75 String versionAttribute) { 76 super.reconnect(model, header, versionAttribute); 77 } 79 80 83 public void write(String indent, PrintWriter writer) { 84 writer.write(write()); 86 } 87 88 } 89 | Popular Tags |