View Javadoc
1   /*
2    * reserved comment block
3    * DO NOT REMOVE OR ALTER!
4    */
5   /*
6    * Copyright 2000-2002,2004 The Apache Software Foundation.
7    *
8    * Licensed under the Apache License, Version 2.0 (the "License");
9    * you may not use this file except in compliance with the License.
10   * You may obtain a copy of the License at
11   *
12   *      http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  
21  package com.sun.org.apache.xerces.internal.dom;
22  
23  import org.w3c.dom.Node;
24  
25  /**
26   * ChildNode inherits from NodeImpl and adds the capability of being a child by
27   * having references to its previous and next siblings.
28   *
29   * @xerces.internal
30   *
31   */
32  public abstract class ChildNode
33      extends NodeImpl {
34  
35      //
36      // Constants
37      //
38  
39      /** Serialization version. */
40      static final long serialVersionUID = -6112455738802414002L;
41  
42      transient StringBuffer fBufferStr = null;
43  
44      //
45      // Data
46      //
47  
48      /** Previous sibling. */
49      protected ChildNode previousSibling;
50  
51      /** Next sibling. */
52      protected ChildNode nextSibling;
53  
54      //
55      // Constructors
56      //
57  
58      /**
59       * No public constructor; only subclasses of Node should be
60       * instantiated, and those normally via a Document's factory methods
61       * <p>
62       * Every Node knows what Document it belongs to.
63       */
64      protected ChildNode(CoreDocumentImpl ownerDocument) {
65          super(ownerDocument);
66      } // <init>(CoreDocumentImpl)
67  
68      /** Constructor for serialization. */
69      public ChildNode() {}
70  
71      //
72      // Node methods
73      //
74  
75      /**
76       * Returns a duplicate of a given node. You can consider this a
77       * generic "copy constructor" for nodes. The newly returned object should
78       * be completely independent of the source object's subtree, so changes
79       * in one after the clone has been made will not affect the other.
80       * <P>
81       * Note: since we never have any children deep is meaningless here,
82       * ParentNode overrides this behavior.
83       * @see ParentNode
84       *
85       * <p>
86       * Example: Cloning a Text node will copy both the node and the text it
87       * contains.
88       * <p>
89       * Example: Cloning something that has children -- Element or Attr, for
90       * example -- will _not_ clone those children unless a "deep clone"
91       * has been requested. A shallow clone of an Attr node will yield an
92       * empty Attr of the same name.
93       * <p>
94       * NOTE: Clones will always be read/write, even if the node being cloned
95       * is read-only, to permit applications using only the DOM API to obtain
96       * editable copies of locked portions of the tree.
97       */
98      public Node cloneNode(boolean deep) {
99  
100         ChildNode newnode = (ChildNode) super.cloneNode(deep);
101 
102         // Need to break the association w/ original kids
103         newnode.previousSibling = null;
104         newnode.nextSibling     = null;
105         newnode.isFirstChild(false);
106 
107         return newnode;
108 
109     } // cloneNode(boolean):Node
110 
111     /**
112      * Returns the parent node of this node
113      */
114     public Node getParentNode() {
115         // if we have an owner, ownerNode is our parent, otherwise it's
116         // our ownerDocument and we don't have a parent
117         return isOwned() ? ownerNode : null;
118     }
119 
120     /*
121      * same as above but returns internal type
122      */
123     final NodeImpl parentNode() {
124         // if we have an owner, ownerNode is our parent, otherwise it's
125         // our ownerDocument and we don't have a parent
126         return isOwned() ? ownerNode : null;
127     }
128 
129     /** The next child of this node's parent, or null if none */
130     public Node getNextSibling() {
131         return nextSibling;
132     }
133 
134     /** The previous child of this node's parent, or null if none */
135     public Node getPreviousSibling() {
136         // if we are the firstChild, previousSibling actually refers to our
137         // parent's lastChild, but we hide that
138         return isFirstChild() ? null : previousSibling;
139     }
140 
141     /*
142      * same as above but returns internal type
143      */
144     final ChildNode previousSibling() {
145         // if we are the firstChild, previousSibling actually refers to our
146         // parent's lastChild, but we hide that
147         return isFirstChild() ? null : previousSibling;
148     }
149 
150 } // class ChildNode