KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > tax > dom > ElementImpl


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.tax.dom;
21
22 import org.w3c.dom.*;
23 import org.netbeans.tax.*;
24
25 /**
26  *
27  * @author Petr Kuzel
28  */

29 class ElementImpl extends NodeImpl implements Element {
30
31     private final TreeElement peer;
32
33     /** Creates a new instance of ElementImpl */
34     public ElementImpl(TreeElement peer) {
35         this.peer = peer;
36     }
37
38
39     /** Retrieves an attribute value by name.
40      * @param name The name of the attribute to retrieve.
41      * @return The <code>Attr</code> value as a string, or the empty string
42      * if that attribute does not have a specified or default value.
43      *
44      */

45     public String JavaDoc getAttribute(String JavaDoc name) {
46         return peer.getAttribute(name).getValue();
47     }
48     
49     /** Retrieves an attribute value by local name and namespace URI.
50      * <br>Documents which do not support the "XML" feature will permit only
51      * the DOM Level 1 calls for creating/setting elements and attributes.
52      * Hence, if you specify a non-null namespace URI, these DOMs will never
53      * find a matching node.
54      * @param namespaceURI The namespace URI of the attribute to retrieve.
55      * @param localName The local name of the attribute to retrieve.
56      * @return The <code>Attr</code> value as a string, or the empty string
57      * if that attribute does not have a specified or default value.
58      * @since DOM Level 2
59      *
60      */

61     public String JavaDoc getAttributeNS(String JavaDoc namespaceURI, String JavaDoc localName) {
62         throw new UOException();
63     }
64     
65     /** Retrieves an attribute node by name.
66      * <br>To retrieve an attribute node by qualified name and namespace URI,
67      * use the <code>getAttributeNodeNS</code> method.
68      * @param name The name (<code>nodeName</code>) of the attribute to
69      * retrieve.
70      * @return The <code>Attr</code> node with the specified name (
71      * <code>nodeName</code>) or <code>null</code> if there is no such
72      * attribute.
73      *
74      */

75     public Attr getAttributeNode(String JavaDoc name) {
76         return Wrapper.wrap(peer.getAttribute(name));
77     }
78     
79     /** Retrieves an <code>Attr</code> node by local name and namespace URI.
80      * <br>Documents which do not support the "XML" feature will permit only
81      * the DOM Level 1 calls for creating/setting elements and attributes.
82      * Hence, if you specify a non-null namespace URI, these DOMs will never
83      * find a matching node.
84      * @param namespaceURI The namespace URI of the attribute to retrieve.
85      * @param localName The local name of the attribute to retrieve.
86      * @return The <code>Attr</code> node with the specified attribute local
87      * name and namespace URI or <code>null</code> if there is no such
88      * attribute.
89      * @since DOM Level 2
90      *
91      */

92     public Attr getAttributeNodeNS(String JavaDoc namespaceURI, String JavaDoc localName) {
93         throw new UOException();
94     }
95     
96     /** A <code>NamedNodeMap</code> containing the attributes of this node (if
97      * it is an <code>Element</code>) or <code>null</code> otherwise.
98      *
99      */

100     public NamedNodeMap getAttributes() {
101         return Wrapper.wrap(peer.getAttributes());
102     }
103     
104     /** A <code>NodeList</code> that contains all children of this node. If
105      * there are no children, this is a <code>NodeList</code> containing no
106      * nodes.
107      *
108      */

109     public NodeList getChildNodes() {
110         return Wrapper.wrap(peer.getChildNodes());
111     }
112     
113     /** Returns a <code>NodeList</code> of all descendant <code>Elements</code>
114      * with a given tag name, in the order in which they are encountered in
115      * a preorder traversal of this <code>Element</code> tree.
116      * @param name The name of the tag to match on. The special value "*"
117      * matches all tags.
118      * @return A list of matching <code>Element</code> nodes.
119      *
120      */

121     public NodeList getElementsByTagName(String JavaDoc name) {
122         throw new UOException();
123     }
124     
125     /** Returns a <code>NodeList</code> of all the descendant
126      * <code>Elements</code> with a given local name and namespace URI in
127      * the order in which they are encountered in a preorder traversal of
128      * this <code>Element</code> tree.
129      * <br>Documents which do not support the "XML" feature will permit only
130      * the DOM Level 1 calls for creating/setting elements and attributes.
131      * Hence, if you specify a non-null namespace URI, these DOMs will never
132      * find a matching node.
133      * @param namespaceURI The namespace URI of the elements to match on. The
134      * special value "*" matches all namespaces.
135      * @param localName The local name of the elements to match on. The
136      * special value "*" matches all local names.
137      * @return A new <code>NodeList</code> object containing all the matched
138      * <code>Elements</code>.
139      * @since DOM Level 2
140      *
141      */

142     public NodeList getElementsByTagNameNS(String JavaDoc namespaceURI, String JavaDoc localName) {
143         throw new UOException();
144     }
145     
146     /** The first child of this node. If there is no such node, this returns
147      * <code>null</code>.
148      *
149      */

150     public Node getFirstChild() {
151         return Wrapper.wrap(peer.getFirstChild());
152     }
153     
154     /** The last child of this node. If there is no such node, this returns
155      * <code>null</code>.
156      *
157      */

158     public Node getLastChild() {
159         return Wrapper.wrap(peer.getLastChild());
160     }
161     
162     
163     /** The node immediately following this node. If there is no such node,
164      * this returns <code>null</code>.
165      *
166      */

167     public Node getNextSibling() {
168         return Children.getNextSibling(peer);
169     }
170     
171     /** The name of this node, depending on its type; see the table above.
172      *
173      */

174     public String JavaDoc getNodeName() {
175         return getTagName();
176     }
177     
178     /** A code representing the type of the underlying object, as defined above.
179      *
180      */

181     public short getNodeType() {
182         return Node.ELEMENT_NODE;
183     }
184     
185     /** The value of this node, depending on its type; see the table above.
186      * When it is defined to be <code>null</code>, setting it has no effect.
187      * @exception DOMException
188      * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
189      * @exception DOMException
190      * DOMSTRING_SIZE_ERR: Raised when it would return more characters than
191      * fit in a <code>DOMString</code> variable on the implementation
192      * platform.
193      *
194      */

195     public String JavaDoc getNodeValue() throws DOMException {
196         return null;
197     }
198     
199     
200     /** The parent of this node. All nodes, except <code>Attr</code>,
201      * <code>Document</code>, <code>DocumentFragment</code>,
202      * <code>Entity</code>, and <code>Notation</code> may have a parent.
203      * However, if a node has just been created and not yet added to the
204      * tree, or if it has been removed from the tree, this is
205      * <code>null</code>.
206      *
207      */

208     public Node getParentNode() {
209         return Wrapper.wrap(peer.getParentNode());
210     }
211     
212     /** The node immediately preceding this node. If there is no such node,
213      * this returns <code>null</code>.
214      *
215      */

216     public Node getPreviousSibling() {
217         return Children.getPreviousSibling(peer);
218     }
219     
220     /** The name of the element. For example, in:
221      * <pre> &lt;elementExample
222      * id="demo"&gt; ... &lt;/elementExample&gt; , </pre>
223      * <code>tagName</code> has
224      * the value <code>"elementExample"</code>. Note that this is
225      * case-preserving in XML, as are all of the operations of the DOM. The
226      * HTML DOM returns the <code>tagName</code> of an HTML element in the
227      * canonical uppercase form, regardless of the case in the source HTML
228      * document.
229      *
230      */

231     public String JavaDoc getTagName() {
232         return peer.getQName();
233     }
234     
235     /** Returns <code>true</code> when an attribute with a given name is
236      * specified on this element or has a default value, <code>false</code>
237      * otherwise.
238      * @param name The name of the attribute to look for.
239      * @return <code>true</code> if an attribute with the given name is
240      * specified on this element or has a default value, <code>false</code>
241      * otherwise.
242      * @since DOM Level 2
243      *
244      */

245     public boolean hasAttribute(String JavaDoc name) {
246         throw new UOException();
247     }
248     
249     /** Returns <code>true</code> when an attribute with a given local name and
250      * namespace URI is specified on this element or has a default value,
251      * <code>false</code> otherwise.
252      * <br>Documents which do not support the "XML" feature will permit only
253      * the DOM Level 1 calls for creating/setting elements and attributes.
254      * Hence, if you specify a non-null namespace URI, these DOMs will never
255      * find a matching node.
256      * @param namespaceURI The namespace URI of the attribute to look for.
257      * @param localName The local name of the attribute to look for.
258      * @return <code>true</code> if an attribute with the given local name
259      * and namespace URI is specified or has a default value on this
260      * element, <code>false</code> otherwise.
261      * @since DOM Level 2
262      *
263      */

264     public boolean hasAttributeNS(String JavaDoc namespaceURI, String JavaDoc localName) {
265         throw new UOException();
266     }
267     
268     /** Returns whether this node (if it is an element) has any attributes.
269      * @return <code>true</code> if this node has any attributes,
270      * <code>false</code> otherwise.
271      * @since DOM Level 2
272      *
273      */

274     public boolean hasAttributes() {
275         return peer.hasAttributes();
276     }
277     
278     /** Returns whether this node has any children.
279      * @return <code>true</code> if this node has any children,
280      * <code>false</code> otherwise.
281      *
282      */

283     public boolean hasChildNodes() {
284         return peer.hasChildNodes();
285     }
286         
287     /** Removes an attribute by name. If the removed attribute is known to have
288      * a default value, an attribute immediately appears containing the
289      * default value as well as the corresponding namespace URI, local name,
290      * and prefix when applicable.
291      * <br>To remove an attribute by local name and namespace URI, use the
292      * <code>removeAttributeNS</code> method.
293      * @param name The name of the attribute to remove.
294      * @exception DOMException
295      * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
296      *
297      */

298     public void removeAttribute(String JavaDoc name) throws DOMException {
299         throw new ROException();
300     }
301     
302     /** Removes an attribute by local name and namespace URI. If the removed
303      * attribute has a default value it is immediately replaced. The
304      * replacing attribute has the same namespace URI and local name, as
305      * well as the original prefix.
306      * <br>Documents which do not support the "XML" feature will permit only
307      * the DOM Level 1 calls for creating/setting elements and attributes.
308      * Hence, if you specify a non-null namespace URI, these DOMs will never
309      * find a matching node.
310      * @param namespaceURI The namespace URI of the attribute to remove.
311      * @param localName The local name of the attribute to remove.
312      * @exception DOMException
313      * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
314      * @since DOM Level 2
315      *
316      */

317     public void removeAttributeNS(String JavaDoc namespaceURI, String JavaDoc localName) throws DOMException {
318         throw new ROException();
319     }
320     
321     /** Removes the specified attribute node. If the removed <code>Attr</code>
322      * has a default value it is immediately replaced. The replacing
323      * attribute has the same namespace URI and local name, as well as the
324      * original prefix, when applicable.
325      * @param oldAttr The <code>Attr</code> node to remove from the attribute
326      * list.
327      * @return The <code>Attr</code> node that was removed.
328      * @exception DOMException
329      * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
330      * <br>NOT_FOUND_ERR: Raised if <code>oldAttr</code> is not an attribute
331      * of the element.
332      *
333      */

334     public Attr removeAttributeNode(Attr oldAttr) throws DOMException {
335         throw new ROException();
336     }
337     
338     
339     /** Adds a new attribute. If an attribute with that name is already present
340      * in the element, its value is changed to be that of the value
341      * parameter. This value is a simple string; it is not parsed as it is
342      * being set. So any markup (such as syntax to be recognized as an
343      * entity reference) is treated as literal text, and needs to be
344      * appropriately escaped by the implementation when it is written out.
345      * In order to assign an attribute value that contains entity
346      * references, the user must create an <code>Attr</code> node plus any
347      * <code>Text</code> and <code>EntityReference</code> nodes, build the
348      * appropriate subtree, and use <code>setAttributeNode</code> to assign
349      * it as the value of an attribute.
350      * <br>To set an attribute with a qualified name and namespace URI, use
351      * the <code>setAttributeNS</code> method.
352      * @param name The name of the attribute to create or alter.
353      * @param value Value to set in string form.
354      * @exception DOMException
355      * INVALID_CHARACTER_ERR: Raised if the specified name contains an
356      * illegal character.
357      * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
358      *
359      */

360     public void setAttribute(String JavaDoc name, String JavaDoc value) throws DOMException {
361         throw new ROException();
362     }
363     
364     /** Adds a new attribute. If an attribute with the same local name and
365      * namespace URI is already present on the element, its prefix is
366      * changed to be the prefix part of the <code>qualifiedName</code>, and
367      * its value is changed to be the <code>value</code> parameter. This
368      * value is a simple string; it is not parsed as it is being set. So any
369      * markup (such as syntax to be recognized as an entity reference) is
370      * treated as literal text, and needs to be appropriately escaped by the
371      * implementation when it is written out. In order to assign an
372      * attribute value that contains entity references, the user must create
373      * an <code>Attr</code> node plus any <code>Text</code> and
374      * <code>EntityReference</code> nodes, build the appropriate subtree,
375      * and use <code>setAttributeNodeNS</code> or
376      * <code>setAttributeNode</code> to assign it as the value of an
377      * attribute.
378      * @param namespaceURI The namespace URI of the attribute to create or
379      * alter.
380      * @param qualifiedName The qualified name of the attribute to create or
381      * alter.
382      * @param value The value to set in string form.
383      * @exception DOMException
384      * INVALID_CHARACTER_ERR: Raised if the specified qualified name
385      * contains an illegal character, per the XML 1.0 specification .
386      * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
387      * <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is
388      * malformed per the Namespaces in XML specification, if the
389      * <code>qualifiedName</code> has a prefix and the
390      * <code>namespaceURI</code> is <code>null</code>, if the
391      * <code>qualifiedName</code> has a prefix that is "xml" and the
392      * <code>namespaceURI</code> is different from "
393      * http://www.w3.org/XML/1998/namespace", or if the
394      * <code>qualifiedName</code>, or its prefix, is "xmlns" and the
395      * <code>namespaceURI</code> is different from "
396      * http://www.w3.org/2000/xmlns/".
397      * <br>NOT_SUPPORTED_ERR: Always thrown if the current document does not
398      * support the <code>"XML"</code> feature, since namespaces were
399      * defined by XML.
400      * @since DOM Level 2
401      *
402      */

403     public void setAttributeNS(String JavaDoc namespaceURI, String JavaDoc qualifiedName, String JavaDoc value) throws DOMException {
404         throw new ROException();
405     }
406     
407     /** Adds a new attribute node. If an attribute with that name (
408      * <code>nodeName</code>) is already present in the element, it is
409      * replaced by the new one.
410      * <br>To add a new attribute node with a qualified name and namespace
411      * URI, use the <code>setAttributeNodeNS</code> method.
412      * @param newAttr The <code>Attr</code> node to add to the attribute list.
413      * @return If the <code>newAttr</code> attribute replaces an existing
414      * attribute, the replaced <code>Attr</code> node is returned,
415      * otherwise <code>null</code> is returned.
416      * @exception DOMException
417      * WRONG_DOCUMENT_ERR: Raised if <code>newAttr</code> was created from a
418      * different document than the one that created the element.
419      * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
420      * <br>INUSE_ATTRIBUTE_ERR: Raised if <code>newAttr</code> is already an
421      * attribute of another <code>Element</code> object. The DOM user must
422      * explicitly clone <code>Attr</code> nodes to re-use them in other
423      * elements.
424      *
425      */

426     public Attr setAttributeNode(Attr newAttr) throws DOMException {
427         throw new ROException();
428     }
429     
430     /** Adds a new attribute. If an attribute with that local name and that
431      * namespace URI is already present in the element, it is replaced by
432      * the new one.
433      * @param newAttr The <code>Attr</code> node to add to the attribute list.
434      * @return If the <code>newAttr</code> attribute replaces an existing
435      * attribute with the same local name and namespace URI, the replaced
436      * <code>Attr</code> node is returned, otherwise <code>null</code> is
437      * returned.
438      * @exception DOMException
439      * WRONG_DOCUMENT_ERR: Raised if <code>newAttr</code> was created from a
440      * different document than the one that created the element.
441      * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
442      * <br>INUSE_ATTRIBUTE_ERR: Raised if <code>newAttr</code> is already an
443      * attribute of another <code>Element</code> object. The DOM user must
444      * explicitly clone <code>Attr</code> nodes to re-use them in other
445      * elements.
446      * <br>NOT_SUPPORTED_ERR: Always thrown if the current document does not
447      * support the <code>"XML"</code> feature, since namespaces were
448      * defined by XML.
449      * @since DOM Level 2
450      *
451      */

452     public Attr setAttributeNodeNS(Attr newAttr) throws DOMException {
453         throw new ROException();
454     }
455     
456 }
457
Popular Tags