org.apache.axiom.om
Interface OMElement

All Superinterfaces:
OMContainer, OMNode
All Known Subinterfaces:
SOAPBody, SOAPEnvelope, SOAPFault, SOAPFaultCode, SOAPFaultDetail, SOAPFaultNode, SOAPFaultReason, SOAPFaultRole, SOAPFaultSubCode, SOAPFaultText, SOAPFaultValue, SOAPHeader, SOAPHeaderBlock

public interface OMElement
extends OMNode, OMContainer

A particular kind of node that represents an element infoset information item.

An element has a collection of children, attributes, and namespaces.

In contrast with DOM, this interface exposes namespaces separately from the attributes.


Field Summary
 
Fields inherited from interface org.apache.axiom.om.OMNode
CDATA_SECTION_NODE, COMMENT_NODE, DTD_NODE, ELEMENT_NODE, ENTITY_REFERENCE_NODE, PI_NODE, SPACE_NODE, TEXT_NODE
 
Method Summary
 OMAttribute addAttribute(OMAttribute attr)
          Adds an attribute to this element.
 OMAttribute addAttribute(java.lang.String attributeName, java.lang.String value, OMNamespace ns)
          Adds an attribute to the current element.
 OMElement cloneOMElement()
          Clones this element.
 OMNamespace declareDefaultNamespace(java.lang.String uri)
          This will declare a default namespace for this element explicitly
 OMNamespace declareNamespace(OMNamespace namespace)
          Declares a namespace with the element as its scope.
 OMNamespace declareNamespace(java.lang.String uri, java.lang.String prefix)
          Creates a namespace in the current element scope.
 OMNamespace findNamespace(java.lang.String uri, java.lang.String prefix)
          Finds a namespace with the given uri and prefix, in the scope of the hierarchy.
 OMNamespace findNamespaceURI(java.lang.String prefix)
          Checks for a namespace in the context of this element with the given prefix and returns the relevant namespace object, if available.
 java.util.Iterator getAllAttributes()
          Returns a list of OMAttributes.
 java.util.Iterator getAllDeclaredNamespaces()
          Returns an iterator for all of the namespaces declared on this element.
 OMAttribute getAttribute(javax.xml.namespace.QName qname)
          Returns a named attribute if present.
 java.lang.String getAttributeValue(javax.xml.namespace.QName qname)
          Returns a named attribute's value, if present.
 OMXMLParserWrapper getBuilder()
          Returns the builder object.
 java.util.Iterator getChildElements()
          Returns a filtered list of children - just the elements.
 OMNamespace getDefaultNamespace()
          This will retrieve the default namespace of this element, if available.
 OMElement getFirstElement()
          Returns the first child element of the element.
 int getLineNumber()
           
 java.lang.String getLocalName()
          Returns the local name of the element.
 OMNamespace getNamespace()
           
 javax.xml.namespace.QName getQName()
          Gets the QName of this node.
 java.lang.String getText()
          Returns the non-empty text children as a String.
 javax.xml.namespace.QName getTextAsQName()
          OMText can contain its information as a QName as well.
 javax.xml.stream.XMLStreamReader getXMLStreamReader()
          Returns the pull parser that will generate the pull events relevant to THIS element.
 javax.xml.stream.XMLStreamReader getXMLStreamReaderWithoutCaching()
          Returns the pull parser that will generate the pull events relevant to THIS element.
 void removeAttribute(OMAttribute attr)
          Method removeAttribute
 javax.xml.namespace.QName resolveQName(java.lang.String qname)
          Turns a prefix:local qname string into a proper QName, evaluating it in the OMElement context.
 void setBuilder(OMXMLParserWrapper wrapper)
          Method setBuilder.
 void setFirstChild(OMNode node)
          Deprecated. This method should not be called, un-intentionally. When some one randomly set the first child, all the links handling will not happen inside this method. So we have moved this method to the less visible interface, OMContainerEx.
 void setLineNumber(int lineNumber)
           
 void setLocalName(java.lang.String localName)
          Method setLocalName
 void setNamespace(OMNamespace namespace)
          Sets the Namespace.
 void setNamespaceWithNoFindInCurrentScope(OMNamespace namespace)
          This will not search the namespace in the scope nor will declare in the current element, as in setNamespace(OMNamespace).
 void setText(javax.xml.namespace.QName text)
           
 void setText(java.lang.String text)
           
 java.lang.String toString()
          This is a convenience method only.
 java.lang.String toStringWithConsume()
          This is a convenience method only.
 
Methods inherited from interface org.apache.axiom.om.OMNode
build, buildWithAttachments, detach, discard, getNextOMSibling, getOMFactory, getParent, getPreviousOMSibling, getType, insertSiblingAfter, insertSiblingBefore, isComplete, serialize, serialize, serialize, serialize, serialize, serializeAndConsume, serializeAndConsume, serializeAndConsume, serializeAndConsume, serializeAndConsume
 
Methods inherited from interface org.apache.axiom.om.OMContainer
addChild, buildNext, getChildren, getChildrenWithName, getFirstChildWithName, getFirstOMChild, isComplete
 

Method Detail

getChildElements

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

Returns:
Returns an iterator over the child elements.
See Also:
OMContainer.getChildren(), OMContainer.getChildrenWithName(javax.xml.namespace.QName)

declareNamespace

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

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. If "" is given, first this will check for an existing namespace with the same uri. If not found, a prefix will be auto-generated.
Returns:
Returns the created namespace information item.
See Also:
declareNamespace(OMNamespace), findNamespace(String, String), getAllDeclaredNamespaces()

declareDefaultNamespace

public OMNamespace declareDefaultNamespace(java.lang.String uri)
This will declare a default namespace for this element explicitly

Parameters:
uri -

getDefaultNamespace

public OMNamespace getDefaultNamespace()
This will retrieve the default namespace of this element, if available. null returned if none is found.


declareNamespace

public OMNamespace declareNamespace(OMNamespace namespace)
Declares a namespace with the element as its scope.

Parameters:
namespace - The namespace to declare.
Returns:
Returns the namespace parameter passed.
See Also:
declareNamespace(String, String), findNamespace(String, String), getAllDeclaredNamespaces()

findNamespace

public OMNamespace findNamespace(java.lang.String uri,
                                 java.lang.String prefix)
Finds a namespace with the given uri and prefix, in the scope of the hierarchy.

Searches from the current element and goes up the hiararchy until a match is found. If no match is found, returns null.

Either prefix or uri should be null. Results are undefined if both are specified.

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:
declareNamespace(String, String), declareNamespace(OMNamespace), getAllDeclaredNamespaces()

findNamespaceURI

public OMNamespace findNamespaceURI(java.lang.String prefix)
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.

Parameters:
prefix -

getAllDeclaredNamespaces

public java.util.Iterator getAllDeclaredNamespaces()
                                            throws OMException
Returns an iterator for all of the namespaces declared on this element.

If you're interested in all namespaces in scope, you need to call this function for all parent elements as well. Note that the iterator may be invalidated by any call to either declareNamespace function.

Returns:
Returns an iterator over the OMNamespace items declared on the current element.
Throws:
OMException
See Also:
findNamespace(String, String), declareNamespace(String, String), declareNamespace(OMNamespace)

getAllAttributes

public java.util.Iterator getAllAttributes()
Returns a list of OMAttributes.

Note that the iterator returned by this function will be invalidated by any addAttribute call.

Returns:
Returns an Iterator of OMAttribute items associated with the element.
See Also:
getAttribute(javax.xml.namespace.QName), addAttribute(OMAttribute), addAttribute(String, String, OMNamespace)

getAttribute

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

Parameters:
qname - the qualified name to search for
Returns:
Returns an OMAttribute with the given name if found, or null

getAttributeValue

public java.lang.String getAttributeValue(javax.xml.namespace.QName qname)
Returns a named attribute's value, if present.

Parameters:
qname - the qualified name to search for
Returns:
Returns a String containing the attribute value, or null

addAttribute

public OMAttribute addAttribute(OMAttribute attr)
Adds an attribute to this element.

There is no order implied by added attributes.

Parameters:
attr - The attribute to add.
Returns:
Returns the passed in attribute.

addAttribute

public OMAttribute addAttribute(java.lang.String attributeName,
                                java.lang.String value,
                                OMNamespace ns)
Adds an attribute to the current element.

This function does not check to make sure that the given attribute value can be serialized directly as an XML value. The caller may, for example, pass a string with the character 0x01.

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 the added attribute.

removeAttribute

public void removeAttribute(OMAttribute attr)
Method removeAttribute

Parameters:
attr -

setBuilder

public void setBuilder(OMXMLParserWrapper wrapper)
Method setBuilder.

Parameters:
wrapper -

getBuilder

public OMXMLParserWrapper getBuilder()
Returns the builder object.

Returns:
Returns the builder object used to construct the underlying XML infoset on the fly.

setFirstChild

public void setFirstChild(OMNode node)
Deprecated. This method should not be called, un-intentionally. When some one randomly set the first child, all the links handling will not happen inside this method. So we have moved this method to the less visible interface, OMContainerEx.

Sets the first child.

Parameters:
node -

getFirstElement

public OMElement getFirstElement()
Returns the first child element of the element.

Returns:
Returns the first child element of the element, or null if none was found.

getXMLStreamReader

public javax.xml.stream.XMLStreamReader getXMLStreamReader()
Returns the pull parser that will generate the pull events relevant to THIS element.

Caching is on.

Returns:
Returns an XMLStreamReader relative to this element.

getXMLStreamReaderWithoutCaching

public javax.xml.stream.XMLStreamReader getXMLStreamReaderWithoutCaching()
Returns the pull parser that will generate the pull events relevant to THIS element.

Caching is off.

Returns:
Returns an XMLStreamReader relative to this element, with no caching.

setText

public void setText(java.lang.String text)
Parameters:
text -

setText

public void setText(javax.xml.namespace.QName text)

getText

public java.lang.String getText()
Returns the non-empty text children as a String.

Returns:
Returns a String representing the concatenation of the child text nodes.

getTextAsQName

public javax.xml.namespace.QName getTextAsQName()
OMText can contain its information as a QName as well. This will return the text as a QName


getLocalName

public java.lang.String getLocalName()
Returns the local name of the element.

Returns:
Returns the local name of the element.

setLocalName

public void setLocalName(java.lang.String localName)
Method setLocalName

Parameters:
localName -

getNamespace

public OMNamespace getNamespace()
                         throws OMException
Returns:
Returns the OMNamespace object associated with this element
Throws:
OMException

setNamespace

public void setNamespace(OMNamespace namespace)
Sets the Namespace. This will first search for a namespace in the current scope with the given namespace. If no namespace is found with the given details, then it will declare a new one. Then that namespace will be assigned to this element.

Parameters:
namespace -

setNamespaceWithNoFindInCurrentScope

public void setNamespaceWithNoFindInCurrentScope(OMNamespace namespace)
This will not search the namespace in the scope nor will declare in the current element, as in setNamespace(OMNamespace). This will just assign the given namespace to the element.

Parameters:
namespace -

getQName

public javax.xml.namespace.QName getQName()
Gets the QName of this node.

Returns:
Returns the QName for the element.

toString

public java.lang.String toString()
This is a convenience method only. This will basically serialize the given OMElement to a String but will build the OMTree in the memory


toStringWithConsume

public java.lang.String toStringWithConsume()
                                     throws javax.xml.stream.XMLStreamException
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.

Throws:
javax.xml.stream.XMLStreamException

resolveQName

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

Parameters:
qname - prefixed qname string to resolve
Returns:
Returns null for any failure to extract a qname.

cloneOMElement

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

Returns:
Returns OMElement.

setLineNumber

public void setLineNumber(int lineNumber)

getLineNumber

public int getLineNumber()


Copyright © 2004-2007 Apache Software Foundation. All Rights Reserved.