KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > plugin > PluginAttribute


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.core.plugin;
12
13 import java.io.PrintWriter JavaDoc;
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 JavaDoc;
21
22 public class PluginAttribute extends PluginObject implements IPluginAttribute {
23     private static final long serialVersionUID = 1L;
24
25     protected String JavaDoc 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 JavaDoc clone() {
41         return new PluginAttribute(this);
42     }
43
44     public boolean equals(Object JavaDoc 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 JavaDoc getValue() {
79         return fValue;
80     }
81
82     void load(Node JavaDoc 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 JavaDoc newValue) throws CoreException {
92         ensureModelEditable();
93         String JavaDoc 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 JavaDoc indent, PrintWriter JavaDoc writer) {
101         if (fValue == null)
102             return;
103         writer.print(indent);
104         writer.print(getName() + "=\"" + getWritableString(fValue) + "\""); //$NON-NLS-1$ //$NON-NLS-2$
105
}
106 }
107
Popular Tags