tigase.jaxmpp.core.client.xml
Class ElementWrapper

java.lang.Object
  extended by tigase.jaxmpp.core.client.xml.ElementWrapper
All Implemented Interfaces:
Element
Direct Known Subclasses:
AbstractField, ErrorElement, JabberDataElement, Stanza, XmppDelay, XMucUserElement

public class ElementWrapper
extends Object
implements Element

Wrapper for Element class.

Author:
bmalkow

Constructor Summary
ElementWrapper(Element element)
           
 
Method Summary
 Element addChild(Element child)
          Add child element to tree and return the added element.
 boolean equals(Object obj)
          
 String getAsString()
          Get this element as XML string.
 String getAttribute(String attName)
          Get attribute by name.
 Map<String,String> getAttributes()
          Get all attributes as a Map.
 Element getChildAfter(Element child)
          Gets the first child after specified child in children list.
protected  String getChildElementValue(String elemName)
           
protected  String getChildElementValue(String elemName, String xmlns)
           
 List<Element> getChildren()
          Get all children of the element.
 List<Element> getChildren(String name)
          Get children by name.
 List<Element> getChildrenNS(String xmlns)
          Get children by namespace.
 Element getChildrenNS(String name, String xmlns)
          Get children by namespace.
 Element getFirstChild()
          Get the first child element of this element.
 Element getFirstChild(String name)
           
 String getName()
          Get name of this element.
 Element getNextSibling()
          Get next sibling to this element or null if no parent or no more siblings exist.
 Element getParent()
          Get parent element of this element.
 String getValue()
          Get element value.
 String getXMLNS()
          Get namespace of this element. traverses up to find actual namespace.
 int hashCode()
          
 void removeAttribute(String key)
          Remove attribute from element.
 void removeChild(Element child)
          Remove child from element.
 void setAttribute(String key, String value)
          Set value of attribute.
 void setAttributes(Map<String,String> attrs)
          Set a number of attributes.
protected  void setChildElementValue(String elemName, String value)
           
protected  void setChildElementValue(String elemName, String xmlns, String value)
           
 void setParent(Element parent)
          Set element parent.
 void setValue(String value)
          Set value of this element.
 void setXMLNS(String xmlns)
          Change the namespace of this element.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ElementWrapper

public ElementWrapper(Element element)
Method Detail

addChild

public Element addChild(Element child)
                 throws XMLException
Add child element to tree and return the added element.

Specified by:
addChild in interface Element
Parameters:
child - Child to add.
Returns:
Added child element.
Throws:
XMLException

equals

public boolean equals(Object obj)

Overrides:
equals in class Object

getAsString

public String getAsString()
                   throws XMLException
Get this element as XML string.

Specified by:
getAsString in interface Element
Returns:
The normalized XML describing this element.
Throws:
XMLException

getAttribute

public String getAttribute(String attName)
                    throws XMLException
Get attribute by name.

Specified by:
getAttribute in interface Element
Parameters:
attName - Name of attribute to fetch.
Returns:
Attribute value or null if no such element exist.
Throws:
XMLException

getAttributes

public Map<String,String> getAttributes()
                                 throws XMLException
Get all attributes as a Map.

Specified by:
getAttributes in interface Element
Returns:
Element's attributes.
Throws:
XMLException

getChildAfter

public Element getChildAfter(Element child)
                      throws XMLException
Gets the first child after specified child in children list. Only to be used internally.

Specified by:
getChildAfter in interface Element
Parameters:
child - The child to look up.
Returns:
The child after specific child.
Throws:
XMLException

getChildElementValue

protected String getChildElementValue(String elemName)
                               throws XMLException
Throws:
XMLException

getChildElementValue

protected String getChildElementValue(String elemName,
                                      String xmlns)
                               throws XMLException
Throws:
XMLException

getChildren

public List<Element> getChildren()
                          throws XMLException
Get all children of the element.

Specified by:
getChildren in interface Element
Returns:
A list containing all child elements.
Throws:
XMLException

getChildren

public List<Element> getChildren(String name)
                          throws XMLException
Get children by name.

Specified by:
getChildren in interface Element
Parameters:
name - Name of the children to get.
Returns:
A list of the Element with the given name.
Throws:
XMLException

getChildrenNS

public List<Element> getChildrenNS(String xmlns)
                            throws XMLException
Get children by namespace.

Specified by:
getChildrenNS in interface Element
Parameters:
xmlns - Namespace of the children to get.
Returns:
A list of children with the given namespace.
Throws:
XMLException

getChildrenNS

public Element getChildrenNS(String name,
                             String xmlns)
                      throws XMLException
Get children by namespace.

Specified by:
getChildrenNS in interface Element
Parameters:
name - Name of the children to get.
xmlns - Namespace of the children to get.
Returns:
A list of Elements with the given name and namespace.
Throws:
XMLException

getFirstChild

public Element getFirstChild()
                      throws XMLException
Get the first child element of this element.

Specified by:
getFirstChild in interface Element
Returns:
First child element or null if no children.
Throws:
XMLException

getFirstChild

public Element getFirstChild(String name)
                      throws XMLException
Throws:
XMLException

getName

public String getName()
               throws XMLException
Get name of this element.

Specified by:
getName in interface Element
Returns:
Name of the element.
Throws:
XMLException

getNextSibling

public Element getNextSibling()
                       throws XMLException
Get next sibling to this element or null if no parent or no more siblings exist.

Specified by:
getNextSibling in interface Element
Returns:
Next sibling element.
Throws:
XMLException

getParent

public Element getParent()
                  throws XMLException
Get parent element of this element. Or null if no parent exist.

Specified by:
getParent in interface Element
Returns:
Parent element.
Throws:
XMLException

getValue

public String getValue()
                throws XMLException
Get element value.

Specified by:
getValue in interface Element
Returns:
Concatenated string value of element or null if none.
Throws:
XMLException

getXMLNS

public String getXMLNS()
                throws XMLException
Get namespace of this element. traverses up to find actual namespace.

Specified by:
getXMLNS in interface Element
Returns:
Namespace of this element.
Throws:
XMLException

hashCode

public int hashCode()

Overrides:
hashCode in class Object

removeAttribute

public void removeAttribute(String key)
                     throws XMLException
Remove attribute from element.

Specified by:
removeAttribute in interface Element
Parameters:
key - Name of attribute to remove.
Throws:
XMLException

removeChild

public void removeChild(Element child)
                 throws XMLException
Remove child from element.

Specified by:
removeChild in interface Element
Parameters:
child - Child element to remove.
Throws:
XMLException

setAttribute

public void setAttribute(String key,
                         String value)
                  throws XMLException
Set value of attribute. Add attribute if it does not exist.

Specified by:
setAttribute in interface Element
Parameters:
key - Name of attribute to set.
value - Value of attribute to set.
Throws:
XMLException

setAttributes

public void setAttributes(Map<String,String> attrs)
                   throws XMLException
Set a number of attributes. Add the ones which does not exist.

Specified by:
setAttributes in interface Element
Parameters:
attrs - Attributes to set.
Throws:
XMLException

setChildElementValue

protected void setChildElementValue(String elemName,
                                    String value)
                             throws XMLException
Throws:
XMLException

setChildElementValue

protected void setChildElementValue(String elemName,
                                    String xmlns,
                                    String value)
                             throws XMLException
Throws:
XMLException

setParent

public void setParent(Element parent)
               throws XMLException
Set element parent. Only to be used internally.

Specified by:
setParent in interface Element
Parameters:
parent - The parent to set for this element.
Throws:
XMLException

setValue

public void setValue(String value)
              throws XMLException
Set value of this element.

Specified by:
setValue in interface Element
Parameters:
value - Value to set.
Throws:
XMLException

setXMLNS

public void setXMLNS(String xmlns)
              throws XMLException
Change the namespace of this element.

Specified by:
setXMLNS in interface Element
Parameters:
xmlns - Namespace to set.
Throws:
XMLException


Copyright © 2006-2012 Tigase. All Rights Reserved.