001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.xerces.dom;
019:
020: import org.w3c.dom.Node;
021:
022: /**
023: * ChildNode inherits from NodeImpl and adds the capability of being a child by
024: * having references to its previous and next siblings.
025: *
026: * @xerces.internal
027: *
028: * @version $Id: ChildNode.java 447266 2006-09-18 05:57:49Z mrglavas $
029: */
030: public abstract class ChildNode extends NodeImpl {
031:
032: //
033: // Constants
034: //
035:
036: /** Serialization version. */
037: static final long serialVersionUID = -6112455738802414002L;
038:
039: //
040: // Data
041: //
042:
043: /** Previous sibling. */
044: protected ChildNode previousSibling;
045:
046: /** Next sibling. */
047: protected ChildNode nextSibling;
048:
049: //
050: // Constructors
051: //
052:
053: /**
054: * No public constructor; only subclasses of Node should be
055: * instantiated, and those normally via a Document's factory methods
056: * <p>
057: * Every Node knows what Document it belongs to.
058: */
059: protected ChildNode(CoreDocumentImpl ownerDocument) {
060: super (ownerDocument);
061: } // <init>(CoreDocumentImpl)
062:
063: /** Constructor for serialization. */
064: public ChildNode() {
065: }
066:
067: //
068: // Node methods
069: //
070:
071: /**
072: * Returns a duplicate of a given node. You can consider this a
073: * generic "copy constructor" for nodes. The newly returned object should
074: * be completely independent of the source object's subtree, so changes
075: * in one after the clone has been made will not affect the other.
076: * <P>
077: * Note: since we never have any children deep is meaningless here,
078: * ParentNode overrides this behavior.
079: * @see ParentNode
080: *
081: * <p>
082: * Example: Cloning a Text node will copy both the node and the text it
083: * contains.
084: * <p>
085: * Example: Cloning something that has children -- Element or Attr, for
086: * example -- will _not_ clone those children unless a "deep clone"
087: * has been requested. A shallow clone of an Attr node will yield an
088: * empty Attr of the same name.
089: * <p>
090: * NOTE: Clones will always be read/write, even if the node being cloned
091: * is read-only, to permit applications using only the DOM API to obtain
092: * editable copies of locked portions of the tree.
093: */
094: public Node cloneNode(boolean deep) {
095:
096: ChildNode newnode = (ChildNode) super .cloneNode(deep);
097:
098: // Need to break the association w/ original kids
099: newnode.previousSibling = null;
100: newnode.nextSibling = null;
101: newnode.isFirstChild(false);
102:
103: return newnode;
104:
105: } // cloneNode(boolean):Node
106:
107: /**
108: * Returns the parent node of this node
109: */
110: public Node getParentNode() {
111: // if we have an owner, ownerNode is our parent, otherwise it's
112: // our ownerDocument and we don't have a parent
113: return isOwned() ? ownerNode : null;
114: }
115:
116: /*
117: * same as above but returns internal type
118: */
119: final NodeImpl parentNode() {
120: // if we have an owner, ownerNode is our parent, otherwise it's
121: // our ownerDocument and we don't have a parent
122: return isOwned() ? ownerNode : null;
123: }
124:
125: /** The next child of this node's parent, or null if none */
126: public Node getNextSibling() {
127: return nextSibling;
128: }
129:
130: /** The previous child of this node's parent, or null if none */
131: public Node getPreviousSibling() {
132: // if we are the firstChild, previousSibling actually refers to our
133: // parent's lastChild, but we hide that
134: return isFirstChild() ? null : previousSibling;
135: }
136:
137: /*
138: * same as above but returns internal type
139: */
140: final ChildNode previousSibling() {
141: // if we are the firstChild, previousSibling actually refers to our
142: // parent's lastChild, but we hide that
143: return isFirstChild() ? null : previousSibling;
144: }
145:
146: } // class ChildNode
|