001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.core.plugin;
011:
012: import java.io.PrintWriter;
013:
014: import org.eclipse.core.runtime.CoreException;
015: import org.eclipse.pde.core.plugin.IPluginAttribute;
016: import org.eclipse.pde.internal.core.ischema.ISchema;
017: import org.eclipse.pde.internal.core.ischema.ISchemaAttribute;
018: import org.eclipse.pde.internal.core.ischema.ISchemaElement;
019: import org.w3c.dom.Node;
020:
021: public class PluginAttribute extends PluginObject implements
022: IPluginAttribute {
023: private static final long serialVersionUID = 1L;
024:
025: protected String fValue;
026:
027: private transient ISchemaAttribute attributeInfo;
028:
029: public PluginAttribute() {
030: }
031:
032: PluginAttribute(IPluginAttribute attribute) {
033: setModel(attribute.getModel());
034: setParent(attribute.getParent());
035: fName = attribute.getName();
036: fValue = attribute.getValue();
037: this .attributeInfo = ((PluginAttribute) attribute)
038: .getAttributeInfo();
039: }
040:
041: public Object clone() {
042: return new PluginAttribute(this );
043: }
044:
045: public boolean equals(Object obj) {
046: if (obj == this )
047: return true;
048: if (obj == null)
049: return false;
050: if (obj instanceof IPluginAttribute) {
051: IPluginAttribute target = (IPluginAttribute) obj;
052: if (target.getModel().equals(getModel()))
053: return false;
054: if (stringEqualWithNull(getName(), target.getName())
055: && stringEqualWithNull(getValue(), target
056: .getValue()))
057: return true;
058: }
059: return false;
060: }
061:
062: public ISchemaAttribute getAttributeInfo() {
063: if (attributeInfo != null) {
064: ISchema schema = attributeInfo.getSchema();
065: if (schema.isDisposed()) {
066: attributeInfo = null;
067: }
068: }
069: if (attributeInfo == null) {
070: PluginElement element = (PluginElement) getParent();
071: ISchemaElement elementInfo = (ISchemaElement) element
072: .getElementInfo();
073: if (elementInfo != null) {
074: attributeInfo = elementInfo.getAttribute(getName());
075: }
076: }
077: return attributeInfo;
078: }
079:
080: public String getValue() {
081: return fValue;
082: }
083:
084: void load(Node node) {
085: fName = node.getNodeName();
086: fValue = node.getNodeValue();
087: }
088:
089: void load(String name, String value) {
090: fName = name;
091: fValue = value;
092: }
093:
094: public void setAttributeInfo(ISchemaAttribute newAttributeInfo) {
095: attributeInfo = newAttributeInfo;
096: }
097:
098: public void setValue(String newValue) throws CoreException {
099: ensureModelEditable();
100: String oldValue = fValue;
101: fValue = newValue;
102: AttributeChangedEvent e = new AttributeChangedEvent(getModel(),
103: getParent(), this , oldValue, newValue);
104: fireModelChanged(e);
105: }
106:
107: public void write(String indent, PrintWriter writer) {
108: if (fValue == null)
109: return;
110: writer.print(indent);
111: writer.print(getName()
112: + "=\"" + getWritableString(fValue) + "\""); //$NON-NLS-1$ //$NON-NLS-2$
113: }
114: }
|