KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.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 JavaDoc;
23 import org.w3c.dom.NodeList JavaDoc;
24
25 public class PluginExtension extends PluginParent implements IPluginExtension {
26
27     private static final long serialVersionUID = 1L;
28     protected String JavaDoc fPoint;
29     private transient ISchema schema;
30
31     public PluginExtension() {
32     }
33     public String JavaDoc getPoint() {
34         return fPoint;
35     }
36     
37     public boolean isValid() {
38         return fPoint != null;
39     }
40         
41     public Object JavaDoc 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 JavaDoc node) {
52         this.fID = getNodeAttribute(node, "id"); //$NON-NLS-1$
53
fName = getNodeAttribute(node, "name"); //$NON-NLS-1$
54
fPoint = getNodeAttribute(node, "point"); //$NON-NLS-1$
55
NodeList JavaDoc children = node.getChildNodes();
56         for (int i = 0; i < children.getLength(); i++) {
57             Node JavaDoc 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")); //$NON-NLS-1$
68
}
69
70     public boolean equals(Object JavaDoc 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             // Objects from the same model must be
78
// binary equal
79
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             // Children
88
return super.equals(obj);
89         }
90         return false;
91     }
92
93     public void setPoint(String JavaDoc point) throws CoreException {
94         ensureModelEditable();
95         String JavaDoc oldValue = fPoint;
96         fPoint = point;
97         firePropertyChanged(P_POINT, oldValue, point);
98     }
99
100     public void restoreProperty(String JavaDoc name, Object JavaDoc oldValue, Object JavaDoc 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 JavaDoc toString() {
110         if (getName() != null)
111             return getName();
112         return getPoint();
113     }
114     public void write(String JavaDoc indent, PrintWriter JavaDoc writer) {
115         writer.print(indent);
116         writer.print("<extension"); //$NON-NLS-1$
117
String JavaDoc attIndent = indent + PluginElement.ATTRIBUTE_SHIFT;
118         if (getId() != null) {
119             writer.println();
120             writer.print(attIndent + "id=\"" + getId() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
121
}
122         if (getName() != null) {
123             writer.println();
124             writer.print(
125                 attIndent + "name=\"" + getWritableString(getName()) + "\""); //$NON-NLS-1$ //$NON-NLS-2$
126
}
127         if (getPoint() != null) {
128             writer.println();
129             writer.print(attIndent + "point=\"" + getPoint() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
130
}
131         writer.println(">"); //$NON-NLS-1$
132
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>"); //$NON-NLS-1$
138
}
139 }
140
Popular Tags