KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Iterator JavaDoc;
23 import org.w3c.dom.*;
24 import org.netbeans.tax.*;
25 import org.netbeans.tax.TreeObjectList;
26
27 /**
28  *
29  * @author Petr Kuzel
30  */

31 class DocumentImpl extends NodeImpl implements Document{
32
33     private final TreeDocumentRoot peer;
34
35     /** Creates a new instance of AttrImpl */
36     public DocumentImpl(TreeDocumentRoot peer) {
37         this.peer = peer;
38     }
39
40     /** Creates an <code>Attr</code> of the given name. Note that the
41      * <code>Attr</code> instance can then be set on an <code>Element</code>
42      * using the <code>setAttributeNode</code> method.
43      * <br>To create an attribute with a qualified name and namespace URI, use
44      * the <code>createAttributeNS</code> method.
45      * @param name The name of the attribute.
46      * @return A new <code>Attr</code> object with the <code>nodeName</code>
47      * attribute set to <code>name</code>, and <code>localName</code>,
48      * <code>prefix</code>, and <code>namespaceURI</code> set to
49      * <code>null</code>. The value of the attribute is the empty string.
50      * @exception DOMException
51      * INVALID_CHARACTER_ERR: Raised if the specified name contains an
52      * illegal character.
53      *
54      */

55     public Attr createAttribute(String JavaDoc name) throws DOMException {
56         throw new ROException();
57     }
58     
59     /** Creates an attribute of the given qualified name and namespace URI.
60      * @param namespaceURI The namespace URI of the attribute to create.
61      * @param qualifiedName The qualified name of the attribute to
62      * instantiate.
63      * @return A new <code>Attr</code> object with the following attributes:
64      * <table border='1'>
65      * <tr>
66      * <th>
67      * Attribute</th>
68      * <th>Value</th>
69      * </tr>
70      * <tr>
71      * <td valign='top' rowspan='1' colspan='1'><code>Node.nodeName</code></td>
72      * <td valign='top' rowspan='1' colspan='1'>qualifiedName</td>
73      * </tr>
74      * <tr>
75      * <td valign='top' rowspan='1' colspan='1'>
76      * <code>Node.namespaceURI</code></td>
77      * <td valign='top' rowspan='1' colspan='1'><code>namespaceURI</code></td>
78      * </tr>
79      * <tr>
80      * <td valign='top' rowspan='1' colspan='1'>
81      * <code>Node.prefix</code></td>
82      * <td valign='top' rowspan='1' colspan='1'>prefix, extracted from
83      * <code>qualifiedName</code>, or <code>null</code> if there is no
84      * prefix</td>
85      * </tr>
86      * <tr>
87      * <td valign='top' rowspan='1' colspan='1'><code>Node.localName</code></td>
88      * <td valign='top' rowspan='1' colspan='1'>local name, extracted from
89      * <code>qualifiedName</code></td>
90      * </tr>
91      * <tr>
92      * <td valign='top' rowspan='1' colspan='1'><code>Attr.name</code></td>
93      * <td valign='top' rowspan='1' colspan='1'>
94      * <code>qualifiedName</code></td>
95      * </tr>
96      * <tr>
97      * <td valign='top' rowspan='1' colspan='1'><code>Node.nodeValue</code></td>
98      * <td valign='top' rowspan='1' colspan='1'>the empty
99      * string</td>
100      * </tr>
101      * </table>
102      * @exception DOMException
103      * INVALID_CHARACTER_ERR: Raised if the specified qualified name
104      * contains an illegal character, per the XML 1.0 specification .
105      * <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is
106      * malformed per the Namespaces in XML specification, if the
107      * <code>qualifiedName</code> has a prefix and the
108      * <code>namespaceURI</code> is <code>null</code>, if the
109      * <code>qualifiedName</code> has a prefix that is "xml" and the
110      * <code>namespaceURI</code> is different from "
111      * http://www.w3.org/XML/1998/namespace", or if the
112      * <code>qualifiedName</code>, or its prefix, is "xmlns" and the
113      * <code>namespaceURI</code> is different from "
114      * http://www.w3.org/2000/xmlns/".
115      * <br>NOT_SUPPORTED_ERR: Always thrown if the current document does not
116      * support the <code>"XML"</code> feature, since namespaces were
117      * defined by XML.
118      * @since DOM Level 2
119      *
120      */

121     public Attr createAttributeNS(String JavaDoc namespaceURI, String JavaDoc qualifiedName) throws DOMException {
122         throw new ROException();
123     }
124     
125     /** Creates a <code>CDATASection</code> node whose value is the specified
126      * string.
127      * @param data The data for the <code>CDATASection</code> contents.
128      * @return The new <code>CDATASection</code> object.
129      * @exception DOMException
130      * NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
131      *
132      */

133     public CDATASection createCDATASection(String JavaDoc data) throws DOMException {
134         throw new ROException();
135     }
136     
137     /** Creates a <code>Comment</code> node given the specified string.
138      * @param data The data for the node.
139      * @return The new <code>Comment</code> object.
140      *
141      */

142     public Comment createComment(String JavaDoc data) {
143         throw new ROException();
144     }
145     
146     /** Creates an empty <code>DocumentFragment</code> object.
147      * @return A new <code>DocumentFragment</code>.
148      *
149      */

150     public DocumentFragment createDocumentFragment() {
151         throw new ROException();
152     }
153     
154     /** Creates an element of the type specified. Note that the instance
155      * returned implements the <code>Element</code> interface, so attributes
156      * can be specified directly on the returned object.
157      * <br>In addition, if there are known attributes with default values,
158      * <code>Attr</code> nodes representing them are automatically created
159      * and attached to the element.
160      * <br>To create an element with a qualified name and namespace URI, use
161      * the <code>createElementNS</code> method.
162      * @param tagName The name of the element type to instantiate. For XML,
163      * this is case-sensitive. For HTML, the <code>tagName</code>
164      * parameter may be provided in any case, but it must be mapped to the
165      * canonical uppercase form by the DOM implementation.
166      * @return A new <code>Element</code> object with the
167      * <code>nodeName</code> attribute set to <code>tagName</code>, and
168      * <code>localName</code>, <code>prefix</code>, and
169      * <code>namespaceURI</code> set to <code>null</code>.
170      * @exception DOMException
171      * INVALID_CHARACTER_ERR: Raised if the specified name contains an
172      * illegal character.
173      *
174      */

175     public Element createElement(String JavaDoc tagName) throws DOMException {
176         throw new ROException();
177     }
178     
179     /** Creates an element of the given qualified name and namespace URI.
180      * @param namespaceURI The namespace URI of the element to create.
181      * @param qualifiedName The qualified name of the element type to
182      * instantiate.
183      * @return A new <code>Element</code> object with the following
184      * attributes:
185      * <table border='1'>
186      * <tr>
187      * <th>Attribute</th>
188      * <th>Value</th>
189      * </tr>
190      * <tr>
191      * <td valign='top' rowspan='1' colspan='1'><code>Node.nodeName</code></td>
192      * <td valign='top' rowspan='1' colspan='1'>
193      * <code>qualifiedName</code></td>
194      * </tr>
195      * <tr>
196      * <td valign='top' rowspan='1' colspan='1'><code>Node.namespaceURI</code></td>
197      * <td valign='top' rowspan='1' colspan='1'>
198      * <code>namespaceURI</code></td>
199      * </tr>
200      * <tr>
201      * <td valign='top' rowspan='1' colspan='1'><code>Node.prefix</code></td>
202      * <td valign='top' rowspan='1' colspan='1'>prefix, extracted
203      * from <code>qualifiedName</code>, or <code>null</code> if there is
204      * no prefix</td>
205      * </tr>
206      * <tr>
207      * <td valign='top' rowspan='1' colspan='1'><code>Node.localName</code></td>
208      * <td valign='top' rowspan='1' colspan='1'>local name, extracted from
209      * <code>qualifiedName</code></td>
210      * </tr>
211      * <tr>
212      * <td valign='top' rowspan='1' colspan='1'><code>Element.tagName</code></td>
213      * <td valign='top' rowspan='1' colspan='1'>
214      * <code>qualifiedName</code></td>
215      * </tr>
216      * </table>
217      * @exception DOMException
218      * INVALID_CHARACTER_ERR: Raised if the specified qualified name
219      * contains an illegal character, per the XML 1.0 specification .
220      * <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is
221      * malformed per the Namespaces in XML specification, if the
222      * <code>qualifiedName</code> has a prefix and the
223      * <code>namespaceURI</code> is <code>null</code>, or if the
224      * <code>qualifiedName</code> has a prefix that is "xml" and the
225      * <code>namespaceURI</code> is different from "
226      * http://www.w3.org/XML/1998/namespace" .
227      * <br>NOT_SUPPORTED_ERR: Always thrown if the current document does not
228      * support the <code>"XML"</code> feature, since namespaces were
229      * defined by XML.
230      * @since DOM Level 2
231      *
232      */

233     public Element createElementNS(String JavaDoc namespaceURI, String JavaDoc qualifiedName) throws DOMException {
234         throw new ROException();
235     }
236     
237     /** Creates an <code>EntityReference</code> object. In addition, if the
238      * referenced entity is known, the child list of the
239      * <code>EntityReference</code> node is made the same as that of the
240      * corresponding <code>Entity</code> node.If any descendant of the
241      * <code>Entity</code> node has an unbound namespace prefix, the
242      * corresponding descendant of the created <code>EntityReference</code>
243      * node is also unbound; (its <code>namespaceURI</code> is
244      * <code>null</code>). The DOM Level 2 does not support any mechanism to
245      * resolve namespace prefixes.
246      * @param name The name of the entity to reference.
247      * @return The new <code>EntityReference</code> object.
248      * @exception DOMException
249      * INVALID_CHARACTER_ERR: Raised if the specified name contains an
250      * illegal character.
251      * <br>NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
252      *
253      */

254     public EntityReference createEntityReference(String JavaDoc name) throws DOMException {
255         throw new ROException();
256     }
257     
258     /** Creates a <code>ProcessingInstruction</code> node given the specified
259      * name and data strings.
260      * @param target The target part of the processing instruction.
261      * @param data The data for the node.
262      * @return The new <code>ProcessingInstruction</code> object.
263      * @exception DOMException
264      * INVALID_CHARACTER_ERR: Raised if the specified target contains an
265      * illegal character.
266      * <br>NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
267      *
268      */

269     public ProcessingInstruction createProcessingInstruction(String JavaDoc target, String JavaDoc data) throws DOMException {
270         throw new ROException();
271     }
272     
273     /** Creates a <code>Text</code> node given the specified string.
274      * @param data The data for the node.
275      * @return The new <code>Text</code> object.
276      *
277      */

278     public Text createTextNode(String JavaDoc data) {
279         throw new ROException();
280     }
281     
282     /** The Document Type Declaration (see <code>DocumentType</code>)
283      * associated with this document. For HTML documents as well as XML
284      * documents without a document type declaration this returns
285      * <code>null</code>. The DOM Level 2 does not support editing the
286      * Document Type Declaration. <code>docType</code> cannot be altered in
287      * any way, including through the use of methods inherited from the
288      * <code>Node</code> interface, such as <code>insertNode</code> or
289      * <code>removeNode</code>.
290      *
291      */

292     public DocumentType getDoctype() {
293         return null; //!!!
294
}
295     
296     /** This is a convenience attribute that allows direct access to the child
297      * node that is the root element of the document. For HTML documents,
298      * this is the element with the tagName "HTML".
299      *
300      */

301     public Element getDocumentElement() {
302         Iterator JavaDoc it = peer.getChildNodes().iterator();
303         while (it.hasNext()) {
304             Object JavaDoc next = it.next();
305             if (next instanceof TreeElement) {
306                 return Wrapper.wrap((TreeElement)next);
307             }
308         }
309         return null;
310     }
311     
312     /** Returns the <code>Element</code> whose <code>ID</code> is given by
313      * <code>elementId</code>. If no such element exists, returns
314      * <code>null</code>. Behavior is not defined if more than one element
315      * has this <code>ID</code>. The DOM implementation must have
316      * information that says which attributes are of type ID. Attributes
317      * with the name "ID" are not of type ID unless so defined.
318      * Implementations that do not know whether attributes are of type ID or
319      * not are expected to return <code>null</code>.
320      * @param elementId The unique <code>id</code> value for an element.
321      * @return The matching element.
322      * @since DOM Level 2
323      *
324      */

325     public Element getElementById(String JavaDoc elementId) {
326         throw new UOException();
327     }
328     
329     /** Returns a <code>NodeList</code> of all the <code>Elements</code> with a
330      * given tag name in the order in which they are encountered in a
331      * preorder traversal of the <code>Document</code> tree.
332      * @param tagname The name of the tag to match on. The special value "*"
333      * matches all tags.
334      * @return A new <code>NodeList</code> object containing all the matched
335      * <code>Elements</code>.
336      *
337      */

338     public NodeList getElementsByTagName(String JavaDoc tagname) {
339         throw new UOException(); //???
340
}
341     
342     /** Returns a <code>NodeList</code> of all the <code>Elements</code> with a
343      * given local name and namespace URI in the order in which they are
344      * encountered in a preorder traversal of the <code>Document</code> tree.
345      * @param namespaceURI The namespace URI of the elements to match on. The
346      * special value "*" matches all namespaces.
347      * @param localName The local name of the elements to match on. The
348      * special value "*" matches all local names.
349      * @return A new <code>NodeList</code> object containing all the matched
350      * <code>Elements</code>.
351      * @since DOM Level 2
352      *
353      */

354     public NodeList getElementsByTagNameNS(String JavaDoc namespaceURI, String JavaDoc localName) {
355         throw new UOException();
356     }
357     
358     /** The <code>DOMImplementation</code> object that handles this document. A
359      * DOM application may use objects from multiple implementations.
360      *
361      */

362     public DOMImplementation getImplementation() {
363         return new DOMImplementationImpl();
364     }
365     
366     /** The name of this node, depending on its type; see the table above.
367      *
368      */

369     public String JavaDoc getNodeName() {
370         return "#document";
371     }
372     
373     /** A code representing the type of the underlying object, as defined above.
374      *
375      */

376     public short getNodeType() {
377         return Node.DOCUMENT_NODE;
378     }
379     
380     /** The value of this node, depending on its type; see the table above.
381      * When it is defined to be <code>null</code>, setting it has no effect.
382      * @exception DOMException
383      * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
384      * @exception DOMException
385      * DOMSTRING_SIZE_ERR: Raised when it would return more characters than
386      * fit in a <code>DOMString</code> variable on the implementation
387      * platform.
388      *
389      */

390     public String JavaDoc getNodeValue() throws DOMException {
391         return null;
392     }
393     
394     /** The parent of this node. All nodes, except <code>Attr</code>,
395      * <code>Document</code>, <code>DocumentFragment</code>,
396      * <code>Entity</code>, and <code>Notation</code> may have a parent.
397      * However, if a node has just been created and not yet added to the
398      * tree, or if it has been removed from the tree, this is
399      * <code>null</code>.
400      *
401      */

402     public Node getParentNode() {
403         return null;
404     }
405     
406     /** Imports a node from another document to this document. The returned
407      * node has no parent; (<code>parentNode</code> is <code>null</code>).
408      * The source node is not altered or removed from the original document;
409      * this method creates a new copy of the source node.
410      * <br>For all nodes, importing a node creates a node object owned by the
411      * importing document, with attribute values identical to the source
412      * node's <code>nodeName</code> and <code>nodeType</code>, plus the
413      * attributes related to namespaces (<code>prefix</code>,
414      * <code>localName</code>, and <code>namespaceURI</code>). As in the
415      * <code>cloneNode</code> operation on a <code>Node</code>, the source
416      * node is not altered.
417      * <br>Additional information is copied as appropriate to the
418      * <code>nodeType</code>, attempting to mirror the behavior expected if
419      * a fragment of XML or HTML source was copied from one document to
420      * another, recognizing that the two documents may have different DTDs
421      * in the XML case. The following list describes the specifics for each
422      * type of node.
423      * <dl>
424      * <dt>ATTRIBUTE_NODE</dt>
425      * <dd>The <code>ownerElement</code> attribute
426      * is set to <code>null</code> and the <code>specified</code> flag is
427      * set to <code>true</code> on the generated <code>Attr</code>. The
428      * descendants of the source <code>Attr</code> are recursively imported
429      * and the resulting nodes reassembled to form the corresponding subtree.
430      * Note that the <code>deep</code> parameter has no effect on
431      * <code>Attr</code> nodes; they always carry their children with them
432      * when imported.</dd>
433      * <dt>DOCUMENT_FRAGMENT_NODE</dt>
434      * <dd>If the <code>deep</code> option
435      * was set to <code>true</code>, the descendants of the source element
436      * are recursively imported and the resulting nodes reassembled to form
437      * the corresponding subtree. Otherwise, this simply generates an empty
438      * <code>DocumentFragment</code>.</dd>
439      * <dt>DOCUMENT_NODE</dt>
440      * <dd><code>Document</code>
441      * nodes cannot be imported.</dd>
442      * <dt>DOCUMENT_TYPE_NODE</dt>
443      * <dd><code>DocumentType</code>
444      * nodes cannot be imported.</dd>
445      * <dt>ELEMENT_NODE</dt>
446      * <dd>Specified attribute nodes of the
447      * source element are imported, and the generated <code>Attr</code>
448      * nodes are attached to the generated <code>Element</code>. Default
449      * attributes are not copied, though if the document being imported into
450      * defines default attributes for this element name, those are assigned.
451      * If the <code>importNode</code> <code>deep</code> parameter was set to
452      * <code>true</code>, the descendants of the source element are
453      * recursively imported and the resulting nodes reassembled to form the
454      * corresponding subtree.</dd>
455      * <dt>ENTITY_NODE</dt>
456      * <dd><code>Entity</code> nodes can be
457      * imported, however in the current release of the DOM the
458      * <code>DocumentType</code> is readonly. Ability to add these imported
459      * nodes to a <code>DocumentType</code> will be considered for addition
460      * to a future release of the DOM.On import, the <code>publicId</code>,
461      * <code>systemId</code>, and <code>notationName</code> attributes are
462      * copied. If a <code>deep</code> import is requested, the descendants
463      * of the the source <code>Entity</code> are recursively imported and
464      * the resulting nodes reassembled to form the corresponding subtree.</dd>
465      * <dt>
466      * ENTITY_REFERENCE_NODE</dt>
467      * <dd>Only the <code>EntityReference</code> itself is
468      * copied, even if a <code>deep</code> import is requested, since the
469      * source and destination documents might have defined the entity
470      * differently. If the document being imported into provides a
471      * definition for this entity name, its value is assigned.</dd>
472      * <dt>NOTATION_NODE</dt>
473      * <dd>
474      * <code>Notation</code> nodes can be imported, however in the current
475      * release of the DOM the <code>DocumentType</code> is readonly. Ability
476      * to add these imported nodes to a <code>DocumentType</code> will be
477      * considered for addition to a future release of the DOM.On import, the
478      * <code>publicId</code> and <code>systemId</code> attributes are copied.
479      * Note that the <code>deep</code> parameter has no effect on
480      * <code>Notation</code> nodes since they never have any children.</dd>
481      * <dt>
482      * PROCESSING_INSTRUCTION_NODE</dt>
483      * <dd>The imported node copies its
484      * <code>target</code> and <code>data</code> values from those of the
485      * source node.</dd>
486      * <dt>TEXT_NODE, CDATA_SECTION_NODE, COMMENT_NODE</dt>
487      * <dd>These three
488      * types of nodes inheriting from <code>CharacterData</code> copy their
489      * <code>data</code> and <code>length</code> attributes from those of
490      * the source node.</dd>
491      * </dl>
492      * @param importedNode The node to import.
493      * @param deep If <code>true</code>, recursively import the subtree under
494      * the specified node; if <code>false</code>, import only the node
495      * itself, as explained above. This has no effect on <code>Attr</code>
496      * , <code>EntityReference</code>, and <code>Notation</code> nodes.
497      * @return The imported node that belongs to this <code>Document</code>.
498      * @exception DOMException
499      * NOT_SUPPORTED_ERR: Raised if the type of node being imported is not
500      * supported.
501      * @since DOM Level 2
502      *
503      */

504     public Node importNode(Node importedNode, boolean deep) throws DOMException {
505         throw new UOException();
506     }
507     
508     /** The first child of this node. If there is no such node, this returns
509      * <code>null</code>.
510      *
511      */

512     public Node getFirstChild() {
513         return getDocumentElement();
514     }
515
516     /** The last child of this node. If there is no such node, this returns
517      * <code>null</code>.
518      *
519      */

520     public Node getLastChild() {
521         return getDocumentElement();
522     }
523
524     /** Returns whether this node has any children.
525      * @return <code>true</code> if this node has any children,
526      * <code>false</code> otherwise.
527      *
528      */

529     public boolean hasChildNodes() {
530         return getDocumentElement() != null;
531     }
532     
533     /** A <code>NodeList</code> that contains all children of this node. If
534      * there are no children, this is a <code>NodeList</code> containing no
535      * nodes.
536      *
537      */

538     public NodeList getChildNodes() {
539         return Wrapper.wrap(peer.getChildNodes());
540     }
541     
542     //
543
// Dom Level 3 methods:
544
//
545

546     public Node adoptNode (Node a) {
547         throw new UOException ();
548     }
549     public String JavaDoc getDocumentURI () {
550         throw new UOException ();
551     }
552     public DOMConfiguration getDomConfig() {
553         throw new UOException ();
554     }
555     public String JavaDoc getInputEncoding() {
556         throw new UOException ();
557     }
558     public boolean getStrictErrorChecking() {
559         throw new UOException ();
560     }
561     public String JavaDoc getXmlEncoding () {
562         throw new UOException ();
563     }
564     public boolean getXmlStandalone() {
565         throw new UOException ();
566     }
567     public String JavaDoc getXmlVersion() {
568         throw new UOException ();
569     }
570     public void normalizeDocument() {
571         throw new UOException ();
572     }
573     public Node renameNode(Node a, String JavaDoc nb, String JavaDoc c) {
574         throw new UOException ();
575     }
576     public void setDocumentURI(String JavaDoc a) {
577         throw new UOException ();
578     }
579     public void setStrictErrorChecking(boolean a) {
580         throw new UOException ();
581     }
582     public void setXmlStandalone(boolean a) {
583         throw new UOException ();
584     }
585     public void setXmlVersion(String JavaDoc a) {
586         throw new UOException ();
587     }
588 }
589
Popular Tags