Package org.xmlpull.v1.builder.impl
Class XmlElementImpl
- java.lang.Object
-
- org.xmlpull.v1.builder.impl.XmlElementImpl
-
- All Implemented Interfaces:
Cloneable,XmlContained,XmlContainer,XmlElement
public class XmlElementImpl extends Object implements XmlElement
This is implementation if XML Infoset Element Information Item.- Version:
- $Revision: 1.41 $
- Author:
- Aleksander Slominski
-
-
Field Summary
-
Fields inherited from interface org.xmlpull.v1.builder.XmlElement
NO_NAMESPACE
-
-
Constructor Summary
Constructors Constructor Description XmlElementImpl(String name)packageXmlElementImpl(String namespaceName, String name)packageXmlElementImpl(XmlNamespace namespace, String name)package
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description XmlAttributeaddAttribute(String name, String value)addAttributeXmlAttributeaddAttribute(String attributeType, String attributePrefix, String attributeNamespace, String attributeName, String attributeValue, boolean specified)Method addAttributeXmlAttributeaddAttribute(String attributeType, XmlNamespace namespace, String name, String value)Method addAttributeXmlAttributeaddAttribute(String attributeType, XmlNamespace namespace, String name, String value, boolean specified)Method addAttributeXmlAttributeaddAttribute(XmlAttribute attributeValueToAdd)Add attribute (adds it to the XML Infoset [namespace attributes] set) Attribute mistXmlAttributeaddAttribute(XmlNamespace namespace, String name, String value)Method addAttributevoidaddChild(int index, Object child)Method addChildvoidaddChild(Object child)NOTE: =child added is _not_ checked if it XmlContainer, caller must manually fix parent in child by calling setParent() !!!!XmlElementaddElement(int pos, XmlElement element)Method addElementXmlElementaddElement(String name)Method addElementXmlElementaddElement(XmlElement element)NOTE: the child element must unattached to be added (it is atttached if it is XmlContainer of recognized type and getParent() != null)XmlElementaddElement(XmlNamespace namespace, String name)Method addElementXmlAttributeattribute(String attributeName)Find attribute that matches given name or namespace Returns null if not found.XmlAttributeattribute(XmlNamespace attributeNamespace, String attributeName)Find attribute that matches given name or namespace Returns null if not found.Iteratorattributes()Return Iterator- null is never returned if there is no children then iteraotr over empty collection is returned Iteratorchildren()Return IteratorObjectclone()Method cloneXmlNamespacedeclareNamespace(String prefix, String namespaceName)Create new namespace with prefix and namespace name (both must be not null) and add it to current element.XmlNamespacedeclareNamespace(XmlNamespace n)Add namespace to current element (both prefix and namespace name must be not null)XmlElementelement(int position)return element at poition (0..count-1) or IndexOutOfBoundsException if positon incorrectXmlElementelement(XmlNamespace n, String name)find first element with name and namespace (if namespace is null it is ignored in search)XmlElementelement(XmlNamespace n, 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 returnedIterableelements(XmlNamespace n, String name)Return all elements that has namespace and name (null is never returned but empty iteraotr)voidensureAttributeCapacity(int minCapacity)Method ensureAttributeCapacityvoidensureChildrenCapacity(int minCapacity)Method ensureChildrenCapacityvoidensureNamespaceDeclarationsCapacity(int minCapacity)Method ensureNamespaceDeclarationsCapacityXmlAttributefindAttribute(String attributeNamespace, String attributeName)Deprecated.XmlElementfindElementByName(String name)XmlElementfindElementByName(String namespaceName, String name)XmlElementfindElementByName(String namespaceName, String name, XmlElement elementToStartLooking)XmlElementfindElementByName(String name, XmlElement elementToStartLooking)StringgetAttributeValue(String attributeNamespaceName, String attributeName)Method getAttributeValueStringgetBaseUri()XML Infoset [base URI] propertyStringgetName()XML Infoset [local name] property.XmlNamespacegetNamespace()Return namespace of current element (XML Infoset [namespace name] and [prefix] properties combined) null is only returned if element was created without namespaceStringgetNamespaceName()Return namespace name (XML Infoset [namespace name]property or null if element has no namespaceXmlContainergetParent()XML Infoset [parent] property.XmlContainergetRoot()Get top most container that is either XmlDocument or XmlElement (may be event this element!!!)booleanhasAttributes()Method hasAttributesbooleanhasChild(Object child)Method hasChildbooleanhasChildren()Method hasChildrenbooleanhasNamespaceDeclarations()Method hasNamespaceDeclarationsvoidinsertChild(int pos, Object childToInsert)XmlNamespacelookupNamespaceByName(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).XmlNamespacelookupNamespaceByPrefix(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.Iteratornamespaces()Return Iterator- null is never returned if there is no children then iteraotr over empty collection is returned XmlElementnewElement(String name)Create unattached elementXmlElementnewElement(String namespace, String name)Method newElementXmlElementnewElement(XmlNamespace namespace, String name)Method newElementXmlNamespacenewNamespace(String namespaceName)Create new namespace with null prefix (namespace name must be not null).XmlNamespacenewNamespace(String prefix, String namespaceName)Create new namespace with prefix and namespace name (both must be not null).voidremoveAllAttributes()Method removeAllAttributesvoidremoveAllChildren()Removes all children - every child that was implementing XmlNode will have set parent to null.voidremoveAllNamespaceDeclarations()Method removeAllNamespaceDeclarationsvoidremoveAttribute(XmlAttribute attr)Method removeAttributevoidremoveChild(Object child)Method removeChildvoidreplaceChild(Object newChild, Object oldChild)Method replaceChildvoidreplaceChildrenWithText(String textContent)Remove all children and then add this text as only child.XmlElementrequiredElement(XmlNamespace n, String name)call element(n, name) and if null was returnedthrow XmlBuilderExceptionIterablerequiredElementContent()Return Iterator- that represents all XmlElement content. StringrequiredTextContent()return children content as text - if there are any no text children throw exceptionvoidsetBaseUri(String baseUri)XML Infoset [base URI] propertyvoidsetName(String name)XML Infoset [local name] property.voidsetNamespace(XmlNamespace namespace)Set namespace ot use for theis element.voidsetParent(XmlContainer parent)Method setParentStringtoString()
-
-
-
Constructor Detail
-
XmlElementImpl
XmlElementImpl(String name)
package
-
XmlElementImpl
XmlElementImpl(XmlNamespace namespace, String name)
package
-
-
Method Detail
-
clone
public Object clone() throws CloneNotSupportedException
Description copied from interface:XmlElementMethod clone- Specified by:
clonein interfaceXmlElement- Overrides:
clonein classObject- Returns:
- an Object
- Throws:
CloneNotSupportedException
-
getRoot
public XmlContainer getRoot()
Description copied from interface:XmlElementGet top most container that is either XmlDocument or XmlElement (may be event this element!!!)- Specified by:
getRootin interfaceXmlElement
-
getParent
public XmlContainer getParent()
Description copied from interface:XmlElementXML Infoset [parent] property. If current element is not child of containing parent XmlElement or XmlDocument then builder exception will be thrown- Specified by:
getParentin interfaceXmlContained- Specified by:
getParentin interfaceXmlElement
-
setParent
public void setParent(XmlContainer parent)
Description copied from interface:XmlElementMethod setParent- Specified by:
setParentin interfaceXmlContained- Specified by:
setParentin interfaceXmlElement- Parameters:
parent- a XmlContainer
-
getNamespace
public XmlNamespace getNamespace()
Description copied from interface:XmlElementReturn namespace of current element (XML Infoset [namespace name] and [prefix] properties combined) null is only returned if element was created without namespace- Specified by:
getNamespacein interfaceXmlElement
-
getNamespaceName
public String getNamespaceName()
Description copied from interface:XmlElementReturn namespace name (XML Infoset [namespace name]property or null if element has no namespace- Specified by:
getNamespaceNamein interfaceXmlElement
-
setNamespace
public void setNamespace(XmlNamespace namespace)
Description copied from interface:XmlElementSet namespace ot use for theis element. Note: namespace prefix is always ignored.- Specified by:
setNamespacein interfaceXmlElement
-
getName
public String getName()
Description copied from interface:XmlElementXML Infoset [local name] property.- Specified by:
getNamein interfaceXmlElement- Returns:
- a String
-
setName
public void setName(String name)
Description copied from interface:XmlElementXML Infoset [local name] property.- Specified by:
setNamein interfaceXmlElement- Parameters:
name- a String
-
getBaseUri
public String getBaseUri()
Description copied from interface:XmlElementXML Infoset [base URI] property- Specified by:
getBaseUriin interfaceXmlElement- Returns:
- a String
-
setBaseUri
public void setBaseUri(String baseUri)
Description copied from interface:XmlElementXML Infoset [base URI] property- Specified by:
setBaseUriin interfaceXmlElement- Parameters:
baseUri- a String
-
attributes
public Iterator attributes()
Description copied from interface:XmlElementReturn Iterator- null is never returned if there is no children then iteraotr over empty collection is returned - Specified by:
attributesin interfaceXmlElement
-
addAttribute
public XmlAttribute addAttribute(XmlAttribute attributeValueToAdd)
Description copied from interface:XmlElementAdd attribute (adds it to the XML Infoset [namespace attributes] set) Attribute mist- Specified by:
addAttributein interfaceXmlElement- Parameters:
attributeValueToAdd- a XmlAttribute- Returns:
- a XmlAttribute
-
addAttribute
public XmlAttribute addAttribute(XmlNamespace namespace, String name, String value)
Description copied from interface:XmlElementMethod addAttribute- Specified by:
addAttributein interfaceXmlElement- Parameters:
namespace- a XmlNamespacename- a Stringvalue- a String- Returns:
- a XmlAttribute
-
addAttribute
public XmlAttribute addAttribute(String name, String value)
Description copied from interface:XmlElementaddAttribute- Specified by:
addAttributein interfaceXmlElement- Parameters:
name- a Stringvalue- a String- Returns:
- a XmlAttribute
-
addAttribute
public XmlAttribute addAttribute(String attributeType, XmlNamespace namespace, String name, String value)
Description copied from interface:XmlElementMethod addAttribute- Specified by:
addAttributein interfaceXmlElement- Parameters:
attributeType- a Stringnamespace- a XmlNamespacename- a Stringvalue- a String- Returns:
- a XmlAttribute
-
addAttribute
public XmlAttribute addAttribute(String attributeType, XmlNamespace namespace, String name, String value, boolean specified)
Description copied from interface:XmlElementMethod addAttribute- Specified by:
addAttributein interfaceXmlElement- Parameters:
attributeType- a Stringnamespace- a XmlNamespacename- a Stringvalue- a Stringspecified- a boolean- Returns:
- a XmlAttribute
-
addAttribute
public XmlAttribute addAttribute(String attributeType, String attributePrefix, String attributeNamespace, String attributeName, String attributeValue, boolean specified)
Description copied from interface:XmlElementMethod addAttribute- Specified by:
addAttributein interfaceXmlElement- Parameters:
attributeType- a StringattributePrefix- a StringattributeNamespace- a StringattributeName- a StringattributeValue- a Stringspecified- a boolean- Returns:
- a XmlAttribute
-
ensureAttributeCapacity
public void ensureAttributeCapacity(int minCapacity)
Description copied from interface:XmlElementMethod ensureAttributeCapacity- Specified by:
ensureAttributeCapacityin interfaceXmlElement- Parameters:
minCapacity- an int
-
getAttributeValue
public String getAttributeValue(String attributeNamespaceName, String attributeName)
Description copied from interface:XmlElementMethod getAttributeValue- Specified by:
getAttributeValuein interfaceXmlElementattributeName- a String- Returns:
- a String
-
hasAttributes
public boolean hasAttributes()
Description copied from interface:XmlElementMethod hasAttributes- Specified by:
hasAttributesin interfaceXmlElement- Returns:
- a boolean
-
attribute
public XmlAttribute attribute(String attributeName)
Description copied from interface:XmlElementFind attribute that matches given name or namespace Returns null if not found. Will match only attribute that have no namesapce.- Specified by:
attributein interfaceXmlElement
-
attribute
public XmlAttribute attribute(XmlNamespace attributeNamespace, String attributeName)
Description copied from interface:XmlElementFind 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:
attributein interfaceXmlElement
-
findAttribute
public XmlAttribute findAttribute(String attributeNamespace, String attributeName)
Deprecated.Description copied from interface:XmlElementFind 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:
findAttributein interfaceXmlElement
-
removeAllAttributes
public void removeAllAttributes()
Description copied from interface:XmlElementMethod removeAllAttributes- Specified by:
removeAllAttributesin interfaceXmlElement
-
removeAttribute
public void removeAttribute(XmlAttribute attr)
Description copied from interface:XmlElementMethod removeAttribute- Specified by:
removeAttributein interfaceXmlElement- Parameters:
attr- a XmlAttribute
-
declareNamespace
public XmlNamespace declareNamespace(String prefix, String namespaceName)
Description copied from interface:XmlElementCreate new namespace with prefix and namespace name (both must be not null) and add it to current element.- Specified by:
declareNamespacein interfaceXmlElement
-
declareNamespace
public XmlNamespace declareNamespace(XmlNamespace n)
Description copied from interface:XmlElementAdd namespace to current element (both prefix and namespace name must be not null)- Specified by:
declareNamespacein interfaceXmlElement
-
hasNamespaceDeclarations
public boolean hasNamespaceDeclarations()
Description copied from interface:XmlElementMethod hasNamespaceDeclarations- Specified by:
hasNamespaceDeclarationsin interfaceXmlElement- Returns:
- a boolean
-
lookupNamespaceByPrefix
public XmlNamespace lookupNamespaceByPrefix(String namespacePrefix)
Description copied from interface:XmlElementFind 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:
lookupNamespaceByPrefixin interfaceXmlElement
-
lookupNamespaceByName
public XmlNamespace lookupNamespaceByName(String namespaceName)
Description copied from interface:XmlElementFind 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:
lookupNamespaceByNamein interfaceXmlElement
-
namespaces
public Iterator namespaces()
Description copied from interface:XmlElementReturn Iterator- null is never returned if there is no children then iteraotr over empty collection is returned - Specified by:
namespacesin interfaceXmlElement
-
newNamespace
public XmlNamespace newNamespace(String namespaceName)
Description copied from interface:XmlElementCreate new namespace with null prefix (namespace name must be not null).- Specified by:
newNamespacein interfaceXmlElement
-
newNamespace
public XmlNamespace newNamespace(String prefix, String namespaceName)
Description copied from interface:XmlElementCreate new namespace with prefix and namespace name (both must be not null).- Specified by:
newNamespacein interfaceXmlElement
-
ensureNamespaceDeclarationsCapacity
public void ensureNamespaceDeclarationsCapacity(int minCapacity)
Description copied from interface:XmlElementMethod ensureNamespaceDeclarationsCapacity- Specified by:
ensureNamespaceDeclarationsCapacityin interfaceXmlElement- Parameters:
minCapacity- an int
-
removeAllNamespaceDeclarations
public void removeAllNamespaceDeclarations()
Description copied from interface:XmlElementMethod removeAllNamespaceDeclarations- Specified by:
removeAllNamespaceDeclarationsin interfaceXmlElement
-
addChild
public void addChild(Object child)
Description copied from interface:XmlElementNOTE: =child added is _not_ checked if it XmlContainer, caller must manually fix parent in child by calling setParent() !!!!- Specified by:
addChildin interfaceXmlElement
-
addChild
public void addChild(int index, Object child)Description copied from interface:XmlElementMethod addChild- Specified by:
addChildin interfaceXmlElement- Parameters:
index- an int (starting from 0)child- an Object
-
addElement
public XmlElement addElement(XmlElement element)
Description copied from interface:XmlElementNOTE: the child element must unattached to be added (it is atttached if it is XmlContainer of recognized type and getParent() != null)- Specified by:
addElementin interfaceXmlElement
-
addElement
public XmlElement addElement(int pos, XmlElement element)
Description copied from interface:XmlElementMethod addElement- Specified by:
addElementin interfaceXmlElement- Parameters:
pos- an int (starting from 0)element- a XmlElement- Returns:
- a XmlElement
-
addElement
public XmlElement addElement(XmlNamespace namespace, String name)
Description copied from interface:XmlElementMethod addElement- Specified by:
addElementin interfaceXmlElement- Parameters:
namespace- a XmlNamespacename- a String- Returns:
- a XmlElement
-
addElement
public XmlElement addElement(String name)
Description copied from interface:XmlElementMethod addElement- Specified by:
addElementin interfaceXmlElement- Parameters:
name- a String- Returns:
- a XmlElement
-
children
public Iterator children()
Description copied from interface:XmlElementReturn Iterator- Specified by:
childrenin interfaceXmlElement
-
requiredElementContent
public Iterable requiredElementContent()
Description copied from interface:XmlElementReturn 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:
requiredElementContentin interfaceXmlElement
-
requiredTextContent
public String requiredTextContent()
Description copied from interface:XmlElementreturn children content as text - if there are any no text children throw exception- Specified by:
requiredTextContentin interfaceXmlElement
-
ensureChildrenCapacity
public void ensureChildrenCapacity(int minCapacity)
Description copied from interface:XmlElementMethod ensureChildrenCapacity- Specified by:
ensureChildrenCapacityin interfaceXmlElement- Parameters:
minCapacity- an int
-
element
public XmlElement element(int position)
Description copied from interface:XmlElementreturn element at poition (0..count-1) or IndexOutOfBoundsException if positon incorrect- Specified by:
elementin interfaceXmlElement
-
requiredElement
public XmlElement requiredElement(XmlNamespace n, String name) throws XmlBuilderException
Description copied from interface:XmlElementcall element(n, name) and if null was returnedthrow XmlBuilderException- Specified by:
requiredElementin interfaceXmlElement- Throws:
XmlBuilderException
-
element
public XmlElement element(XmlNamespace n, String name)
Description copied from interface:XmlElementfind first element with name and namespace (if namespace is null it is ignored in search)- Specified by:
elementin interfaceXmlElement
-
element
public XmlElement element(XmlNamespace n, String name, boolean create)
Description copied from interface:XmlElementfind 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:
elementin interfaceXmlElement
-
elements
public Iterable elements(XmlNamespace n, String name)
Description copied from interface:XmlElementReturn all elements that has namespace and name (null is never returned but empty iteraotr)- Specified by:
elementsin interfaceXmlElement
-
findElementByName
public XmlElement findElementByName(String name)
- Specified by:
findElementByNamein interfaceXmlElement
-
findElementByName
public XmlElement findElementByName(String namespaceName, String name, XmlElement elementToStartLooking)
- Specified by:
findElementByNamein interfaceXmlElement
-
findElementByName
public XmlElement findElementByName(String name, XmlElement elementToStartLooking)
- Specified by:
findElementByNamein interfaceXmlElement
-
findElementByName
public XmlElement findElementByName(String namespaceName, String name)
- Specified by:
findElementByNamein interfaceXmlElement
-
hasChild
public boolean hasChild(Object child)
Description copied from interface:XmlElementMethod hasChild- Specified by:
hasChildin interfaceXmlElement- Parameters:
child- an Object- Returns:
- a boolean
-
hasChildren
public boolean hasChildren()
Description copied from interface:XmlElementMethod hasChildren- Specified by:
hasChildrenin interfaceXmlElement- Returns:
- a boolean
-
insertChild
public void insertChild(int pos, Object childToInsert)- Specified by:
insertChildin interfaceXmlElement
-
newElement
public XmlElement newElement(String name)
Description copied from interface:XmlElementCreate unattached element- Specified by:
newElementin interfaceXmlElement
-
newElement
public XmlElement newElement(String namespace, String name)
Description copied from interface:XmlElementMethod newElement- Specified by:
newElementin interfaceXmlElement- Parameters:
namespace- a Stringname- a String- Returns:
- a XmlElement
-
newElement
public XmlElement newElement(XmlNamespace namespace, String name)
Description copied from interface:XmlElementMethod newElement- Specified by:
newElementin interfaceXmlElement- Parameters:
namespace- a XmlNamespacename- a String- Returns:
- a XmlElement
-
replaceChild
public void replaceChild(Object newChild, Object oldChild)
Description copied from interface:XmlElementMethod replaceChild- Specified by:
replaceChildin interfaceXmlElement- Parameters:
newChild- an ObjectoldChild- an Object
-
removeAllChildren
public void removeAllChildren()
Description copied from interface:XmlElementRemoves all children - every child that was implementing XmlNode will have set parent to null.- Specified by:
removeAllChildrenin interfaceXmlElement
-
removeChild
public void removeChild(Object child)
Description copied from interface:XmlElementMethod removeChild- Specified by:
removeChildin interfaceXmlElement- Parameters:
child- an Object
-
replaceChildrenWithText
public void replaceChildrenWithText(String textContent)
Description copied from interface:XmlElementRemove all children and then add this text as only child.- Specified by:
replaceChildrenWithTextin interfaceXmlElement
-
-