KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > text > plugin > PluginDocumentNodeFactory


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.text.plugin;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.pde.core.plugin.IPluginAttribute;
15 import org.eclipse.pde.core.plugin.IPluginElement;
16 import org.eclipse.pde.core.plugin.IPluginExtension;
17 import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
18 import org.eclipse.pde.core.plugin.IPluginImport;
19 import org.eclipse.pde.core.plugin.IPluginLibrary;
20 import org.eclipse.pde.core.plugin.IPluginModelFactory;
21 import org.eclipse.pde.core.plugin.IPluginObject;
22 import org.eclipse.pde.internal.core.text.IDocumentAttribute;
23 import org.eclipse.pde.internal.core.text.IDocumentNode;
24
25 public class PluginDocumentNodeFactory implements IPluginModelFactory {
26     
27     private PluginModelBase fModel;
28
29     public PluginDocumentNodeFactory(PluginModelBase model) {
30         fModel = model;
31     }
32     
33     public IDocumentNode createDocumentNode(String JavaDoc name, IDocumentNode parent) {
34         if (parent == null)
35             return createPluginBase(name);
36         
37         if (parent instanceof PluginBaseNode) {
38             if ("extension".equals(name)) //$NON-NLS-1$
39
return (IDocumentNode)createExtension();
40             if ("extension-point".equals(name)) //$NON-NLS-1$
41
return (IDocumentNode)createExtensionPoint();
42         } else {
43             if (name.equals("import") && parent instanceof PluginElementNode) { //$NON-NLS-1$
44
if (((PluginElementNode)parent).getName().equals("requires")) { //$NON-NLS-1$
45
IDocumentNode ancestor = parent.getParentNode();
46                     if (ancestor != null && ancestor instanceof PluginBaseNode) {
47                         return (IDocumentNode)createImport();
48                     }
49                 }
50             } else if (name.equals("library") && parent instanceof PluginElementNode) { //$NON-NLS-1$
51
if (((PluginElementNode)parent).getName().equals("runtime")) { //$NON-NLS-1$
52
IDocumentNode ancestor = parent.getParentNode();
53                     if (ancestor != null && ancestor instanceof PluginBaseNode) {
54                         return (IDocumentNode)createLibrary();
55                     }
56                 }
57             }
58         }
59         IDocumentNode node = (IDocumentNode)createElement((IPluginObject)parent);
60         node.setXMLTagName(name);
61         return node;
62     }
63     
64     public IDocumentAttribute createAttribute(String JavaDoc name, String JavaDoc value, IDocumentNode enclosingElement) {
65         PluginAttribute attribute = new PluginAttribute();
66         try {
67             attribute.setName(name);
68             attribute.setValue(value);
69         } catch (CoreException e) {
70         }
71         attribute.setEnclosingElement(enclosingElement);
72         attribute.setModel(fModel);
73         attribute.setInTheModel(true);
74         return attribute;
75     }
76     
77     private PluginBaseNode createPluginBase(String JavaDoc name) {
78         return (PluginBaseNode)fModel.createPluginBase(name.equals("fragment")); //$NON-NLS-1$
79

80     }
81
82     /* (non-Javadoc)
83      * @see org.eclipse.pde.core.plugin.IPluginModelFactory#createImport()
84      */

85     public IPluginImport createImport() {
86         PluginImportNode node = new PluginImportNode();
87         node.setModel(fModel);
88         node.setXMLTagName("import"); //$NON-NLS-1$
89
return node;
90     }
91     
92     public IPluginImport createImport(String JavaDoc pluginId) {
93         PluginImportNode node = new PluginImportNode(pluginId);
94         node.setModel(fModel);
95         node.setXMLTagName("import"); //$NON-NLS-1$
96
return node;
97     }
98
99     /* (non-Javadoc)
100      * @see org.eclipse.pde.core.plugin.IPluginModelFactory#createLibrary()
101      */

102     public IPluginLibrary createLibrary() {
103         PluginLibraryNode node = new PluginLibraryNode();
104         node.setModel(fModel);
105         node.setXMLTagName("library"); //$NON-NLS-1$
106
return node;
107     }
108
109     /* (non-Javadoc)
110      * @see org.eclipse.pde.core.plugin.IExtensionsModelFactory#createAttribute(org.eclipse.pde.core.plugin.IPluginElement)
111      */

112     public IPluginAttribute createAttribute(IPluginElement element) {
113         return null;
114     }
115
116     /* (non-Javadoc)
117      * @see org.eclipse.pde.core.plugin.IExtensionsModelFactory#createElement(org.eclipse.pde.core.plugin.IPluginObject)
118      */

119     public IPluginElement createElement(IPluginObject parent) {
120         PluginElementNode node = new PluginElementNode();
121         node.setModel(fModel);
122         return node;
123     }
124
125     /* (non-Javadoc)
126      * @see org.eclipse.pde.core.plugin.IExtensionsModelFactory#createExtension()
127      */

128     public IPluginExtension createExtension() {
129         PluginExtensionNode node = new PluginExtensionNode();
130         node.setModel(fModel);
131         node.setXMLTagName("extension"); //$NON-NLS-1$
132
return node;
133     }
134
135     /* (non-Javadoc)
136      * @see org.eclipse.pde.core.plugin.IExtensionsModelFactory#createExtensionPoint()
137      */

138     public IPluginExtensionPoint createExtensionPoint() {
139         PluginExtensionPointNode node = new PluginExtensionPointNode();
140         node.setModel(fModel);
141         node.setXMLTagName("extension-point"); //$NON-NLS-1$
142
return node;
143     }
144 }
145
Popular Tags