Class DefaultElement
- All Implemented Interfaces:
Serializable, Cloneable, Branch, Element, Node
- Direct Known Subclasses:
BeanElement, DOMElement, IndexedElement, UserDataElement
DefaultElement
is the default DOM4J default implementation of
an XML element.
- Version:
- $Revision: 1.59 $
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Object
Lazily constructes list of attributesprivate Object
Stores null for no content, a Node for a single content node or a List for multiple content nodes.private static final DocumentFactory
TheDocumentFactory
instance used by defaultprivate Branch
Stores the parent branch of this node which is either a Document if this element is the root element in a document, or another Element if it is a child of the root document, or null if it has not been added to a document yet.private QName
TheQName
for this elementFields inherited from class AbstractElement
USE_STRINGVALUE_SEPARATOR, VERBOSE_TOSTRING
Fields inherited from class AbstractBranch
DEFAULT_CONTENT_LIST_SIZE
Fields inherited from class AbstractNode
NODE_TYPE_NAMES
Fields inherited from interface 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
ConstructorsConstructorDescriptionDefaultElement
(String name) DefaultElement
(String name, Namespace namespace) DefaultElement
(QName qname) DefaultElement
(QName qname, int attributeCount) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds the givenAttribute
to this element.Returns any additional namespaces declarations for this element other than namespace returned via theElement.getNamespace()
method.additionalNamespaces
(String defaultNamespaceURI) protected void
addNewNode
(Node node) Like addNode() but does not require a parent checkattribute
(int index) Returns the attribute at the specified indexGets theReturns the attribute with the given nameDOCUMENT ME!int
DOCUMENT ME!DOCUMENT ME!DOCUMENT ME!attributeList
(int size) DOCUMENT ME!void
Clears the content for this branch, removing anyNode
instances this branch may contain.clone()
clone
will return a deep clone or if this node is read-only then clone will return the same instance.DOCUMENT ME!Returns all the namespaces declared by this element.Returns the first element for the given local name and any namespace.Returns the first element for the given fully qualified name.getDocument
returns theDocument
that thisNode
is part of if this node supports the parent relationship.protected DocumentFactory
getNamespaceForPrefix
(String prefix) Returns theNamespace
which is mapped to the given prefix or null if it could not be found.getNamespaceForURI
(String uri) Returns theNamespace
which is mapped to the given URI or null if it could not be found.getParent
returns the parentElement
if this node supports the parent relationship or null if it is the root element or does not support the parent relationship.getQName()
Returns theQName
of this element which represents the local name, the qualified name and theNamespace
.Returns the XPath string-value of this node.getText()
Returns the text of this node.int
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.node
(int index) Returns theNode
at the specified index position.int
Returns the number ofNode
instances that this branch contains.Returns an iterator through the content nodes of this branchprocessingInstruction
(String target) DOCUMENT ME!Returns a list of all the processing instructions in this branch.processingInstructions
(String target) Returns a list of the processing instructions for the given target.boolean
Removes the givenAttribute
from this element.protected boolean
removeNode
(Node node) boolean
removeProcessingInstruction
(String target) Removes the processing instruction for the given target if it existsprotected void
setAttributeList
(List<Attribute> attributeList) void
setAttributes
(List<Attribute> attributes) Sets the attributes that this element containsvoid
setContent
(List<Node> content) Sets the contents of this branch as aList
ofNode
instances.void
setDocument
(Document document) setDocument
sets the document of this node if the parent relationship is supported or does nothing if the parent relationship is not supported.void
setParent
sets the parent relationship of this node if the parent relationship is supported or does nothing if the parent relationship is not supported.void
Sets theQName
of this element which represents the local name, the qualified name and theNamespace
.boolean
supportsParent
returns true if this node supports the parent relationship.Methods inherited from class AbstractElement
accept, add, add, add, add, add, add, add, add, addAttribute, addAttribute, addCDATA, addComment, addElement, addEntity, addNamespace, addNewNode, addNode, addNode, addProcessingInstruction, addProcessingInstruction, addText, appendAttributes, asXML, attributeValue, attributeValue, attributeValue, attributeValue, childAdded, childRemoved, createAttributeList, createAttributeList, createCopy, createCopy, createCopy, createElement, createElement, createSingleIterator, elementIterator, elementIterator, elementIterator, elementIterator, elements, elements, elements, elements, elementText, elementText, elementTextTrim, elementTextTrim, ensureAttributesCapacity, getData, getName, getNamespace, getNamespacePrefix, getNamespacesForURI, getNamespaceURI, getNodeType, getPath, getQName, getQualifiedName, getUniquePath, getXPathNameStep, getXPathResult, hasMixedContent, isRootElement, isTextOnly, normalize, remove, remove, remove, remove, remove, remove, remove, remove, setAttributes, setAttributeValue, setAttributeValue, setData, setName, setNamespace, setText, toString, write
Methods inherited from class AbstractBranch
addElement, addElement, addElement, appendContent, content, contentRemoved, createContentList, createContentList, createEmptyList, createResultList, createSingleResultList, elementByID, elementID, getContentAsStringValue, getContentAsText, getTextTrim, hasContent, invalidNodeTypeAddException, isReadOnly, setProcessingInstructions
Methods inherited from class AbstractNode
asXPathResult, createPattern, createXPath, createXPathFilter, createXPathResult, detach, getNodeTypeName, getPath, getUniquePath, matches, numberValueOf, selectNodes, selectNodes, selectNodes, selectObject, selectSingleNode, valueOf
Methods inherited from class Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface Branch
addElement, addElement, appendContent, content, elementByID, setProcessingInstructions
Methods inherited from interface Element
getTextTrim
Methods inherited from interface Node
asXPathResult, createXPath, detach, getNodeTypeName, getPath, getUniquePath, hasContent, isReadOnly, matches, numberValueOf, selectNodes, selectNodes, selectNodes, selectObject, selectSingleNode, valueOf
-
Field Details
-
DOCUMENT_FACTORY
TheDocumentFactory
instance used by default -
qname
TheQName
for this element -
parentBranch
Stores the parent branch of this node which is either a Document if this element is the root element in a document, or another Element if it is a child of the root document, or null if it has not been added to a document yet. -
Stores null for no content, a Node for a single content node or a List for multiple content nodes. The List will be lazily constructed when required.
-
attributes
Lazily constructes list of attributes
-
-
Constructor Details
-
DefaultElement
-
DefaultElement
-
DefaultElement
-
DefaultElement
-
-
Method Details
-
getParent
Description copied from interface:Node
getParent
returns the parentElement
if this node supports the parent relationship or null if it is the root element or does not support the parent relationship.This method is an optional feature and may not be supported for all
Node
implementations.- Specified by:
getParent
in interfaceNode
- Overrides:
getParent
in classAbstractNode
- Returns:
- the parent of this node or null if it is the root of the tree or the parent relationship is not supported.
-
setParent
Description copied from interface:Node
setParent
sets the parent relationship of this node if the parent relationship is supported or does nothing if the parent relationship is not supported.This method should only be called from inside an
Element
implementation method and is not intended for general use.- Specified by:
setParent
in interfaceNode
- Overrides:
setParent
in classAbstractNode
- Parameters:
parent
- is the new parent of this node.
-
getDocument
Description copied from interface:Node
getDocument
returns theDocument
that thisNode
is part of if this node supports the parent relationship.This method is an optional feature and may not be supported for all
Node
implementations.- Specified by:
getDocument
in interfaceNode
- Overrides:
getDocument
in classAbstractNode
- Returns:
- the document of this node or null if this feature is not
supported or the node is not associated with a
Document
-
setDocument
Description copied from interface:Node
setDocument
sets the document of this node if the parent relationship is supported or does nothing if the parent relationship is not supported.This method should only be called from inside a
Document
implementation method and is not intended for general use.- Specified by:
setDocument
in interfaceNode
- Overrides:
setDocument
in classAbstractNode
- Parameters:
document
- is the new document of this node.
-
supportsParent
public boolean supportsParent()Description copied from interface:Node
supportsParent
returns true if this node supports the parent relationship.Some XML tree implementations are singly linked and only support downward navigation through children relationships. The default case is that both parent and children relationships are supported though for memory and performance reasons the parent relationship may not be supported.
- Specified by:
supportsParent
in interfaceNode
- Overrides:
supportsParent
in classAbstractNode
- Returns:
- true if this node supports the parent relationship or false it is not supported
-
getQName
-
setQName
-
getText
-
getStringValue
Description copied from interface:Node
Returns the XPath string-value of this node. The behaviour of this method is defined in the XPath specification .- Specified by:
getStringValue
in interfaceElement
- Specified by:
getStringValue
in interfaceNode
- Overrides:
getStringValue
in classAbstractElement
- Returns:
- the text from all the child Text and Element nodes appended together.
-
clone
Description copied from interface:Node
clone
will return a deep clone or if this node is read-only then clone will return the same instance.- Specified by:
clone
in interfaceNode
- Overrides:
clone
in classAbstractNode
- Returns:
- a deep clone of myself or myself if I am read only.
-
getNamespaceForPrefix
Description copied from interface:Element
Returns theNamespace
which is mapped to the given prefix or null if it could not be found.- Specified by:
getNamespaceForPrefix
in interfaceElement
- Overrides:
getNamespaceForPrefix
in classAbstractElement
- Parameters:
prefix
- DOCUMENT ME!- Returns:
- the
Namespace
associated with the given prefix
-
getNamespaceForURI
Description copied from interface:Element
Returns theNamespace
which is mapped to the given URI or null if it could not be found. If there is more than oneNamespace
mapped to the URI, which of them will be returned is undetermined.- Specified by:
getNamespaceForURI
in interfaceElement
- Overrides:
getNamespaceForURI
in classAbstractElement
- Parameters:
uri
- DOCUMENT ME!- Returns:
- the
Namespace
associated with the given URI
-
declaredNamespaces
Description copied from interface:Element
Returns all the namespaces declared by this element. If no namespaces are declared for this element then an empty list will be returned. The list is backed by the element such that changes to the list will be reflected in the element though the reverse is not the case.- Specified by:
declaredNamespaces
in interfaceElement
- Overrides:
declaredNamespaces
in classAbstractElement
- Returns:
- a list of namespaces declared for this element.
-
additionalNamespaces
Description copied from interface:Element
Returns any additional namespaces declarations for this element other than namespace returned via theElement.getNamespace()
method. If no additional namespace declarations are present for this element then an empty list will be returned. The list is backed by the element such that changes to the list will be reflected in the element though the reverse is not the case.- Specified by:
additionalNamespaces
in interfaceElement
- Overrides:
additionalNamespaces
in classAbstractElement
- Returns:
- a list of any additional namespace declarations.
-
additionalNamespaces
- Overrides:
additionalNamespaces
in classAbstractElement
-
processingInstructions
Description copied from interface:Branch
Returns a list of all the processing instructions in this branch. The list is backed by this branch so that changes to the list will be reflected in the branch but the reverse is not the case.- Specified by:
processingInstructions
in interfaceBranch
- Overrides:
processingInstructions
in classAbstractElement
- Returns:
- a backed list of the processing instructions
-
processingInstructions
Description copied from interface:Branch
Returns a list of the processing instructions for the given target. The list is backed by this branch so that changes to the list will be reflected in the branch but the reverse is not the case.- Specified by:
processingInstructions
in interfaceBranch
- Overrides:
processingInstructions
in classAbstractElement
- Parameters:
target
- DOCUMENT ME!- Returns:
- a backed list of the processing instructions
-
processingInstruction
Description copied from interface:Branch
DOCUMENT ME!- Specified by:
processingInstruction
in interfaceBranch
- Overrides:
processingInstruction
in classAbstractElement
- Parameters:
target
- DOCUMENT ME!- Returns:
- the processing instruction for the given target
-
removeProcessingInstruction
Description copied from interface:Branch
Removes the processing instruction for the given target if it exists- Specified by:
removeProcessingInstruction
in interfaceBranch
- Overrides:
removeProcessingInstruction
in classAbstractElement
- Parameters:
target
- DOCUMENT ME!- Returns:
- true if a processing instruction was removed else false
-
element
Description copied from interface:Element
Returns the first element for the given local name and any namespace.- Specified by:
element
in interfaceElement
- Overrides:
element
in classAbstractElement
- Parameters:
name
- DOCUMENT ME!- Returns:
- the first element with the given local name
-
element
Description copied from interface:Element
Returns the first element for the given fully qualified name.- Specified by:
element
in interfaceElement
- Overrides:
element
in classAbstractElement
- Parameters:
qName
- is the fully qualified name to search for- Returns:
- the first element with the given fully qualified name
-
element
- Overrides:
element
in classAbstractElement
-
setContent
-
clearContent
public void clearContent()Description copied from interface:Branch
Clears the content for this branch, removing anyNode
instances this branch may contain. -
node
-
indexOf
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.- Specified by:
indexOf
in interfaceBranch
- Overrides:
indexOf
in classAbstractElement
- Parameters:
node
- the content child node to find.- Returns:
- the index of the given node starting at 0 or -1 if the node is not a child node of this branch
-
nodeCount
public int nodeCount()Description copied from interface:Branch
Returns the number ofNode
instances that this branch contains.- Specified by:
nodeCount
in interfaceBranch
- Overrides:
nodeCount
in classAbstractElement
- Returns:
- the number of nodes this branch contains
-
nodeIterator
Description copied from interface:Branch
Returns an iterator through the content nodes of this branch- Specified by:
nodeIterator
in interfaceBranch
- Overrides:
nodeIterator
in classAbstractElement
- Returns:
- an iterator through the content nodes of this branch
-
attributes
Description copied from interface:Element
Returns theAttribute
instances this element contains as a backedList
so that the attributes may be modified directly using theList
interface. TheList
is backed by theElement
so that changes to the list are reflected in the element and vice versa.- Specified by:
attributes
in interfaceElement
- Overrides:
attributes
in classAbstractElement
- Returns:
- the attributes that this element contains as a
List
-
setAttributes
-
attributeIterator
Description copied from interface:Element
DOCUMENT ME!- Specified by:
attributeIterator
in interfaceElement
- Overrides:
attributeIterator
in classAbstractElement
- Returns:
- an iterator over the attributes of this element
-
attribute
Description copied from interface:Element
Returns the attribute at the specified indexGets the- Specified by:
attribute
in interfaceElement
- Overrides:
attribute
in classAbstractElement
- Parameters:
index
- DOCUMENT ME!- Returns:
- the attribute at the specified index where index >= 0 and index < number of attributes or throws an IndexOutOfBoundsException if the index is not within the allowable range
-
attributeCount
public int attributeCount()Description copied from interface:Element
DOCUMENT ME!- Specified by:
attributeCount
in interfaceElement
- Overrides:
attributeCount
in classAbstractElement
- Returns:
- the number of attributes this element contains
-
attribute
Description copied from interface:Element
Returns the attribute with the given name- Specified by:
attribute
in interfaceElement
- Overrides:
attribute
in classAbstractElement
- Parameters:
name
- DOCUMENT ME!- Returns:
- the attribute for the given local name in any namespace. If there are more than one attributes with the given local name in different namespaces then the first one is returned.
-
attribute
Description copied from interface:Element
DOCUMENT ME!- Specified by:
attribute
in interfaceElement
- Overrides:
attribute
in classAbstractElement
- Parameters:
qName
- is the fully qualified name- Returns:
- the attribute for the given fully qualified name or null if it could not be found.
-
attribute
- Overrides:
attribute
in classAbstractElement
-
add
Description copied from interface:Element
Adds the givenAttribute
to this element. If the given node already has a parent defined then anIllegalAddException
will be thrown. Attributes with null values are silently ignored. If the value of the attribute is null then this method call will remove any attributes with the QName of this attribute.- Specified by:
add
in interfaceElement
- Overrides:
add
in classAbstractElement
- Parameters:
attribute
- is the attribute to be added
-
remove
Description copied from interface:Element
Removes the givenAttribute
from this element.- Specified by:
remove
in interfaceElement
- Overrides:
remove
in classAbstractElement
- Parameters:
attribute
- is the attribute to be removed- Returns:
- true if the attribute was removed
-
addNewNode
Description copied from class:AbstractElement
Like addNode() but does not require a parent check- Overrides:
addNewNode
in classAbstractElement
- Parameters:
node
- DOCUMENT ME!
-
removeNode
- Overrides:
removeNode
in classAbstractElement
-
contentList
Description copied from class:AbstractBranch
DOCUMENT ME!- Specified by:
contentList
in classAbstractBranch
- Returns:
- the internal List used to manage the content
-
attributeList
Description copied from class:AbstractElement
DOCUMENT ME!- Specified by:
attributeList
in classAbstractElement
- Returns:
- the internal List used to store attributes or creates one if one is not available
-
attributeList
Description copied from class:AbstractElement
DOCUMENT ME!- Specified by:
attributeList
in classAbstractElement
- Parameters:
size
- DOCUMENT ME!- Returns:
- the internal List used to store attributes or creates one with the specified size if one is not available
-
setAttributeList
-
getDocumentFactory
- Overrides:
getDocumentFactory
in classAbstractElement
-