KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > model > plugin > PluginDocumentNodeFactory


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.ui.model.plugin;
12
13 import org.eclipse.core.runtime.*;
14 import org.eclipse.pde.core.plugin.*;
15 import org.eclipse.pde.internal.ui.model.*;
16
17 public class PluginDocumentNodeFactory implements IPluginModelFactory {
18     
19     private PluginModelBase fModel;
20
21     public PluginDocumentNodeFactory(PluginModelBase model) {
22         fModel = model;
23     }
24     
25     public IDocumentNode createDocumentNode(String JavaDoc name, IDocumentNode parent) {
26         if (parent == null)
27             return createPluginBase(name);
28         
29         if (parent instanceof PluginBaseNode) {
30             if ("extension".equals(name)) //$NON-NLS-1$
31
return createExtension(parent);
32             if ("extension-point".equals(name)) //$NON-NLS-1$
33
return createExtensionPoint(parent);
34         } else {
35             if (name.equals("import") && parent instanceof PluginElementNode) { //$NON-NLS-1$
36
if (((PluginElementNode)parent).getName().equals("requires")) { //$NON-NLS-1$
37
IDocumentNode ancestor = parent.getParentNode();
38                     if (ancestor != null && ancestor instanceof PluginBaseNode) {
39                         return createImport(parent);
40                     }
41                 }
42             } else if (name.equals("library") && parent instanceof PluginElementNode) { //$NON-NLS-1$
43
if (((PluginElementNode)parent).getName().equals("runtime")) { //$NON-NLS-1$
44
IDocumentNode ancestor = parent.getParentNode();
45                     if (ancestor != null && ancestor instanceof PluginBaseNode) {
46                         return createLibrary(parent);
47                     }
48                 }
49             }
50             
51             
52         }
53         return createElement(name, parent);
54     }
55     
56     /**
57      * @param parent
58      * @return
59      */

60     private IDocumentNode createLibrary(IDocumentNode parent) {
61         PluginLibraryNode node = new PluginLibraryNode();
62         node.setParentNode(parent);
63         node.setModel(fModel);
64         node.setInTheModel(true);
65         return node;
66     }
67
68     /**
69      * @param parent
70      */

71     private IDocumentNode createImport(IDocumentNode parent) {
72         PluginImportNode node = new PluginImportNode();
73         node.setParentNode(parent);
74         node.setModel(fModel);
75         node.setInTheModel(true);
76         return node;
77     }
78
79     /**
80      * @param name
81      * @param parent
82      * @return
83      */

84     private IDocumentNode createElement(String JavaDoc name, IDocumentNode parent) {
85         PluginElementNode node = new PluginElementNode();
86         try {
87             node.setName(name);
88             node.setParentNode(parent);
89             node.setModel(fModel);
90             node.setInTheModel(true);
91         } catch (CoreException e) {
92         }
93         return node;
94     }
95
96     /**
97      * @param name
98      * @param parent
99      * @return
100      */

101     private PluginExtensionPointNode createExtensionPoint(IDocumentNode parent) {
102         PluginExtensionPointNode node = new PluginExtensionPointNode();
103         node.setParentNode(parent);
104         node.setModel(fModel);
105         node.setInTheModel(true);
106         return node;
107     }
108
109     /**
110      * @param name
111      * @return
112      */

113     private PluginExtensionNode createExtension(IDocumentNode parent) {
114         PluginExtensionNode node = new PluginExtensionNode();
115         node.setParentNode(parent);
116         node.setModel(fModel);
117         node.setInTheModel(true);
118         return node;
119     }
120
121     public IDocumentAttribute createAttribute(String JavaDoc name, String JavaDoc value, IDocumentNode enclosingElement) {
122         PluginAttribute attribute = new PluginAttribute();
123         try {
124             attribute.setName(name);
125             attribute.setValue(value);
126         } catch (CoreException e) {
127         }
128         attribute.setEnclosingElement(enclosingElement);
129         attribute.setModel(fModel);
130         attribute.setInTheModel(true);
131         return attribute;
132     }
133     
134     private PluginBaseNode createPluginBase(String JavaDoc name) {
135         return (PluginBaseNode)fModel.createPluginBase(name.equals("fragment")); //$NON-NLS-1$
136

137     }
138
139     /* (non-Javadoc)
140      * @see org.eclipse.pde.core.plugin.IPluginModelFactory#createImport()
141      */

142     public IPluginImport createImport() {
143         PluginImportNode node = new PluginImportNode();
144         node.setModel(fModel);
145         node.setXMLTagName("import"); //$NON-NLS-1$
146
return node;
147     }
148
149     /* (non-Javadoc)
150      * @see org.eclipse.pde.core.plugin.IPluginModelFactory#createLibrary()
151      */

152     public IPluginLibrary createLibrary() {
153         PluginLibraryNode node = new PluginLibraryNode();
154         node.setModel(fModel);
155         node.setXMLTagName("library"); //$NON-NLS-1$
156
return node;
157     }
158
159     /* (non-Javadoc)
160      * @see org.eclipse.pde.core.plugin.IExtensionsModelFactory#createAttribute(org.eclipse.pde.core.plugin.IPluginElement)
161      */

162     public IPluginAttribute createAttribute(IPluginElement element) {
163         return null;
164     }
165
166     /* (non-Javadoc)
167      * @see org.eclipse.pde.core.plugin.IExtensionsModelFactory#createElement(org.eclipse.pde.core.plugin.IPluginObject)
168      */

169     public IPluginElement createElement(IPluginObject parent) {
170         PluginElementNode node = new PluginElementNode();
171         node.setModel(fModel);
172         node.setParentNode((IDocumentNode)parent);
173         return node;
174     }
175
176     /* (non-Javadoc)
177      * @see org.eclipse.pde.core.plugin.IExtensionsModelFactory#createExtension()
178      */

179     public IPluginExtension createExtension() {
180         PluginExtensionNode node = new PluginExtensionNode();
181         node.setModel(fModel);
182         node.setXMLTagName("extension"); //$NON-NLS-1$
183
return node;
184     }
185
186     /* (non-Javadoc)
187      * @see org.eclipse.pde.core.plugin.IExtensionsModelFactory#createExtensionPoint()
188      */

189     public IPluginExtensionPoint createExtensionPoint() {
190         PluginExtensionPointNode node = new PluginExtensionPointNode();
191         node.setModel(fModel);
192         node.setXMLTagName("extension-point"); //$NON-NLS-1$
193
return node;
194     }
195 }
196
Popular Tags