KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > text > syntax > dom > EndTag


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.text.syntax.dom;
21
22 import java.util.*;
23
24 import org.w3c.dom.*;
25 import org.netbeans.modules.xml.text.syntax.*;
26 import org.netbeans.modules.xml.spi.dom.*;
27 import org.netbeans.editor.*;
28
29 /**
30  * End element of ELEMENT_NODE.
31  * //??? should it be implementing Node?
32  */

33 public class EndTag extends Tag {
34
35     public EndTag(XMLSyntaxSupport support, TokenItem from, int to, String JavaDoc name) {
36         super( support, from, to, name, null );
37         this.name = name;
38     }
39
40     /**
41      * Create properly bound attributes
42      */

43     public synchronized org.w3c.dom.NamedNodeMap JavaDoc getAttributes() {
44         Tag start = getStartTag();
45         if (start != null) {
46             return start.getAttributes();
47         } else {
48             return NamedNodeMapImpl.EMPTY;
49         }
50     }
51     
52     public boolean hasChildNodes() {
53         SyntaxElement prev = getPrevious();
54         if (prev == null) return false;
55         if (prev instanceof EndTag && ((EndTag)prev).getStartTag() == null) return false;
56         if (prev instanceof StartTag) return false;
57         return true;
58     }
59     
60     public NodeList getChildNodes() {
61         
62         List list = new ArrayList();
63         Node prev = hasChildNodes() ? findPrevious(this) : null;
64         
65         while (prev != null) {
66             list.add(0, prev);
67             prev = prev.getPreviousSibling();
68         }
69         
70         return new NodeListImpl(list);
71     }
72     
73     protected Tag getStartTag() {
74         
75         SyntaxNode prev = findPrevious();
76         
77         while (prev != null) {
78             if (prev instanceof StartTag) {
79                 // check well-formedness
80
StartTag startTag = (StartTag) prev;
81                 if (startTag.getNodeName().equals(getNodeName())) {
82                     return startTag;
83                 } else {
84                     return null;
85                 }
86             } else if (prev instanceof EndTag) {
87                 EndTag endTag = (EndTag) prev;
88                 prev = endTag.getStartTag();
89                 if (prev == null) return null;
90                 prev = prev.findPrevious();
91             } else {
92                 prev = prev.findPrevious();
93             }
94         }
95         
96         return null;
97     }
98     
99     protected Tag getEndTag() {
100         return this;
101     }
102     
103     public String JavaDoc toString() {
104         return "EndTag(\"" + name + "\") " + first;
105     }
106     
107 }
108
109
Popular Tags