1 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 name, IDocumentNode parent) { 26 if (parent == null) 27 return createPluginBase(name); 28 29 if (parent instanceof PluginBaseNode) { 30 if ("extension".equals(name)) return createExtension(parent); 32 if ("extension-point".equals(name)) return createExtensionPoint(parent); 34 } else { 35 if (name.equals("import") && parent instanceof PluginElementNode) { if (((PluginElementNode)parent).getName().equals("requires")) { 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) { if (((PluginElementNode)parent).getName().equals("runtime")) { 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 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 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 84 private IDocumentNode createElement(String 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 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 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 name, String 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 name) { 135 return (PluginBaseNode)fModel.createPluginBase(name.equals("fragment")); 137 } 138 139 142 public IPluginImport createImport() { 143 PluginImportNode node = new PluginImportNode(); 144 node.setModel(fModel); 145 node.setXMLTagName("import"); return node; 147 } 148 149 152 public IPluginLibrary createLibrary() { 153 PluginLibraryNode node = new PluginLibraryNode(); 154 node.setModel(fModel); 155 node.setXMLTagName("library"); return node; 157 } 158 159 162 public IPluginAttribute createAttribute(IPluginElement element) { 163 return null; 164 } 165 166 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 179 public IPluginExtension createExtension() { 180 PluginExtensionNode node = new PluginExtensionNode(); 181 node.setModel(fModel); 182 node.setXMLTagName("extension"); return node; 184 } 185 186 189 public IPluginExtensionPoint createExtensionPoint() { 190 PluginExtensionPointNode node = new PluginExtensionPointNode(); 191 node.setModel(fModel); 192 node.setXMLTagName("extension-point"); return node; 194 } 195 } 196 | Popular Tags |