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.text.plugin;
011:
012: import java.io.PrintWriter;
013:
014: import org.eclipse.core.runtime.CoreException;
015: import org.eclipse.pde.core.IModel;
016: import org.eclipse.pde.core.plugin.IPluginExtension;
017: import org.eclipse.pde.internal.core.PDECore;
018: import org.eclipse.pde.internal.core.ischema.ISchema;
019: import org.eclipse.pde.internal.core.schema.SchemaRegistry;
020: import org.eclipse.pde.internal.core.text.IDocumentAttributeNode;
021: import org.eclipse.pde.internal.core.text.IDocumentElementNode;
022:
023: public class PluginExtensionNode extends PluginParentNode implements
024: IPluginExtension {
025:
026: private static final long serialVersionUID = 1L;
027: private transient ISchema fSchema;
028:
029: /* (non-Javadoc)
030: * @see org.eclipse.pde.core.plugin.IPluginExtension#getPoint()
031: */
032: public String getPoint() {
033: return getXMLAttributeValue(P_POINT);
034: }
035:
036: /* (non-Javadoc)
037: * @see org.eclipse.pde.core.plugin.IPluginExtension#setPoint(java.lang.String)
038: */
039: public void setPoint(String point) throws CoreException {
040: setXMLAttribute(P_POINT, point);
041: }
042:
043: /* (non-Javadoc)
044: * @see org.eclipse.pde.core.plugin.IPluginObject#setName(java.lang.String)
045: */
046: public void setName(String name) throws CoreException {
047: setXMLAttribute(P_NAME, name);
048: }
049:
050: /* (non-Javadoc)
051: * @see org.eclipse.pde.core.plugin.IPluginObject#getName()
052: */
053: public String getName() {
054: return getXMLAttributeValue(P_NAME);
055: }
056:
057: /* (non-Javadoc)
058: * @see org.eclipse.pde.core.plugin.IPluginObject#getTranslatedName()
059: */
060: public String getTranslatedName() {
061: String name = getName();
062: if (name != null && name.trim().length() > 0)
063: return getResourceString(name);
064: String point = getPoint();
065: ISchema schema = PDECore.getDefault().getSchemaRegistry()
066: .getSchema(point);
067: return schema == null ? "" : schema.getName(); //$NON-NLS-1$
068: }
069:
070: /* (non-Javadoc)
071: * @see org.eclipse.pde.core.IIdentifiable#getId()
072: */
073: public String getId() {
074: return getXMLAttributeValue(P_ID);
075: }
076:
077: /* (non-Javadoc)
078: * @see org.eclipse.pde.core.IIdentifiable#setId(java.lang.String)
079: */
080: public void setId(String id) throws CoreException {
081: setXMLAttribute(P_ID, id);
082: }
083:
084: /* (non-Javadoc)
085: * @see org.eclipse.pde.internal.ui.model.plugin.PluginObjectNode#write()
086: */
087: public String write(boolean indent) {
088: String sep = getLineDelimiter();
089: StringBuffer buffer = new StringBuffer();
090: if (indent)
091: buffer.append(getIndent());
092: buffer.append(writeShallow(false));
093: IDocumentElementNode[] children = getChildNodes();
094: for (int i = 0; i < children.length; i++) {
095: children[i].setLineIndent(getLineIndent() + 3);
096: buffer.append(sep + children[i].write(true));
097: }
098: buffer.append(sep + getIndent() + "</extension>"); //$NON-NLS-1$
099: return buffer.toString();
100: }
101:
102: /* (non-Javadoc)
103: * @see org.eclipse.pde.internal.core.text.plugin.PluginObjectNode#write(java.lang.String, java.io.PrintWriter)
104: */
105: public void write(String indent, PrintWriter writer) {
106: // Used for text transfers for copy, cut, paste operations
107: writer.write(write(true));
108: }
109:
110: /* (non-Javadoc)
111: * @see org.eclipse.pde.internal.ui.model.plugin.PluginObjectNode#writeShallow(boolean)
112: */
113: public String writeShallow(boolean terminate) {
114: String sep = getLineDelimiter();
115: String attrIndent = " "; //$NON-NLS-1$
116: StringBuffer buffer = new StringBuffer("<extension"); //$NON-NLS-1$
117: IDocumentAttributeNode attr = getDocumentAttribute(P_ID);
118: if (attr != null
119: && attr.getAttributeValue().trim().length() > 0)
120: buffer
121: .append(sep + getIndent() + attrIndent
122: + attr.write());
123: attr = getDocumentAttribute(P_NAME);
124: if (attr != null
125: && attr.getAttributeValue().trim().length() > 0)
126: buffer
127: .append(sep + getIndent() + attrIndent
128: + attr.write());
129: attr = getDocumentAttribute(P_POINT);
130: if (attr != null
131: && attr.getAttributeValue().trim().length() > 0)
132: buffer
133: .append(sep + getIndent() + attrIndent
134: + attr.write());
135: if (terminate)
136: buffer.append("/"); //$NON-NLS-1$
137: buffer.append(">"); //$NON-NLS-1$
138: return buffer.toString();
139: }
140:
141: /* (non-Javadoc)
142: * @see org.eclipse.pde.core.plugin.IPluginExtension#getSchema()
143: */
144: public Object getSchema() {
145: if (fSchema == null) {
146: SchemaRegistry registry = PDECore.getDefault()
147: .getSchemaRegistry();
148: fSchema = registry.getSchema(getPoint());
149: } else if (fSchema.isDisposed()) {
150: fSchema = null;
151: }
152: return fSchema;
153: }
154:
155: /* (non-Javadoc)
156: * @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.IDocumentElementNode)
157: */
158: public void reconnect(IDocumentElementNode parent, IModel model) {
159: super .reconnect(parent, model);
160: // Transient Field: Schema
161: // Not necessary to reconnect schema.
162: // getSchema will retrieve the schema on demand if it is null
163: fSchema = null;
164: }
165:
166: }
|