org.apache.axis2.om.impl.llom
Class OMElementImpl

java.lang.Object
  extended byorg.apache.axis2.om.impl.llom.OMNodeImpl
      extended byorg.apache.axis2.om.impl.llom.OMElementImpl
All Implemented Interfaces:
OMConstants, OMContainer, OMContainerEx, OMElement, OMNode, OMNodeEx
Direct Known Subclasses:
RPCRequestElement, RPCResponseElement, SOAPElement, SOAPHeaderBlockImpl

public class OMElementImpl
extends OMNodeImpl
implements OMElement, OMConstants, OMContainerEx

Class OMElementImpl


Field Summary
protected  HashMap attributes
          Field attributes
protected  OMNode firstChild
          Field firstChild
protected  String localName
          Field localName
protected  HashMap namespaces
          Field namespaces
protected  int noPrefixNamespaceCounter
          Field noPrefixNamespaceCounter
protected  OMNamespace ns
          Field ns
 
Fields inherited from class org.apache.axis2.om.impl.llom.OMNodeImpl
builder, done, nextSibling, nodeType, parent, previousSibling
 
Fields inherited from interface org.apache.axis2.om.OMNode
CDATA_SECTION_NODE, COMMENT_NODE, DTD_NODE, ELEMENT_NODE, ENTITY_REFERENCE_NODE, PI_NODE, SPACE_NODE, TEXT_NODE
 
Fields inherited from interface org.apache.axis2.om.OMConstants
ARRAY_ITEM_LOCALNAME, ARRAY_ITEM_NS_PREFIX, ARRAY_ITEM_NSURI, ARRAY_ITEM_QNAME, DEFAULT_CHAR_SET_ENCODING, DEFAULT_XML_VERSION, PULL_TYPE_BUILDER, PUSH_TYPE_BUILDER, XMLNS_NS_PREFIX, XMLNS_NS_URI, XMLNS_PREFIX, XMLNS_URI
 
Constructor Summary
OMElementImpl(QName qname, OMContainer parent)
          It is assumed that the QName passed contains, at least, the localName for this element.
OMElementImpl(String localName, OMNamespace ns)
          Constructor OMElementImpl.
OMElementImpl(String localName, OMNamespace ns, OMContainer parent)
          This is the basic constructor for OMElement.
OMElementImpl(String localName, OMNamespace ns, OMContainer parent, OMXMLParserWrapper builder)
          Constructor OMElementImpl.
 
Method Summary
 OMAttribute addAttribute(OMAttribute attr)
          Inserts an attribute to this element.
 OMAttribute addAttribute(String attributeName, String value, OMNamespace ns)
          Method addAttribute.
 void addChild(OMNode child)
          Adds child to the element.
 void buildNext()
          Forces the parser to proceed, if parser has not yet finished with the XML input.
 OMElement cloneOMElement()
          Clones this element.
 OMNamespace declareNamespace(OMNamespace namespace)
          Declares a namespace with the element as its scope.
 OMNamespace declareNamespace(String uri, String prefix)
          Creates a namespace in the current element scope.
 OMNode detach()
          Removes this information item and its children, from the model completely.
 void discard()
          Method discard.
 OMNamespace findNamespace(String uri, String prefix)
          Finds a namespace with the given uri and prefix, in the scope of the document.
 OMNamespace findNamespaceURI(String prefix)
          Checks for a namespace in the context of this element with the given prefix and returns the relevant namespace object, if available.
 Iterator getAllAttributes()
          Returns a List of OMAttributes.
 Iterator getAllDeclaredNamespaces()
          Method getAllDeclaredNamespaces.
 OMAttribute getAttribute(QName qname)
          Returns a named attribute if present.
 String getAttributeValue(QName qname)
          Returns a named attribute's value, if present.
 OMXMLParserWrapper getBuilder()
          Method getBuilder.
 Iterator getChildElements()
          Returns a filtered list of children - just the elements.
 Iterator getChildren()
          Returns a collection of this element.
 Iterator getChildrenWithName(QName elementQName)
          Searches for children with a given QName and returns an iterator to traverse through the OMNodes.
 OMElement getFirstChildWithName(QName elementQName)
          Method getFirstChildWithName.
 OMElement getFirstElement()
          Gets first element.
 OMNode getFirstOMChild()
          Method getFirstOMChild.
 String getLocalName()
          Method getLocalName.
 OMNamespace getNamespace()
          Method getNamespace.
 OMNode getNextOMSibling()
          Gets the next sibling.
 QName getQName()
          Method getQName.
 String getText()
          Selects all the text children and concatinates them to a single string.
 String getTrimmedText()
          Returns the concatination string of TRIMMED values of all OMText child nodes of this element.
 int getType()
          Gets the type of node, as this is the super class of all the nodes.
 XMLStreamReader getXMLStreamReader()
          Method getXMLStreamReader.
 XMLStreamReader getXMLStreamReaderWithoutCaching()
          Method getXMLStreamReaderWithoutCaching.
 boolean isComplete()
          Method isComplete.
 void removeAttribute(OMAttribute attr)
          Method removeAttribute.
 QName resolveQName(String qname)
          Converts a prefix:local qname string into a proper QName, evaluating it in the OMElement context.
 void serialize(OMOutputImpl omOutput)
          Method serialize.
protected  void serialize(OMOutputImpl omOutput, boolean cache)
           
 void serializeAndConsume(OMOutputImpl omOutput)
          This method serializes and consumes without building the object structure in memory.
 void setBuilder(OMXMLParserWrapper wrapper)
          Method setBuilder.
 void setFirstChild(OMNode firstChild)
          Method setFirstChild.
 void setLocalName(String localName)
          Method setLocalName.
 void setNamespace(OMNamespace namespace)
          Method setNamespace.
 void setText(String text)
          Sets the text of the given element.
 String toString()
          This is a convenience method only.
 String toStringWithConsume()
          This is a convenience method only.
 
Methods inherited from class org.apache.axis2.om.impl.llom.OMNodeImpl
build, getParent, getPreviousOMSibling, insertSiblingAfter, insertSiblingBefore, serialize, serialize, serialize, serialize, serialize, serializeAndConsume, serializeAndConsume, serializeAndConsume, serializeAndConsume, serializeAndConsume, setComplete, setNextOMSibling, setParent, setPreviousOMSibling, setType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.axis2.om.OMNode
build, getParent, getPreviousOMSibling, insertSiblingAfter, insertSiblingBefore, serialize, serialize, serialize, serialize, serialize, serializeAndConsume, serializeAndConsume, serializeAndConsume, serializeAndConsume, serializeAndConsume
 
Methods inherited from interface org.apache.axis2.om.impl.OMContainerEx
setComplete
 

Field Detail

ns

protected OMNamespace ns
Field ns


localName

protected String localName
Field localName


firstChild

protected OMNode firstChild
Field firstChild


namespaces

protected HashMap namespaces
Field namespaces


attributes

protected HashMap attributes
Field attributes


noPrefixNamespaceCounter

protected int noPrefixNamespaceCounter
Field noPrefixNamespaceCounter

Constructor Detail

OMElementImpl

public OMElementImpl(String localName,
                     OMNamespace ns,
                     OMContainer parent,
                     OMXMLParserWrapper builder)
Constructor OMElementImpl.


OMElementImpl

public OMElementImpl(String localName,
                     OMNamespace ns)
Constructor OMElementImpl.


OMElementImpl

public OMElementImpl(String localName,
                     OMNamespace ns,
                     OMContainer parent)
This is the basic constructor for OMElement. All the other constructors depends on this.

Parameters:
localName - - this MUST always be not null
ns - - can be null
parent - - this should be an OMContainer

OMElementImpl

public OMElementImpl(QName qname,
                     OMContainer parent)
              throws OMException
It is assumed that the QName passed contains, at least, the localName for this element.

Parameters:
qname - - this should be valid qname according to javax.xml.namespace.QName
Throws:
OMException
Method Detail

addChild

public void addChild(OMNode child)
Adds child to the element. One can decide whether to append the child or to add to the front of the children list.

Specified by:
addChild in interface OMContainer
Parameters:
child -

getChildrenWithName

public Iterator getChildrenWithName(QName elementQName)
Searches for children with a given QName and returns an iterator to traverse through the OMNodes. This QName can contain any combination of prefix, localname and URI.

Specified by:
getChildrenWithName in interface OMContainer
Parameters:
elementQName - The QName specifying namespace and local name to match.
Returns:
Returns an iterator of OMElement items that match the given QName appropriately.
Throws:
OMException

getFirstChildWithName

public OMElement getFirstChildWithName(QName elementQName)
                                throws OMException
Method getFirstChildWithName.

Specified by:
getFirstChildWithName in interface OMContainer
Parameters:
elementQName - The QName to use for matching.
Returns:
Returns the first element in document order that matches the elementQName criteria.
Throws:
OMException
See Also:
OMContainer.getChildrenWithName(javax.xml.namespace.QName)

getNextOMSibling

public OMNode getNextOMSibling()
                        throws OMException
Gets the next sibling. This can be an OMAttribute or OMText or OMELement for others.

Specified by:
getNextOMSibling in interface OMNode
Overrides:
getNextOMSibling in class OMNodeImpl
Returns:
Returns OMNode.
Throws:
OMException

getChildren

public Iterator getChildren()
Returns a collection of this element. Children can be of types OMElement, OMText.

Specified by:
getChildren in interface OMContainer
Returns:
Returns children.
See Also:
OMContainer.getFirstChildWithName(javax.xml.namespace.QName), OMContainer.getChildrenWithName(javax.xml.namespace.QName)

getChildElements

public Iterator getChildElements()
Returns a filtered list of children - just the elements.

Specified by:
getChildElements in interface OMElement
Returns:
Returns an iterator of the child elements.
See Also:
OMContainer.getChildren(), OMContainer.getChildrenWithName(javax.xml.namespace.QName)

declareNamespace

public OMNamespace declareNamespace(String uri,
                                    String prefix)
Creates a namespace in the current element scope.

Specified by:
declareNamespace in interface OMElement
Parameters:
uri - The namespace to declare in the current scope. The caller is expected to ensure that the URI is a valid namespace name.
prefix - The prefix to associate with the given namespace. The caller is expected to ensure that this is a valid XML prefix.
Returns:
Returns namespace.
See Also:
OMElement.declareNamespace(OMNamespace), OMElement.findNamespace(String, String), OMElement.getAllDeclaredNamespaces()

declareNamespace

public OMNamespace declareNamespace(OMNamespace namespace)
Description copied from interface: OMElement
Declares a namespace with the element as its scope.

Specified by:
declareNamespace in interface OMElement
Parameters:
namespace - The namespace to declare
Returns:
Returns namespace.
See Also:
OMElement.declareNamespace(String, String), OMElement.findNamespace(String, String), OMElement.getAllDeclaredNamespaces()

findNamespace

public OMNamespace findNamespace(String uri,
                                 String prefix)
Finds a namespace with the given uri and prefix, in the scope of the document. Starts to find from the current element and goes up in the hiararchy until one is found. If none is found, returns null.

Specified by:
findNamespace in interface OMElement
Parameters:
uri - The namespace to look for. If this is specified, prefix should be null.
prefix - The prefix to look for. If this is specified, uri should be null.
Returns:
Returns the matching namespace declaration, or null if none was found.
See Also:
OMElement.declareNamespace(String, String), OMElement.declareNamespace(OMNamespace), OMElement.getAllDeclaredNamespaces()

findNamespaceURI

public OMNamespace findNamespaceURI(String prefix)
Description copied from interface: OMElement
Checks for a namespace in the context of this element with the given prefix and returns the relevant namespace object, if available. If not available, returns null.

Specified by:
findNamespaceURI in interface OMElement
Parameters:
prefix -

getAllDeclaredNamespaces

public Iterator getAllDeclaredNamespaces()
Method getAllDeclaredNamespaces.

Specified by:
getAllDeclaredNamespaces in interface OMElement
Returns:
Returns Iterator.
See Also:
OMElement.findNamespace(String, String), OMElement.declareNamespace(String, String), OMElement.declareNamespace(OMNamespace)

getAllAttributes

public Iterator getAllAttributes()
Returns a List of OMAttributes.

Specified by:
getAllAttributes in interface OMElement
Returns:
Returns iterator.
See Also:
OMElement.getAttribute(javax.xml.namespace.QName), OMElement.addAttribute(OMAttribute), OMElement.addAttribute(String, String, OMNamespace)

getAttribute

public OMAttribute getAttribute(QName qname)
Returns a named attribute if present.

Specified by:
getAttribute in interface OMElement
Parameters:
qname - the qualified name to search for
Returns:
Returns an OMAttribute with the given name if found, or null

getAttributeValue

public String getAttributeValue(QName qname)
Returns a named attribute's value, if present.

Specified by:
getAttributeValue in interface OMElement
Parameters:
qname - the qualified name to search for
Returns:
Returns a String containing the attribute value, or null.

addAttribute

public OMAttribute addAttribute(OMAttribute attr)
Inserts an attribute to this element. Implementor can decide as to insert this in the front or at the end of set of attributes.

Specified by:
addAttribute in interface OMElement
Parameters:
attr - The attribute to add.
Returns:
Returns attribute.

removeAttribute

public void removeAttribute(OMAttribute attr)
Method removeAttribute.

Specified by:
removeAttribute in interface OMElement
Parameters:
attr -

addAttribute

public OMAttribute addAttribute(String attributeName,
                                String value,
                                OMNamespace ns)
Method addAttribute.

Specified by:
addAttribute in interface OMElement
Parameters:
attributeName - The "local name" for the attribute.
value - The string value of the attribute.
ns - The namespace has to be one of the in scope namespace. i.e. the passed namespace must be declared in the parent element of this attribute or ancestors of the parent element of the attribute.
Returns:
Returns OMAttribute.

setBuilder

public void setBuilder(OMXMLParserWrapper wrapper)
Method setBuilder.

Specified by:
setBuilder in interface OMElement
Parameters:
wrapper -

getBuilder

public OMXMLParserWrapper getBuilder()
Method getBuilder.

Specified by:
getBuilder in interface OMElement
Returns:
Returns OMXMLParserWrapper.

buildNext

public void buildNext()
Forces the parser to proceed, if parser has not yet finished with the XML input.

Specified by:
buildNext in interface OMContainer

getFirstOMChild

public OMNode getFirstOMChild()
Method getFirstOMChild.

Specified by:
getFirstOMChild in interface OMContainer
Returns:
Returns child.

setFirstChild

public void setFirstChild(OMNode firstChild)
Method setFirstChild.

Specified by:
setFirstChild in interface OMElement
Parameters:
firstChild -

detach

public OMNode detach()
              throws OMException
Removes this information item and its children, from the model completely.

Specified by:
detach in interface OMNode
Overrides:
detach in class OMNodeImpl
Throws:
OMException

isComplete

public boolean isComplete()
Method isComplete.

Specified by:
isComplete in interface OMNode
Overrides:
isComplete in class OMNodeImpl
Returns:
Returns boolean.

getType

public int getType()
Gets the type of node, as this is the super class of all the nodes.

Specified by:
getType in interface OMNode
Overrides:
getType in class OMNodeImpl
Returns:
Returns the type of node as indicated by OMNodeImpl.setType(int)
See Also:
OMNodeImpl.setType(int)

getXMLStreamReader

public XMLStreamReader getXMLStreamReader()
Method getXMLStreamReader.

Specified by:
getXMLStreamReader in interface OMElement
Returns:
Returns an XMLStreamReader relative to this element.
See Also:
OMElement.getXMLStreamReader()

getXMLStreamReaderWithoutCaching

public XMLStreamReader getXMLStreamReaderWithoutCaching()
Method getXMLStreamReaderWithoutCaching.

Specified by:
getXMLStreamReaderWithoutCaching in interface OMElement
Returns:
Returns an XMLStreamReader relative to this element, with no caching.
See Also:
OMElement.getXMLStreamReaderWithoutCaching()

setText

public void setText(String text)
Sets the text of the given element. caution - This method will wipe out all the text elements (and hence any mixed content) before setting the text.

Specified by:
setText in interface OMElement
Parameters:
text -

getText

public String getText()
Selects all the text children and concatinates them to a single string.

Specified by:
getText in interface OMElement
Returns:
Returns String.

getTrimmedText

public String getTrimmedText()
Returns the concatination string of TRIMMED values of all OMText child nodes of this element. This is included purely to improve usability.


serialize

public void serialize(OMOutputImpl omOutput)
               throws XMLStreamException
Method serialize.

Specified by:
serialize in interface OMNodeEx
Overrides:
serialize in class OMNodeImpl
Parameters:
omOutput -
Throws:
XMLStreamException
See Also:
OMNodeImpl.serialize(org.apache.axis2.om.impl.OMOutputImpl)

serialize

protected void serialize(OMOutputImpl omOutput,
                         boolean cache)
                  throws XMLStreamException
Throws:
XMLStreamException

serializeAndConsume

public void serializeAndConsume(OMOutputImpl omOutput)
                         throws XMLStreamException
This method serializes and consumes without building the object structure in memory. Misuse of this method will cause loss of data. So it is advised to use populateYourSelf() method, before calling this method, if one wants to preserve data in the stream. This was requested during the second Axis2 summit.

Specified by:
serializeAndConsume in interface OMNodeEx
Overrides:
serializeAndConsume in class OMNodeImpl
Parameters:
omOutput -
Throws:
XMLStreamException
See Also:
OMNodeImpl.serializeAndConsume(org.apache.axis2.om.impl.OMOutputImpl)

getFirstElement

public OMElement getFirstElement()
Gets first element.

Specified by:
getFirstElement in interface OMElement
Returns:
Returns element.

getLocalName

public String getLocalName()
Method getLocalName.

Specified by:
getLocalName in interface OMElement
Returns:
Returns local name.

setLocalName

public void setLocalName(String localName)
Method setLocalName.

Specified by:
setLocalName in interface OMElement
Parameters:
localName -

getNamespace

public OMNamespace getNamespace()
                         throws OMException
Method getNamespace.

Specified by:
getNamespace in interface OMElement
Returns:
Returns the OMNamespace object associated with this element
Throws:
OMException

setNamespace

public void setNamespace(OMNamespace namespace)
Method setNamespace.

Specified by:
setNamespace in interface OMElement
Parameters:
namespace -

getQName

public QName getQName()
Method getQName.

Specified by:
getQName in interface OMElement
Returns:
Returns QName.

toStringWithConsume

public String toStringWithConsume()
                           throws XMLStreamException
Description copied from interface: OMElement
This is a convenience method only. This basically serializes the given OMElement to a String but will NOT build the OMTree in the memory. So you are at your own risk of losing information.

Specified by:
toStringWithConsume in interface OMElement
Throws:
XMLStreamException

toString

public String toString()
Description copied from interface: OMElement
This is a convenience method only. This will basically serialize the given OMElement to a String but will build the OMTree in the memory

Specified by:
toString in interface OMElement

discard

public void discard()
             throws OMException
Method discard.

Specified by:
discard in interface OMNode
Throws:
OMException

resolveQName

public QName resolveQName(String qname)
Converts a prefix:local qname string into a proper QName, evaluating it in the OMElement context. Unprefixed qnames resolve to the local namespace.

Specified by:
resolveQName in interface OMElement
Parameters:
qname - prefixed qname string to resolve
Returns:
Returns null for any failure to extract a qname.

cloneOMElement

public OMElement cloneOMElement()
Description copied from interface: OMElement
Clones this element. Since both elements are build compleletely, you will lose the differed building capability.

Specified by:
cloneOMElement in interface OMElement
Returns:
Returns OMElement.