KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > dom > ChildNode


1 /*
2  * Copyright 2000-2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.xerces.dom;
18
19 import org.w3c.dom.Node JavaDoc;
20
21 /**
22  * ChildNode inherits from NodeImpl and adds the capability of being a child by
23  * having references to its previous and next siblings.
24  *
25  * @xerces.internal
26  *
27  * @version $Id: ChildNode.java,v 1.10 2004/10/05 17:12:51 mrglavas Exp $
28  */

29 public abstract class ChildNode
30     extends NodeImpl {
31
32     //
33
// Constants
34
//
35

36     /** Serialization version. */
37     static final long serialVersionUID = -6112455738802414002L;
38
39     transient StringBuffer JavaDoc fBufferStr = null;
40     
41     //
42
// Data
43
//
44

45     /** Previous sibling. */
46     protected ChildNode previousSibling;
47
48     /** Next sibling. */
49     protected ChildNode nextSibling;
50
51     //
52
// Constructors
53
//
54

55     /**
56      * No public constructor; only subclasses of Node should be
57      * instantiated, and those normally via a Document's factory methods
58      * <p>
59      * Every Node knows what Document it belongs to.
60      */

61     protected ChildNode(CoreDocumentImpl ownerDocument) {
62         super(ownerDocument);
63     } // <init>(CoreDocumentImpl)
64

65     /** Constructor for serialization. */
66     public ChildNode() {}
67
68     //
69
// Node methods
70
//
71

72     /**
73      * Returns a duplicate of a given node. You can consider this a
74      * generic "copy constructor" for nodes. The newly returned object should
75      * be completely independent of the source object's subtree, so changes
76      * in one after the clone has been made will not affect the other.
77      * <P>
78      * Note: since we never have any children deep is meaningless here,
79      * ParentNode overrides this behavior.
80      * @see ParentNode
81      *
82      * <p>
83      * Example: Cloning a Text node will copy both the node and the text it
84      * contains.
85      * <p>
86      * Example: Cloning something that has children -- Element or Attr, for
87      * example -- will _not_ clone those children unless a "deep clone"
88      * has been requested. A shallow clone of an Attr node will yield an
89      * empty Attr of the same name.
90      * <p>
91      * NOTE: Clones will always be read/write, even if the node being cloned
92      * is read-only, to permit applications using only the DOM API to obtain
93      * editable copies of locked portions of the tree.
94      */

95     public Node JavaDoc cloneNode(boolean deep) {
96
97         ChildNode newnode = (ChildNode) super.cloneNode(deep);
98         
99         // Need to break the association w/ original kids
100
newnode.previousSibling = null;
101         newnode.nextSibling = null;
102         newnode.isFirstChild(false);
103
104         return newnode;
105
106     } // cloneNode(boolean):Node
107

108     /**
109      * Returns the parent node of this node
110      */

111     public Node JavaDoc getParentNode() {
112         // if we have an owner, ownerNode is our parent, otherwise it's
113
// our ownerDocument and we don't have a parent
114
return isOwned() ? ownerNode : null;
115     }
116
117     /*
118      * same as above but returns internal type
119      */

120     final NodeImpl parentNode() {
121         // if we have an owner, ownerNode is our parent, otherwise it's
122
// our ownerDocument and we don't have a parent
123
return isOwned() ? ownerNode : null;
124     }
125
126     /** The next child of this node's parent, or null if none */
127     public Node JavaDoc getNextSibling() {
128         return nextSibling;
129     }
130
131     /** The previous child of this node's parent, or null if none */
132     public Node JavaDoc getPreviousSibling() {
133         // if we are the firstChild, previousSibling actually refers to our
134
// parent's lastChild, but we hide that
135
return isFirstChild() ? null : previousSibling;
136     }
137
138     /*
139      * same as above but returns internal type
140      */

141     final ChildNode previousSibling() {
142         // if we are the firstChild, previousSibling actually refers to our
143
// parent's lastChild, but we hide that
144
return isFirstChild() ? null : previousSibling;
145     }
146
147 } // class ChildNode
148
Popular Tags