KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > builders > JarManifestHeader


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.builders;
12
13 import org.eclipse.osgi.util.ManifestElement;
14 import org.eclipse.osgi.util.NLS;
15 import org.eclipse.pde.internal.PDEMessages;
16 import org.osgi.framework.BundleException;
17
18 public class JarManifestHeader implements IHeader {
19     private JarManifestErrorReporter fErrorReporter;
20
21     private int fLineNumber;
22
23     private int fLines;
24
25     private ManifestElement[] fManifestElements;
26
27     private String JavaDoc fName;
28
29     private String JavaDoc fValue;
30
31     /**
32      *
33      * @param name
34      * @param value
35      * @param lineNumber
36      * @param errorReporter
37      * JarManinfestErrorReporter or null
38      */

39     public JarManifestHeader(String JavaDoc name, String JavaDoc value, int lineNumber,
40             JarManifestErrorReporter errorReporter) {
41         fName = name;
42         fValue = value;
43         fLineNumber = lineNumber;
44         fErrorReporter = errorReporter;
45         fLines = 1;
46     }
47
48     public void append(String JavaDoc value) {
49         fValue += value;
50         fLines++;
51     }
52
53     public ManifestElement[] getElements() {
54         if (fManifestElements == null) {
55             if (getValue().trim().length() > 0) {
56                 try {
57                     fManifestElements = ManifestElement.parseHeader(getName(),
58                             getValue());
59                 } catch (BundleException be) {
60                     fManifestElements = new ManifestElement[0];
61                     if (fErrorReporter != null) {
62                         String JavaDoc message = NLS.bind(PDEMessages.BundleErrorReporter_parseHeader, getName()); //$NON-NLS-1$
63
fErrorReporter.report(message, getLineNumber() + 1,
64                                 CompilerFlags.ERROR);
65                     }
66                 }
67             } else {
68                 fManifestElements = new ManifestElement[0];
69             }
70         }
71         return fManifestElements;
72     }
73
74     public int getLineNumber() {
75         return fLineNumber;
76     }
77
78     public int getLinesSpan() {
79         return fLines;
80     }
81
82     public String JavaDoc getName() {
83         return fName;
84     }
85
86     public String JavaDoc getValue() {
87         return fValue;
88     }
89
90     public String JavaDoc toString() {
91         return fName + "=" + fValue; //$NON-NLS-1$
92
}
93
94 }
95
Popular Tags