Top Description Fields Constructors Methods
nu.xom

public abstract Class ParentNode

extends Node
Class Inheritance
Known Direct Subclasses
nu.xom.Document, nu.xom.DocumentFragment, nu.xom.Element

The generic superclass for nodes that have children. Not counting subclasses, there are exactly two such public classes in XOM:

This class provides methods to add and remove child nodes.

Author
Elliotte Rusty Harold
Version
1.3.0

Field Summary

Modifier and TypeField and Description
pack-priv String
pack-priv int
pack-priv Node[]

Constructor Summary

AccessConstructor and Description
pack-priv
ParentNode()

Creates a new ParentNode object.

Method Summary

Modifier and TypeMethod and Description
pack-priv final void
_insertChild(Node child, int position)

public void
appendChild(Node
node to append to this node
child
)

Appends a node to the children of this node.

private void
checkCapacity(int position)

pack-priv void
fastInsertChild(Node child, int position)

pack-priv void
pack-priv final String
pack-priv String
public Node

Returns:

the node at the requested position
getChild
(int
index of the node to return
position
)

Implements abstract nu.xom.Node.getChild.

Returns the child of this node at the specified position.

public int

Returns:

the number of children of this node
getChildCount
()

Implements abstract nu.xom.Node.getChildCount.

Returns the number of child nodes this node contains.

public int

Returns:

the position of the argument node among the children of this node
indexOf
(Node
the node whose position is desired
child
)

Returns the position of a node within the children of this node.

public void
insertChild(Node
the node to insert
child
,
int
where to insert the child
position
)

Inserts a child node at the specified position.

pack-priv abstract void
insertionAllowed(Node child, int position)

public Node

Returns:

the node which was removed
removeChild
(int
index of the node to remove
position
)

Removes the child of this node at the specified position.

public Node

Returns:

the node which was removed
removeChild
(Node
child node to remove
child
)

Removes the specified child of this node.

public void
replaceChild(Node
the node removed from the tree
oldChild
,
Node
the node inserted into the tree
newChild
)

Replaces an existing child with a new child node.

pack-priv void
public abstract void
setBaseURI(String
the new base URI for this node
URI
)

Sets the URI against which relative URIs in this node will be resolved.

Inherited from nu.xom.Node:
copydetachequalsgetBaseURIgetDocumentgetParentgetRootgetValuehashCodeisAttributeisCommentisDocTypeisDocumentisDocumentFragmentisElementisProcessingInstructionisTextqueryquerysetParenttoXML

Field Detail

actualBaseURIback to summary
pack-priv String actualBaseURI
childCountback to summary
pack-priv int childCount
childrenback to summary
pack-priv Node[] children

Constructor Detail

ParentNodeback to summary
pack-priv ParentNode()

Creates a new ParentNode object. Can only be invoked by other members of the nu.xom package.

Method Detail

_insertChildback to summary
pack-priv final void _insertChild(Node child, int position)
appendChildback to summary
public void appendChild(Node child)

Appends a node to the children of this node.

Parameters
child:Node

node to append to this node

Exceptions
IllegalAddException:
if this node cannot have children of this type
MultipleParentException:
if child already has a parent
NullPointerException:
if child is null
checkCapacityback to summary
private void checkCapacity(int position)
fastInsertChildback to summary
pack-priv void fastInsertChild(Node child, int position)
fillInBaseURIback to summary
pack-priv void fillInBaseURI(Element removed)
findActualBaseURIback to summary
pack-priv final String findActualBaseURI()
getActualBaseURIback to summary
pack-priv String getActualBaseURI()
getChildback to summary
public Node getChild(int position)

Implements abstract nu.xom.Node.getChild.

Returns the child of this node at the specified position. Indexes begin at 0 and count up to one less than the number of children in this node.

Parameters
position:int

index of the node to return

Returns:Node

the node at the requested position

Exceptions
IndexOutOfBoundsException:
if the index is negative or greater than or equal to the number of children of this node
getChildCountback to summary
public int getChildCount()

Implements abstract nu.xom.Node.getChildCount.

Returns the number of child nodes this node contains. This is always greater than or equal to 0.

Returns:int

the number of children of this node

indexOfback to summary
public int indexOf(Node child)

Returns the position of a node within the children of this node. This is a number between 0 and one less than the number of children of this node. It returns -1 if child does not have this node as a parent.

This method does a linear search through the node's children. On average, it executes in O(N) where N is the number of children of the node.

Parameters
child:Node

the node whose position is desired

Returns:int

the position of the argument node among the children of this node

insertChildback to summary
public void insertChild(Node child, int position)

Inserts a child node at the specified position. The child node previously at that position (if any) and all subsequent child nodes are moved up by one. That is, when inserting a node at 2, the old node at 2 is moved to 3, the old child at 3 is moved to 4, and so forth. Inserting at position 0 makes the child the first child of this node. Inserting at the position getChildCount() makes the child the last child of the node.

All the other methods that add a node to the tree ultimately invoke this method.

Parameters
child:Node

the node to insert

position:int

where to insert the child

Exceptions
IllegalAddException:
if this node cannot have a child of the argument's type
MultipleParentException:
if child already has a parent
NullPointerException:
if child is null
IndexOutOfBoundsException:
if the position is negative or greater than the number of children of this node
insertionAllowedback to summary
pack-priv abstract void insertionAllowed(Node child, int position)
removeChildback to summary
public Node removeChild(int position)

Removes the child of this node at the specified position. Indexes begin at 0 and count up to one less than the number of children in this node.

Parameters
position:int

index of the node to remove

Returns:Node

the node which was removed

Exceptions
IndexOutOfBoundsException:
if the index is negative or greater than or equal to the number of children of this node
removeChildback to summary
public Node removeChild(Node child)

Removes the specified child of this node.

Parameters
child:Node

child node to remove

Returns:Node

the node which was removed

Exceptions
NoSuchChildException:
if child is not in fact a child of this node
replaceChildback to summary
public void replaceChild(Node oldChild, Node newChild)

Replaces an existing child with a new child node. If oldChild is not a child of this node, then a NoSuchChildException is thrown.

Parameters
oldChild:Node

the node removed from the tree

newChild:Node

the node inserted into the tree

Exceptions
MultipleParentException:
if newChild already has a parent
NoSuchChildException:
if oldChild is not a child of this node
NullPointerException:
if either argument is null
IllegalAddException:
if this node cannot have children of the type of newChild
setActualBaseURIback to summary
pack-priv void setActualBaseURI(String uri)
setBaseURIback to summary
public abstract void setBaseURI(String URI)

Sets the URI against which relative URIs in this node will be resolved. Generally, it's only necessary to set this property if it's different from a node's parent's base URI, as it may be in a document assembled from multiple entities or by XInclude.

Relative URIs are not allowed here. Base URIs must be absolute. However, the base URI may be set to null or the empty string to indicate that the node has no explicit base URI. In this case, it inherits the base URI of its parent node, if any.

URIs with fragment identifiers are also not allowed. The value passed to this method must be a pure URI, not a URI reference.

You can also add an xml:base attribute to an element in the same way you'd add any other namespaced attribute to an element. If an element's base URI conflicts with its xml:base attribute, then the value found in the xml:base attribute is used.

If the base URI is null or the empty string and there is no xml:base attribute, then the base URI is determined by the nearest ancestor node which does have a base URI. Moving such a node from one location to another can change its base URI.

Parameters
URI:String

the new base URI for this node

Exceptions
MalformedURIException:
if URI is not a legal RFC 3986 absolute URI