Top Description Fields Constructors Methods
org.dom4j.tree

public abstract Class AbstractBranch

extends AbstractNode
implements Branch
Class Inheritance
All Implemented Interfaces
org.dom4j.Branch, org.dom4j.Node, java.lang.Cloneable
Known Direct Subclasses
org.dom4j.tree.AbstractDocument, org.dom4j.tree.AbstractElement
Imports
org.dom4j.*, java.util.ArrayList, .Iterator, .List, .StringTokenizer

AbstractBranch is an abstract base class for tree implementors to use for implementation inheritence.
Author
James Strachan
Version
$Revision: 1.44 $

Field Summary

Modifier and TypeField and Description
protected static final int
Inherited from org.dom4j.tree.AbstractNode:
NODE_TYPE_NAMES

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
add(Node
is the given node to add
node
)

Implements org.dom4j.Branch.add.

Adds the given Node or throws IllegalAddException if the given node is not of a valid type.
public void
add(Comment
is the comment to be added
comment
)

Implements org.dom4j.Branch.add.

Adds the given Comment to this branch.
public void
add(Element
is the element to be added
element
)

Implements org.dom4j.Branch.add.

Adds the given Element to this branch.
public void
add(ProcessingInstruction
is the processing instruction to be added
pi
)

Implements org.dom4j.Branch.add.

Adds the given ProcessingInstruction to this branch.
public Element
addElement(String
is the name for the Element node.
name
)

Implements org.dom4j.Branch.addElement.

Adds a new Element node with the given name to this branch and returns a reference to the new node.
public Element
addElement(String
is the fully qualified name of the Element
qualifiedName
,
String
is the URI of the namespace to use
namespaceURI
)

Implements org.dom4j.Branch.addElement.

Adds a new Element node with the given qualified name and namespace URI to this branch and returns a reference to the new node.
public Element
addElement(QName
is the qualified name for the Element node.
qname
)

Implements org.dom4j.Branch.addElement.

Adds a new Element node with the given QNameto this branch and returns a reference to the new node.
public Element
addElement(String name, String prefix, String uri)

protected abstract void
addNode(Node node)

protected abstract void
addNode(int index, Node node)

public void
appendContent(Branch
is the branch whose content will be added to me.
branch
)

Implements org.dom4j.Branch.appendContent.

Appends the content of the given branch to this branch instance.
protected abstract void
childAdded(Node
DOCUMENT ME!
node
)

Called when a new child node has been added to me to allow any parent relationships to be created or events to be fired.

protected abstract void
childRemoved(Node
DOCUMENT ME!
node
)

Called when a child node has been removed to allow any parent relationships to be deleted or events to be fired.

public List<Node>
content()

Implements org.dom4j.Branch.content.

Returns the content nodes of this branch as a backed Listso that the content of this branch may be modified directly using the Listinterface.
protected abstract List<Node>

Returns:

the internal List used to manage the content
contentList
()

DOCUMENT ME!

protected void
contentRemoved()

Called when the given List content has been removed so each node should have its parent and document relationships cleared

protected List<Node>

Returns:

DOCUMENT ME!
createContentList
()

A Factory Method pattern which creates a List implementation used to store content

protected List<Node>

Returns:

DOCUMENT ME!
createContentList
(int
DOCUMENT ME!
size
)

A Factory Method pattern which creates a List implementation used to store content

protected <
DOCUMENT ME!
T extends Node
>
List<T>

Returns:

DOCUMENT ME!
createEmptyList
()

A Factory Method pattern which creates an empty a BackedList implementation

protected <
DOCUMENT ME!
T extends Node
>
BackedList<T>

Returns:

DOCUMENT ME!
createResultList
()

A Factory Method pattern which creates a BackedList implementation used to store results of a filtered content query.

protected <
DOCUMENT ME!
T extends Node
>
List<T>

Returns:

DOCUMENT ME!
createSingleResultList
(T
DOCUMENT ME!
result
)

A Factory Method pattern which creates a BackedList implementation which contains a single result

public Element
elementByID(String
DOCUMENT ME!
elementID
)

Implements org.dom4j.Branch.elementByID.

Returns the element of the given ID attribute value.
protected String

Returns:

the ID of the given Element
elementID
(Element
DOCUMENT ME!
element
)

DOCUMENT ME!

protected String

Returns:

the XPath defined string-value of the given content object
getContentAsStringValue
(Object
DOCUMENT ME!
content
)

DOCUMENT ME!

protected String

Returns:

the text value of the given content object as text which returns the text value of CDATA, Entity or Text nodes
getContentAsText
(Object
DOCUMENT ME!
content
)

DOCUMENT ME!

public String
getText()

Overrides org.dom4j.tree.AbstractNode.getText.

Implements org.dom4j.Node.getText.

Returns the text of this node.

public String
public boolean
hasContent()

Overrides org.dom4j.tree.AbstractNode.hasContent.

Implements org.dom4j.Node.hasContent.

hasContent returns true if this node is a Branch (either an Element or a Document) and it contains at least one content node such as a child Element or Text node.

public int
indexOf(Node
the content child node to find.
node
)

Implements org.dom4j.Branch.indexOf.

Returns the index of the given node if it is a child node of this branch or -1 if the given node is not a child node.
protected void
invalidNodeTypeAddException(Node
DOCUMENT ME!
node
)

Called when an invalid node has been added.

public boolean
isReadOnly()

Overrides org.dom4j.tree.AbstractNode.isReadOnly.

Implements org.dom4j.Node.isReadOnly.

isReadOnly returns true if this node is read only and cannot be modified.

public Node
node(int
the index of the node to return.
index
)

Implements org.dom4j.Branch.node.

Returns the Node at the specified index position.
public int
nodeCount()

Implements org.dom4j.Branch.nodeCount.

Returns the number of Node instances that this branch contains.
public Iterator<Node>
nodeIterator()

Implements org.dom4j.Branch.nodeIterator.

Returns an iterator through the content nodes of this branch
public boolean
remove(Node
is the given node to be removed
node
)

Implements org.dom4j.Branch.remove.

Removes the given Node if the node is an immediate child of this branch.
public boolean
remove(Comment
is the comment to be removed
comment
)

Implements org.dom4j.Branch.remove.

Removes the given Comment if the node is an immediate child of this branch.
public boolean
remove(Element
is the element to be removed
element
)

Implements org.dom4j.Branch.remove.

Removes the given Element if the node is an immediate child of this branch.
public boolean
remove(ProcessingInstruction
is the processing instruction to be removed
pi
)

Implements org.dom4j.Branch.remove.

Removes the given ProcessingInstruction if the node is an immediate child of this branch.
protected abstract boolean
public void
setProcessingInstructions(List<ProcessingInstruction>
DOCUMENT ME!
listOfPIs
)

Implements org.dom4j.Branch.setProcessingInstructions.

Sets all the processing instructions for this branch
Inherited from org.dom4j.tree.AbstractNode:
asXPathResultclonecreatePatterncreateXPathcreateXPathFiltercreateXPathResultdetachgetDocumentgetDocumentFactorygetNamegetNodeTypegetNodeTypeNamegetParentgetPathgetStringValuegetUniquePathmatchesnumberValueOfselectNodesselectNodesselectNodesselectObjectselectSingleNodesetDocumentsetNamesetParentsetTextsupportsParentvalueOfwrite

Field Detail

DEFAULT_CONTENT_LIST_SIZEback to summary
protected static final int DEFAULT_CONTENT_LIST_SIZE

Constructor Detail

AbstractBranchback to summary
public AbstractBranch()

Method Detail

addback to summary
public void add(Node node)

Implements org.dom4j.Branch.add.

Doc from org.dom4j.Branch.add.

Adds the given Node or throws IllegalAddException if the given node is not of a valid type. This is a polymorphic method which will call the typesafe method for the node type such as add(Element) or add(Comment).

Parameters
node:Node

is the given node to add

addback to summary
public void add(Comment comment)

Implements org.dom4j.Branch.add.

Doc from org.dom4j.Branch.add.

Adds the given Comment to this branch. If the given node already has a parent defined then an IllegalAddException will be thrown.

Parameters
comment:Comment

is the comment to be added

addback to summary
public void add(Element element)

Implements org.dom4j.Branch.add.

Doc from org.dom4j.Branch.add.

Adds the given Element to this branch. If the given node already has a parent defined then an IllegalAddException will be thrown.

Parameters
element:Element

is the element to be added

addback to summary
public void add(ProcessingInstruction pi)

Implements org.dom4j.Branch.add.

Doc from org.dom4j.Branch.add.

Adds the given ProcessingInstruction to this branch. If the given node already has a parent defined then an IllegalAddException will be thrown.

Parameters
pi:ProcessingInstruction

is the processing instruction to be added

addElementback to summary
public Element addElement(String name)

Implements org.dom4j.Branch.addElement.

Doc from org.dom4j.Branch.addElement.

Adds a new Element node with the given name to this branch and returns a reference to the new node.

Parameters
name:String

is the name for the Element node.

Returns:Element

the newly added Element node.

addElementback to summary
public Element addElement(String qualifiedName, String namespaceURI)

Implements org.dom4j.Branch.addElement.

Doc from org.dom4j.Branch.addElement.

Adds a new Element node with the given qualified name and namespace URI to this branch and returns a reference to the new node.

Parameters
qualifiedName:String

is the fully qualified name of the Element

namespaceURI:String

is the URI of the namespace to use

Returns:Element

the newly added Element node.

addElementback to summary
public Element addElement(QName qname)

Implements org.dom4j.Branch.addElement.

Doc from org.dom4j.Branch.addElement.

Adds a new Element node with the given QNameto this branch and returns a reference to the new node.

Parameters
qname:QName

is the qualified name for the Element node.

Returns:Element

the newly added Element node.

addElementback to summary
public Element addElement(String name, String prefix, String uri)
addNodeback to summary
protected abstract void addNode(Node node)
addNodeback to summary
protected abstract void addNode(int index, Node node)
appendContentback to summary
public void appendContent(Branch branch)

Implements org.dom4j.Branch.appendContent.

Doc from org.dom4j.Branch.appendContent.

Appends the content of the given branch to this branch instance. This method behaves like the java.util.Collection#addAll(java.util.Collection) method.

Parameters
branch:Branch

is the branch whose content will be added to me.

childAddedback to summary
protected abstract void childAdded(Node node)

Called when a new child node has been added to me to allow any parent relationships to be created or events to be fired.

Parameters
node:Node

DOCUMENT ME!

childRemovedback to summary
protected abstract void childRemoved(Node node)

Called when a child node has been removed to allow any parent relationships to be deleted or events to be fired.

Parameters
node:Node

DOCUMENT ME!

contentback to summary
public List<Node> content()

Implements org.dom4j.Branch.content.

Doc from org.dom4j.Branch.content.

Returns the content nodes of this branch as a backed Listso that the content of this branch may be modified directly using the Listinterface. The List is backed by the Branch so that changes to the list are reflected in the branch and vice versa.

Returns:List<Node>

the nodes that this branch contains as a List

contentListback to summary
protected abstract List<Node> contentList()

DOCUMENT ME!

Returns:List<Node>

the internal List used to manage the content

contentRemovedback to summary
protected void contentRemoved()

Called when the given List content has been removed so each node should have its parent and document relationships cleared

createContentListback to summary
protected List<Node> createContentList()

A Factory Method pattern which creates a List implementation used to store content

Returns:List<Node>

DOCUMENT ME!

createContentListback to summary
protected List<Node> createContentList(int size)

A Factory Method pattern which creates a List implementation used to store content

Parameters
size:int

DOCUMENT ME!

Returns:List<Node>

DOCUMENT ME!

createEmptyListback to summary
protected <T extends Node> List<T> createEmptyList()

A Factory Method pattern which creates an empty a BackedList implementation

Parameters
<T>
DOCUMENT ME!
Returns:List<T>

DOCUMENT ME!

createResultListback to summary
protected <T extends Node> BackedList<T> createResultList()

A Factory Method pattern which creates a BackedList implementation used to store results of a filtered content query.

Parameters
<T>
DOCUMENT ME!
Returns:BackedList<T>

DOCUMENT ME!

createSingleResultListback to summary
protected <T extends Node> List<T> createSingleResultList(T result)

A Factory Method pattern which creates a BackedList implementation which contains a single result

Parameters
<T>
DOCUMENT ME!
result:T

DOCUMENT ME!

Returns:List<T>

DOCUMENT ME!

elementByIDback to summary
public Element elementByID(String elementID)

Implements org.dom4j.Branch.elementByID.

Doc from org.dom4j.Branch.elementByID.

Returns the element of the given ID attribute value. If this tree is capable of understanding which attribute value should be used for the ID then it should be used, otherwise this method should return null.

Parameters
elementID:String

DOCUMENT ME!

Returns:Element

DOCUMENT ME!

elementIDback to summary
protected String elementID(Element element)

DOCUMENT ME!

Parameters
element:Element

DOCUMENT ME!

Returns:String

the ID of the given Element

getContentAsStringValueback to summary
protected String getContentAsStringValue(Object content)

DOCUMENT ME!

Parameters
content:Object

DOCUMENT ME!

Returns:String

the XPath defined string-value of the given content object

getContentAsTextback to summary
protected String getContentAsText(Object content)

DOCUMENT ME!

Parameters
content:Object

DOCUMENT ME!

Returns:String

the text value of the given content object as text which returns the text value of CDATA, Entity or Text nodes

getTextback to summary
public String getText()

Overrides org.dom4j.tree.AbstractNode.getText.

Implements org.dom4j.Node.getText.

Doc from org.dom4j.Node.getText.

Returns the text of this node.

Returns:String

the text for this node.

getTextTrimback to summary
public String getTextTrim()
hasContentback to summary
public boolean hasContent()

Overrides org.dom4j.tree.AbstractNode.hasContent.

Implements org.dom4j.Node.hasContent.

Doc from org.dom4j.Node.hasContent.

hasContent returns true if this node is a Branch (either an Element or a Document) and it contains at least one content node such as a child Element or Text node.

Returns:boolean

true if this Node is a Branch with a nodeCount() of one or more.

Annotations
@Override
indexOfback to summary
public int indexOf(Node node)

Implements org.dom4j.Branch.indexOf.

Doc from org.dom4j.Branch.indexOf.

Returns the index of the given node if it is a child node of this branch or -1 if the given node is not a child node.

Parameters
node:Node

the content child node to find.

Returns:int

the index of the given node starting at 0 or -1 if the node is not a child node of this branch

invalidNodeTypeAddExceptionback to summary
protected void invalidNodeTypeAddException(Node node)

Called when an invalid node has been added. Throws an IllegalAddException.

Parameters
node:Node

DOCUMENT ME!

Exceptions
IllegalAddException:
DOCUMENT ME!
isReadOnlyback to summary
public boolean isReadOnly()

Overrides org.dom4j.tree.AbstractNode.isReadOnly.

Implements org.dom4j.Node.isReadOnly.

Doc from org.dom4j.Node.isReadOnly.

isReadOnly returns true if this node is read only and cannot be modified. Any attempt to modify a read-only Node will result in an UnsupportedOperationException being thrown.

Returns:boolean

true if this Node is read only and cannot be modified otherwise false.

Annotations
@Override
nodeback to summary
public Node node(int index)

Implements org.dom4j.Branch.node.

Doc from org.dom4j.Branch.node.

Returns the Node at the specified index position.

Parameters
index:int

the index of the node to return.

Returns:Node

the Node at the specified position.

nodeCountback to summary
public int nodeCount()

Implements org.dom4j.Branch.nodeCount.

Doc from org.dom4j.Branch.nodeCount.

Returns the number of Node instances that this branch contains.

Returns:int

the number of nodes this branch contains

nodeIteratorback to summary
public Iterator<Node> nodeIterator()

Implements org.dom4j.Branch.nodeIterator.

Doc from org.dom4j.Branch.nodeIterator.

Returns an iterator through the content nodes of this branch

Returns:Iterator<Node>

an iterator through the content nodes of this branch

removeback to summary
public boolean remove(Node node)

Implements org.dom4j.Branch.remove.

Doc from org.dom4j.Branch.remove.

Removes the given Node if the node is an immediate child of this branch. If the given node is not an immediate child of this branch then the Node#detach()method should be used instead. This is a polymorphic method which will call the typesafe method for the node type such as remove(Element) or remove(Comment).

Parameters
node:Node

is the given node to be removed

Returns:boolean

true if the node was removed

removeback to summary
public boolean remove(Comment comment)

Implements org.dom4j.Branch.remove.

Doc from org.dom4j.Branch.remove.

Removes the given Comment if the node is an immediate child of this branch. If the given node is not an immediate child of this branch then the Node#detach()method should be used instead.

Parameters
comment:Comment

is the comment to be removed

Returns:boolean

true if the comment was removed

removeback to summary
public boolean remove(Element element)

Implements org.dom4j.Branch.remove.

Doc from org.dom4j.Branch.remove.

Removes the given Element if the node is an immediate child of this branch. If the given node is not an immediate child of this branch then the Node#detach()method should be used instead.

Parameters
element:Element

is the element to be removed

Returns:boolean

true if the element was removed

removeback to summary
public boolean remove(ProcessingInstruction pi)

Implements org.dom4j.Branch.remove.

Doc from org.dom4j.Branch.remove.

Removes the given ProcessingInstruction if the node is an immediate child of this branch. If the given node is not an immediate child of this branch then the Node#detach()method should be used instead.

Parameters
pi:ProcessingInstruction

is the processing instruction to be removed

Returns:boolean

true if the processing instruction was removed

removeNodeback to summary
protected abstract boolean removeNode(Node node)
setProcessingInstructionsback to summary
public void setProcessingInstructions(List<ProcessingInstruction> listOfPIs)

Implements org.dom4j.Branch.setProcessingInstructions.

Doc from org.dom4j.Branch.setProcessingInstructions.

Sets all the processing instructions for this branch

Parameters
listOfPIs:List<ProcessingInstruction>

DOCUMENT ME!