KickJava   Java API By Example, From Geeks To Geeks.

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


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.ibundle.IBundle;
15 import org.osgi.framework.BundleException;
16
17 public class SingleManifestHeader extends ManifestHeader {
18
19     private static final long serialVersionUID = 1L;
20     
21     private PDEManifestElement fElement;
22     
23     public SingleManifestHeader(String JavaDoc name, String JavaDoc value, IBundle bundle, String JavaDoc lineDelimiter) {
24         super(name, value, bundle, lineDelimiter);
25     }
26     
27     protected void processValue(String JavaDoc value) {
28         try {
29             ManifestElement[] elements = ManifestElement.parseHeader(getName(), value);
30             if (elements.length > 0)
31                 fElement = new PDEManifestElement(this, elements[0]);
32         } catch (BundleException e) {
33         }
34         if (fElement == null)
35             fElement = new PDEManifestElement(this, ""); //$NON-NLS-1$
36
fValue = value;
37     }
38     
39     public void setAttribute(String JavaDoc key, String JavaDoc value) {
40         fElement.setAttribute(key, value);
41         update();
42     }
43     
44     public void setDirective(String JavaDoc key, String JavaDoc value) {
45         fElement.setDirective(key, value);
46         update();
47     }
48     
49     public void setMainComponent(String JavaDoc value) {
50         if (value == null)
51             fElement.setValueComponents((String JavaDoc[])null);
52         else
53             fElement.setValueComponents(new String JavaDoc[] {value});
54         update();
55     }
56     
57     public String JavaDoc getAttribute(String JavaDoc key) {
58         return fElement.getAttribute(key);
59     }
60     
61     public String JavaDoc getDirective(String JavaDoc key) {
62         return fElement.getDirective(key);
63     }
64     
65     public String JavaDoc getMainComponent() {
66         return fElement.getValue();
67     }
68     
69     public void update() {
70         // single headers will fire a change by default
71
update(true);
72     }
73     
74     public void update(boolean notify) {
75         String JavaDoc old = fValue;
76         fValue = fElement.write();
77         if (notify)
78             fBundle.getModel().fireModelObjectChanged(this, fName, old, fValue);
79     }
80
81 }
82
Popular Tags