KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dom4j > dom > DOMComment


1 /*
2  * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
3  *
4  * This software is open source.
5  * See the bottom of this file for the licence.
6  */

7
8 package org.dom4j.dom;
9
10 import org.dom4j.Element;
11 import org.dom4j.tree.DefaultComment;
12
13 import org.w3c.dom.DOMException JavaDoc;
14 import org.w3c.dom.Document JavaDoc;
15 import org.w3c.dom.NamedNodeMap JavaDoc;
16 import org.w3c.dom.NodeList JavaDoc;
17
18 /**
19  * <p>
20  * <code>DOMText</code> implements a Text node which supports the W3C DOM API.
21  * </p>
22  *
23  * @author <a HREF="mailto:jstrachan@apache.org">James Strachan </a>
24  * @version $Revision: 1.12 $
25  */

26 public class DOMComment extends DefaultComment implements org.w3c.dom.Comment JavaDoc {
27     public DOMComment(String JavaDoc text) {
28         super(text);
29     }
30
31     public DOMComment(Element parent, String JavaDoc text) {
32         super(parent, text);
33     }
34
35     // org.w3c.dom.Node interface
36
// -------------------------------------------------------------------------
37
public boolean supports(String JavaDoc feature, String JavaDoc version) {
38         return DOMNodeHelper.supports(this, feature, version);
39     }
40
41     public String JavaDoc getNamespaceURI() {
42         return DOMNodeHelper.getNamespaceURI(this);
43     }
44
45     public String JavaDoc getPrefix() {
46         return DOMNodeHelper.getPrefix(this);
47     }
48
49     public void setPrefix(String JavaDoc prefix) throws DOMException JavaDoc {
50         DOMNodeHelper.setPrefix(this, prefix);
51     }
52
53     public String JavaDoc getLocalName() {
54         return DOMNodeHelper.getLocalName(this);
55     }
56
57     public String JavaDoc getNodeName() {
58         return "#comment";
59     }
60
61     // already part of API
62
//
63
// public short getNodeType();
64
public String JavaDoc getNodeValue() throws DOMException JavaDoc {
65         return DOMNodeHelper.getNodeValue(this);
66     }
67
68     public void setNodeValue(String JavaDoc nodeValue) throws DOMException JavaDoc {
69         DOMNodeHelper.setNodeValue(this, nodeValue);
70     }
71
72     public org.w3c.dom.Node JavaDoc getParentNode() {
73         return DOMNodeHelper.getParentNode(this);
74     }
75
76     public NodeList JavaDoc getChildNodes() {
77         return DOMNodeHelper.getChildNodes(this);
78     }
79
80     public org.w3c.dom.Node JavaDoc getFirstChild() {
81         return DOMNodeHelper.getFirstChild(this);
82     }
83
84     public org.w3c.dom.Node JavaDoc getLastChild() {
85         return DOMNodeHelper.getLastChild(this);
86     }
87
88     public org.w3c.dom.Node JavaDoc getPreviousSibling() {
89         return DOMNodeHelper.getPreviousSibling(this);
90     }
91
92     public org.w3c.dom.Node JavaDoc getNextSibling() {
93         return DOMNodeHelper.getNextSibling(this);
94     }
95
96     public NamedNodeMap JavaDoc getAttributes() {
97         return null;
98     }
99
100     public Document JavaDoc getOwnerDocument() {
101         return DOMNodeHelper.getOwnerDocument(this);
102     }
103
104     public org.w3c.dom.Node JavaDoc insertBefore(org.w3c.dom.Node JavaDoc newChild,
105             org.w3c.dom.Node JavaDoc refChild) throws DOMException JavaDoc {
106         checkNewChildNode(newChild);
107
108         return DOMNodeHelper.insertBefore(this, newChild, refChild);
109     }
110
111     public org.w3c.dom.Node JavaDoc replaceChild(org.w3c.dom.Node JavaDoc newChild,
112             org.w3c.dom.Node JavaDoc oldChild) throws DOMException JavaDoc {
113         checkNewChildNode(newChild);
114
115         return DOMNodeHelper.replaceChild(this, newChild, oldChild);
116     }
117
118     public org.w3c.dom.Node JavaDoc removeChild(org.w3c.dom.Node JavaDoc oldChild)
119             throws DOMException JavaDoc {
120         return DOMNodeHelper.removeChild(this, oldChild);
121     }
122
123     public org.w3c.dom.Node JavaDoc appendChild(org.w3c.dom.Node JavaDoc newChild)
124             throws DOMException JavaDoc {
125         checkNewChildNode(newChild);
126
127         return DOMNodeHelper.appendChild(this, newChild);
128     }
129
130     private void checkNewChildNode(org.w3c.dom.Node JavaDoc newChild)
131             throws DOMException JavaDoc {
132         throw new DOMException JavaDoc(DOMException.HIERARCHY_REQUEST_ERR,
133                 "Comment nodes cannot have children");
134     }
135
136     public boolean hasChildNodes() {
137         return DOMNodeHelper.hasChildNodes(this);
138     }
139
140     public org.w3c.dom.Node JavaDoc cloneNode(boolean deep) {
141         return DOMNodeHelper.cloneNode(this, deep);
142     }
143
144     public void normalize() {
145         DOMNodeHelper.normalize(this);
146     }
147
148     public boolean isSupported(String JavaDoc feature, String JavaDoc version) {
149         return DOMNodeHelper.isSupported(this, feature, version);
150     }
151
152     public boolean hasAttributes() {
153         return DOMNodeHelper.hasAttributes(this);
154     }
155
156     // org.w3c.dom.CharacterData interface
157
// -------------------------------------------------------------------------
158
public String JavaDoc getData() throws DOMException JavaDoc {
159         return DOMNodeHelper.getData(this);
160     }
161
162     public void setData(String JavaDoc data) throws DOMException JavaDoc {
163         DOMNodeHelper.setData(this, data);
164     }
165
166     public int getLength() {
167         return DOMNodeHelper.getLength(this);
168     }
169
170     public String JavaDoc substringData(int offset, int count) throws DOMException JavaDoc {
171         return DOMNodeHelper.substringData(this, offset, count);
172     }
173
174     public void appendData(String JavaDoc arg) throws DOMException JavaDoc {
175         DOMNodeHelper.appendData(this, arg);
176     }
177
178     public void insertData(int offset, String JavaDoc arg) throws DOMException JavaDoc {
179         DOMNodeHelper.insertData(this, offset, arg);
180     }
181
182     public void deleteData(int offset, int count) throws DOMException JavaDoc {
183         DOMNodeHelper.deleteData(this, offset, count);
184     }
185
186     public void replaceData(int offset, int count, String JavaDoc arg)
187             throws DOMException JavaDoc {
188         DOMNodeHelper.replaceData(this, offset, count, arg);
189     }
190 }
191
192 /*
193  * Redistribution and use of this software and associated documentation
194  * ("Software"), with or without modification, are permitted provided that the
195  * following conditions are met:
196  *
197  * 1. Redistributions of source code must retain copyright statements and
198  * notices. Redistributions must also contain a copy of this document.
199  *
200  * 2. Redistributions in binary form must reproduce the above copyright notice,
201  * this list of conditions and the following disclaimer in the documentation
202  * and/or other materials provided with the distribution.
203  *
204  * 3. The name "DOM4J" must not be used to endorse or promote products derived
205  * from this Software without prior written permission of MetaStuff, Ltd. For
206  * written permission, please contact dom4j-info@metastuff.com.
207  *
208  * 4. Products derived from this Software may not be called "DOM4J" nor may
209  * "DOM4J" appear in their names without prior written permission of MetaStuff,
210  * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
211  *
212  * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
213  *
214  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
215  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
216  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
217  * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
218  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
219  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
220  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
221  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
222  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
223  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
224  * POSSIBILITY OF SUCH DAMAGE.
225  *
226  * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
227  */

228
Popular Tags