2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.xml.text.syntax.dom;
45
import org.netbeans.modules.xml.text.syntax.*;
46
import org.netbeans.modules.xml.spi.dom.*;
47
import org.netbeans.editor.*;
50
* It represents higher level abstraction elements implementing
53
* Known differences to DOM specs:
54
* <li> <code>getParentNode()</code> may return <code>null</code>
55
* <li> NOT_SUPPORTED_ERR is thrown from <code>get_XXX_By_YYY()</code>
56
* <li> implements <code>equals</code>ity at DOM Node level
58
* Instances are produced by {@link XMLSyntaxSupport}.
65
public abstract class SyntaxNode extends SyntaxElement implements Node {
67
/** Creates new SyntaxNode */
68
public SyntaxNode(XMLSyntaxSupport support, TokenItem first, int to) {
69
super( support, first, to);
73
* Default implementation returning first previous <code>SyntaxNode</code>
74
* or <code>null</code>. It is <code>StartTag</code> aware.
76
public Node getPreviousSibling() {
77
SyntaxNode prev = findPrevious(this);
79
// stop at start tag (it forms hiearchy)
80
if (prev instanceof StartTag) {
88
* Find previous SyntaxNode instance or <code>null</code>.
90
static SyntaxNode findPrevious(SyntaxElement el) {
91
SyntaxElement prev = el.getPrevious();
92
while ((prev instanceof SyntaxNode) == false) {
93
if (prev == null) return null;
94
prev = prev.getPrevious();
96
return (SyntaxNode) prev;
100
* Find previous SyntaxNode instance or <code>null</code>.
102
SyntaxNode findPrevious() {
103
return findPrevious(this);
107
* Default implementation returning first next <code>SyntaxNode</code>
108
* or <code>null</code>. It is <code>EndTag</code> aware.
110
public Node getNextSibling() {
111
SyntaxNode next = findNext(this);
113
// stop at end tag (it forms hiearchy)
114
if (next instanceof EndTag) {
124
* Find previous SyntaxNode instance or <code>null</code>.
126
static SyntaxNode findNext(SyntaxElement el) {
127
SyntaxElement next = el.getNext();
128
while ((next instanceof SyntaxNode) == false) {
129
if (next == null) return null;
130
next = next.getNext();
132
return (SyntaxNode) next;
136
* Find previous SyntaxNode instance or <code>null</code>.
138
SyntaxNode findNext() {
139
return findNext(this);
143
* First previous start tag at higher level is my parent.
144
* Skip all end-tag start-tag pairs at the same level.
145
* @return SyntaxNode or <code>null</code>
147
public Node getParentNode() {
148
SyntaxNode prev = findPrevious();
152
while ( prev != null ) {
153
if (prev instanceof StartTag) {
154
return (Element) prev;
155
} else if (prev instanceof EndTag) { // traverse end-start tag pairs
156
prev = ((EndTag)prev).getStartTag();
157
if (prev == null) break;
158
prev = prev.findPrevious();
160
prev = prev.findPrevious();
164
if (prev == null) break;
166
} while ( (prev instanceof SyntaxNode) == false );
171
return getOwnerDocument(); //??? return a DocumentFragment with some kids? or null
175
public org.w3c.dom.Document getOwnerDocument() {
176
return new DocumentImpl(this);
179
// default DOM Node implementation ~~~~~~~~~~~~~~~~~~~~~~~~``
181
public String getNodeName() {
188
public boolean isSupported(String str, String str1) {
189
throw new UOException();
192
public void setPrefix(String str) throws org.w3c.dom.DOMException {
193
throw new ROException();
196
public String getPrefix() {
197
throw new UOException();
201
* It is rather abstract to force all to reimplement.
203
public abstract short getNodeType();
205
public org.w3c.dom.Node replaceChild(org.w3c.dom.Node node, org.w3c.dom.Node node1) throws org.w3c.dom.DOMException {
206
throw new ROException();
209
public org.w3c.dom.Node cloneNode(boolean param) {
210
return (Node) this; //we are immutable, only problem with references may appear
213
public org.w3c.dom.Node insertBefore(org.w3c.dom.Node node, org.w3c.dom.Node node1) throws org.w3c.dom.DOMException {
214
throw new ROException();
217
public String getNamespaceURI() {
218
throw new UOException();
221
public org.w3c.dom.NamedNodeMap getAttributes() {
222
return NamedNodeMapImpl.EMPTY;
225
public org.w3c.dom.NodeList getChildNodes() {
226
return NodeListImpl.EMPTY;
229
public String getNodeValue() throws org.w3c.dom.DOMException {
230
// attribute, text, pi data
234
public org.w3c.dom.Node appendChild(org.w3c.dom.Node node) throws org.w3c.dom.DOMException {
235
throw new ROException();
238
public String getLocalName() {
239
throw new UOException();
242
public void setNodeValue(String str) throws org.w3c.dom.DOMException {
243
throw new ROException();
246
public org.w3c.dom.Node getLastChild() {
251
public boolean hasAttributes() {
252
throw new UOException();
255
public void normalize() {
256
// ignore we are modmalized by default
259
public org.w3c.dom.Node removeChild(org.w3c.dom.Node node) throws org.w3c.dom.DOMException {
260
throw new ROException();
266
public boolean hasChildNodes() {
273
public org.w3c.dom.Node getFirstChild() {
278
// Implementation of DOM Level 3 methods
281
public short compareDocumentPosition (Node a) {
282
throw new UOException();
285
public String getBaseURI() {
286
throw new UOException();
288
public Object getFeature(String a, String b) {
289
throw new UOException();
291
public String getTextContent () {
292
throw new UOException();
294
public Object getUserData(String a) {
295
throw new UOException();
297
public boolean isDefaultNamespace (String a) {
298
throw new UOException();
300
public boolean isEqualNode(Node a) {
301
throw new UOException();
303
public boolean isSameNode(Node a) {
304
throw new UOException();
306
public String lookupNamespaceURI(String a) {
307
throw new UOException();
309
public String lookupPrefix(String a) {
310
throw new UOException();
312
public void setTextContent(String a) {
313
throw new UOException();
315
public Object setUserData(String a, Object b, UserDataHandler c) {
316
throw new UOException();
318
// Implementation of DOM Level 3 methods for Text
319
public Text replaceWholeText (String a) {
320
throw new UOException ();
322
public String getWholeText() {
323
throw new UOException ();
325
public boolean isElementContentWhitespace() {
326
throw new UOException ();
328
// Implementation of DOM Level 3 methods for Element
329
public TypeInfo getSchemaTypeInfo() {
330
throw new UOException ();
332
public void setIdAttribute(String a, boolean b) {
333
throw new UOException ();
335
public void setIdAttributeNS(String a, String b, boolean c) {
336
throw new UOException ();
338
public void setIdAttributeNode(Attr a, boolean b) {
339
throw new UOException ();