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.IPluginAttribute; 17 import org.eclipse.pde.internal.core.ischema.ISchema; 18 import org.eclipse.pde.internal.core.ischema.ISchemaAttribute; 19 import org.eclipse.pde.internal.core.ischema.ISchemaElement; 20 import org.w3c.dom.Node ; 21 22 public class PluginAttribute extends PluginObject implements IPluginAttribute { 23 private static final long serialVersionUID = 1L; 24 25 protected String fValue; 26 27 private transient ISchemaAttribute attributeInfo; 28 29 public PluginAttribute() { 30 } 31 32 PluginAttribute(IPluginAttribute attribute) { 33 setModel(attribute.getModel()); 34 setParent(attribute.getParent()); 35 fName = attribute.getName(); 36 fValue = attribute.getValue(); 37 this.attributeInfo = ((PluginAttribute) attribute).getAttributeInfo(); 38 } 39 40 public Object clone() { 41 return new PluginAttribute(this); 42 } 43 44 public boolean equals(Object obj) { 45 if (obj == this) 46 return true; 47 if (obj == null) 48 return false; 49 if (obj instanceof IPluginAttribute) { 50 IPluginAttribute target = (IPluginAttribute) obj; 51 if (target.getModel().equals(getModel())) 52 return false; 53 if (stringEqualWithNull(getName(), target.getName()) 54 && stringEqualWithNull(getValue(), target.getValue())) 55 return true; 56 } 57 return false; 58 } 59 60 public ISchemaAttribute getAttributeInfo() { 61 if (attributeInfo != null) { 62 ISchema schema = attributeInfo.getSchema(); 63 if (schema.isDisposed()) { 64 attributeInfo = null; 65 } 66 } 67 if (attributeInfo == null) { 68 PluginElement element = (PluginElement) getParent(); 69 ISchemaElement elementInfo = (ISchemaElement) element 70 .getElementInfo(); 71 if (elementInfo != null) { 72 attributeInfo = elementInfo.getAttribute(getName()); 73 } 74 } 75 return attributeInfo; 76 } 77 78 public String getValue() { 79 return fValue; 80 } 81 82 void load(Node node) { 83 fName = node.getNodeName(); 84 fValue = node.getNodeValue(); 85 } 86 87 public void setAttributeInfo(ISchemaAttribute newAttributeInfo) { 88 attributeInfo = newAttributeInfo; 89 } 90 91 public void setValue(String newValue) throws CoreException { 92 ensureModelEditable(); 93 String oldValue = fValue; 94 fValue = newValue; 95 AttributeChangedEvent e = new AttributeChangedEvent(getModel(), 96 getParent(), this, oldValue, newValue); 97 fireModelChanged(e); 98 } 99 100 public void write(String indent, PrintWriter writer) { 101 if (fValue == null) 102 return; 103 writer.print(indent); 104 writer.print(getName() + "=\"" + getWritableString(fValue) + "\""); } 106 } 107 | Popular Tags |