01: /*******************************************************************************
02: * Copyright (c) 2005, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.core.text.bundle;
11:
12: import org.eclipse.osgi.util.ManifestElement;
13: import org.eclipse.pde.internal.core.ibundle.IBundle;
14: import org.osgi.framework.BundleException;
15:
16: public class SingleManifestHeader extends ManifestHeader {
17:
18: private static final long serialVersionUID = 1L;
19:
20: private PDEManifestElement fElement;
21:
22: public SingleManifestHeader(String name, String value,
23: IBundle bundle, String lineDelimiter) {
24: super (name, value, bundle, lineDelimiter);
25: }
26:
27: protected void processValue(String value) {
28: try {
29: ManifestElement[] elements = ManifestElement.parseHeader(
30: getName(), value);
31: if (elements.length > 0)
32: fElement = new PDEManifestElement(this , elements[0]);
33: } catch (BundleException e) {
34: }
35: if (fElement == null)
36: fElement = new PDEManifestElement(this , ""); //$NON-NLS-1$
37: fValue = value;
38: }
39:
40: public void setAttribute(String key, String value) {
41: fElement.setAttribute(key, value);
42: update();
43: }
44:
45: public void setDirective(String key, String value) {
46: fElement.setDirective(key, value);
47: update();
48: }
49:
50: public void setMainComponent(String value) {
51: if (value == null)
52: fElement.setValueComponents((String[]) null);
53: else
54: fElement.setValueComponents(new String[] { value });
55: update();
56: }
57:
58: public String getAttribute(String key) {
59: return fElement.getAttribute(key);
60: }
61:
62: public String getDirective(String key) {
63: return fElement.getDirective(key);
64: }
65:
66: public String getMainComponent() {
67: return fElement.getValue();
68: }
69:
70: public void update() {
71: // single headers will fire a change by default
72: update(true);
73: }
74:
75: public void update(boolean notify) {
76: String old = fValue;
77: fValue = fElement.write();
78: if (notify)
79: fBundle.getModel().fireModelObjectChanged(this, fName, old,
80: fValue);
81: }
82:
83: }
|