KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > apache > xerces > dom > NodeImpl


1  /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Xerces" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 1999, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57
58 package org.enhydra.apache.xerces.dom;
59
60 import java.io.IOException JavaDoc;
61 import java.io.ObjectOutputStream JavaDoc;
62 import java.io.Serializable JavaDoc;
63
64 import org.w3c.dom.DOMException JavaDoc;
65 import org.w3c.dom.Document JavaDoc;
66 import org.w3c.dom.NamedNodeMap JavaDoc;
67 import org.w3c.dom.Node JavaDoc;
68 import org.w3c.dom.NodeList JavaDoc;
69 import org.w3c.dom.UserDataHandler JavaDoc;
70 import org.w3c.dom.events.Event JavaDoc;
71 import org.w3c.dom.events.EventListener JavaDoc;
72 import org.w3c.dom.events.EventTarget JavaDoc;
73
74 /**
75  * NodeImpl provides the basic structure of a DOM tree. It is never used
76  * directly, but instead is subclassed to add type and data
77  * information, and additional methods, appropriate to each node of
78  * the tree. Only its subclasses should be instantiated -- and those,
79  * with the exception of Document itself, only through a specific
80  * Document's factory methods.
81  * <P>
82  * The Node interface provides shared behaviors such as siblings and
83  * children, both for consistancy and so that the most common tree
84  * operations may be performed without constantly having to downcast
85  * to specific node types. When there is no obvious mapping for one of
86  * these queries, it will respond with null.
87  * Note that the default behavior is that children are forbidden. To
88  * permit them, the subclass ParentNode overrides several methods.
89  * <P>
90  * NodeImpl also implements NodeList, so it can return itself in
91  * response to the getChildNodes() query. This eliminiates the need
92  * for a separate ChildNodeList object. Note that this is an
93  * IMPLEMENTATION DETAIL; applications should _never_ assume that
94  * this identity exists.
95  * <P>
96  * All nodes in a single document must originate
97  * in that document. (Note that this is much tighter than "must be
98  * same implementation") Nodes are all aware of their ownerDocument,
99  * and attempts to mismatch will throw WRONG_DOCUMENT_ERR.
100  * <P>
101  * However, to save memory not all nodes always have a direct reference
102  * to their ownerDocument. When a node is owned by another node it relies
103  * on its owner to store its ownerDocument. Parent nodes always store it
104  * though, so there is never more than one level of indirection.
105  * And when a node doesn't have an owner, ownerNode refers to its
106  * ownerDocument.
107  * <p>
108  * This class doesn't directly support mutation events, however, it still
109  * implements the EventTarget interface and forward all related calls to the
110  * document so that the document class do so.
111  *
112  * @author Arnaud Le Hors, IBM
113  * @author Joe Kesselman, IBM
114  * @version
115  * @since PR-DOM-Level-1-19980818.
116  */

117 public abstract class NodeImpl
118     implements Node JavaDoc, NodeList JavaDoc, EventTarget JavaDoc, Cloneable JavaDoc, Serializable JavaDoc {
119
120     //
121
// Constants
122
//
123

124     /** Serialization version. */
125     static final long serialVersionUID = -6316591992167219696L;
126
127     // public
128

129     /** Element definition node type. */
130     public static final short ELEMENT_DEFINITION_NODE = -1;
131
132     //
133
// Data
134
//
135

136     // links
137

138     protected NodeImpl ownerNode; // typically the parent but not always!
139

140     // data
141

142     protected short flags;
143
144     protected final static short READONLY = 0x1<<0;
145     protected final static short SYNCDATA = 0x1<<1;
146     protected final static short SYNCCHILDREN = 0x1<<2;
147     protected final static short OWNED = 0x1<<3;
148     protected final static short FIRSTCHILD = 0x1<<4;
149     protected final static short SPECIFIED = 0x1<<5;
150     protected final static short IGNORABLEWS = 0x1<<6;
151     protected final static short HASSTRING = 0x1<<7;
152     protected final static short UNNORMALIZED = 0x1<<8;
153
154     //
155
// Constructors
156
//
157

158     /**
159      * No public constructor; only subclasses of Node should be
160      * instantiated, and those normally via a Document's factory methods
161      * <p>
162      * Every Node knows what Document it belongs to.
163      */

164     protected NodeImpl(CoreDocumentImpl ownerDocument) {
165         // as long as we do not have any owner, ownerNode is our ownerDocument
166
ownerNode = ownerDocument;
167     } // <init>(CoreDocumentImpl)
168

169     /** Constructor for serialization. */
170     public NodeImpl() {}
171
172     //
173
// Node methods
174
//
175

176     /**
177      * A short integer indicating what type of node this is. The named
178      * constants for this value are defined in the org.w3c.dom.Node interface.
179      */

180     public abstract short getNodeType();
181
182     /**
183      * the name of this node.
184      */

185     public abstract String JavaDoc getNodeName();
186     
187     /**
188      * Returns the node value.
189      */

190     public String JavaDoc getNodeValue() {
191         return null; // overridden in some subclasses
192
}
193
194     /**
195      * Sets the node value.
196      * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR)
197      */

198     public void setNodeValue(String JavaDoc x)
199         throws DOMException JavaDoc {
200         // Default behavior is to do nothing, overridden in some subclasses
201
}
202
203     /**
204      * Adds a child node to the end of the list of children for this node.
205      * Convenience shorthand for insertBefore(newChild,null).
206      * @see #insertBefore(Node, Node)
207      * <P>
208      * By default we do not accept any children, ParentNode overrides this.
209      * @see ParentNode
210      *
211      * @returns newChild, in its new state (relocated, or emptied in the
212      * case of DocumentNode.)
213      *
214      * @throws DOMException(HIERARCHY_REQUEST_ERR) if newChild is of a
215      * type that shouldn't be a child of this node.
216      *
217      * @throws DOMException(WRONG_DOCUMENT_ERR) if newChild has a
218      * different owner document than we do.
219      *
220      * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if this node is
221      * read-only.
222      */

223     public Node JavaDoc appendChild(Node JavaDoc newChild) throws DOMException JavaDoc {
224         return insertBefore(newChild, null);
225     }
226
227     /**
228      * Returns a duplicate of a given node. You can consider this a
229      * generic "copy constructor" for nodes. The newly returned object should
230      * be completely independent of the source object's subtree, so changes
231      * in one after the clone has been made will not affect the other.
232      * <P>
233      * Note: since we never have any children deep is meaningless here,
234      * ParentNode overrides this behavior.
235      * @see ParentNode
236      *
237      * <p>
238      * Example: Cloning a Text node will copy both the node and the text it
239      * contains.
240      * <p>
241      * Example: Cloning something that has children -- Element or Attr, for
242      * example -- will _not_ clone those children unless a "deep clone"
243      * has been requested. A shallow clone of an Attr node will yield an
244      * empty Attr of the same name.
245      * <p>
246      * NOTE: Clones will always be read/write, even if the node being cloned
247      * is read-only, to permit applications using only the DOM API to obtain
248      * editable copies of locked portions of the tree.
249      */

250     public Node JavaDoc cloneNode(boolean deep) {
251
252         if (needsSyncData()) {
253             synchronizeData();
254     }
255         
256         NodeImpl newnode;
257         try {
258             newnode = (NodeImpl)clone();
259         }
260         catch (CloneNotSupportedException JavaDoc e) {
261 // Revisit : don't fail silently - but don't want to tie to parser guts
262
// System.out.println("UNEXPECTED "+e);
263
return null;
264         }
265         
266         // Need to break the association w/ original kids
267
newnode.ownerNode = ownerDocument();
268         newnode.isOwned(false);
269
270         // REVISIT: What to do when readOnly? -Ac
271
newnode.isReadOnly(false);
272
273         return newnode;
274
275     } // cloneNode(boolean):Node
276

277     /**
278      * Find the Document that this Node belongs to (the document in
279      * whose context the Node was created). The Node may or may not
280      * currently be part of that Document's actual contents.
281      */

282     public Document JavaDoc getOwnerDocument() {
283         // if we have an owner simply forward the request
284
// otherwise ownerNode is our ownerDocument
285
if (isOwned()) {
286             return ownerNode.ownerDocument();
287         } else {
288             return (Document JavaDoc) ownerNode;
289         }
290     }
291
292     /**
293      * same as above but returns internal type and this one is not overridden
294      * by CoreDocumentImpl to return null
295      */

296     CoreDocumentImpl ownerDocument() {
297         // if we have an owner simply forward the request
298
// otherwise ownerNode is our ownerDocument
299
if (isOwned()) {
300             return ownerNode.ownerDocument();
301         } else {
302             return (CoreDocumentImpl) ownerNode;
303         }
304     }
305
306     /**
307      * NON-DOM
308      * set the ownerDocument of this node
309      */

310     void setOwnerDocument(CoreDocumentImpl doc) {
311         if (needsSyncData()) {
312             synchronizeData();
313         }
314         // if we have an owner we rely on it to have it right
315
// otherwise ownerNode is our ownerDocument
316
if (!isOwned()) {
317             ownerNode = doc;
318         }
319     }
320
321     /**
322      * Obtain the DOM-tree parent of this node, or null if it is not
323      * currently active in the DOM tree (perhaps because it has just been
324      * created or removed). Note that Document, DocumentFragment, and
325      * Attribute will never have parents.
326      */

327     public Node JavaDoc getParentNode() {
328         return null; // overriden by ChildNode
329
}
330
331     /*
332      * same as above but returns internal type
333      */

334     NodeImpl parentNode() {
335         return null;
336     }
337
338     /** The next child of this node's parent, or null if none */
339     public Node JavaDoc getNextSibling() {
340         return null; // default behavior, overriden in ChildNode
341
}
342
343     /** The previous child of this node's parent, or null if none */
344     public Node JavaDoc getPreviousSibling() {
345         return null; // default behavior, overriden in ChildNode
346
}
347
348     ChildNode previousSibling() {
349         return null; // default behavior, overriden in ChildNode
350
}
351
352     /**
353      * Return the collection of attributes associated with this node,
354      * or null if none. At this writing, Element is the only type of node
355      * which will ever have attributes.
356      *
357      * @see ElementImpl
358      */

359     public NamedNodeMap JavaDoc getAttributes() {
360         return null; // overridden in ElementImpl
361
}
362
363     /**
364      * Returns whether this node (if it is an element) has any attributes.
365      * @return <code>true</code> if this node has any attributes,
366      * <code>false</code> otherwise.
367      * @since DOM Level 2
368      * @see ElementImpl
369      */

370     public boolean hasAttributes() {
371         return false; // overridden in ElementImpl
372
}
373
374     /**
375      * Test whether this node has any children. Convenience shorthand
376      * for (Node.getFirstChild()!=null)
377      * <P>
378      * By default we do not have any children, ParentNode overrides this.
379      * @see ParentNode
380      */

381     public boolean hasChildNodes() {
382         return false;
383     }
384
385     /**
386      * Obtain a NodeList enumerating all children of this node. If there
387      * are none, an (initially) empty NodeList is returned.
388      * <p>
389      * NodeLists are "live"; as children are added/removed the NodeList
390      * will immediately reflect those changes. Also, the NodeList refers
391      * to the actual nodes, so changes to those nodes made via the DOM tree
392      * will be reflected in the NodeList and vice versa.
393      * <p>
394      * In this implementation, Nodes implement the NodeList interface and
395      * provide their own getChildNodes() support. Other DOMs may solve this
396      * differently.
397      */

398     public NodeList JavaDoc getChildNodes() {
399         return this;
400     }
401
402     /** The first child of this Node, or null if none.
403      * <P>
404      * By default we do not have any children, ParentNode overrides this.
405      * @see ParentNode
406      */

407     public Node JavaDoc getFirstChild() {
408         return null;
409     }
410
411     /** The first child of this Node, or null if none.
412      * <P>
413      * By default we do not have any children, ParentNode overrides this.
414      * @see ParentNode
415      */

416     public Node JavaDoc getLastChild() {
417     return null;
418     }
419
420     /**
421      * Move one or more node(s) to our list of children. Note that this
422      * implicitly removes them from their previous parent.
423      * <P>
424      * By default we do not accept any children, ParentNode overrides this.
425      * @see ParentNode
426      *
427      * @param newChild The Node to be moved to our subtree. As a
428      * convenience feature, inserting a DocumentNode will instead insert
429      * all its children.
430      *
431      * @param refChild Current child which newChild should be placed
432      * immediately before. If refChild is null, the insertion occurs
433      * after all existing Nodes, like appendChild().
434      *
435      * @returns newChild, in its new state (relocated, or emptied in the
436      * case of DocumentNode.)
437      *
438      * @throws DOMException(HIERARCHY_REQUEST_ERR) if newChild is of a
439      * type that shouldn't be a child of this node, or if newChild is an
440      * ancestor of this node.
441      *
442      * @throws DOMException(WRONG_DOCUMENT_ERR) if newChild has a
443      * different owner document than we do.
444      *
445      * @throws DOMException(NOT_FOUND_ERR) if refChild is not a child of
446      * this node.
447      *
448      * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if this node is
449      * read-only.
450      */

451     public Node JavaDoc insertBefore(Node JavaDoc newChild, Node JavaDoc refChild)
452     throws DOMException JavaDoc {
453     throw new DOMException JavaDoc(DOMException.HIERARCHY_REQUEST_ERR,
454                    "DOM006 Hierarchy request error");
455     }
456
457     /**
458      * Remove a child from this Node. The removed child's subtree
459      * remains intact so it may be re-inserted elsewhere.
460      * <P>
461      * By default we do not have any children, ParentNode overrides this.
462      * @see ParentNode
463      *
464      * @return oldChild, in its new state (removed).
465      *
466      * @throws DOMException(NOT_FOUND_ERR) if oldChild is not a child of
467      * this node.
468      *
469      * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if this node is
470      * read-only.
471      */

472     public Node JavaDoc removeChild(Node JavaDoc oldChild)
473         throws DOMException JavaDoc {
474     throw new DOMException JavaDoc(DOMException.NOT_FOUND_ERR,
475                    "DOM008 Not found");
476     }
477
478     /**
479      * Make newChild occupy the location that oldChild used to
480      * have. Note that newChild will first be removed from its previous
481      * parent, if any. Equivalent to inserting newChild before oldChild,
482      * then removing oldChild.
483      * <P>
484      * By default we do not have any children, ParentNode overrides this.
485      * @see ParentNode
486      *
487      * @returns oldChild, in its new state (removed).
488      *
489      * @throws DOMException(HIERARCHY_REQUEST_ERR) if newChild is of a
490      * type that shouldn't be a child of this node, or if newChild is
491      * one of our ancestors.
492      *
493      * @throws DOMException(WRONG_DOCUMENT_ERR) if newChild has a
494      * different owner document than we do.
495      *
496      * @throws DOMException(NOT_FOUND_ERR) if oldChild is not a child of
497      * this node.
498      *
499      * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if this node is
500      * read-only.
501      */

502     public Node JavaDoc replaceChild(Node JavaDoc newChild, Node JavaDoc oldChild)
503         throws DOMException JavaDoc {
504     throw new DOMException JavaDoc(DOMException.HIERARCHY_REQUEST_ERR,
505                    "DOM006 Hierarchy request error");
506     }
507
508     //
509
// NodeList methods
510
//
511

512     /**
513      * NodeList method: Count the immediate children of this node
514      * <P>
515      * By default we do not have any children, ParentNode overrides this.
516      * @see ParentNode
517      *
518      * @return int
519      */

520     public int getLength() {
521     return 0;
522     }
523
524     /**
525      * NodeList method: Return the Nth immediate child of this node, or
526      * null if the index is out of bounds.
527      * <P>
528      * By default we do not have any children, ParentNode overrides this.
529      * @see ParentNode
530      *
531      * @return org.w3c.dom.Node
532      * @param Index int
533      */

534     public Node JavaDoc item(int index) {
535     return null;
536     }
537
538     //
539
// DOM2: methods, getters, setters
540
//
541

542     /**
543      * Puts all <code>Text</code> nodes in the full depth of the sub-tree
544      * underneath this <code>Node</code>, including attribute nodes, into a
545      * "normal" form where only markup (e.g., tags, comments, processing
546      * instructions, CDATA sections, and entity references) separates
547      * <code>Text</code> nodes, i.e., there are no adjacent <code>Text</code>
548      * nodes. This can be used to ensure that the DOM view of a document is
549      * the same as if it were saved and re-loaded, and is useful when
550      * operations (such as XPointer lookups) that depend on a particular
551      * document tree structure are to be used.In cases where the document
552      * contains <code>CDATASections</code>, the normalize operation alone may
553      * not be sufficient, since XPointers do not differentiate between
554      * <code>Text</code> nodes and <code>CDATASection</code> nodes.
555      * <p>
556      * Note that this implementation simply calls normalize() on this Node's
557      * children. It is up to implementors or Node to override normalize()
558      * to take action.
559      */

560     public void normalize() {
561     /* by default we do not have any children,
562        ParentNode overrides this behavior */

563     }
564
565     /**
566      * Introduced in DOM Level 2. <p>
567      * Tests whether the DOM implementation implements a specific feature and
568      * that feature is supported by this node.
569      * @param feature The package name of the feature to test. This is the same
570      * name as what can be passed to the method hasFeature on
571      * DOMImplementation.
572      * @param version This is the version number of the package name to
573      * test. In Level 2, version 1, this is the string "2.0". If the version is
574      * not specified, supporting any version of the feature will cause the
575      * method to return true.
576      * @return boolean Returns true if this node defines a subtree within which
577      * the specified feature is supported, false otherwise.
578      * @since WD-DOM-Level-2-19990923
579      */

580     public boolean isSupported(String JavaDoc feature, String JavaDoc version)
581     {
582         return ownerDocument().getImplementation().hasFeature(feature,
583                                                               version);
584     }
585
586     /**
587      * Introduced in DOM Level 2. <p>
588      *
589      * The namespace URI of this node, or null if it is unspecified. When this
590      * node is of any type other than ELEMENT_NODE and ATTRIBUTE_NODE, this is
591      * always null and setting it has no effect. <p>
592      *
593      * This is not a computed value that is the result of a namespace lookup
594      * based on an examination of the namespace declarations in scope. It is
595      * merely the namespace URI given at creation time.<p>
596      *
597      * For nodes created with a DOM Level 1 method, such as createElement
598      * from the Document interface, this is null.
599      * @since WD-DOM-Level-2-19990923
600      * @see AttrNSImpl
601      * @see ElementNSImpl
602      */

603     public String JavaDoc getNamespaceURI()
604     {
605         return null;
606     }
607
608     /**
609      * Introduced in DOM Level 2. <p>
610      *
611      * The namespace prefix of this node, or null if it is unspecified. When
612      * this node is of any type other than ELEMENT_NODE and ATTRIBUTE_NODE this
613      * is always null and setting it has no effect.<p>
614      *
615      * For nodes created with a DOM Level 1 method, such as createElement
616      * from the Document interface, this is null. <p>
617      *
618      * @since WD-DOM-Level-2-19990923
619      * @see AttrNSImpl
620      * @see ElementNSImpl
621      */

622     public String JavaDoc getPrefix()
623     {
624         return null;
625     }
626
627     /**
628      * Introduced in DOM Level 2. <p>
629      *
630      * The namespace prefix of this node, or null if it is unspecified. When
631      * this node is of any type other than ELEMENT_NODE and ATTRIBUTE_NODE
632      * this is always null and setting it has no effect.<p>
633      *
634      * For nodes created with a DOM Level 1 method, such as createElement from
635      * the Document interface, this is null.<p>
636      *
637      * Note that setting this attribute changes the nodeName attribute, which
638      * holds the qualified name, as well as the tagName and name attributes of
639      * the Element and Attr interfaces, when applicable.<p>
640      *
641      * @throws INVALID_CHARACTER_ERR Raised if the specified
642      * prefix contains an invalid character.
643      *
644      * @since WD-DOM-Level-2-19990923
645      * @see AttrNSImpl
646      * @see ElementNSImpl
647      */

648     public void setPrefix(String JavaDoc prefix)
649         throws DOMException JavaDoc
650     {
651     throw new DOMException JavaDoc(DOMException.NAMESPACE_ERR,
652                    "DOM003 Namespace error");
653     }
654
655     /**
656      * Introduced in DOM Level 2. <p>
657      *
658      * Returns the local part of the qualified name of this node.
659      * For nodes created with a DOM Level 1 method, such as createElement
660      * from the Document interface, and for nodes of any type other than
661      * ELEMENT_NODE and ATTRIBUTE_NODE this is the same as the nodeName
662      * attribute.
663      * @since WD-DOM-Level-2-19990923
664      * @see AttrNSImpl
665      * @see ElementNSImpl
666      */

667     public String JavaDoc getLocalName()
668     {
669         return null;
670     }
671     
672     //
673
// EventTarget support
674
//
675

676     public void addEventListener(String JavaDoc type, EventListener JavaDoc listener,
677                                  boolean useCapture) {
678         // simply forward to Document
679
ownerDocument().addEventListener(this, type, listener, useCapture);
680     }
681
682     public void removeEventListener(String JavaDoc type, EventListener JavaDoc listener,
683                                     boolean useCapture) {
684         // simply forward to Document
685
ownerDocument().removeEventListener(this, type, listener, useCapture);
686     }
687
688     public boolean dispatchEvent(Event JavaDoc event) {
689         // simply forward to Document
690
return ownerDocument().dispatchEvent(this, event);
691     }
692
693     //
694
// Public methods
695
//
696

697     /**
698      * NON-DOM: PR-DOM-Level-1-19980818 mentions readonly nodes in conjunction
699      * with Entities, but provides no API to support this.
700      * <P>
701      * Most DOM users should not touch this method. Its anticpated use
702      * is during construction of EntityRefernces, where it will be used to
703      * lock the contents replicated from Entity so they can't be casually
704      * altered. It _could_ be published as a DOM extension, if desired.
705      * <P>
706      * Note: since we never have any children deep is meaningless here,
707      * ParentNode overrides this behavior.
708      * @see ParentNode
709      *
710      * @param readOnly True or false as desired.
711      * @param deep If true, children are also toggled. Note that this will
712      * not change the state of an EntityReference or its children,
713      * which are always read-only.
714      */

715     public void setReadOnly(boolean readOnly, boolean deep) {
716
717         if (needsSyncData()) {
718             synchronizeData();
719         }
720         isReadOnly(readOnly);
721
722     } // setReadOnly(boolean,boolean)
723

724     /**
725      * NON-DOM: Returns true if this node is read-only. This is a
726      * shallow check.
727      */

728     public boolean getReadOnly() {
729
730         if (needsSyncData()) {
731             synchronizeData();
732         }
733         return isReadOnly();
734
735     } // getReadOnly():boolean
736

737     /**
738      * NON-DOM: As an alternative to subclassing the DOM, this implementation
739      * has been extended with the ability to attach an object to each node.
740      * (If you need multiple objects, you can attach a collection such as a
741      * vector or hashtable, then attach your application information to that.)
742      * <p><b>Important Note:</b> You are responsible for removing references
743      * to your data on nodes that are no longer used. Failure to do so will
744      * prevent the nodes, your data is attached to, to be garbage collected
745      * until the whole document is.
746      *
747      * @param data the object to store or null to remove any existing reference
748      */

749     public void setUserData(Object JavaDoc data) {
750         ownerDocument().setUserData(this, data);
751     }
752
753     /**
754      * NON-DOM:
755      * Returns the user data associated to this node.
756      */

757     public Object JavaDoc getUserData() {
758         return ownerDocument().getUserData(this);
759     }
760
761     //
762
// Protected methods
763
//
764

765     /**
766      * Denotes that this node has changed.
767      */

768     protected void changed() {
769         // we do not actually store this information on every node, we only
770
// have a global indicator on the Document. Doing otherwise cost us too
771
// much for little gain.
772
ownerDocument().changed();
773     }
774
775     /**
776      * Returns the number of changes to this node.
777      */

778     protected int changes() {
779         // we do not actually store this information on every node, we only
780
// have a global indicator on the Document. Doing otherwise cost us too
781
// much for little gain.
782
return ownerDocument().changes();
783     }
784
785     /**
786      * Override this method in subclass to hook in efficient
787      * internal data structure.
788      */

789     protected void synchronizeData() {
790         // By default just change the flag to avoid calling this method again
791
needsSyncData(false);
792     }
793
794
795     /*
796      * Flags setters and getters
797      */

798
799     final boolean isReadOnly() {
800         return (flags & READONLY) != 0;
801     }
802
803     final void isReadOnly(boolean value) {
804         flags = (short) (value ? flags | READONLY : flags & ~READONLY);
805     }
806
807     final boolean needsSyncData() {
808         return (flags & SYNCDATA) != 0;
809     }
810
811     final void needsSyncData(boolean value) {
812         flags = (short) (value ? flags | SYNCDATA : flags & ~SYNCDATA);
813     }
814
815     final boolean needsSyncChildren() {
816         return (flags & SYNCCHILDREN) != 0;
817     }
818
819     final void needsSyncChildren(boolean value) {
820         flags = (short) (value ? flags | SYNCCHILDREN : flags & ~SYNCCHILDREN);
821     }
822
823     final boolean isOwned() {
824         return (flags & OWNED) != 0;
825     }
826
827     final void isOwned(boolean value) {
828         flags = (short) (value ? flags | OWNED : flags & ~OWNED);
829     }
830
831     final boolean isFirstChild() {
832         return (flags & FIRSTCHILD) != 0;
833     }
834
835     final void isFirstChild(boolean value) {
836         flags = (short) (value ? flags | FIRSTCHILD : flags & ~FIRSTCHILD);
837     }
838
839     final boolean isSpecified() {
840         return (flags & SPECIFIED) != 0;
841     }
842
843     final void isSpecified(boolean value) {
844         flags = (short) (value ? flags | SPECIFIED : flags & ~SPECIFIED);
845     }
846
847     // inconsistent name to avoid clash with public method on TextImpl
848
final boolean internalIsIgnorableWhitespace() {
849         return (flags & IGNORABLEWS) != 0;
850     }
851
852     final void isIgnorableWhitespace(boolean value) {
853         flags = (short) (value ? flags | IGNORABLEWS : flags & ~IGNORABLEWS);
854     }
855
856     final boolean hasStringValue() {
857         return (flags & HASSTRING) != 0;
858     }
859
860     final void hasStringValue(boolean value) {
861         flags = (short) (value ? flags | HASSTRING : flags & ~HASSTRING);
862     }
863
864     final boolean isNormalized() {
865         return (flags & UNNORMALIZED) == 0;
866     }
867
868     final void isNormalized(boolean value) {
869         // See if flag should propagate to parent.
870
if (!value && isNormalized() && ownerNode != null) {
871             ownerNode.isNormalized(false);
872         }
873         flags = (short) (value ? flags & ~UNNORMALIZED : flags | UNNORMALIZED);
874     }
875
876     //
877
// Object methods
878
//
879

880     /** NON-DOM method for debugging convenience. */
881     public String JavaDoc toString() {
882         return "["+getNodeName()+": "+getNodeValue()+"]";
883     }
884
885     //
886
// Serialization methods
887
//
888

889     /** Serialize object. */
890     private void writeObject(ObjectOutputStream JavaDoc out) throws IOException JavaDoc {
891
892         // synchronize data
893
if (needsSyncData()) {
894             synchronizeData();
895         }
896         // write object
897
out.defaultWriteObject();
898
899     } // writeObject(ObjectOutputStream)
900

901
902     /* (non-Javadoc)
903      * @see org.w3c.dom.Node#compareDocumentPosition(org.w3c.dom.Node)
904      */

905     public short compareDocumentPosition(Node JavaDoc arg0) throws DOMException JavaDoc {
906         // TODO Auto-generated method stub
907
return 0;
908     }
909     /* (non-Javadoc)
910      * @see org.w3c.dom.Node#getBaseURI()
911      */

912     public String JavaDoc getBaseURI() {
913         // TODO Auto-generated method stub
914
return null;
915     }
916     /* (non-Javadoc)
917      * @see org.w3c.dom.Node#getFeature(java.lang.String, java.lang.String)
918      */

919     public Object JavaDoc getFeature(String JavaDoc arg0, String JavaDoc arg1) {
920         // TODO Auto-generated method stub
921
return null;
922     }
923     /* (non-Javadoc)
924      * @see org.w3c.dom.Node#getTextContent()
925      */

926     public String JavaDoc getTextContent() throws DOMException JavaDoc {
927         // TODO Auto-generated method stub
928
return null;
929     }
930     /* (non-Javadoc)
931      * @see org.w3c.dom.Node#getUserData(java.lang.String)
932      */

933     public Object JavaDoc getUserData(String JavaDoc arg0) {
934         // TODO Auto-generated method stub
935
return null;
936     }
937     /* (non-Javadoc)
938      * @see org.w3c.dom.Node#isDefaultNamespace(java.lang.String)
939      */

940     public boolean isDefaultNamespace(String JavaDoc arg0) {
941         // TODO Auto-generated method stub
942
return false;
943     }
944     /* (non-Javadoc)
945      * @see org.w3c.dom.Node#isEqualNode(org.w3c.dom.Node)
946      */

947     public boolean isEqualNode(Node JavaDoc arg0) {
948         // TODO Auto-generated method stub
949
return false;
950     }
951     /* (non-Javadoc)
952      * @see org.w3c.dom.Node#isSameNode(org.w3c.dom.Node)
953      */

954     public boolean isSameNode(Node JavaDoc arg0) {
955         // TODO Auto-generated method stub
956
return false;
957     }
958     /* (non-Javadoc)
959      * @see org.w3c.dom.Node#lookupNamespaceURI(java.lang.String)
960      */

961     public String JavaDoc lookupNamespaceURI(String JavaDoc arg0) {
962         // TODO Auto-generated method stub
963
return null;
964     }
965     /* (non-Javadoc)
966      * @see org.w3c.dom.Node#lookupPrefix(java.lang.String)
967      */

968     public String JavaDoc lookupPrefix(String JavaDoc arg0) {
969         // TODO Auto-generated method stub
970
return null;
971     }
972     /* (non-Javadoc)
973      * @see org.w3c.dom.Node#setTextContent(java.lang.String)
974      */

975     public void setTextContent(String JavaDoc arg0) throws DOMException JavaDoc {
976         // TODO Auto-generated method stub
977

978     }
979     /* (non-Javadoc)
980      * @see org.w3c.dom.Node#setUserData(java.lang.String, java.lang.Object, org.w3c.dom.UserDataHandler)
981      */

982     public Object JavaDoc setUserData(String JavaDoc arg0, Object JavaDoc arg1, UserDataHandler JavaDoc arg2) {
983         // TODO Auto-generated method stub
984
return null;
985     }
986
987 } // class NodeImpl
988
Popular Tags