org.xmlpull.v1.builder.impl
Class XmlElementImpl

java.lang.Object
  extended by org.xmlpull.v1.builder.impl.XmlElementImpl
All Implemented Interfaces:
java.lang.Cloneable, XmlContained, XmlContainer, XmlElement

public class XmlElementImpl
extends java.lang.Object
implements XmlElement

This is implementation if XML Infoset Element Information Item.


Field Summary
 
Fields inherited from interface org.xmlpull.v1.builder.XmlElement
NO_NAMESPACE
 
Method Summary
 XmlAttribute addAttribute(java.lang.String name, java.lang.String value)
          addAttribute
 XmlAttribute addAttribute(java.lang.String attributeType, java.lang.String attributePrefix, java.lang.String attributeNamespace, java.lang.String attributeName, java.lang.String attributeValue, boolean specified)
          Method addAttribute
 XmlAttribute addAttribute(java.lang.String attributeType, XmlNamespace namespace, java.lang.String name, java.lang.String value)
          Method addAttribute
 XmlAttribute addAttribute(java.lang.String attributeType, XmlNamespace namespace, java.lang.String name, java.lang.String value, boolean specified)
          Method addAttribute
 XmlAttribute addAttribute(XmlAttribute attributeValueToAdd)
          Add attribute (adds it to the XML Infoset [namespace attributes] set) Attribute mist
 XmlAttribute addAttribute(XmlNamespace namespace, java.lang.String name, java.lang.String value)
          Method addAttribute
 void addChild(int index, java.lang.Object child)
          Method addChild
 void addChild(java.lang.Object child)
          NOTE: =child added is _not_ checked if it XmlContainer, caller must manually fix parent in child by calling setParent() !!!!
 XmlElement addElement(int pos, XmlElement element)
          Method addElement
 XmlElement addElement(java.lang.String name)
          Method addElement
 XmlElement addElement(XmlElement element)
          NOTE: the child element must unattached to be added (it is atttached if it is XmlContainer of recognized type and getParent() !
 XmlElement addElement(XmlNamespace namespace, java.lang.String name)
          Method addElement
 XmlAttribute attribute(java.lang.String attributeName)
          Find attribute that matches given name or namespace Returns null if not found.
 XmlAttribute attribute(XmlNamespace attributeNamespace, java.lang.String attributeName)
          Find attribute that matches given name or namespace Returns null if not found.
 java.util.Iterator attributes()
          Return Iterator - null is never returned if there is no children then iteraotr over empty collection is returned
 java.util.Iterator children()
          Return Iterator - null is never returned if there is no children then iteraotr over empty collection is returned
 java.lang.Object clone()
          Method clone
 XmlNamespace declareNamespace(java.lang.String prefix, java.lang.String namespaceName)
          Create new namespace with prefix and namespace name (both must be not null) and add it to current element.
 XmlNamespace declareNamespace(XmlNamespace n)
          Add namespace to current element (both prefix and namespace name must be not null)
 XmlElement element(int position)
          return element at poition (0..count-1) or IndexOutOfBoundsException if positon incorrect
 XmlElement element(XmlNamespace n, java.lang.String name)
          find first element with name and namespace (if namespace is null it is ignored in search)
 XmlElement element(XmlNamespace n, java.lang.String name, boolean create)
          find first element with name and namespace (if namespace is null it is ignored in search) if no matching element is found then new element is created, appended to children, and returned
 Iterable elements(XmlNamespace n, java.lang.String name)
          Return all elements that has namespace and name (null is never returned but empty iteraotr)
 void ensureAttributeCapacity(int minCapacity)
          Method ensureAttributeCapacity
 void ensureChildrenCapacity(int minCapacity)
          Method ensureChildrenCapacity
 void ensureNamespaceDeclarationsCapacity(int minCapacity)
          Method ensureNamespaceDeclarationsCapacity
 XmlAttribute findAttribute(java.lang.String attributeNamespace, java.lang.String attributeName)
          Deprecated.  
 XmlElement findElementByName(java.lang.String name)
           
 XmlElement findElementByName(java.lang.String namespaceName, java.lang.String name)
           
 XmlElement findElementByName(java.lang.String namespaceName, java.lang.String name, XmlElement elementToStartLooking)
           
 XmlElement findElementByName(java.lang.String name, XmlElement elementToStartLooking)
           
 java.lang.String getAttributeValue(java.lang.String attributeNamespaceName, java.lang.String attributeName)
          Method getAttributeValue
 java.lang.String getBaseUri()
          XML Infoset [base URI] property
 java.lang.String getName()
          XML Infoset [local name] property.
 XmlNamespace getNamespace()
          Return namespace of current element (XML Infoset [namespace name] and [prefix] properties combined) null is only returned if element was created without namespace
 java.lang.String getNamespaceName()
          Return namespace name (XML Infoset [namespace name]property or null if element has no namespace
 XmlContainer getParent()
          XML Infoset [parent] property.
 XmlContainer getRoot()
          Get top most container that is either XmlDocument or XmlElement (may be event this element!!!)
 boolean hasAttributes()
          Method hasAttributes
 boolean hasChild(java.lang.Object child)
          Method hasChild
 boolean hasChildren()
          Method hasChildren
 boolean hasNamespaceDeclarations()
          Method hasNamespaceDeclarations
 void insertChild(int pos, java.lang.Object childToInsert)
           
 XmlNamespace lookupNamespaceByName(java.lang.String namespaceName)
          Find namespace (will have non empty prefix) corresponding to namespace name checking first current elemen and if not found continue in parent (if element has parent).
 XmlNamespace lookupNamespaceByPrefix(java.lang.String namespacePrefix)
          Find namespace (will have non empty prefix) corresponding to namespace prefix checking first current elemen and if not found continue in parent (if element has parent) and so on.
 java.util.Iterator namespaces()
          Return Iterator - null is never returned if there is no children then iteraotr over empty collection is returned
 XmlElement newElement(java.lang.String name)
          Create unattached element
 XmlElement newElement(java.lang.String namespace, java.lang.String name)
          Method newElement
 XmlElement newElement(XmlNamespace namespace, java.lang.String name)
          Method newElement
 XmlNamespace newNamespace(java.lang.String namespaceName)
          Create new namespace with null prefix (namespace name must be not null).
 XmlNamespace newNamespace(java.lang.String prefix, java.lang.String namespaceName)
          Create new namespace with prefix and namespace name (both must be not null).
 void removeAllAttributes()
          Method removeAllAttributes
 void removeAllChildren()
          Removes all children - every child that was implementing XmlNode will have set parent to null.
 void removeAllNamespaceDeclarations()
          Method removeAllNamespaceDeclarations
 void removeAttribute(XmlAttribute attr)
          Method removeAttribute
 void removeChild(java.lang.Object child)
          Method removeChild
 void replaceChild(java.lang.Object newChild, java.lang.Object oldChild)
          Method replaceChild
 void replaceChildrenWithText(java.lang.String textContent)
          Remove all children and then add this text as only child.
 XmlElement requiredElement(XmlNamespace n, java.lang.String name)
          call element(n, name) and if null was returnedthrow XmlBuilderException
 Iterable requiredElementContent()
          Return Iterator - that represents all XmlElement content.
 java.lang.String requiredTextContent()
          return children content as text - if there are any no text children throw exception
 void setBaseUri(java.lang.String baseUri)
          XML Infoset [base URI] property
 void setName(java.lang.String name)
          XML Infoset [local name] property.
 void setNamespace(XmlNamespace namespace)
          Set namespace ot use for theis element.
 void setParent(XmlContainer parent)
          Method setParent
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Description copied from interface: XmlElement
Method clone

Specified by:
clone in interface XmlElement
Overrides:
clone in class java.lang.Object
Returns:
an Object
Throws:
java.lang.CloneNotSupportedException

getRoot

public XmlContainer getRoot()
Description copied from interface: XmlElement
Get top most container that is either XmlDocument or XmlElement (may be event this element!!!)

Specified by:
getRoot in interface XmlElement

getParent

public XmlContainer getParent()
Description copied from interface: XmlElement
XML Infoset [parent] property. If current element is not child of containing parent XmlElement or XmlDocument then builder exception will be thrown

Specified by:
getParent in interface XmlContained
Specified by:
getParent in interface XmlElement

setParent

public void setParent(XmlContainer parent)
Description copied from interface: XmlElement
Method setParent

Specified by:
setParent in interface XmlContained
Specified by:
setParent in interface XmlElement
Parameters:
parent - a XmlContainer

getNamespace

public XmlNamespace getNamespace()
Description copied from interface: XmlElement
Return namespace of current element (XML Infoset [namespace name] and [prefix] properties combined) null is only returned if element was created without namespace

Specified by:
getNamespace in interface XmlElement

getNamespaceName

public java.lang.String getNamespaceName()
Description copied from interface: XmlElement
Return namespace name (XML Infoset [namespace name]property or null if element has no namespace

Specified by:
getNamespaceName in interface XmlElement

setNamespace

public void setNamespace(XmlNamespace namespace)
Description copied from interface: XmlElement
Set namespace ot use for theis element. Note: namespace prefix is always ignored.

Specified by:
setNamespace in interface XmlElement

getName

public java.lang.String getName()
Description copied from interface: XmlElement
XML Infoset [local name] property.

Specified by:
getName in interface XmlElement
Returns:
a String

setName

public void setName(java.lang.String name)
Description copied from interface: XmlElement
XML Infoset [local name] property.

Specified by:
setName in interface XmlElement
Parameters:
name - a String

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getBaseUri

public java.lang.String getBaseUri()
Description copied from interface: XmlElement
XML Infoset [base URI] property

Specified by:
getBaseUri in interface XmlElement
Returns:
a String

setBaseUri

public void setBaseUri(java.lang.String baseUri)
Description copied from interface: XmlElement
XML Infoset [base URI] property

Specified by:
setBaseUri in interface XmlElement
Parameters:
baseUri - a String

attributes

public java.util.Iterator attributes()
Description copied from interface: XmlElement
Return Iterator - null is never returned if there is no children then iteraotr over empty collection is returned

Specified by:
attributes in interface XmlElement

addAttribute

public XmlAttribute addAttribute(XmlAttribute attributeValueToAdd)
Description copied from interface: XmlElement
Add attribute (adds it to the XML Infoset [namespace attributes] set) Attribute mist

Specified by:
addAttribute in interface XmlElement
Parameters:
attributeValueToAdd - a XmlAttribute
Returns:
a XmlAttribute

addAttribute

public XmlAttribute addAttribute(XmlNamespace namespace,
                                 java.lang.String name,
                                 java.lang.String value)
Description copied from interface: XmlElement
Method addAttribute

Specified by:
addAttribute in interface XmlElement
Parameters:
namespace - a XmlNamespace
name - a String
value - a String
Returns:
a XmlAttribute

addAttribute

public XmlAttribute addAttribute(java.lang.String name,
                                 java.lang.String value)
Description copied from interface: XmlElement
addAttribute

Specified by:
addAttribute in interface XmlElement
Parameters:
name - a String
value - a String
Returns:
a XmlAttribute

addAttribute

public XmlAttribute addAttribute(java.lang.String attributeType,
                                 XmlNamespace namespace,
                                 java.lang.String name,
                                 java.lang.String value)
Description copied from interface: XmlElement
Method addAttribute

Specified by:
addAttribute in interface XmlElement
Parameters:
attributeType - a String
namespace - a XmlNamespace
name - a String
value - a String
Returns:
a XmlAttribute

addAttribute

public XmlAttribute addAttribute(java.lang.String attributeType,
                                 XmlNamespace namespace,
                                 java.lang.String name,
                                 java.lang.String value,
                                 boolean specified)
Description copied from interface: XmlElement
Method addAttribute

Specified by:
addAttribute in interface XmlElement
Parameters:
attributeType - a String
namespace - a XmlNamespace
name - a String
value - a String
specified - a boolean
Returns:
a XmlAttribute

addAttribute

public XmlAttribute addAttribute(java.lang.String attributeType,
                                 java.lang.String attributePrefix,
                                 java.lang.String attributeNamespace,
                                 java.lang.String attributeName,
                                 java.lang.String attributeValue,
                                 boolean specified)
Description copied from interface: XmlElement
Method addAttribute

Specified by:
addAttribute in interface XmlElement
Parameters:
attributeType - a String
attributePrefix - a String
attributeNamespace - a String
attributeName - a String
attributeValue - a String
specified - a boolean
Returns:
a XmlAttribute

ensureAttributeCapacity

public void ensureAttributeCapacity(int minCapacity)
Description copied from interface: XmlElement
Method ensureAttributeCapacity

Specified by:
ensureAttributeCapacity in interface XmlElement
Parameters:
minCapacity - an int

getAttributeValue

public java.lang.String getAttributeValue(java.lang.String attributeNamespaceName,
                                          java.lang.String attributeName)
Description copied from interface: XmlElement
Method getAttributeValue

Specified by:
getAttributeValue in interface XmlElement
attributeName - a String
Returns:
a String

hasAttributes

public boolean hasAttributes()
Description copied from interface: XmlElement
Method hasAttributes

Specified by:
hasAttributes in interface XmlElement
Returns:
a boolean

attribute

public XmlAttribute attribute(java.lang.String attributeName)
Description copied from interface: XmlElement
Find attribute that matches given name or namespace Returns null if not found. Will match only attribute that have no namesapce.

Specified by:
attribute in interface XmlElement

attribute

public XmlAttribute attribute(XmlNamespace attributeNamespace,
                              java.lang.String attributeName)
Description copied from interface: XmlElement
Find attribute that matches given name or namespace Returns null if not found. NOTE: if namespace is null in this case it will match only attributes that have no namespace.

Specified by:
attribute in interface XmlElement

findAttribute

public XmlAttribute findAttribute(java.lang.String attributeNamespace,
                                  java.lang.String attributeName)
Deprecated. 

Description copied from interface: XmlElement
Find attribute that matches given name or namespace Returns null if not found. NOTE: if namespace is null in this case it will match only attributes that has no namespace.

Specified by:
findAttribute in interface XmlElement

removeAllAttributes

public void removeAllAttributes()
Description copied from interface: XmlElement
Method removeAllAttributes

Specified by:
removeAllAttributes in interface XmlElement

removeAttribute

public void removeAttribute(XmlAttribute attr)
Description copied from interface: XmlElement
Method removeAttribute

Specified by:
removeAttribute in interface XmlElement
Parameters:
attr - a XmlAttribute

declareNamespace

public XmlNamespace declareNamespace(java.lang.String prefix,
                                     java.lang.String namespaceName)
Description copied from interface: XmlElement
Create new namespace with prefix and namespace name (both must be not null) and add it to current element.

Specified by:
declareNamespace in interface XmlElement

declareNamespace

public XmlNamespace declareNamespace(XmlNamespace n)
Description copied from interface: XmlElement
Add namespace to current element (both prefix and namespace name must be not null)

Specified by:
declareNamespace in interface XmlElement

hasNamespaceDeclarations

public boolean hasNamespaceDeclarations()
Description copied from interface: XmlElement
Method hasNamespaceDeclarations

Specified by:
hasNamespaceDeclarations in interface XmlElement
Returns:
a boolean

lookupNamespaceByPrefix

public XmlNamespace lookupNamespaceByPrefix(java.lang.String namespacePrefix)
Description copied from interface: XmlElement
Find namespace (will have non empty prefix) corresponding to namespace prefix checking first current elemen and if not found continue in parent (if element has parent) and so on.

Specified by:
lookupNamespaceByPrefix in interface XmlElement

lookupNamespaceByName

public XmlNamespace lookupNamespaceByName(java.lang.String namespaceName)
Description copied from interface: XmlElement
Find namespace (will have non empty prefix) corresponding to namespace name checking first current elemen and if not found continue in parent (if element has parent). and so on.

Specified by:
lookupNamespaceByName in interface XmlElement

namespaces

public java.util.Iterator namespaces()
Description copied from interface: XmlElement
Return Iterator - null is never returned if there is no children then iteraotr over empty collection is returned

Specified by:
namespaces in interface XmlElement

newNamespace

public XmlNamespace newNamespace(java.lang.String namespaceName)
Description copied from interface: XmlElement
Create new namespace with null prefix (namespace name must be not null).

Specified by:
newNamespace in interface XmlElement

newNamespace

public XmlNamespace newNamespace(java.lang.String prefix,
                                 java.lang.String namespaceName)
Description copied from interface: XmlElement
Create new namespace with prefix and namespace name (both must be not null).

Specified by:
newNamespace in interface XmlElement

ensureNamespaceDeclarationsCapacity

public void ensureNamespaceDeclarationsCapacity(int minCapacity)
Description copied from interface: XmlElement
Method ensureNamespaceDeclarationsCapacity

Specified by:
ensureNamespaceDeclarationsCapacity in interface XmlElement
Parameters:
minCapacity - an int

removeAllNamespaceDeclarations

public void removeAllNamespaceDeclarations()
Description copied from interface: XmlElement
Method removeAllNamespaceDeclarations

Specified by:
removeAllNamespaceDeclarations in interface XmlElement

addChild

public void addChild(java.lang.Object child)
Description copied from interface: XmlElement
NOTE: =child added is _not_ checked if it XmlContainer, caller must manually fix parent in child by calling setParent() !!!!

Specified by:
addChild in interface XmlElement

addChild

public void addChild(int index,
                     java.lang.Object child)
Description copied from interface: XmlElement
Method addChild

Specified by:
addChild in interface XmlElement
Parameters:
index - an int (starting from 0)
child - an Object

addElement

public XmlElement addElement(XmlElement element)
Description copied from interface: XmlElement
NOTE: the child element must unattached to be added (it is atttached if it is XmlContainer of recognized type and getParent() != null)

Specified by:
addElement in interface XmlElement

addElement

public XmlElement addElement(int pos,
                             XmlElement element)
Description copied from interface: XmlElement
Method addElement

Specified by:
addElement in interface XmlElement
Parameters:
pos - an int (starting from 0)
element - a XmlElement
Returns:
a XmlElement

addElement

public XmlElement addElement(XmlNamespace namespace,
                             java.lang.String name)
Description copied from interface: XmlElement
Method addElement

Specified by:
addElement in interface XmlElement
Parameters:
namespace - a XmlNamespace
name - a String
Returns:
a XmlElement

addElement

public XmlElement addElement(java.lang.String name)
Description copied from interface: XmlElement
Method addElement

Specified by:
addElement in interface XmlElement
Parameters:
name - a String
Returns:
a XmlElement

children

public java.util.Iterator children()
Description copied from interface: XmlElement
Return Iterator - null is never returned if there is no children then iteraotr over empty collection is returned

Specified by:
children in interface XmlElement

requiredElementContent

public Iterable requiredElementContent()
Description copied from interface: XmlElement
Return Iterator - that represents all XmlElement content. When used exception will be thrown if non white space children are found (as expected no mixed content!).

Specified by:
requiredElementContent in interface XmlElement

requiredTextContent

public java.lang.String requiredTextContent()
Description copied from interface: XmlElement
return children content as text - if there are any no text children throw exception

Specified by:
requiredTextContent in interface XmlElement

ensureChildrenCapacity

public void ensureChildrenCapacity(int minCapacity)
Description copied from interface: XmlElement
Method ensureChildrenCapacity

Specified by:
ensureChildrenCapacity in interface XmlElement
Parameters:
minCapacity - an int

element

public XmlElement element(int position)
Description copied from interface: XmlElement
return element at poition (0..count-1) or IndexOutOfBoundsException if positon incorrect

Specified by:
element in interface XmlElement

requiredElement

public XmlElement requiredElement(XmlNamespace n,
                                  java.lang.String name)
                           throws XmlBuilderException
Description copied from interface: XmlElement
call element(n, name) and if null was returnedthrow XmlBuilderException

Specified by:
requiredElement in interface XmlElement
Throws:
XmlBuilderException

element

public XmlElement element(XmlNamespace n,
                          java.lang.String name)
Description copied from interface: XmlElement
find first element with name and namespace (if namespace is null it is ignored in search)

Specified by:
element in interface XmlElement

element

public XmlElement element(XmlNamespace n,
                          java.lang.String name,
                          boolean create)
Description copied from interface: XmlElement
find first element with name and namespace (if namespace is null it is ignored in search) if no matching element is found then new element is created, appended to children, and returned

Specified by:
element in interface XmlElement

elements

public Iterable elements(XmlNamespace n,
                         java.lang.String name)
Description copied from interface: XmlElement
Return all elements that has namespace and name (null is never returned but empty iteraotr)

Specified by:
elements in interface XmlElement

findElementByName

public XmlElement findElementByName(java.lang.String name)
Specified by:
findElementByName in interface XmlElement

findElementByName

public XmlElement findElementByName(java.lang.String namespaceName,
                                    java.lang.String name,
                                    XmlElement elementToStartLooking)
Specified by:
findElementByName in interface XmlElement

findElementByName

public XmlElement findElementByName(java.lang.String name,
                                    XmlElement elementToStartLooking)
Specified by:
findElementByName in interface XmlElement

findElementByName

public XmlElement findElementByName(java.lang.String namespaceName,
                                    java.lang.String name)
Specified by:
findElementByName in interface XmlElement

hasChild

public boolean hasChild(java.lang.Object child)
Description copied from interface: XmlElement
Method hasChild

Specified by:
hasChild in interface XmlElement
Parameters:
child - an Object
Returns:
a boolean

hasChildren

public boolean hasChildren()
Description copied from interface: XmlElement
Method hasChildren

Specified by:
hasChildren in interface XmlElement
Returns:
a boolean

insertChild

public void insertChild(int pos,
                        java.lang.Object childToInsert)
Specified by:
insertChild in interface XmlElement

newElement

public XmlElement newElement(java.lang.String name)
Description copied from interface: XmlElement
Create unattached element

Specified by:
newElement in interface XmlElement

newElement

public XmlElement newElement(java.lang.String namespace,
                             java.lang.String name)
Description copied from interface: XmlElement
Method newElement

Specified by:
newElement in interface XmlElement
Parameters:
namespace - a String
name - a String
Returns:
a XmlElement

newElement

public XmlElement newElement(XmlNamespace namespace,
                             java.lang.String name)
Description copied from interface: XmlElement
Method newElement

Specified by:
newElement in interface XmlElement
Parameters:
namespace - a XmlNamespace
name - a String
Returns:
a XmlElement

replaceChild

public void replaceChild(java.lang.Object newChild,
                         java.lang.Object oldChild)
Description copied from interface: XmlElement
Method replaceChild

Specified by:
replaceChild in interface XmlElement
Parameters:
newChild - an Object
oldChild - an Object

removeAllChildren

public void removeAllChildren()
Description copied from interface: XmlElement
Removes all children - every child that was implementing XmlNode will have set parent to null.

Specified by:
removeAllChildren in interface XmlElement

removeChild

public void removeChild(java.lang.Object child)
Description copied from interface: XmlElement
Method removeChild

Specified by:
removeChild in interface XmlElement
Parameters:
child - an Object

replaceChildrenWithText

public void replaceChildrenWithText(java.lang.String textContent)
Description copied from interface: XmlElement
Remove all children and then add this text as only child.

Specified by:
replaceChildrenWithText in interface XmlElement