public class ElementImpl extends ParentNode implements Element, OMElement, OMConstants
Modifier and Type | Field and Description |
---|---|
protected String |
localName |
protected OMNamespace |
namespace |
firstChild, lastChild
nextSibling, parentNode, previousSibling
builder, done, factory, FIRSTCHILD, flags, NORMALIZED, OWNED, ownerNode, READONLY, SPECIFIED
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_PRECEDING, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
CDATA_SECTION_NODE, COMMENT_NODE, DTD_NODE, ELEMENT_NODE, ENTITY_REFERENCE_NODE, PI_NODE, SPACE_NODE, TEXT_NODE
ARRAY_ITEM_LOCALNAME, ARRAY_ITEM_NS_PREFIX, ARRAY_ITEM_NSURI, ARRAY_ITEM_QNAME, DATA_HANDLER, DEFAULT_CHAR_SET_ENCODING, DEFAULT_DEFAULT_NAMESPACE, DEFAULT_XML_VERSION, IS_BINARY, IS_DATA_HANDLERS_AWARE, PULL_TYPE_BUILDER, PUSH_TYPE_BUILDER, XMLATTRTYPE_CDATA, XMLATTRTYPE_ENTITIES, XMLATTRTYPE_ENTITY, XMLATTRTYPE_ID, XMLATTRTYPE_IDREF, XMLATTRTYPE_IDREFS, XMLATTRTYPE_NMTOKEN, XMLATTRTYPE_NMTOKENS, XMLATTRTYPE_NOTATION, XMLNS_NS_PREFIX, XMLNS_NS_URI, XMLNS_PREFIX, XMLNS_URI
Constructor and Description |
---|
ElementImpl(DocumentImpl ownerDocument,
String tagName,
NamespaceImpl ns,
OMFactory factory)
Creates a new element with the namespace.
|
ElementImpl(DocumentImpl ownerDocument,
String tagName,
NamespaceImpl ns,
OMXMLParserWrapper builder,
OMFactory factory) |
ElementImpl(DocumentImpl ownerDocument,
String tagName,
OMFactory factory) |
ElementImpl(OMFactory factory) |
ElementImpl(ParentNode parentNode,
String tagName,
NamespaceImpl ns,
OMFactory factory) |
ElementImpl(ParentNode parentNode,
String tagName,
NamespaceImpl ns,
OMXMLParserWrapper builder,
OMFactory factory) |
ElementImpl(String tagName,
NamespaceImpl ns,
OMXMLParserWrapper builder,
OMFactory factory) |
Modifier and Type | Method and Description |
---|---|
OMAttribute |
addAttribute(OMAttribute attr)
Adds an attribute to this element.
|
OMAttribute |
addAttribute(String localName,
String value,
OMNamespace ns)
Adds an attribute to this element.
|
void |
buildWithAttachments()
Parses this node and builds the object structure in memory.
|
Node |
cloneNode(boolean deep) |
OMElement |
cloneOMElement()
Creates a clone which belongs to a new document.
|
OMNamespace |
declareDefaultNamespace(String uri)
We use "" to store the default namespace of this element.
|
OMNamespace |
declareNamespace(OMNamespace namespace)
Allows overriding an existing declaration if the same prefix was used.
|
OMNamespace |
declareNamespace(String uri,
String prefix)
Allows overriding an existing declaration if the same prefix was used.
|
void |
discard()
Discards a node.
|
OMNamespace |
findNamespace(String uri,
String prefix)
Finds a namespace with the given uri and prefix, in the scope of the hierarchy.
|
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()
Returns an iterator for all of the namespaces declared on this element.
|
OMAttribute |
getAttribute(QName qname)
Returns a named attribute if present.
|
String |
getAttribute(String name)
Looks in the local list of attributes and returns if found.
|
Attr |
getAttributeNode(String name)
Retrieves an attribute node by name.
|
Attr |
getAttributeNodeNS(String namespaceURI,
String localName)
Retrieves an attribute node by local name and namespace URI.
|
String |
getAttributeNS(String namespaceURI,
String localName)
Retrieves an attribute value by local name and namespace URI.
|
NamedNodeMap |
getAttributes()
Returns the set of attributes of this node and the namespace declarations available.
|
String |
getAttributeValue(QName qname)
Returns a named attribute's value, if present.
|
Iterator |
getChildElements()
Returns a filtered list of children - just the elements.
|
OMNamespace |
getDefaultNamespace()
This will retrieve the default namespace of this element, if available. null returned if none
is found.
|
NodeList |
getElementsByTagName(String name) |
NodeList |
getElementsByTagNameNS(String namespaceURI,
String localName) |
OMElement |
getFirstElement()
Returns the first Element node.
|
int |
getLineNumber() |
String |
getLocalName()
Returns the local name of this element node
|
OMNamespace |
getNamespace()
Returns the namespace of this element.
|
String |
getNamespaceURI()
Returns the value of the namespace URI.
|
String |
getNamespaceURI(String prefix)
Returns the namespace uri, given the prefix.
|
OMNode |
getNextOMSibling()
Default behavior returns null, overriden in ChildNode.
|
String |
getNodeName() |
short |
getNodeType() |
String |
getPrefix()
Returns the namespace prefix of this element node
|
QName |
getQName()
Returns the QName of this element.
|
TypeInfo |
getSchemaTypeInfo() |
String |
getTagName() |
String |
getText()
Gets all the text children and concatinates them to a single string.
|
QName |
getTextAsQName()
OMText can contain its information as a QName as well.
|
String |
getTrimmedText() |
int |
getType()
Returns the type of node.
|
boolean |
hasAttribute(String name) |
boolean |
hasAttributeNS(String namespaceURI,
String localName)
Returns whether the given attribute is available or not.
|
boolean |
hasAttributes()
Returns whether this element contains any attribute or not.
|
void |
internalSerialize(javax.xml.stream.XMLStreamWriter writer,
boolean cache)
Serializes the node.
|
void |
removeAttribute(OMAttribute attr)
Removes an attribute from the element.
|
void |
removeAttribute(String name)
Removes an attribute by name.
|
Attr |
removeAttributeNode(Attr oldAttr)
Removes the specified attribute node.
|
void |
removeAttributeNS(String namespaceURI,
String localName) |
boolean |
removeNamespace(String prefix)
Removes a declared namespace given its prefix.
|
QName |
resolveQName(String qname)
Resolves a QName literal in the namespace context defined by this element and produces a
corresponding
QName object. |
void |
setAttribute(String name,
String value) |
Attr |
setAttributeNode(Attr attr)
Adds a new attribute node.
|
Attr |
setAttributeNodeNS(Attr attr) |
void |
setAttributeNS(String namespaceURI,
String qualifiedName,
String value)
Adds a new attribute.
|
void |
setBuilder(OMXMLParserWrapper wrapper)
Sets the OM builder.
|
void |
setIdAttribute(String name,
boolean isId) |
void |
setIdAttributeNode(Attr idAttr,
boolean isId) |
void |
setIdAttributeNS(String namespaceURI,
String localName,
boolean isId) |
void |
setLineNumber(int lineNumber) |
void |
setLocalName(String localName)
Sets the local name.
|
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).
|
protected void |
setOwnerDocument(DocumentImpl document)
Sets the owner document.
|
void |
setText(QName text)
Set the content of this element to the given QName.
|
void |
setText(String text)
Creates a text node with the given value and adds it to the element.
|
void |
setType(int nodeType) |
String |
toString()
Overridden toString() for ease of debugging.
|
String |
toStringWithConsume()
This is a convenience method only.
|
addChild, buildNext, getBuilder, getChildNodes, getChildren, getChildrenWithLocalName, getChildrenWithName, getChildrenWithNamespaceURI, getFirstChild, getFirstChildWithName, getFirstOMChild, getFirstOMChildIfAvailable, getLastChild, getTextContent, getXMLStreamReader, getXMLStreamReader, getXMLStreamReaderWithoutCaching, hasChildNodes, importNode, insertBefore, removeChild, replaceChild, setFirstChild, setLastChild, setTextContent
detach, getNextOMSiblingIfAvailable, getNextSibling, getParent, getParentNode, getPreviousOMSibling, getPreviousSibling, insertSiblingAfter, insertSiblingBefore, setNextOMSibling, setParent, setPreviousOMSibling
appendChild, build, close, compareDocumentPosition, getBaseURI, getFeature, getLength, getNodeValue, getOMFactory, getOwnerDocument, getUserData, internalSerialize, internalSerializeAndConsume, isComplete, isDefaultNamespace, isEqualNode, isSameNode, isSupported, item, lookupNamespaceURI, lookupPrefix, normalize, serialize, serialize, serialize, serialize, serialize, serialize, serializeAndConsume, serializeAndConsume, serializeAndConsume, serializeAndConsume, serializeAndConsume, setComplete, setNodeValue, setPrefix, setUserData
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
appendChild, compareDocumentPosition, getBaseURI, getChildNodes, getFeature, getFirstChild, getLastChild, getNextSibling, getNodeValue, getOwnerDocument, getParentNode, getPreviousSibling, getTextContent, getUserData, hasChildNodes, insertBefore, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, normalize, removeChild, replaceChild, setNodeValue, setPrefix, setTextContent, setUserData
serialize, serialize, serialize, serialize, serializeAndConsume, serializeAndConsume, serializeAndConsume, serializeAndConsume, setFirstChild
detach, getParent, getPreviousOMSibling, insertSiblingAfter, insertSiblingBefore
addChild, buildNext, getBuilder, getChildren, getChildrenWithLocalName, getChildrenWithName, getChildrenWithNamespaceURI, getFirstChildWithName, getFirstOMChild, getXMLStreamReader, getXMLStreamReader, getXMLStreamReaderWithoutCaching
build, close, getOMFactory, isComplete, serialize, serialize, serializeAndConsume
setComplete
protected OMNamespace namespace
protected String localName
public ElementImpl(DocumentImpl ownerDocument, String tagName, OMFactory factory)
ownerDocument
- ownerDocumenttagName
- tagNamefactory
- OMFactorypublic ElementImpl(DocumentImpl ownerDocument, String tagName, NamespaceImpl ns, OMFactory factory)
ownerDocument
- tagName
- ns
- factory
- public ElementImpl(DocumentImpl ownerDocument, String tagName, NamespaceImpl ns, OMXMLParserWrapper builder, OMFactory factory)
public ElementImpl(ParentNode parentNode, String tagName, NamespaceImpl ns, OMFactory factory)
public ElementImpl(ParentNode parentNode, String tagName, NamespaceImpl ns, OMXMLParserWrapper builder, OMFactory factory)
public ElementImpl(String tagName, NamespaceImpl ns, OMXMLParserWrapper builder, OMFactory factory)
public ElementImpl(OMFactory factory)
public short getNodeType()
getNodeType
in interface Node
public String getNodeName()
getNodeName
in interface Node
public String getNamespaceURI()
getNamespaceURI
in interface OMElement
getNamespaceURI
in interface Node
getNamespaceURI
in class NodeImpl
null
if the element has no namespacepublic int getType() throws OMException
OMNode
getType
in interface OMNode
OMNode.ELEMENT_NODE
, OMNode.TEXT_NODE
, OMNode.CDATA_SECTION_NODE
,
OMNode.COMMENT_NODE
, OMNode.DTD_NODE
, OMNode.PI_NODE
, OMNode.ENTITY_REFERENCE_NODE
or OMNode.SPACE_NODE
.OMException
public void setType(int nodeType) throws OMException
setType
in interface OMNodeEx
OMException
public String getTagName()
getTagName
in interface Element
public void removeAttribute(String name) throws DOMException
removeAttribute
in interface Element
name
- The name of the attribute to removeDOMException
Element.removeAttribute(String)
public void removeAttributeNS(String namespaceURI, String localName) throws DOMException
removeAttributeNS
in interface Element
DOMException
public Attr removeAttributeNode(Attr oldAttr) throws DOMException
removeAttributeNode
in interface Element
DOMException
Element.removeAttributeNode(org.w3c.dom.Attr)
public boolean hasAttribute(String name)
hasAttribute
in interface Element
public boolean hasAttributeNS(String namespaceURI, String localName)
hasAttributeNS
in interface Element
Element.hasAttributeNS(String, String)
public String getAttribute(String name)
getAttribute
in interface Element
Element.getAttribute(String)
public Attr getAttributeNode(String name)
getAttributeNode
in interface Element
Element.getAttributeNode(String)
public String getAttributeNS(String namespaceURI, String localName)
getAttributeNS
in interface Element
Element.getAttributeNS(String, String)
public Attr getAttributeNodeNS(String namespaceURI, String localName)
getAttributeNodeNS
in interface Element
Element.getAttributeNodeNS(String, String)
public Attr setAttributeNode(Attr attr) throws DOMException
setAttributeNode
in interface Element
DOMException
Element.setAttributeNode(org.w3c.dom.Attr)
public void setAttribute(String name, String value) throws DOMException
setAttribute
in interface Element
DOMException
public Attr setAttributeNodeNS(Attr attr) throws DOMException
setAttributeNodeNS
in interface Element
DOMException
public void setAttributeNS(String namespaceURI, String qualifiedName, String value) throws DOMException
setAttributeNS
in interface Element
DOMException
Element.setAttributeNS(String, String, String)
public boolean hasAttributes()
hasAttributes
in interface Node
hasAttributes
in class NodeImpl
public NodeList getElementsByTagNameNS(String namespaceURI, String localName)
getElementsByTagNameNS
in interface Element
public NodeList getElementsByTagName(String name)
getElementsByTagName
in interface Element
public OMAttribute addAttribute(OMAttribute attr)
OMElement
If the attribute already has an owner, the attribute is cloned (i.e. its name, value and
namespace are copied to a new attribute) and the new attribute is added to the element.
Otherwise the existing instance specified by the attr
parameter is added to
the element. In both cases the owner of the added attribute is set to be the particular
OMElement
.
If there is already an attribute with the same name and namespace URI, it will be replaced
and its owner set to null
.
In the particular case where the attribute specified by attr
is already owned
by the element, calling this method has no effect.
Attributes are not stored in any particular order. In particular, there is no guarantee
that the added attribute will be returned as the last item by the iterator produced by
a subsequent call to OMElement.getAllAttributes()
.
If the attribute being added has a namespace, but no corresponding namespace declaration is in scope for the element (i.e. declared on the element or one of its ancestors), a new namespace declaration is added to the element. Note that both the namespace prefix and URI are taken into account when looking for an existing namespace declaration.
addAttribute
in interface OMElement
attr
- The attribute to add.attr
, depending on whether the attribute specified
by this parameter already has an owner or not.(org.apache.axiom.om.OMAttribute)
public OMAttribute addAttribute(String localName, String value, OMNamespace ns)
OMElement
If the element already has an attribute with the same local name and namespace URI, then this
existing attribute will be removed from the element, i.e. this method will always create a
new OMAttribute
instance and never update an existing one.
addAttribute
in interface OMElement
localName
- The local name for the attribute.value
- The string value of the attribute. 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.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.public OMNamespace declareNamespace(OMNamespace namespace)
declareNamespace
in interface OMElement
namespace
- The namespace to declare.(org.apache.axiom.om.OMNamespace)
public OMNamespace declareNamespace(String uri, String prefix)
declareNamespace
in interface OMElement
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.OMElement.declareNamespace(String, String)
public OMNamespace declareDefaultNamespace(String uri)
declareDefaultNamespace
in interface OMElement
uri
- public OMNamespace getDefaultNamespace()
OMElement
getDefaultNamespace
in interface OMElement
public OMNamespace findNamespace(String uri, String prefix)
OMElement
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.
findNamespace
in interface OMElement
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.OMElement.findNamespace(String, String)
public OMNamespace findNamespaceURI(String prefix)
OMElement
findNamespaceURI
in interface OMElement
public OMAttribute getAttribute(QName qname)
getAttribute
in interface OMElement
qname
- the qualified name to search for(javax.xml.namespace.QName)
public String getAttributeValue(QName qname)
getAttributeValue
in interface OMElement
qname
- the qualified name to search forpublic OMElement getFirstElement()
getFirstElement
in interface OMElement
OMElement.getFirstElement()
public OMNamespace getNamespace()
getNamespace
in interface OMElement
null
if the element has no namespaceOMElement.getNamespace()
public QName getQName()
getQName
in interface OMElement
QName
for the element.OMElement.getQName()
public String getText()
getText
in interface OMElement
OMElement.getText()
public QName getTextAsQName()
OMElement
getTextAsQName
in interface OMElement
public String getTrimmedText()
public void removeAttribute(OMAttribute attr)
removeAttribute
in interface OMElement
(org.apache.axiom.om.OMAttribute)
public void setBuilder(OMXMLParserWrapper wrapper)
setBuilder
in interface OMElement
(org.apache.axiom.om.OMXMLParserWrapper)
public void setLocalName(String localName)
setLocalName
in interface OMElement
OMElement.setLocalName(String)
public void setNamespace(OMNamespace namespace)
setNamespace
in interface OMElement
(org.apache.axiom.om.OMNamespace)
public void setNamespaceWithNoFindInCurrentScope(OMNamespace namespace)
OMElement
setNamespaceWithNoFindInCurrentScope
in interface OMElement
public void setText(String text)
setText
in interface OMElement
OMElement.setText(String)
public void setText(QName text)
OMElement
public void internalSerialize(javax.xml.stream.XMLStreamWriter writer, boolean cache) throws javax.xml.stream.XMLStreamException
OMNodeEx
OMSerializable.serialize(XMLStreamWriter, boolean)
instead.internalSerialize
in interface OMNodeEx
cache
- indicates if caching should be enabledjavax.xml.stream.XMLStreamException
public String toStringWithConsume() throws javax.xml.stream.XMLStreamException
OMElement
toStringWithConsume
in interface OMElement
javax.xml.stream.XMLStreamException
public String toString()
toString
in interface OMElement
toString
in class Object
Object.toString()
public Iterator getChildElements()
OMElement
getChildElements
in interface OMElement
OMContainer.getChildren()
,
OMContainer.getChildrenWithName(javax.xml.namespace.QName)
public Iterator getAllDeclaredNamespaces() throws OMException
OMElement
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.
getAllDeclaredNamespaces
in interface OMElement
OMNamespace
items declared on the current
element.OMException
OMElement.getAllDeclaredNamespaces()
public Iterator getAllAttributes()
OMElement
Note that the iterator returned by this function will be invalidated by any addAttribute call.
getAllAttributes
in interface OMElement
Iterator
of OMAttribute
items associated with the
element.OMElement.getAllAttributes()
public String getLocalName()
getLocalName
in interface OMElement
getLocalName
in interface Node
getLocalName
in class NodeImpl
Node.getLocalName()
public String getPrefix()
getPrefix
in interface Node
getPrefix
in class NodeImpl
Node.getPrefix()
protected void setOwnerDocument(DocumentImpl document)
NodeImpl
setOwnerDocument
in class NodeImpl
(org.apache.axiom.om.impl.dom.DocumentImpl)
public QName resolveQName(String qname)
OMElement
QName
object. The implementation uses the algorithm defined by the XML
Schema specification. In particular, the namespace for an unprefixed QName is the default
namespace (not the null namespace), i.e. QNames are resolved in the same way as element
names.resolveQName
in interface OMElement
qname
- the QName literal to resolveQName
object, or null
if the QName can't be resolved, i.e.
if the prefix is not bound in the namespace context of this elementpublic OMElement cloneOMElement()
cloneOMElement
in interface OMElement
OMElement.cloneOMElement()
public void setLineNumber(int lineNumber)
setLineNumber
in interface OMElement
public int getLineNumber()
getLineNumber
in interface OMElement
public Node cloneNode(boolean deep)
cloneNode
in interface Node
cloneNode
in class ParentNode
public NamedNodeMap getAttributes()
getAttributes
in interface Node
getAttributes
in class NodeImpl
ElementImpl
public String getNamespaceURI(String prefix)
prefix
- public boolean removeNamespace(String prefix)
prefix
- public OMNode getNextOMSibling() throws OMException
NodeImpl
getNextOMSibling
in interface OMNode
getNextOMSibling
in class ChildNode
OMException
public void discard() throws OMException
OMNode
discard
in interface OMNode
discard
in class ChildNode
OMException
public void setIdAttribute(String name, boolean isId) throws DOMException
setIdAttribute
in interface Element
DOMException
public void setIdAttributeNS(String namespaceURI, String localName, boolean isId) throws DOMException
setIdAttributeNS
in interface Element
DOMException
public void setIdAttributeNode(Attr idAttr, boolean isId) throws DOMException
setIdAttributeNode
in interface Element
DOMException
public TypeInfo getSchemaTypeInfo()
getSchemaTypeInfo
in interface Element
public void buildWithAttachments()
NodeImpl
buildWithAttachments
in interface OMNode
buildWithAttachments
in class NodeImpl
Copyright © 2004-2013 The Apache Software Foundation. All Rights Reserved.