KickJava   Java API By Example, From Geeks To Geeks.

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


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.eclipse.pde.internal.core.ibundle.IBundle;
17 import org.osgi.framework.BundleException;
18 import org.osgi.framework.Constants;
19
20 public abstract class BasePackageHeader extends CompositeManifestHeader {
21
22     private static final long serialVersionUID = 1L;
23     
24     public BasePackageHeader(String JavaDoc name, String JavaDoc value, IBundle bundle, String JavaDoc lineDelimiter) {
25         super(name, value, bundle, lineDelimiter, true);
26     }
27
28     protected String JavaDoc getVersionAttribute() {
29         int manifestVersion = BundlePluginBase.getBundleManifestVersion(getBundle());
30         return (manifestVersion < 2) ? ICoreConstants.PACKAGE_SPECIFICATION_VERSION : Constants.VERSION_ATTRIBUTE;
31     }
32     
33     public void addPackage(PackageObject object) {
34         addManifestElement(object);
35     }
36     
37     public Object JavaDoc removePackage(PackageObject object) {
38         return removeManifestElement(object);
39     }
40     
41     public boolean hasPackage(String JavaDoc packageName) {
42         return hasElement(packageName);
43     }
44     
45     public Object JavaDoc removePackage(String JavaDoc name) {
46         return removeManifestElement(name);
47     }
48     
49     public boolean renamePackage(String JavaDoc oldName, String JavaDoc newName) {
50         if (hasPackage(oldName)) {
51             PackageObject object = (PackageObject)removeManifestElement(oldName);
52             object.setName(newName);
53             addManifestElement(object);
54             return true;
55         }
56         return false;
57     }
58     
59     protected void processValue(String JavaDoc value) {
60         try {
61             ManifestElement[] elements = ManifestElement.parseHeader(fName, value);
62             for (int i = 0; i < elements.length; i++) {
63                 if (elements[i].getValueComponents().length > 1) {
64                     // if package element has multiple value components, create a new Element to represent each value (bug 160233)
65
String JavaDoc[] values = elements[i].getValueComponents();
66                     for (int j = 0; j < values.length; j++) {
67                         PDEManifestElement elem = createElement(elements[i]);
68                         elem.setValueComponents(new String JavaDoc[] { values [j] });
69                         addManifestElement(elem, false);
70                     }
71                 } else {
72                     addManifestElement(createElement(elements[i]), false);
73                 }
74             }
75         } catch (BundleException e) {
76         }
77     }
78
79 }
80
Popular Tags