001: /*******************************************************************************
002: * Copyright (c) 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;
011:
012: import org.eclipse.core.runtime.CoreException;
013: import org.eclipse.pde.internal.core.util.PDEXMLHelper;
014:
015: /**
016: * DocumentAttributeNode
017: *
018: */
019: public class DocumentAttributeNode extends DocumentXMLNode implements
020: IDocumentAttributeNode {
021:
022: private static final long serialVersionUID = 1L;
023:
024: private transient IDocumentElementNode fEnclosingElement;
025: private transient int fNameOffset;
026: private transient int fNameLength;
027: private transient int fValueOffset;
028: private transient int fValueLength;
029:
030: private String fValue;
031: private String fName;
032:
033: /**
034: *
035: */
036: public DocumentAttributeNode() {
037: fEnclosingElement = null;
038: fNameOffset = -1;
039: fNameLength = -1;
040: fValueOffset = -1;
041: fValueLength = -1;
042: fValue = null;
043: fName = null;
044: }
045:
046: /* (non-Javadoc)
047: * @see org.eclipse.pde.internal.core.text.IDocumentAttributeNode#getAttributeName()
048: */
049: public String getAttributeName() {
050: return fName;
051: }
052:
053: /* (non-Javadoc)
054: * @see org.eclipse.pde.internal.core.text.IDocumentAttributeNode#getAttributeValue()
055: */
056: public String getAttributeValue() {
057: return fValue;
058: }
059:
060: /* (non-Javadoc)
061: * @see org.eclipse.pde.internal.core.text.IDocumentAttributeNode#getEnclosingElement()
062: */
063: public IDocumentElementNode getEnclosingElement() {
064: return fEnclosingElement;
065: }
066:
067: /* (non-Javadoc)
068: * @see org.eclipse.pde.internal.core.text.IDocumentAttributeNode#getNameLength()
069: */
070: public int getNameLength() {
071: return fNameLength;
072: }
073:
074: /* (non-Javadoc)
075: * @see org.eclipse.pde.internal.core.text.IDocumentAttributeNode#getNameOffset()
076: */
077: public int getNameOffset() {
078: return fNameOffset;
079: }
080:
081: /* (non-Javadoc)
082: * @see org.eclipse.pde.internal.core.text.IDocumentAttributeNode#getValueLength()
083: */
084: public int getValueLength() {
085: return fValueLength;
086: }
087:
088: /* (non-Javadoc)
089: * @see org.eclipse.pde.internal.core.text.IDocumentAttributeNode#getValueOffset()
090: */
091: public int getValueOffset() {
092: return fValueOffset;
093: }
094:
095: /* (non-Javadoc)
096: * @see org.eclipse.pde.internal.core.text.IDocumentAttributeNode#setAttributeName(java.lang.String)
097: */
098: public void setAttributeName(String name) throws CoreException {
099: fName = name;
100: }
101:
102: /* (non-Javadoc)
103: * @see org.eclipse.pde.internal.core.text.IDocumentAttributeNode#setAttributeValue(java.lang.String)
104: */
105: public void setAttributeValue(String value) throws CoreException {
106: fValue = value;
107: }
108:
109: /* (non-Javadoc)
110: * @see org.eclipse.pde.internal.core.text.IDocumentAttributeNode#setEnclosingElement(org.eclipse.pde.internal.core.text.IDocumentElementNode)
111: */
112: public void setEnclosingElement(IDocumentElementNode node) {
113: fEnclosingElement = node;
114: }
115:
116: /* (non-Javadoc)
117: * @see org.eclipse.pde.internal.core.text.IDocumentAttributeNode#setNameLength(int)
118: */
119: public void setNameLength(int length) {
120: fNameLength = length;
121: }
122:
123: /* (non-Javadoc)
124: * @see org.eclipse.pde.internal.core.text.IDocumentAttributeNode#setNameOffset(int)
125: */
126: public void setNameOffset(int offset) {
127: fNameOffset = offset;
128: }
129:
130: /* (non-Javadoc)
131: * @see org.eclipse.pde.internal.core.text.IDocumentAttributeNode#setValueLength(int)
132: */
133: public void setValueLength(int length) {
134: fValueLength = length;
135: }
136:
137: /* (non-Javadoc)
138: * @see org.eclipse.pde.internal.core.text.IDocumentAttributeNode#setValueOffset(int)
139: */
140: public void setValueOffset(int offset) {
141: fValueOffset = offset;
142: }
143:
144: /* (non-Javadoc)
145: * @see org.eclipse.pde.internal.core.text.IDocumentAttributeNode#write()
146: */
147: public String write() {
148: return fName + "=\"" + //$NON-NLS-1$
149: PDEXMLHelper.getWritableAttributeString(fValue) + "\""; //$NON-NLS-1$
150: }
151:
152: /* (non-Javadoc)
153: * @see org.eclipse.pde.internal.core.text.IDocumentAttributeNode#reconnect(org.eclipse.pde.internal.core.text.IDocumentElementNode)
154: */
155: public void reconnect(IDocumentElementNode parent) {
156: // Transient field: Enclosing element
157: // Essentially is the parent (an element)
158: // Note: Parent field from plugin document node parent seems to be
159: // null; but, we will set it any ways
160: fEnclosingElement = parent;
161: // Transient field: Name Length
162: fNameLength = -1;
163: // Transient field: Name Offset
164: fNameOffset = -1;
165: // Transient field: Value Length
166: fValueLength = -1;
167: // Transient field: Value Offset
168: fValueOffset = -1;
169: }
170:
171: /* (non-Javadoc)
172: * @see org.eclipse.pde.internal.core.text.IDocumentRange#getLength()
173: */
174: public int getLength() {
175: // Implemented for backwards compatibility with utility methods that
176: // assume that an attribute is a document range.
177: // Stems from the problem that attributes are considered as elements
178: // in the hierarchy in the manifest model
179:
180: // Includes: name length + equal + start quote
181: int len1 = getValueOffset() - getNameOffset();
182: // Includes: value length
183: int len2 = getValueLength();
184: // Includes: end quote
185: int len3 = 1;
186: // Total
187: int length = len1 + len2 + len3;
188:
189: return length;
190: }
191:
192: /* (non-Javadoc)
193: * @see org.eclipse.pde.internal.core.text.IDocumentRange#getOffset()
194: */
195: public int getOffset() {
196: // Implemented for backwards compatibility with utility methods that
197: // assume that an attribute is a document range.
198: // Stems from the problem that attributes are considered as elements
199: // in the hierarchy in the manifest model
200: return getNameOffset();
201: }
202:
203: /* (non-Javadoc)
204: * @see org.eclipse.pde.internal.core.text.IDocumentXMLNode#getXMLType()
205: */
206: public int getXMLType() {
207: return F_TYPE_ATTRIBUTE;
208: }
209:
210: }
|