KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > text > bundle > RequireBundleObject


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 JavaDoc 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 JavaDoc id) {
31         String JavaDoc old = getId();
32         setValue(id);
33         fHeader.update();
34         firePropertyChanged(this, fHeader.getName(), old, id);
35     }
36     
37     public String JavaDoc getId() {
38         return getValue();
39     }
40     
41     public void setVersion(String JavaDoc version) {
42         String JavaDoc old = getVersion();
43         // Reset the previous value
44
setAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE, null);
45         // Parse the version String into segments
46
String JavaDoc[] values = ManifestElement.getArrayFromList(version);
47         // If there are values, add them
48
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 JavaDoc getVersion() {
59         String JavaDoc[] versionSegments =
60             getAttributes(Constants.BUNDLE_VERSION_ATTRIBUTE);
61         StringBuffer JavaDoc version = new StringBuffer JavaDoc();
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"); //$NON-NLS-1$
84
} 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)); //$NON-NLS-1$
100
}
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"); //$NON-NLS-1$
110
} 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)); //$NON-NLS-1$
126
}
127
128 }
129
Popular Tags