001: /*******************************************************************************
002: * Copyright (c) 2005, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.core.text.bundle;
011:
012: import org.eclipse.osgi.util.ManifestElement;
013: import org.eclipse.pde.internal.core.ICoreConstants;
014: import org.eclipse.pde.internal.core.bundle.BundlePluginBase;
015: import org.osgi.framework.Constants;
016:
017: public class RequireBundleObject extends PDEManifestElement {
018:
019: private static final long serialVersionUID = 1L;
020:
021: public RequireBundleObject(ManifestHeader header, String value) {
022: super (header, value);
023: }
024:
025: public RequireBundleObject(ManifestHeader header,
026: ManifestElement manifestElement) {
027: super (header, manifestElement);
028: }
029:
030: public void setId(String id) {
031: String old = getId();
032: setValue(id);
033: fHeader.update();
034: firePropertyChanged(this , fHeader.getName(), old, id);
035: }
036:
037: public String getId() {
038: return getValue();
039: }
040:
041: public void setVersion(String version) {
042: String old = getVersion();
043: // Reset the previous value
044: setAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE, null);
045: // Parse the version String into segments
046: String[] values = ManifestElement.getArrayFromList(version);
047: // If there are values, add them
048: if ((values != null) && (values.length > 0)) {
049: for (int i = 0; i < values.length; i++) {
050: addAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE,
051: values[i]);
052: }
053: }
054: fHeader.update();
055: firePropertyChanged(this , Constants.BUNDLE_VERSION_ATTRIBUTE,
056: old, version);
057: }
058:
059: public String getVersion() {
060: String[] versionSegments = getAttributes(Constants.BUNDLE_VERSION_ATTRIBUTE);
061: StringBuffer version = new StringBuffer();
062: if (versionSegments == null) {
063: return null;
064: } else if (versionSegments.length == 0) {
065: return null;
066: } else if (versionSegments.length == 1) {
067: version.append(versionSegments[0]);
068: } else if (versionSegments.length == 2) {
069: version.append(versionSegments[0]);
070: version.append(',');
071: version.append(versionSegments[1]);
072: }
073: return version.toString();
074: }
075:
076: public void setOptional(boolean optional) {
077: boolean old = isOptional();
078: int bundleManifestVersion = BundlePluginBase
079: .getBundleManifestVersion(fHeader.getBundle());
080: if (optional) {
081: if (bundleManifestVersion > 1)
082: setDirective(Constants.RESOLUTION_DIRECTIVE,
083: Constants.RESOLUTION_OPTIONAL);
084: else
085: setAttribute(ICoreConstants.OPTIONAL_ATTRIBUTE, "true"); //$NON-NLS-1$
086: } else {
087: if (bundleManifestVersion > 1)
088: setDirective(Constants.RESOLUTION_DIRECTIVE, null);
089: else
090: setAttribute(ICoreConstants.OPTIONAL_ATTRIBUTE, null);
091: }
092: fHeader.update();
093: firePropertyChanged(this , Constants.RESOLUTION_DIRECTIVE,
094: Boolean.toString(old), Boolean.toString(optional));
095: }
096:
097: public boolean isOptional() {
098: int bundleManifestVersion = BundlePluginBase
099: .getBundleManifestVersion(fHeader.getBundle());
100: if (bundleManifestVersion > 1)
101: return Constants.RESOLUTION_OPTIONAL
102: .equals(getDirective(Constants.RESOLUTION_DIRECTIVE));
103:
104: return "true".equals(getAttribute(ICoreConstants.OPTIONAL_ATTRIBUTE)); //$NON-NLS-1$
105: }
106:
107: public void setReexported(boolean export) {
108: boolean old = isReexported();
109: int bundleManifestVersion = BundlePluginBase
110: .getBundleManifestVersion(fHeader.getBundle());
111: if (export) {
112: if (bundleManifestVersion > 1)
113: setDirective(Constants.VISIBILITY_DIRECTIVE,
114: Constants.VISIBILITY_REEXPORT);
115: else
116: setAttribute(ICoreConstants.REPROVIDE_ATTRIBUTE, "true"); //$NON-NLS-1$
117: } else {
118: if (bundleManifestVersion > 1)
119: setDirective(Constants.VISIBILITY_DIRECTIVE, null);
120: else
121: setAttribute(ICoreConstants.REPROVIDE_ATTRIBUTE, null);
122: }
123: fHeader.update();
124: firePropertyChanged(this , Constants.VISIBILITY_DIRECTIVE,
125: Boolean.toString(old), Boolean.toString(export));
126: }
127:
128: public boolean isReexported() {
129: int bundleManifestVersion = BundlePluginBase
130: .getBundleManifestVersion(fHeader.getBundle());
131: if (bundleManifestVersion > 1)
132: return Constants.VISIBILITY_REEXPORT
133: .equals(getDirective(Constants.VISIBILITY_DIRECTIVE));
134:
135: return "true".equals(getAttribute(ICoreConstants.REPROVIDE_ATTRIBUTE)); //$NON-NLS-1$
136: }
137:
138: }
|