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.ICoreConstants; 15 import org.eclipse.pde.internal.core.bundle.BundlePluginBase; 16 import org.osgi.framework.Constants; 17 18 public class RequireBundleObject extends PDEManifestElement { 19 20 private static final long serialVersionUID = 1L; 21 22 public RequireBundleObject(ManifestHeader header, String value) { 23 super(header, value); 24 } 25 26 public RequireBundleObject(ManifestHeader header, ManifestElement manifestElement) { 27 super(header, manifestElement); 28 } 29 30 public void setId(String id) { 31 String old = getId(); 32 setValue(id); 33 fHeader.update(); 34 firePropertyChanged(this, fHeader.getName(), old, id); 35 } 36 37 public String getId() { 38 return getValue(); 39 } 40 41 public void setVersion(String version) { 42 String old = getVersion(); 43 setAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE, null); 45 String [] values = ManifestElement.getArrayFromList(version); 47 if ((values != null) && 49 (values.length > 0)) { 50 for (int i = 0; i < values.length; i++) { 51 addAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE, values[i]); 52 } 53 } 54 fHeader.update(); 55 firePropertyChanged(this, Constants.BUNDLE_VERSION_ATTRIBUTE, old, version); 56 } 57 58 public String getVersion() { 59 String [] versionSegments = 60 getAttributes(Constants.BUNDLE_VERSION_ATTRIBUTE); 61 StringBuffer version = new StringBuffer (); 62 if (versionSegments == null) { 63 return null; 64 } else if (versionSegments.length == 0) { 65 return null; 66 } else if (versionSegments.length == 1) { 67 version.append(versionSegments[0]); 68 } else if (versionSegments.length == 2) { 69 version.append(versionSegments[0]); 70 version.append(','); 71 version.append(versionSegments[1]); 72 } 73 return version.toString(); 74 } 75 76 public void setOptional(boolean optional) { 77 boolean old = isOptional(); 78 int bundleManifestVersion = BundlePluginBase.getBundleManifestVersion(fHeader.getBundle()); 79 if (optional) { 80 if (bundleManifestVersion > 1) 81 setDirective(Constants.RESOLUTION_DIRECTIVE, Constants.RESOLUTION_OPTIONAL); 82 else 83 setAttribute(ICoreConstants.OPTIONAL_ATTRIBUTE, "true"); } else { 85 if (bundleManifestVersion > 1) 86 setDirective(Constants.RESOLUTION_DIRECTIVE, null); 87 else 88 setAttribute(ICoreConstants.OPTIONAL_ATTRIBUTE, null); 89 } 90 fHeader.update(); 91 firePropertyChanged(this, Constants.RESOLUTION_DIRECTIVE, Boolean.toString(old), Boolean.toString(optional)); 92 } 93 94 public boolean isOptional() { 95 int bundleManifestVersion = BundlePluginBase.getBundleManifestVersion(fHeader.getBundle()); 96 if (bundleManifestVersion > 1) 97 return Constants.RESOLUTION_OPTIONAL.equals(getDirective(Constants.RESOLUTION_DIRECTIVE)); 98 99 return "true".equals(getAttribute(ICoreConstants.OPTIONAL_ATTRIBUTE)); } 101 102 public void setReexported(boolean export) { 103 boolean old = isReexported(); 104 int bundleManifestVersion = BundlePluginBase.getBundleManifestVersion(fHeader.getBundle()); 105 if (export) { 106 if (bundleManifestVersion > 1) 107 setDirective(Constants.VISIBILITY_DIRECTIVE, Constants.VISIBILITY_REEXPORT); 108 else 109 setAttribute(ICoreConstants.REPROVIDE_ATTRIBUTE, "true"); } else { 111 if (bundleManifestVersion > 1) 112 setDirective(Constants.VISIBILITY_DIRECTIVE, null); 113 else 114 setAttribute(ICoreConstants.REPROVIDE_ATTRIBUTE, null); 115 } 116 fHeader.update(); 117 firePropertyChanged(this, Constants.VISIBILITY_DIRECTIVE, Boolean.toString(old), Boolean.toString(export)); 118 } 119 120 public boolean isReexported() { 121 int bundleManifestVersion = BundlePluginBase.getBundleManifestVersion(fHeader.getBundle()); 122 if (bundleManifestVersion > 1) 123 return Constants.VISIBILITY_REEXPORT.equals(getDirective(Constants.VISIBILITY_DIRECTIVE)); 124 125 return "true".equals(getAttribute(ICoreConstants.REPROVIDE_ATTRIBUTE)); } 127 128 } 129 | Popular Tags |