1 11 package org.eclipse.pde.internal.core.plugin; 12 13 import java.io.PrintWriter ; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.pde.core.plugin.IPluginElement; 17 import org.eclipse.pde.core.plugin.IPluginExtension; 18 import org.eclipse.pde.core.plugin.IPluginObject; 19 import org.eclipse.pde.internal.core.PDECore; 20 import org.eclipse.pde.internal.core.ischema.ISchema; 21 import org.eclipse.pde.internal.core.schema.SchemaRegistry; 22 import org.w3c.dom.Node ; 23 import org.w3c.dom.NodeList ; 24 25 public class PluginExtension extends PluginParent implements IPluginExtension { 26 27 private static final long serialVersionUID = 1L; 28 protected String fPoint; 29 private transient ISchema schema; 30 31 public PluginExtension() { 32 } 33 public String getPoint() { 34 return fPoint; 35 } 36 37 public boolean isValid() { 38 return fPoint != null; 39 } 40 41 public Object getSchema() { 42 if (schema == null) { 43 SchemaRegistry registry = PDECore.getDefault().getSchemaRegistry(); 44 schema = registry.getSchema(fPoint); 45 } else if (schema.isDisposed()) { 46 schema = null; 47 } 48 return schema; 49 } 50 51 void load(Node node) { 52 this.fID = getNodeAttribute(node, "id"); fName = getNodeAttribute(node, "name"); fPoint = getNodeAttribute(node, "point"); NodeList children = node.getChildNodes(); 56 for (int i = 0; i < children.getLength(); i++) { 57 Node child = children.item(i); 58 if (child.getNodeType() == Node.ELEMENT_NODE) { 59 PluginElement childElement = new PluginElement(); 60 childElement.setModel(getModel()); 61 childElement.setInTheModel(true); 62 childElement.setParent(this); 63 this.fChildren.add(childElement); 64 childElement.load(child); 65 } 66 } 67 fStartLine = Integer.parseInt(getNodeAttribute(node, "line")); } 69 70 public boolean equals(Object obj) { 71 if (obj == this) 72 return true; 73 if (obj == null) 74 return false; 75 if (obj instanceof IPluginExtension) { 76 IPluginExtension target = (IPluginExtension) obj; 77 if (target.getModel().equals(getModel())) 80 return false; 81 if (!stringEqualWithNull(target.getId(), getId())) 82 return false; 83 if (!stringEqualWithNull(target.getName(), getName())) 84 return false; 85 if (!stringEqualWithNull(target.getPoint(), getPoint())) 86 return false; 87 return super.equals(obj); 89 } 90 return false; 91 } 92 93 public void setPoint(String point) throws CoreException { 94 ensureModelEditable(); 95 String oldValue = fPoint; 96 fPoint = point; 97 firePropertyChanged(P_POINT, oldValue, point); 98 } 99 100 public void restoreProperty(String name, Object oldValue, Object newValue) 101 throws CoreException { 102 if (name.equals(P_POINT)) { 103 setPoint(newValue != null ? newValue.toString() : null); 104 return; 105 } 106 super.restoreProperty(name, oldValue, newValue); 107 } 108 109 public String toString() { 110 if (getName() != null) 111 return getName(); 112 return getPoint(); 113 } 114 public void write(String indent, PrintWriter writer) { 115 writer.print(indent); 116 writer.print("<extension"); String attIndent = indent + PluginElement.ATTRIBUTE_SHIFT; 118 if (getId() != null) { 119 writer.println(); 120 writer.print(attIndent + "id=\"" + getId() + "\""); } 122 if (getName() != null) { 123 writer.println(); 124 writer.print( 125 attIndent + "name=\"" + getWritableString(getName()) + "\""); } 127 if (getPoint() != null) { 128 writer.println(); 129 writer.print(attIndent + "point=\"" + getPoint() + "\""); } 131 writer.println(">"); IPluginObject[] children = getChildren(); 133 for (int i = 0; i < children.length; i++) { 134 IPluginElement child = (IPluginElement) children[i]; 135 child.write(indent + PluginElement.ELEMENT_SHIFT, writer); 136 } 137 writer.println(indent + "</extension>"); } 139 } 140 | Popular Tags |