KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > plugin > Extensions


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.plugin;
12
13 import java.io.PrintWriter JavaDoc;
14
15 import org.eclipse.pde.core.plugin.IPluginExtension;
16 import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
17 import org.eclipse.pde.internal.core.PDEState;
18 import org.w3c.dom.Node JavaDoc;
19 import org.w3c.dom.NodeList JavaDoc;
20
21 public class Extensions extends AbstractExtensions {
22     
23     private static final long serialVersionUID = 1L;
24     
25     private boolean fValid;
26     private boolean fIsFragment;
27
28     public Extensions() {
29     }
30
31     void load(Extensions srcPluginBase) {
32         super.load(srcPluginBase);
33         fValid = hasRequiredAttributes();
34     }
35
36     void load(Node JavaDoc node, String JavaDoc schemaVersion) {
37         fSchemaVersion = schemaVersion;
38         if (node == null)
39             return;
40         NodeList JavaDoc children = node.getChildNodes();
41         for (int i = 0; i < children.getLength(); i++) {
42             Node JavaDoc child = children.item(i);
43             if (child.getNodeType() == Node.ELEMENT_NODE) {
44                 processChild(child);
45             }
46         }
47         fValid = hasRequiredAttributes();
48     }
49     
50     void load(PDEState state, long bundleID) {
51         Node JavaDoc[] nodes = state.getAllExtensions(bundleID);
52         for (int i = 0; i < nodes.length; i++) {
53             Node JavaDoc child = nodes[i];
54             if (child.getNodeType() == Node.ELEMENT_NODE) {
55                 processChild(child);
56             }
57         }
58         fValid = hasRequiredAttributes();
59         fSchemaVersion = state.getSchemaVersion(bundleID);
60     }
61
62     public void reset() {
63         super.reset();
64         fValid=false;
65     }
66     
67     public boolean isValid() {
68         return fValid;
69     }
70
71     public void write(String JavaDoc indent, PrintWriter JavaDoc writer) {
72         writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); //$NON-NLS-1$
73
if (fSchemaVersion != null)
74             writer.println("<?eclipse version=\"" + fSchemaVersion + "\"?>"); //$NON-NLS-1$ //$NON-NLS-2$
75
writer.println(fIsFragment ? "<fragment>" : "<plugin>"); //$NON-NLS-1$ //$NON-NLS-2$
76

77         String JavaDoc firstIndent = " "; //$NON-NLS-1$
78

79         Object JavaDoc [] children = getExtensionPoints();
80         if (children.length > 0)
81             writer.println();
82         for (int i = 0; i < children.length; i++) {
83             ((IPluginExtensionPoint) children[i]).write(firstIndent, writer);
84         }
85     
86         // add extensions
87
children = getExtensions();
88         if (children.length > 0)
89             writer.println();
90         for (int i = 0; i < children.length; i++) {
91             ((IPluginExtension) children[i]).write(firstIndent, writer);
92         }
93         writer.println();
94         writer.println(fIsFragment ? "</fragment>" : "</plugin>"); //$NON-NLS-1$ //$NON-NLS-2$
95
}
96     
97     public void setIsFragment(boolean isFragment) {
98         fIsFragment = isFragment;
99     }
100 }
101
Popular Tags