Package org.dom4j.tree
Class AbstractBranch
- java.lang.Object
 - 
- org.dom4j.tree.AbstractNode
 - 
- org.dom4j.tree.AbstractBranch
 
 
 
- 
- All Implemented Interfaces:
 Serializable,Cloneable,Branch,Node
- Direct Known Subclasses:
 AbstractDocument,AbstractElement
public abstract class AbstractBranch extends AbstractNode implements Branch
AbstractBranchis 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 intDEFAULT_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 voidadd(Comment comment)Adds the givenCommentto this branch.voidadd(Element element)Adds the givenElementto this branch.voidadd(Node node)Adds the givenNodeor throwsIllegalAddExceptionif the given node is not of a valid type.voidadd(ProcessingInstruction pi)Adds the givenProcessingInstructionto this branch.ElementaddElement(String name)Adds a newElementnode with the given name to this branch and returns a reference to the new node.ElementaddElement(String qualifiedName, String namespaceURI)Adds a newElementnode with the given qualified name and namespace URI to this branch and returns a reference to the new node.ElementaddElement(String name, String prefix, String uri)ElementaddElement(QName qname)Adds a newElementnode with the givenQNameto this branch and returns a reference to the new node.protected abstract voidaddNode(int index, Node node)protected abstract voidaddNode(Node node)voidappendContent(Branch branch)Appends the content of the given branch to this branch instance.protected abstract voidchildAdded(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 voidchildRemoved(Node node)Called when a child node has been removed to allow any parent relationships to be deleted or events to be fired.List<Node>content()protected abstract List<Node>contentList()DOCUMENT ME!protected voidcontentRemoved()Called when the given List content has been removed so each node should have its parent and document relationships clearedprotected List<Node>createContentList()A Factory Method pattern which creates a List implementation used to store contentprotected List<Node>createContentList(int size)A Factory Method pattern which creates a List implementation used to store contentprotected <T extends Node>
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>
List<T>createSingleResultList(T result)A Factory Method pattern which creates a BackedList implementation which contains a single resultElementelementByID(String elementID)Returns the element of the given ID attribute value.protected StringelementID(Element element)DOCUMENT ME!protected StringgetContentAsStringValue(Object content)DOCUMENT ME!protected StringgetContentAsText(Object content)DOCUMENT ME!StringgetText()Returns the text of this node.StringgetTextTrim()booleanhasContent()hasContentreturns 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.intindexOf(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 voidinvalidNodeTypeAddException(Node node)Called when an invalid node has been added.booleanisReadOnly()isReadOnlyreturns true if this node is read only and cannot be modified.Nodenode(int index)Returns theNodeat the specified index position.intnodeCount()Returns the number ofNodeinstances that this branch contains.Iterator<Node>nodeIterator()Returns an iterator through the content nodes of this branchbooleanremove(Comment comment)Removes the givenCommentif the node is an immediate child of this branch.booleanremove(Element element)Removes the givenElementif the node is an immediate child of this branch.booleanremove(Node node)Removes the givenNodeif the node is an immediate child of this branch.booleanremove(ProcessingInstruction pi)Removes the givenProcessingInstructionif the node is an immediate child of this branch.protected abstract booleanremoveNode(Node node)voidsetProcessingInstructions(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:NodeisReadOnlyreturns true if this node is read only and cannot be modified. Any attempt to modify a read-onlyNodewill result in anUnsupportedOperationExceptionbeing thrown.- Specified by:
 isReadOnlyin interfaceNode- Overrides:
 isReadOnlyin classAbstractNode- Returns:
 - true if this 
Nodeis read only and cannot be modified otherwise false. 
 
- 
hasContent
public boolean hasContent()
Description copied from interface:NodehasContentreturns 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:
 hasContentin interfaceNode- Overrides:
 hasContentin classAbstractNode- Returns:
 - true if this 
Nodeis a Branch with a nodeCount() of one or more. 
 
- 
getText
public String getText()
Description copied from interface:NodeReturns the text of this node.
- Specified by:
 getTextin interfaceNode- Overrides:
 getTextin classAbstractNode- Returns:
 - the text for this node.
 
 
- 
getContentAsText
protected String getContentAsText(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 String getContentAsStringValue(Object content)
DOCUMENT ME!- Parameters:
 content- DOCUMENT ME!- Returns:
 - the XPath defined string-value of the given content object
 
 
- 
getTextTrim
public String getTextTrim()
 
- 
setProcessingInstructions
public void setProcessingInstructions(List<ProcessingInstruction> listOfPIs)
Description copied from interface:BranchSets all the processing instructions for this branch- Specified by:
 setProcessingInstructionsin interfaceBranch- Parameters:
 listOfPIs- DOCUMENT ME!
 
- 
addElement
public Element addElement(String name)
Description copied from interface:BranchAdds a newElementnode with the given name to this branch and returns a reference to the new node.- Specified by:
 addElementin interfaceBranch- Parameters:
 name- is the name for theElementnode.- Returns:
 - the newly added 
Elementnode. 
 
- 
addElement
public Element addElement(String qualifiedName, String namespaceURI)
Description copied from interface:BranchAdds a newElementnode with the given qualified name and namespace URI to this branch and returns a reference to the new node.- Specified by:
 addElementin interfaceBranch- Parameters:
 qualifiedName- is the fully qualified name of the ElementnamespaceURI- is the URI of the namespace to use- Returns:
 - the newly added 
Elementnode. 
 
- 
addElement
public Element addElement(QName qname)
Description copied from interface:BranchAdds a newElementnode with the givenQNameto this branch and returns a reference to the new node.- Specified by:
 addElementin interfaceBranch- Parameters:
 qname- is the qualified name for theElementnode.- Returns:
 - the newly added 
Elementnode. 
 
- 
add
public void add(Node node)
Description copied from interface:BranchAdds the givenNodeor throwsIllegalAddExceptionif 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:BranchRemoves the givenNodeif 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:BranchAdds the givenCommentto this branch. If the given node already has a parent defined then anIllegalAddExceptionwill be thrown. 
- 
add
public void add(Element element)
Description copied from interface:BranchAdds the givenElementto this branch. If the given node already has a parent defined then anIllegalAddExceptionwill be thrown. 
- 
add
public void add(ProcessingInstruction pi)
Description copied from interface:BranchAdds the givenProcessingInstructionto this branch. If the given node already has a parent defined then anIllegalAddExceptionwill be thrown. 
- 
remove
public boolean remove(Comment comment)
Description copied from interface:BranchRemoves the givenCommentif 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:BranchRemoves the givenElementif 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:BranchRemoves the givenProcessingInstructionif 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(String elementID)
Description copied from interface:BranchReturns 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:
 elementByIDin interfaceBranch- Parameters:
 elementID- DOCUMENT ME!- Returns:
 - DOCUMENT ME!
 
 
- 
appendContent
public void appendContent(Branch branch)
Description copied from interface:BranchAppends the content of the given branch to this branch instance. This method behaves like theCollection.addAll(java.util.Collection)method.- Specified by:
 appendContentin interfaceBranch- Parameters:
 branch- is the branch whose content will be added to me.
 
- 
node
public Node node(int index)
Description copied from interface:BranchReturns theNodeat the specified index position. 
- 
nodeCount
public int nodeCount()
Description copied from interface:BranchReturns the number ofNodeinstances that this branch contains. 
- 
indexOf
public int indexOf(Node node)
Description copied from interface:BranchReturns 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 Iterator<Node> nodeIterator()
Description copied from interface:BranchReturns an iterator through the content nodes of this branch- Specified by:
 nodeIteratorin interfaceBranch- Returns:
 - an iterator through the content nodes of this branch
 
 
- 
elementID
protected String elementID(Element element)
DOCUMENT ME!- Parameters:
 element- DOCUMENT ME!- Returns:
 - the ID of the given 
Element 
 
- 
contentList
protected abstract List<Node> contentList()
DOCUMENT ME!- Returns:
 - the internal List used to manage the content
 
 
- 
createContentList
protected List<Node> createContentList()
A Factory Method pattern which creates a List implementation used to store content- Returns:
 - DOCUMENT ME!
 
 
- 
createContentList
protected 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> 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> 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!
 
 - 
 
 -