KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > text > plugin > PluginExtensionNode


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.text.plugin;
12
13 import java.io.PrintWriter JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.pde.core.plugin.IPluginExtension;
17 import org.eclipse.pde.core.plugin.ISharedPluginModel;
18 import org.eclipse.pde.internal.core.PDECore;
19 import org.eclipse.pde.internal.core.ischema.ISchema;
20 import org.eclipse.pde.internal.core.schema.SchemaRegistry;
21 import org.eclipse.pde.internal.core.text.IDocumentAttribute;
22 import org.eclipse.pde.internal.core.text.IDocumentNode;
23
24 public class PluginExtensionNode extends PluginParentNode implements
25         IPluginExtension, IDocumentExtension {
26     
27     private static final long serialVersionUID = 1L;
28     private transient ISchema fSchema;
29
30     /* (non-Javadoc)
31      * @see org.eclipse.pde.core.plugin.IPluginExtension#getPoint()
32      */

33     public String JavaDoc getPoint() {
34         return getXMLAttributeValue(P_POINT);
35     }
36     /* (non-Javadoc)
37      * @see org.eclipse.pde.core.plugin.IPluginExtension#setPoint(java.lang.String)
38      */

39     public void setPoint(String JavaDoc point) throws CoreException {
40         setXMLAttribute(P_POINT, point);
41     }
42     
43     /* (non-Javadoc)
44      * @see org.eclipse.pde.core.plugin.IPluginObject#setName(java.lang.String)
45      */

46     public void setName(String JavaDoc name) throws CoreException {
47         setXMLAttribute(P_NAME, name);
48     }
49     
50     /* (non-Javadoc)
51      * @see org.eclipse.pde.core.plugin.IPluginObject#getName()
52      */

53     public String JavaDoc getName() {
54         return getXMLAttributeValue(P_NAME);
55     }
56     
57     /* (non-Javadoc)
58      * @see org.eclipse.pde.core.plugin.IPluginObject#getTranslatedName()
59      */

60     public String JavaDoc getTranslatedName() {
61         String JavaDoc name = getName();
62         if (name != null && name.trim().length() > 0)
63             return getResourceString(name);
64         String JavaDoc point = getPoint();
65         ISchema schema = PDECore.getDefault().getSchemaRegistry().getSchema(point);
66         return schema == null ? "" : schema.getName(); //$NON-NLS-1$
67
}
68     /* (non-Javadoc)
69      * @see org.eclipse.pde.core.IIdentifiable#getId()
70      */

71     public String JavaDoc getId() {
72         return getXMLAttributeValue(P_ID);
73     }
74     /* (non-Javadoc)
75      * @see org.eclipse.pde.core.IIdentifiable#setId(java.lang.String)
76      */

77     public void setId(String JavaDoc id) throws CoreException {
78         setXMLAttribute(P_ID, id);
79     }
80     
81     /* (non-Javadoc)
82      * @see org.eclipse.pde.internal.ui.model.plugin.PluginObjectNode#write()
83      */

84     public String JavaDoc write(boolean indent) {
85         String JavaDoc sep = getLineDelimiter();
86         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
87         if (indent)
88             buffer.append(getIndent());
89         buffer.append(writeShallow(false));
90         IDocumentNode[] children = getChildNodes();
91         for (int i = 0; i < children.length; i++) {
92             children[i].setLineIndent(getLineIndent() + 3);
93             buffer.append(sep + children[i].write(true));
94         }
95         buffer.append(sep + getIndent() + "</extension>"); //$NON-NLS-1$
96
return buffer.toString();
97     }
98     
99     /* (non-Javadoc)
100      * @see org.eclipse.pde.internal.core.text.plugin.PluginObjectNode#write(java.lang.String, java.io.PrintWriter)
101      */

102     public void write(String JavaDoc indent, PrintWriter JavaDoc writer) {
103         // Used for text transfers for copy, cut, paste operations
104
writer.write(write(true));
105     }
106     
107     /* (non-Javadoc)
108      * @see org.eclipse.pde.internal.ui.model.plugin.PluginObjectNode#writeShallow(boolean)
109      */

110     public String JavaDoc writeShallow(boolean terminate) {
111         String JavaDoc sep = getLineDelimiter();
112         String JavaDoc attrIndent = " "; //$NON-NLS-1$
113
StringBuffer JavaDoc buffer = new StringBuffer JavaDoc("<extension"); //$NON-NLS-1$
114
IDocumentAttribute attr = getDocumentAttribute(P_ID);
115         if (attr != null && attr.getAttributeValue().trim().length() > 0)
116             buffer.append(sep + getIndent() + attrIndent + attr.write());
117         attr = getDocumentAttribute(P_NAME);
118         if (attr != null && attr.getAttributeValue().trim().length() > 0)
119             buffer.append(sep + getIndent() + attrIndent + attr.write());
120         attr = getDocumentAttribute(P_POINT);
121         if (attr != null && attr.getAttributeValue().trim().length() > 0)
122             buffer.append(sep + getIndent() + attrIndent + attr.write());
123         if (terminate)
124             buffer.append("/"); //$NON-NLS-1$
125
buffer.append(">"); //$NON-NLS-1$
126
return buffer.toString();
127     }
128     
129     /* (non-Javadoc)
130      * @see org.eclipse.pde.core.plugin.IPluginExtension#getSchema()
131      */

132     public Object JavaDoc getSchema() {
133         if (fSchema == null) {
134             SchemaRegistry registry = PDECore.getDefault().getSchemaRegistry();
135             fSchema = registry.getSchema(getPoint());
136         } else if (fSchema.isDisposed()) {
137             fSchema = null;
138         }
139         return fSchema;
140     }
141     
142     /* (non-Javadoc)
143      * @see org.eclipse.pde.internal.core.text.plugin.PluginObjectNode#reconnect(org.eclipse.pde.core.plugin.ISharedPluginModel, org.eclipse.pde.internal.core.ischema.ISchema, org.eclipse.pde.internal.core.text.IDocumentNode)
144      */

145     public void reconnect(ISharedPluginModel model, ISchema schema, IDocumentNode parent) {
146         super.reconnect(model, schema, parent);
147         // Transient Field: Schema
148
fSchema = schema;
149     }
150
151 }
152
Popular Tags