ParentNode inherits from NodeImpl and adds the capability of having child
nodes. Not every node in the DOM can have children, so only nodes that can
should inherit from this class and pay the price for it.
ParentNode, just like NodeImpl, also implements NodeList, so it can
return itself in response to the getChildNodes() query. This eliminiates
the need for a separate ChildNodeList object. Note that this is an
IMPLEMENTATION DETAIL; applications should _never_ assume that
this identity exists.
While we have a direct reference to the first child, the last child is
stored as the previous sibling of the first child. First child nodes are
marked as being so, and getNextSibling hides this fact.
Returns a duplicate of a given node. You can consider this a
generic "copy constructor" for nodes. The newly returned object should
be completely independent of the source object's subtree, so changes
in one after the clone has been made will not affect the other.
Example: Cloning a Text node will copy both the node and the text it
Example: Cloning something that has children -- Element or Attr, for
example -- will _not_ clone those children unless a "deep clone"
has been requested. A shallow clone of an Attr node will yield an
empty Attr of the same name.
NOTE: Clones will always be read/write, even if the node being cloned
is read-only, to permit applications using only the DOM API to obtain
editable copies of locked portions of the tree.
Obtain a NodeList enumerating all children of this node. If there
are none, an (initially) empty NodeList is returned.
NodeLists are "live"; as children are added/removed the NodeList
will immediately reflect those changes. Also, the NodeList refers
to the actual nodes, so changes to those nodes made via the DOM tree
will be reflected in the NodeList and vice versa.
In this implementation, Nodes implement the NodeList interface and
provide their own getChildNodes() support. Other DOMs may solve this
Make newChild occupy the location that oldChild used to
have. Note that newChild will first be removed from its previous
parent, if any. Equivalent to inserting newChild before oldChild,
then removing oldChild.
Override this method in subclass to hook in efficient
internal data structure.
protected final void synchronizeChildren(int nodeIndex)
Synchronizes the node's children with the internal structure.
Fluffing the children at once solves a lot of work to keep
the two structures in sync. The problem gets worse when
editing the tree -- this makes it a lot easier.
Even though this is only used in deferred classes this method is
put here so that it can be shared by all deferred classes.