KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.builders;
12
13 import org.eclipse.osgi.util.ManifestElement;
14 import org.eclipse.osgi.util.NLS;
15 import org.eclipse.pde.internal.core.PDECoreMessages;
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(PDECoreMessages.BundleErrorReporter_parseHeader, getName());
63                         fErrorReporter.report(message, getLineNumber() + 1,
64                                 CompilerFlags.ERROR,
65                                 PDEMarkerFactory.CAT_FATAL);
66                     }
67                 }
68             } else {
69                 fManifestElements = new ManifestElement[0];
70             }
71         }
72         return fManifestElements;
73     }
74
75     public int getLineNumber() {
76         return fLineNumber;
77     }
78
79     public int getLinesSpan() {
80         return fLines;
81     }
82
83     public String JavaDoc getName() {
84         return fName;
85     }
86
87     public String JavaDoc getValue() {
88         return fValue;
89     }
90
91     public String JavaDoc toString() {
92         return fName + "=" + fValue; //$NON-NLS-1$
93
}
94
95 }
96
Popular Tags