001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.tax.dom;
043:
044: import org.w3c.dom.*;
045: import org.netbeans.tax.*;
046:
047: /**
048: *
049: * @author Petr Kuzel
050: */
051: class CommentImpl extends NodeImpl implements Comment {
052:
053: private final TreeComment peer;
054:
055: /** Creates a new instance of AttrImpl */
056: public CommentImpl(TreeComment peer) {
057: this .peer = peer;
058: }
059:
060: /** Append the string to the end of the character data of the node. Upon
061: * success, <code>data</code> provides access to the concatenation of
062: * <code>data</code> and the <code>DOMString</code> specified.
063: * @param arg The <code>DOMString</code> to append.
064: * @exception DOMException
065: * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
066: *
067: */
068: public void appendData(String arg) throws DOMException {
069: throw new ROException();
070: }
071:
072: /** Remove a range of 16-bit units from the node. Upon success,
073: * <code>data</code> and <code>length</code> reflect the change.
074: * @param offset The offset from which to start removing.
075: * @param count The number of 16-bit units to delete. If the sum of
076: * <code>offset</code> and <code>count</code> exceeds
077: * <code>length</code> then all 16-bit units from <code>offset</code>
078: * to the end of the data are deleted.
079: * @exception DOMException
080: * INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is
081: * negative or greater than the number of 16-bit units in
082: * <code>data</code>, or if the specified <code>count</code> is
083: * negative.
084: * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
085: *
086: */
087: public void deleteData(int offset, int count) throws DOMException {
088: throw new ROException();
089: }
090:
091: /** The character data of the node that implements this interface. The DOM
092: * implementation may not put arbitrary limits on the amount of data
093: * that may be stored in a <code>CharacterData</code> node. However,
094: * implementation limits may mean that the entirety of a node's data may
095: * not fit into a single <code>DOMString</code>. In such cases, the user
096: * may call <code>substringData</code> to retrieve the data in
097: * appropriately sized pieces.
098: * @exception DOMException
099: * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
100: * @exception DOMException
101: * DOMSTRING_SIZE_ERR: Raised when it would return more characters than
102: * fit in a <code>DOMString</code> variable on the implementation
103: * platform.
104: *
105: */
106: public String getData() throws DOMException {
107: return peer.getData();
108: }
109:
110: /** The number of 16-bit units that are available through <code>data</code>
111: * and the <code>substringData</code> method below. This may have the
112: * value zero, i.e., <code>CharacterData</code> nodes may be empty.
113: *
114: */
115: public int getLength() {
116: return peer.getLength();
117: }
118:
119: /** The name of this node, depending on its type; see the table above.
120: *
121: */
122: public String getNodeName() {
123: return "#comment";
124: }
125:
126: /** A code representing the type of the underlying object, as defined above.
127: *
128: */
129: public short getNodeType() {
130: return Node.COMMENT_NODE;
131: }
132:
133: /** The value of this node, depending on its type; see the table above.
134: * When it is defined to be <code>null</code>, setting it has no effect.
135: * @exception DOMException
136: * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
137: * @exception DOMException
138: * DOMSTRING_SIZE_ERR: Raised when it would return more characters than
139: * fit in a <code>DOMString</code> variable on the implementation
140: * platform.
141: *
142: */
143: public String getNodeValue() throws DOMException {
144: return getData();
145: }
146:
147: /** The parent of this node. All nodes, except <code>Attr</code>,
148: * <code>Document</code>, <code>DocumentFragment</code>,
149: * <code>Entity</code>, and <code>Notation</code> may have a parent.
150: * However, if a node has just been created and not yet added to the
151: * tree, or if it has been removed from the tree, this is
152: * <code>null</code>.
153: *
154: */
155: public Node getParentNode() {
156:
157: TreeParentNode parent = peer.getParentNode();
158: if (parent == null) {
159: return null;
160: }
161:
162: Node result = null;
163: try {
164: result = Wrapper.wrap(parent);
165: } catch (RuntimeException ex) {
166: }
167:
168: return result;
169: }
170:
171: /** Insert a string at the specified 16-bit unit offset.
172: * @param offset The character offset at which to insert.
173: * @param arg The <code>DOMString</code> to insert.
174: * @exception DOMException
175: * INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is
176: * negative or greater than the number of 16-bit units in
177: * <code>data</code>.
178: * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
179: *
180: */
181: public void insertData(int offset, String arg) throws DOMException {
182: throw new ROException();
183: }
184:
185: /** Replace the characters starting at the specified 16-bit unit offset
186: * with the specified string.
187: * @param offset The offset from which to start replacing.
188: * @param count The number of 16-bit units to replace. If the sum of
189: * <code>offset</code> and <code>count</code> exceeds
190: * <code>length</code>, then all 16-bit units to the end of the data
191: * are replaced; (i.e., the effect is the same as a <code>remove</code>
192: * method call with the same range, followed by an <code>append</code>
193: * method invocation).
194: * @param arg The <code>DOMString</code> with which the range must be
195: * replaced.
196: * @exception DOMException
197: * INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is
198: * negative or greater than the number of 16-bit units in
199: * <code>data</code>, or if the specified <code>count</code> is
200: * negative.
201: * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
202: *
203: */
204: public void replaceData(int offset, int count, String arg)
205: throws DOMException {
206: throw new ROException();
207: }
208:
209: /** The character data of the node that implements this interface. The DOM
210: * implementation may not put arbitrary limits on the amount of data
211: * that may be stored in a <code>CharacterData</code> node. However,
212: * implementation limits may mean that the entirety of a node's data may
213: * not fit into a single <code>DOMString</code>. In such cases, the user
214: * may call <code>substringData</code> to retrieve the data in
215: * appropriately sized pieces.
216: * @exception DOMException
217: * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
218: * @exception DOMException
219: * DOMSTRING_SIZE_ERR: Raised when it would return more characters than
220: * fit in a <code>DOMString</code> variable on the implementation
221: * platform.
222: *
223: */
224: public void setData(String data) throws DOMException {
225: throw new ROException();
226: }
227:
228: /** Extracts a range of data from the node.
229: * @param offset Start offset of substring to extract.
230: * @param count The number of 16-bit units to extract.
231: * @return The specified substring. If the sum of <code>offset</code> and
232: * <code>count</code> exceeds the <code>length</code>, then all 16-bit
233: * units to the end of the data are returned.
234: * @exception DOMException
235: * INDEX_SIZE_ERR: Raised if the specified <code>offset</code> is
236: * negative or greater than the number of 16-bit units in
237: * <code>data</code>, or if the specified <code>count</code> is
238: * negative.
239: * <br>DOMSTRING_SIZE_ERR: Raised if the specified range of text does
240: * not fit into a <code>DOMString</code>.
241: *
242: */
243: public String substringData(int offset, int count)
244: throws DOMException {
245: try {
246: return peer.substringData(offset, count);
247: } catch (InvalidArgumentException ex) {
248: throw new UOException();
249: }
250: }
251:
252: /** The node immediately preceding this node. If there is no such node,
253: * this returns <code>null</code>.
254: *
255: */
256: public Node getPreviousSibling() {
257: return Children.getPreviousSibling(peer);
258: }
259:
260: /** The node immediately following this node. If there is no such node,
261: * this returns <code>null</code>.
262: *
263: */
264: public Node getNextSibling() {
265: return Children.getNextSibling(peer);
266: }
267:
268: }
|