1 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 name, IDocumentNode parent) { 34 if (parent == null) 35 return createPluginBase(name); 36 37 if (parent instanceof PluginBaseNode) { 38 if ("extension".equals(name)) return (IDocumentNode)createExtension(); 40 if ("extension-point".equals(name)) return (IDocumentNode)createExtensionPoint(); 42 } else { 43 if (name.equals("import") && parent instanceof PluginElementNode) { if (((PluginElementNode)parent).getName().equals("requires")) { 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) { if (((PluginElementNode)parent).getName().equals("runtime")) { 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 name, String 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 name) { 78 return (PluginBaseNode)fModel.createPluginBase(name.equals("fragment")); 80 } 81 82 85 public IPluginImport createImport() { 86 PluginImportNode node = new PluginImportNode(); 87 node.setModel(fModel); 88 node.setXMLTagName("import"); return node; 90 } 91 92 public IPluginImport createImport(String pluginId) { 93 PluginImportNode node = new PluginImportNode(pluginId); 94 node.setModel(fModel); 95 node.setXMLTagName("import"); return node; 97 } 98 99 102 public IPluginLibrary createLibrary() { 103 PluginLibraryNode node = new PluginLibraryNode(); 104 node.setModel(fModel); 105 node.setXMLTagName("library"); return node; 107 } 108 109 112 public IPluginAttribute createAttribute(IPluginElement element) { 113 return null; 114 } 115 116 119 public IPluginElement createElement(IPluginObject parent) { 120 PluginElementNode node = new PluginElementNode(); 121 node.setModel(fModel); 122 return node; 123 } 124 125 128 public IPluginExtension createExtension() { 129 PluginExtensionNode node = new PluginExtensionNode(); 130 node.setModel(fModel); 131 node.setXMLTagName("extension"); return node; 133 } 134 135 138 public IPluginExtensionPoint createExtensionPoint() { 139 PluginExtensionPointNode node = new PluginExtensionPointNode(); 140 node.setModel(fModel); 141 node.setXMLTagName("extension-point"); return node; 143 } 144 } 145 | Popular Tags |