org.dom4j.tree
Class DefaultElement

java.lang.Object
  extended by org.dom4j.tree.AbstractNode
      extended by org.dom4j.tree.AbstractBranch
          extended by org.dom4j.tree.AbstractElement
              extended by org.dom4j.tree.DefaultElement
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Branch, Element, Node
Direct Known Subclasses:
BeanElement, DatatypeElement, DOMElement, IndexedElement, UserDataElement

public class DefaultElement
extends AbstractElement

DefaultElement is the default DOM4J default implementation of an XML element.

Version:
$Revision: 1.59 $
Author:
James Strachan
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.dom4j.tree.AbstractElement
EMPTY_ITERATOR, EMPTY_LIST, USE_STRINGVALUE_SEPARATOR, VERBOSE_TOSTRING
 
Fields inherited from class org.dom4j.tree.AbstractBranch
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
DefaultElement(QName qname)
           
DefaultElement(QName qname, int attributeCount)
           
DefaultElement(java.lang.String name)
           
DefaultElement(java.lang.String name, Namespace namespace)
           
 
Method Summary
 void add(Attribute attribute)
          Adds the given Attribute to this element.
 java.util.List additionalNamespaces()
           Returns any additional namespaces declarations for this element other than namespace returned via the Element.getNamespace()method.
 java.util.List additionalNamespaces(java.lang.String defaultNamespaceURI)
           
protected  void addNewNode(Node node)
          Like addNode() but does not require a parent check
 Attribute attribute(int index)
          Returns the attribute at the specified indexGets the
 Attribute attribute(QName qName)
          DOCUMENT ME!
 Attribute attribute(java.lang.String name)
          Returns the attribute with the given name
 Attribute attribute(java.lang.String name, Namespace namespace)
           
 int attributeCount()
          DOCUMENT ME!
 java.util.Iterator attributeIterator()
          DOCUMENT ME!
protected  java.util.List attributeList()
          DOCUMENT ME!
protected  java.util.List attributeList(int size)
          DOCUMENT ME!
 java.util.List attributes()
           Returns the Attributeinstances this element contains as a backed Listso that the attributes may be modified directly using the Listinterface.
 void clearContent()
          Clears the content for this branch, removing any Node instances this branch may contain.
 java.lang.Object clone()
           clone will return a deep clone or if this node is read-only then clone will return the same instance.
protected  java.util.List contentList()
          DOCUMENT ME!
 java.util.List declaredNamespaces()
           Returns all the namespaces declared by this element.
 Element element(QName qName)
          Returns the first element for the given fully qualified name.
 Element element(java.lang.String name)
          Returns the first element for the given local name and any namespace.
 Element element(java.lang.String name, Namespace namespace)
           
 Document getDocument()
           getDocument returns the Document that this Node is part of if this node supports the parent relationship.
protected  DocumentFactory getDocumentFactory()
           
 Namespace getNamespaceForPrefix(java.lang.String prefix)
           Returns the Namespace which is mapped to the given prefix or null if it could not be found.
 Namespace getNamespaceForURI(java.lang.String uri)
           Returns the Namespace which is mapped to the given URI or null if it could not be found.
 Element getParent()
           getParent returns the parent Element if this node supports the parent relationship or null if it is the root element or does not support the parent relationship.
 QName getQName()
           Returns the QName of this element which represents the local name, the qualified name and the Namespace.
 java.lang.String getStringValue()
          Returns the XPath string-value of this node.
 java.lang.String getText()
           Returns the text of this node.
 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.
 Node node(int index)
          Returns the Node at the specified index position.
 int nodeCount()
          Returns the number of Node instances that this branch contains.
 java.util.Iterator nodeIterator()
          Returns an iterator through the content nodes of this branch
 ProcessingInstruction processingInstruction(java.lang.String target)
          DOCUMENT ME!
 java.util.List processingInstructions()
           Returns a list of all the processing instructions in this branch.
 java.util.List processingInstructions(java.lang.String target)
           Returns a list of the processing instructions for the given target.
 boolean remove(Attribute attribute)
          Removes the given Attribute from this element.
protected  boolean removeNode(Node node)
           
 boolean removeProcessingInstruction(java.lang.String target)
          Removes the processing instruction for the given target if it exists
protected  void setAttributeList(java.util.List attributeList)
           
 void setAttributes(java.util.List attributes)
          Sets the attributes that this element contains
 void setContent(java.util.List content)
          Sets the contents of this branch as a List of Node 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(Element parent)
           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 setQName(QName name)
           Sets the QName of this element which represents the local name, the qualified name and the Namespace.
 boolean supportsParent()
           supportsParent returns true if this node supports the parent relationship.
 
Methods inherited from class org.dom4j.tree.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 org.dom4j.tree.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 org.dom4j.tree.AbstractNode
asXPathResult, createPattern, createXPath, createXPathFilter, createXPathResult, detach, getNodeTypeName, getPath, getUniquePath, matches, numberValueOf, selectNodes, selectNodes, selectNodes, selectObject, selectSingleNode, valueOf
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.dom4j.Element
getTextTrim
 
Methods inherited from interface org.dom4j.Branch
addElement, addElement, appendContent, content, elementByID, setProcessingInstructions
 
Methods inherited from interface org.dom4j.Node
asXPathResult, createXPath, detach, getNodeTypeName, getPath, getUniquePath, hasContent, isReadOnly, matches, numberValueOf, selectNodes, selectNodes, selectNodes, selectObject, selectSingleNode, valueOf
 

Constructor Detail

DefaultElement

public DefaultElement(java.lang.String name)

DefaultElement

public DefaultElement(QName qname)

DefaultElement

public DefaultElement(QName qname,
                      int attributeCount)

DefaultElement

public DefaultElement(java.lang.String name,
                      Namespace namespace)
Method Detail

getParent

public Element getParent()
Description copied from interface: Node

getParent returns the parent Element 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 interface Node
Overrides:
getParent in class AbstractNode
Returns:
the parent of this node or null if it is the root of the tree or the parent relationship is not supported.

setParent

public void setParent(Element parent)
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 interface Node
Overrides:
setParent in class AbstractNode
Parameters:
parent - is the new parent of this node.

getDocument

public Document getDocument()
Description copied from interface: Node

getDocument returns the Document that this Node 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 interface Node
Overrides:
getDocument in class AbstractNode
Returns:
the document of this node or null if this feature is not supported or the node is not associated with a Document

setDocument

public void setDocument(Document document)
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 interface Node
Overrides:
setDocument in class AbstractNode
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 interface Node
Overrides:
supportsParent in class AbstractNode
Returns:
true if this node supports the parent relationship or false it is not supported

getQName

public QName getQName()
Description copied from interface: Element

Returns the QName of this element which represents the local name, the qualified name and the Namespace.

Returns:
the QName associated with this element

setQName

public void setQName(QName name)
Description copied from interface: Element

Sets the QName of this element which represents the local name, the qualified name and the Namespace.

Parameters:
name - is the QName to be associated with this element

getText

public java.lang.String getText()
Description copied from interface: Node

Returns the text of this node.

Specified by:
getText in interface Element
Specified by:
getText in interface Node
Overrides:
getText in class AbstractBranch
Returns:
the text for this node.

getStringValue

public java.lang.String 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 interface Element
Specified by:
getStringValue in interface Node
Overrides:
getStringValue in class AbstractElement
Returns:
the text from all the child Text and Element nodes appended together.

clone

public java.lang.Object 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 interface Node
Overrides:
clone in class AbstractNode
Returns:
a deep clone of myself or myself if I am read only.

getNamespaceForPrefix

public Namespace getNamespaceForPrefix(java.lang.String prefix)
Description copied from interface: Element

Returns the Namespace which is mapped to the given prefix or null if it could not be found.

Specified by:
getNamespaceForPrefix in interface Element
Overrides:
getNamespaceForPrefix in class AbstractElement
Parameters:
prefix - DOCUMENT ME!
Returns:
the Namespace associated with the given prefix

getNamespaceForURI

public Namespace getNamespaceForURI(java.lang.String uri)
Description copied from interface: Element

Returns the Namespace which is mapped to the given URI or null if it could not be found. If there is more than one Namespace mapped to the URI, which of them will be returned is undetermined.

Specified by:
getNamespaceForURI in interface Element
Overrides:
getNamespaceForURI in class AbstractElement
Parameters:
uri - DOCUMENT ME!
Returns:
the Namespace associated with the given URI

declaredNamespaces

public java.util.List 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 interface Element
Overrides:
declaredNamespaces in class AbstractElement
Returns:
a list of namespaces declared for this element.

additionalNamespaces

public java.util.List additionalNamespaces()
Description copied from interface: Element

Returns any additional namespaces declarations for this element other than namespace returned via the Element.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 interface Element
Overrides:
additionalNamespaces in class AbstractElement
Returns:
a list of any additional namespace declarations.

additionalNamespaces

public java.util.List additionalNamespaces(java.lang.String defaultNamespaceURI)
Overrides:
additionalNamespaces in class AbstractElement

processingInstructions

public java.util.List 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 interface Branch
Overrides:
processingInstructions in class AbstractElement
Returns:
a backed list of the processing instructions

processingInstructions

public java.util.List processingInstructions(java.lang.String target)
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 interface Branch
Overrides:
processingInstructions in class AbstractElement
Parameters:
target - DOCUMENT ME!
Returns:
a backed list of the processing instructions

processingInstruction

public ProcessingInstruction processingInstruction(java.lang.String target)
Description copied from interface: Branch
DOCUMENT ME!

Specified by:
processingInstruction in interface Branch
Overrides:
processingInstruction in class AbstractElement
Parameters:
target - DOCUMENT ME!
Returns:
the processing instruction for the given target

removeProcessingInstruction

public boolean removeProcessingInstruction(java.lang.String target)
Description copied from interface: Branch
Removes the processing instruction for the given target if it exists

Specified by:
removeProcessingInstruction in interface Branch
Overrides:
removeProcessingInstruction in class AbstractElement
Parameters:
target - DOCUMENT ME!
Returns:
true if a processing instruction was removed else false

element

public Element element(java.lang.String name)
Description copied from interface: Element
Returns the first element for the given local name and any namespace.

Specified by:
element in interface Element
Overrides:
element in class AbstractElement
Parameters:
name - DOCUMENT ME!
Returns:
the first element with the given local name

element

public Element element(QName qName)
Description copied from interface: Element
Returns the first element for the given fully qualified name.

Specified by:
element in interface Element
Overrides:
element in class AbstractElement
Parameters:
qName - is the fully qualified name to search for
Returns:
the first element with the given fully qualified name

element

public Element element(java.lang.String name,
                       Namespace namespace)
Overrides:
element in class AbstractElement

setContent

public void setContent(java.util.List content)
Description copied from interface: Branch
Sets the contents of this branch as a List of Node instances.

Parameters:
content - is the list of nodes to use as the content for this branch.

clearContent

public void clearContent()
Description copied from interface: Branch
Clears the content for this branch, removing any Node instances this branch may contain.


node

public Node node(int index)
Description copied from interface: Branch
Returns the Node at the specified index position.

Specified by:
node in interface Branch
Overrides:
node in class AbstractElement
Parameters:
index - the index of the node to return.
Returns:
the Node at the specified position.

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.

Specified by:
indexOf in interface Branch
Overrides:
indexOf in class AbstractElement
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 of Node instances that this branch contains.

Specified by:
nodeCount in interface Branch
Overrides:
nodeCount in class AbstractElement
Returns:
the number of nodes this branch contains

nodeIterator

public java.util.Iterator nodeIterator()
Description copied from interface: Branch
Returns an iterator through the content nodes of this branch

Specified by:
nodeIterator in interface Branch
Overrides:
nodeIterator in class AbstractElement
Returns:
an iterator through the content nodes of this branch

attributes

public java.util.List attributes()
Description copied from interface: Element

Returns the Attributeinstances this element contains as a backed Listso that the attributes may be modified directly using the Listinterface. The List is backed by the Element so that changes to the list are reflected in the element and vice versa.

Specified by:
attributes in interface Element
Overrides:
attributes in class AbstractElement
Returns:
the attributes that this element contains as a List

setAttributes

public void setAttributes(java.util.List attributes)
Description copied from interface: Element
Sets the attributes that this element contains

Parameters:
attributes - DOCUMENT ME!

attributeIterator

public java.util.Iterator attributeIterator()
Description copied from interface: Element
DOCUMENT ME!

Specified by:
attributeIterator in interface Element
Overrides:
attributeIterator in class AbstractElement
Returns:
an iterator over the attributes of this element

attribute

public Attribute attribute(int index)
Description copied from interface: Element
Returns the attribute at the specified indexGets the

Specified by:
attribute in interface Element
Overrides:
attribute in class AbstractElement
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 interface Element
Overrides:
attributeCount in class AbstractElement
Returns:
the number of attributes this element contains

attribute

public Attribute attribute(java.lang.String name)
Description copied from interface: Element
Returns the attribute with the given name

Specified by:
attribute in interface Element
Overrides:
attribute in class AbstractElement
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

public Attribute attribute(QName qName)
Description copied from interface: Element
DOCUMENT ME!

Specified by:
attribute in interface Element
Overrides:
attribute in class AbstractElement
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

public Attribute attribute(java.lang.String name,
                           Namespace namespace)
Overrides:
attribute in class AbstractElement

add

public void add(Attribute attribute)
Description copied from interface: Element
Adds the given Attribute to this element. If the given node already has a parent defined then an IllegalAddException 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 interface Element
Overrides:
add in class AbstractElement
Parameters:
attribute - is the attribute to be added

remove

public boolean remove(Attribute attribute)
Description copied from interface: Element
Removes the given Attribute from this element.

Specified by:
remove in interface Element
Overrides:
remove in class AbstractElement
Parameters:
attribute - is the attribute to be removed
Returns:
true if the attribute was removed

addNewNode

protected void addNewNode(Node node)
Description copied from class: AbstractElement
Like addNode() but does not require a parent check

Overrides:
addNewNode in class AbstractElement
Parameters:
node - DOCUMENT ME!

removeNode

protected boolean removeNode(Node node)
Overrides:
removeNode in class AbstractElement

contentList

protected java.util.List contentList()
Description copied from class: AbstractBranch
DOCUMENT ME!

Specified by:
contentList in class AbstractBranch
Returns:
the internal List used to manage the content

attributeList

protected java.util.List attributeList()
Description copied from class: AbstractElement
DOCUMENT ME!

Specified by:
attributeList in class AbstractElement
Returns:
the internal List used to store attributes or creates one if one is not available

attributeList

protected java.util.List attributeList(int size)
Description copied from class: AbstractElement
DOCUMENT ME!

Specified by:
attributeList in class AbstractElement
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

protected void setAttributeList(java.util.List attributeList)

getDocumentFactory

protected DocumentFactory getDocumentFactory()
Overrides:
getDocumentFactory in class AbstractElement


Copyright ? 2005 MetaStuff Ltd. All Rights Reserved. Hosted by

SourceForge Logo