Package org.dom4j.tree
Class AbstractBranch
- java.lang.Object
-
- org.dom4j.tree.AbstractNode
-
- org.dom4j.tree.AbstractBranch
-
- Direct Known Subclasses:
AbstractDocument
,AbstractElement
public abstract class AbstractBranch extends AbstractNode implements Branch
AbstractBranch
is an abstract base class for tree implementors to use for implementation inheritence.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected static int
DEFAULT_CONTENT_LIST_SIZE
-
Fields inherited from class org.dom4j.tree.AbstractNode
NODE_TYPE_NAMES
-
Fields inherited from interface org.dom4j.Node
ANY_NODE, ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_REFERENCE_NODE, MAX_NODE_TYPE, NAMESPACE_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE, UNKNOWN_NODE
-
-
Constructor Summary
Constructors Constructor Description AbstractBranch()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
add(Comment comment)
Adds the givenComment
to this branch.void
add(Element element)
Adds the givenElement
to this branch.void
add(Node node)
Adds the givenNode
or throwsIllegalAddException
if the given node is not of a valid type.void
add(ProcessingInstruction pi)
Adds the givenProcessingInstruction
to this branch.Element
addElement(java.lang.String name)
Adds a newElement
node with the given name to this branch and returns a reference to the new node.Element
addElement(java.lang.String qualifiedName, java.lang.String namespaceURI)
Adds a newElement
node with the given qualified name and namespace URI to this branch and returns a reference to the new node.Element
addElement(java.lang.String name, java.lang.String prefix, java.lang.String uri)
Element
addElement(QName qname)
Adds a newElement
node with the givenQName
to this branch and returns a reference to the new node.protected abstract void
addNode(int index, Node node)
protected abstract void
addNode(Node node)
void
appendContent(Branch branch)
Appends the content of the given branch to this branch instance.java.util.List<Node>
content()
Returns the content nodes of this branch as a backedList
so that the content of this branch may be modified directly using theList
interface.protected abstract java.util.List<Node>
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 clearedprotected java.util.List<Node>
createContentList()
A Factory Method pattern which creates a List implementation used to store contentprotected java.util.List<Node>
createContentList(int size)
A Factory Method pattern which creates a List implementation used to store contentprotected <T extends Node>
java.util.List<T>createEmptyList()
A Factory Method pattern which creates an empty a BackedList implementationprotected <T extends Node>
BackedList<T>createResultList()
A Factory Method pattern which creates a BackedList implementation used to store results of a filtered content query.protected <T extends Node>
java.util.List<T>createSingleResultList(T result)
A Factory Method pattern which creates a BackedList implementation which contains a single resultElement
elementByID(java.lang.String elementID)
Returns the element of the given ID attribute value.protected java.lang.String
elementID(Element element)
DOCUMENT ME!protected java.lang.String
getContentAsStringValue(java.lang.Object content)
DOCUMENT ME!protected java.lang.String
getContentAsText(java.lang.Object content)
DOCUMENT ME!java.lang.String
getText()
Returns the text of this node.java.lang.String
getTextTrim()
boolean
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.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.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.int
indexOf(Node node)
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 node)
Called when an invalid node has been added.boolean
isReadOnly()
isReadOnly
returns true if this node is read only and cannot be modified.Node
node(int index)
Returns theNode
at the specified index position.int
nodeCount()
Returns the number ofNode
instances that this branch contains.java.util.Iterator<Node>
nodeIterator()
Returns an iterator through the content nodes of this branchboolean
remove(Comment comment)
Removes the givenComment
if the node is an immediate child of this branch.boolean
remove(Element element)
Removes the givenElement
if the node is an immediate child of this branch.boolean
remove(Node node)
Removes the givenNode
if the node is an immediate child of this branch.boolean
remove(ProcessingInstruction pi)
Removes the givenProcessingInstruction
if the node is an immediate child of this branch.protected abstract boolean
removeNode(Node node)
void
setProcessingInstructions(java.util.List<ProcessingInstruction> listOfPIs)
Sets all the processing instructions for this branch-
Methods inherited from class org.dom4j.tree.AbstractNode
asXPathResult, clone, createPattern, createXPath, createXPathFilter, createXPathResult, detach, getDocument, getDocumentFactory, getName, getNodeType, getNodeTypeName, getParent, getPath, getStringValue, getUniquePath, matches, numberValueOf, selectNodes, selectNodes, selectNodes, selectObject, selectSingleNode, setDocument, setName, setParent, setText, supportsParent, valueOf, write
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.dom4j.Branch
clearContent, normalize, processingInstruction, processingInstructions, processingInstructions, removeProcessingInstruction, setContent
-
Methods inherited from interface org.dom4j.Node
accept, asXML, asXPathResult, clone, createXPath, detach, getDocument, getName, getNodeType, getNodeTypeName, getParent, getPath, getPath, getStringValue, getUniquePath, getUniquePath, matches, numberValueOf, selectNodes, selectNodes, selectNodes, selectObject, selectSingleNode, setDocument, setName, setParent, setText, supportsParent, valueOf, write
-
-
-
-
Field Detail
-
DEFAULT_CONTENT_LIST_SIZE
protected static final int DEFAULT_CONTENT_LIST_SIZE
- See Also:
- Constant Field Values
-
-
Method Detail
-
isReadOnly
public boolean isReadOnly()
Description copied from interface:Node
isReadOnly
returns true if this node is read only and cannot be modified. Any attempt to modify a read-onlyNode
will result in anUnsupportedOperationException
being thrown.- Specified by:
isReadOnly
in interfaceNode
- Overrides:
isReadOnly
in classAbstractNode
- Returns:
- true if this
Node
is read only and cannot be modified otherwise false.
-
hasContent
public boolean hasContent()
Description copied from interface:Node
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.- Specified by:
hasContent
in interfaceNode
- Overrides:
hasContent
in classAbstractNode
- Returns:
- true if this
Node
is a Branch with a nodeCount() of one or more.
-
content
public java.util.List<Node> content()
Description copied from interface:Branch
Returns the content nodes of this branch as a backedList
so that the content of this branch may be modified directly using theList
interface. TheList
is backed by theBranch
so that changes to the list are reflected in the branch and vice versa.
-
getText
public java.lang.String getText()
Description copied from interface:Node
Returns the text of this node.
- Specified by:
getText
in interfaceNode
- Overrides:
getText
in classAbstractNode
- Returns:
- the text for this node.
-
getContentAsText
protected java.lang.String getContentAsText(java.lang.Object content)
DOCUMENT ME!- Parameters:
content
- DOCUMENT ME!- Returns:
- the text value of the given content object as text which returns the text value of CDATA, Entity or Text nodes
-
getContentAsStringValue
protected java.lang.String getContentAsStringValue(java.lang.Object content)
DOCUMENT ME!- Parameters:
content
- DOCUMENT ME!- Returns:
- the XPath defined string-value of the given content object
-
getTextTrim
public java.lang.String getTextTrim()
-
setProcessingInstructions
public void setProcessingInstructions(java.util.List<ProcessingInstruction> listOfPIs)
Description copied from interface:Branch
Sets all the processing instructions for this branch- Specified by:
setProcessingInstructions
in interfaceBranch
- Parameters:
listOfPIs
- DOCUMENT ME!
-
addElement
public Element addElement(java.lang.String name)
Description copied from interface:Branch
Adds a newElement
node with the given name to this branch and returns a reference to the new node.- Specified by:
addElement
in interfaceBranch
- Parameters:
name
- is the name for theElement
node.- Returns:
- the newly added
Element
node.
-
addElement
public Element addElement(java.lang.String qualifiedName, java.lang.String namespaceURI)
Description copied from interface:Branch
Adds a newElement
node with the given qualified name and namespace URI to this branch and returns a reference to the new node.- Specified by:
addElement
in interfaceBranch
- Parameters:
qualifiedName
- is the fully qualified name of the ElementnamespaceURI
- is the URI of the namespace to use- Returns:
- the newly added
Element
node.
-
addElement
public Element addElement(QName qname)
Description copied from interface:Branch
Adds a newElement
node with the givenQName
to this branch and returns a reference to the new node.- Specified by:
addElement
in interfaceBranch
- Parameters:
qname
- is the qualified name for theElement
node.- Returns:
- the newly added
Element
node.
-
addElement
public Element addElement(java.lang.String name, java.lang.String prefix, java.lang.String uri)
-
add
public void add(Node node)
Description copied from interface:Branch
Adds the givenNode
or throwsIllegalAddException
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).
-
remove
public boolean remove(Node node)
Description copied from interface:Branch
Removes the givenNode
if the node is an immediate child of this branch. If the given node is not an immediate child of this branch then theNode.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).
-
add
public void add(Comment comment)
Description copied from interface:Branch
Adds the givenComment
to this branch. If the given node already has a parent defined then anIllegalAddException
will be thrown.
-
add
public void add(Element element)
Description copied from interface:Branch
Adds the givenElement
to this branch. If the given node already has a parent defined then anIllegalAddException
will be thrown.
-
add
public void add(ProcessingInstruction pi)
Description copied from interface:Branch
Adds the givenProcessingInstruction
to this branch. If the given node already has a parent defined then anIllegalAddException
will be thrown.
-
remove
public boolean remove(Comment comment)
Description copied from interface:Branch
Removes the givenComment
if the node is an immediate child of this branch. If the given node is not an immediate child of this branch then theNode.detach()
method should be used instead.
-
remove
public boolean remove(Element element)
Description copied from interface:Branch
Removes the givenElement
if the node is an immediate child of this branch. If the given node is not an immediate child of this branch then theNode.detach()
method should be used instead.
-
remove
public boolean remove(ProcessingInstruction pi)
Description copied from interface:Branch
Removes the givenProcessingInstruction
if the node is an immediate child of this branch. If the given node is not an immediate child of this branch then theNode.detach()
method should be used instead.
-
elementByID
public Element elementByID(java.lang.String elementID)
Description copied from interface:Branch
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.- Specified by:
elementByID
in interfaceBranch
- Parameters:
elementID
- DOCUMENT ME!- Returns:
- DOCUMENT ME!
-
appendContent
public void appendContent(Branch branch)
Description copied from interface:Branch
Appends the content of the given branch to this branch instance. This method behaves like theCollection.addAll(java.util.Collection)
method.- Specified by:
appendContent
in interfaceBranch
- Parameters:
branch
- is the branch whose content will be added to me.
-
node
public Node node(int index)
Description copied from interface:Branch
Returns theNode
at the specified index position.
-
nodeCount
public int nodeCount()
Description copied from interface:Branch
Returns the number ofNode
instances that this branch contains.
-
indexOf
public int indexOf(Node node)
Description copied from interface:Branch
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.
-
nodeIterator
public java.util.Iterator<Node> nodeIterator()
Description copied from interface:Branch
Returns an iterator through the content nodes of this branch- Specified by:
nodeIterator
in interfaceBranch
- Returns:
- an iterator through the content nodes of this branch
-
elementID
protected java.lang.String elementID(Element element)
DOCUMENT ME!- Parameters:
element
- DOCUMENT ME!- Returns:
- the ID of the given
Element
-
contentList
protected abstract java.util.List<Node> contentList()
DOCUMENT ME!- Returns:
- the internal List used to manage the content
-
createContentList
protected java.util.List<Node> createContentList()
A Factory Method pattern which creates a List implementation used to store content- Returns:
- DOCUMENT ME!
-
createContentList
protected java.util.List<Node> createContentList(int size)
A Factory Method pattern which creates a List implementation used to store content- Parameters:
size
- DOCUMENT ME!- Returns:
- DOCUMENT ME!
-
createResultList
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.- Type Parameters:
T
- DOCUMENT ME!- Returns:
- DOCUMENT ME!
-
createSingleResultList
protected <T extends Node> java.util.List<T> createSingleResultList(T result)
A Factory Method pattern which creates a BackedList implementation which contains a single result- Type Parameters:
T
- DOCUMENT ME!- Parameters:
result
- DOCUMENT ME!- Returns:
- DOCUMENT ME!
-
createEmptyList
protected <T extends Node> java.util.List<T> createEmptyList()
A Factory Method pattern which creates an empty a BackedList implementation- Type Parameters:
T
- DOCUMENT ME!- Returns:
- DOCUMENT ME!
-
addNode
protected abstract void addNode(Node node)
-
addNode
protected abstract void addNode(int index, Node node)
-
removeNode
protected abstract boolean removeNode(Node node)
-
childAdded
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
- DOCUMENT ME!
-
childRemoved
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
- DOCUMENT ME!
-
contentRemoved
protected void contentRemoved()
Called when the given List content has been removed so each node should have its parent and document relationships cleared
-
invalidNodeTypeAddException
protected void invalidNodeTypeAddException(Node node)
Called when an invalid node has been added. Throws anIllegalAddException
.- Parameters:
node
- DOCUMENT ME!- Throws:
IllegalAddException
- DOCUMENT ME!
-
-