public class OMSourcedElementImpl extends OMElementImpl implements OMSourcedElement
Element backed by an arbitrary data source. When necessary, this element will be expanded by creating a parser from the data source.
Whenever methods are added to the base OMElementImpl
class the corresponding methods must be added to this class (there's a unit test to verify that
this has been done, just to make sure nothing gets accidentally broken). If the method only
requires the element name and/or namespace information, the base class method can be called
directly. Otherwise, the element must be expanded into a full OM tree (by calling the forceExpand()
method) before the base class method is called. This will typically involve a
heavy overhead penalty, so should be avoided if possible.
attributes, builder, firstChild, lastChild, localName, namespaces, ns, qName, state
nextSibling, parent, previousSibling
factory
CDATA_SECTION_NODE, COMMENT_NODE, DTD_NODE, ELEMENT_NODE, ENTITY_REFERENCE_NODE, PI_NODE, SPACE_NODE, TEXT_NODE
COMPLETE, DISCARDED, INCOMPLETE
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 |
---|
OMSourcedElementImpl(OMContainer parent,
String localName,
OMNamespace ns,
OMXMLParserWrapper builder,
OMFactory factory,
boolean generateNSDecl) |
OMSourcedElementImpl(OMFactory factory,
OMDataSource source) |
OMSourcedElementImpl(QName qName,
OMFactory factory,
OMDataSource source)
Constructor that takes a QName instead of the local name and the namespace seperately
|
OMSourcedElementImpl(String localName,
OMNamespace ns,
OMContainer parent,
OMFactory factory) |
OMSourcedElementImpl(String localName,
OMNamespace ns,
OMFactory factory,
OMDataSource source)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
OMAttribute |
addAttribute(OMAttribute attr)
Inserts an attribute to this element.
|
OMAttribute |
addAttribute(String attributeName,
String value,
OMNamespace namespace)
Adds an attribute to this element.
|
void |
addChild(OMNode omNode)
Adds the given node as the last child of this container.
|
void |
addChild(OMNode omNode,
boolean fromBuilder) |
OMNamespace |
addNamespaceDeclaration(String uri,
String prefix)
Adds a namespace declaration without doing any additional checks.
|
void |
build()
Builds itself.
|
void |
buildWithAttachments()
Parses this node and builds the object structure in memory.
|
OMInformationItem |
clone(OMCloneOptions options)
Clone this information item.
|
OMElement |
cloneOMElement()
Clones this element and its descendants using default options.
|
protected OMElement |
createClone(OMCloneOptions options,
OMContainer targetParent) |
protected OMSourcedElement |
createClone(OMCloneOptions options,
OMDataSource ds) |
OMNamespace |
declareDefaultNamespace(String uri)
Add a namespace declaration for the default namespace to this element.
|
OMNamespace |
declareNamespace(OMNamespace namespace)
Declares a namespace with the element as its scope.
|
OMNamespace |
declareNamespace(String uri,
String prefix)
Add a namespace declaration for the given namespace URI to this element, optionally
generating a prefix for that namespace.
|
OMNode |
detach()
Removes this information item and its children, from the model completely.
|
void |
discard()
Method discard.
|
void |
discarded() |
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 |
getChildrenWithLocalName(String localName)
Returns an iterator for child nodes matching the local name.
|
Iterator |
getChildrenWithName(QName elementQName)
Searches for children with a given QName and returns an iterator to traverse through the
OMNodes.
|
Iterator |
getChildrenWithNamespaceURI(String uri)
Returns an iterator for child nodes matching the namespace uri.
|
OMDataSource |
getDataSource()
Provide access to the data source encapsulated in OMSourcedElement.
|
OMNamespace |
getDefaultNamespace()
Get the default namespace in scope on this element.
|
Iterator |
getDescendants(boolean includeSelf)
Get an iterator over all descendants of the container.
|
OMElement |
getFirstChildWithName(QName elementQName)
Method getFirstChildWithName.
|
OMElement |
getFirstElement()
Gets first element.
|
OMNode |
getFirstOMChild()
Method getFirstOMChild.
|
OMNode |
getFirstOMChildIfAvailable()
Get the first child if it is available.
|
OMNode |
getLastKnownOMChild() |
int |
getLineNumber() |
String |
getLocalName()
Method getLocalName.
|
OMNamespace |
getNamespace()
Get the namespace this information item is part of.
|
NamespaceContext |
getNamespaceContext(boolean detached)
Get the namespace context of this element, as determined by the namespace declarations
present on this element and its ancestors.
|
Iterator |
getNamespacesInScope()
Get an iterator that returns all namespaces in scope for this element.
|
String |
getNamespaceURI()
Get the namespace URI of this information item.
|
OMNode |
getNextOMSibling()
Returns the next sibling.
|
OMNode |
getNextOMSiblingIfAvailable()
Get the next sibling if it is available.
|
Object |
getObject(Class dataSourceClass)
Get the object that backs the data source set on this element.
|
String |
getPrefix()
Get the prefix of this information item.
|
QName |
getQName()
Method getQName.
|
SAXSource |
getSAXSource(boolean cache)
Get a
SAXSource representation for this node. |
int |
getState() |
String |
getText()
Returns the non-empty text children as a string.
|
QName |
getTextAsQName()
Resolve the content of this element to a
QName . |
Reader |
getTextAsStream(boolean cache)
Returns a stream representing the concatenation of the text nodes that are children of a
this element.
|
int |
getType()
Returns the type of node.
|
XMLStreamReader |
getXMLStreamReader()
Get a pull parser representation of this element with caching enabled.
|
XMLStreamReader |
getXMLStreamReader(boolean cache)
Get a pull parser representation of this information item.
|
XMLStreamReader |
getXMLStreamReader(boolean cache,
OMXMLStreamReaderConfiguration configuration)
Get a pull parser representation of this information item.
|
XMLStreamReader |
getXMLStreamReaderWithoutCaching()
Get a pull parser representation of this element with caching disabled.
|
void |
internalSerialize(XMLStreamWriter writer,
boolean cache)
Serializes the node.
|
boolean |
isComplete()
Indicates whether parser has parsed this information item completely or not.
|
boolean |
isExpanded()
Check if element has been expanded into tree.
|
void |
removeAttribute(OMAttribute attr)
Removes the given attribute from this element.
|
void |
removeChildren()
Remove all children from this container.
|
QName |
resolveQName(String qname)
Resolves a QName literal in the namespace context defined by this element and produces a
corresponding
QName object. |
void |
serialize(OutputStream output)
Serialize the node with caching enabled.
|
void |
serialize(OutputStream output,
OMOutputFormat format)
Serialize the node with caching enabled.
|
void |
serialize(Writer writer)
Serialize the node with caching enabled.
|
void |
serialize(Writer writer,
OMOutputFormat format)
Serialize the node with caching enabled.
|
void |
serialize(XMLStreamWriter xmlWriter)
Serializes the information item with caching.
|
void |
serializeAndConsume(OutputStream output)
Serialize the node without caching.
|
void |
serializeAndConsume(OutputStream output,
OMOutputFormat format)
Serialize the node without caching.
|
void |
serializeAndConsume(Writer writer)
Serialize the node without caching.
|
void |
serializeAndConsume(Writer writer,
OMOutputFormat format)
Serialize the node without caching.
|
void |
serializeAndConsume(XMLStreamWriter xmlWriter)
Serializes the information item without caching.
|
void |
setBuilder(OMXMLParserWrapper wrapper)
Method setBuilder.
|
void |
setComplete(boolean value)
setComplete override The OMSourcedElement has its own isolated builder/reader during the
expansion process.
|
OMDataSource |
setDataSource(OMDataSource dataSource)
setOMDataSource
|
void |
setFirstChild(OMNode node)
Method setFirstChild.
|
void |
setLastChild(OMNode omNode)
forcefully set the last element in this parent element
|
void |
setLineNumber(int lineNumber) |
void |
setLocalName(String localName)
Method setLocalName.
|
void |
setNamespace(OMNamespace namespace)
Set the namespace for this element.
|
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(QName text)
Set the content of this element to the given
QName . |
void |
setText(String text)
Set the content of this element to the given text.
|
String |
toString()
Convenience method to serialize the element to a string with caching enabled.
|
String |
toStringWithConsume()
Convenience method to serialize the element to a string without caching.
|
void |
undeclarePrefix(String prefix)
Add a namespace declaration that undeclares a given prefix.
|
void |
writeTextTo(Writer out,
boolean cache)
Write the content of the text nodes that are children of a given element to a
Writer . |
getIParentNode, getParent, getPreviousOMSibling, insertSiblingAfter, insertSiblingBefore, internalSerialize, internalSerializeAndConsume, setNextOMSibling, setParent, setPreviousOMSibling
close, getOMFactory, serialize
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getParent, getPreviousOMSibling, insertSiblingAfter, insertSiblingBefore
close, serialize
getOMFactory
getIParentNode
internalSerialize, internalSerializeAndConsume, setNextOMSibling, setParent, setPreviousOMSibling
public OMSourcedElementImpl(OMFactory factory, OMDataSource source)
public OMSourcedElementImpl(String localName, OMNamespace ns, OMFactory factory, OMDataSource source)
localName
- ns
- factory
- source
- public OMSourcedElementImpl(QName qName, OMFactory factory, OMDataSource source)
qName
- factory
- source
- public OMSourcedElementImpl(String localName, OMNamespace ns, OMContainer parent, OMFactory factory)
public OMSourcedElementImpl(OMContainer parent, String localName, OMNamespace ns, OMXMLParserWrapper builder, OMFactory factory, boolean generateNSDecl)
public boolean isExpanded()
isExpanded
in interface OMSourcedElement
true
if expanded, false
if notpublic Iterator getChildElements()
OMElementImpl
getChildElements
in interface OMElement
getChildElements
in class OMElementImpl
OMContainer.getChildren()
,
OMContainer.getChildrenWithName(javax.xml.namespace.QName)
public OMNamespace declareNamespace(String uri, String prefix)
OMElement
Note that this method can't be used to declare a default namespace. For that purpose use
OMElement.declareDefaultNamespace(String)
or OMElement.declareNamespace(OMNamespace)
.
declareNamespace
in interface OMElement
declareNamespace
in class OMElementImpl
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 null
or the empty string is
given, a prefix will be auto-generated. Please note that using the empty string
for this purpose is deprecated and will no longer be supported in Axiom 1.3.OMElement.declareNamespace(OMNamespace)
,
OMElement.findNamespace(String, String)
,
OMElement.getAllDeclaredNamespaces()
public OMNamespace declareDefaultNamespace(String uri)
OMElement
Note that this method will never change the namespace of the element itself. If an attempt is made to add a namespace declaration that conflicts with the namespace information of the element, an exception is thrown.
declareDefaultNamespace
in interface OMElement
declareDefaultNamespace
in class OMElementImpl
uri
- The default namespace to declare in the current scope. The caller is expected to
ensure that the URI is a valid namespace name.public OMNamespace getDefaultNamespace()
OMElement
getDefaultNamespace
in interface OMElement
getDefaultNamespace
in class OMElementImpl
null
if no default namespace is in scope. This
method never returns an OMNamespace
object with an empty namespace URI; if
the element or one of its ancestors has a xmlns="" declaration, then
null
is returned. Note that if the method returns an OMNamespace
object, then its prefix will obviously be the empty string.public OMNamespace declareNamespace(OMNamespace namespace)
OMElement
declareNamespace
in interface OMElement
declareNamespace
in class OMElementImpl
namespace
- The namespace to declare. If the prefix specified by the OMNamespace
object is null
, then a prefix will be generated.OMElement.declareNamespace(String, String)
,
OMElement.findNamespace(String, String)
,
OMElement.getAllDeclaredNamespaces()
public OMNamespace addNamespaceDeclaration(String uri, String prefix)
OMElementEx
In contrast to OMElement.declareNamespace(String, String)
this method can be used to
declare the default namespace.
addNamespaceDeclaration
in interface OMElementEx
addNamespaceDeclaration
in class OMElementImpl
uri
- the namespace to declare; must not be null
prefix
- the prefix to associate with the given namespace; must not be null
public void undeclarePrefix(String prefix)
OMElement
A namespace declaration with empty namespace name will be added even if no existing namespace declaration for the given prefix is in scope in the context of the current element. If a namespace declaration for the given prefix is already defined on this element, it will be replaced.
The namespace declaration created by this method will be returned by
OMElement.getAllDeclaredNamespaces()
. It is represented as an OMNamespace
object for
which OMNamespace.getNamespaceURI()
returns an empty string.
undeclarePrefix
in interface OMElement
undeclarePrefix
in class OMElementImpl
prefix
- the prefix to undeclarepublic OMNamespace findNamespace(String uri, String prefix)
OMElementImpl
findNamespace
in interface OMElement
findNamespace
in class OMElementImpl
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.declareNamespace(String, String)
,
OMElement.declareNamespace(OMNamespace)
,
OMElement.getAllDeclaredNamespaces()
public OMNamespace findNamespaceURI(String prefix)
OMElement
findNamespaceURI
in interface OMElement
findNamespaceURI
in class OMElementImpl
public Iterator getAllDeclaredNamespaces() throws OMException
OMElementImpl
getAllDeclaredNamespaces
in interface OMElement
getAllDeclaredNamespaces
in class OMElementImpl
OMException
public Iterator getNamespacesInScope() throws OMException
OMElement
OMNamespace
object with that prefix, and this object specifies
the namespace URI bound to the prefix. The iterator returns an OMNamespace
object
with an empty prefix if and only if there is a default namespace. It will never return an
OMNamespace
object with both the prefix and the namespace URI set to the empty
string, even if the element or one of its ancestors has a namespace declaration of the form
xmlns="".
The order in which the iterator returns the namespaces is undefined, and invoking the
Iterator.remove()
method on the returned iterator is not supported. The iterator may
be a "live" object, which means that results are undefined if the document is modified (in a
way that would modify the namespace context for the element) while the iterator is in use.
getNamespacesInScope
in interface OMElement
getNamespacesInScope
in class OMElementImpl
OMException
public NamespaceContext getNamespaceContext(boolean detached)
OMElement
The method supports two different NamespaceContext
implementation variants:
NamespaceContext
.
Typically, creating a live NamespaceContext
is cheaper, but the lookup performance of
a detached NamespaceContext
is better. The detached variant should always be used if
the reference to the NamespaceContext
is kept longer than the object model itself,
because in this case a live NamespaceContext
would prevent the object model from
being garbage collected.
getNamespaceContext
in interface OMElement
getNamespaceContext
in class OMElementImpl
detached
- true
if the method should return a detached implementation,
false
if the method should return a live objectpublic Iterator getAllAttributes()
OMElementImpl
getAllAttributes
in interface OMElement
getAllAttributes
in class OMElementImpl
OMElement.getAttribute(javax.xml.namespace.QName)
,
OMElement.addAttribute(OMAttribute)
,
OMElement.addAttribute(String, String, OMNamespace)
public OMAttribute getAttribute(QName qname)
OMElementImpl
getAttribute
in interface OMElement
getAttribute
in class OMElementImpl
qname
- the qualified name to search forpublic String getAttributeValue(QName qname)
OMElementImpl
getAttributeValue
in interface OMElement
getAttributeValue
in class OMElementImpl
qname
- the qualified name to search forpublic OMAttribute addAttribute(OMAttribute attr)
OMElementImpl
The owner of the attribute is set to be the particular OMElement
.
If the attribute already has an owner then 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. It's owner is then set to be the particular OMElement
.
addAttribute
in interface OMElement
addAttribute
in class OMElementImpl
attr
- The attribute to add.OMAttributeImpl.equals(Object)
public OMAttribute addAttribute(String attributeName, String value, OMNamespace namespace)
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
addAttribute
in class OMElementImpl
attributeName
- 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.namespace
- 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 void removeAttribute(OMAttribute attr)
OMElement
removeAttribute
in interface OMElement
removeAttribute
in class OMElementImpl
attr
- the attribute to removepublic void setBuilder(OMXMLParserWrapper wrapper)
OMElementImpl
setBuilder
in interface OMElement
setBuilder
in class OMElementImpl
public OMXMLParserWrapper getBuilder()
OMElementImpl
getBuilder
in interface IParentNode
getBuilder
in interface OMContainer
getBuilder
in class OMElementImpl
public void setFirstChild(OMNode node)
OMElementImpl
setFirstChild
in interface IContainer
setFirstChild
in class OMElementImpl
public void setLastChild(OMNode omNode)
IContainer
setLastChild
in interface IContainer
setLastChild
in class OMElementImpl
public OMElement getFirstElement()
OMElementImpl
getFirstElement
in interface OMElement
getFirstElement
in class OMElementImpl
public XMLStreamReader getXMLStreamReader(boolean cache)
OMContainer
XMLStreamReader
instance that produces a sequence of StAX events for this element and
its content. The sequence of events is independent of the state of this element and the value
of the cache
parameter, but the side effects of calling this method and
consuming the reader are different:
State | cache |
Side effects |
---|---|---|
The element is fully built (or was created programmatically). | true |
No side effects. The reader will synthesize StAX events from the object model. |
false |
||
The element is partially built, i.e. deferred parsing is taking place. | true |
When a StAX event is requested from the reader, it will built the information item (if necessary) and synthesize the StAX event. If the caller completely consumes the reader, the element will be completely built. Otherwise it will be partially built. |
false |
The reader will delegate to the underlying parser starting from the event corresponding to the last information item that has been built. In other words, after synthesizing a number of events, the reader will switch to delegation mode. An attempt to access the object model afterwards will result in an error. |
To free any resources associated with the returned reader, the caller MUST invoke the
XMLStreamReader.close()
method.
The returned reader MAY implement the extension defined by
DataHandlerReader
and any binary content will
be reported using this extension. More precisely, if the object model contains an
OMText
instance with OMText.isBinary()
returning true
(or
would contain such an instance after it has been fully built), then its data will always be
exposed through this extension.
The caller MUST NOT make any other assumption about the returned reader, in particular about its runtime type.
Note (non normative): For various reasons, existing code based on Axiom versions prior to 1.2.9 makes assumptions on the returned reader that should no longer be considered valid:
OMStAXWrapper
. While it is true that Axiom internally uses
this class to synthesize StAX events, it may wrap this instance in another reader
implementation. E.g. depending on the log level, the reader will be wrapped using
OMXMLStreamReaderValidator
. This was already the case in
Axiom versions prior to 1.2.9. It should also be noted that instances of
OMSourcedElement
(which extends the present interface) may return a reader that is
not implemented using OMStAXWrapper
.OMXMLStreamReader
interface of the returned reader to switch
off MTOM inlining using OMXMLStreamReader.setInlineMTOM(boolean)
. This has now been
deprecated and it is recommended to use
XOPEncodingStreamReader
instead.OMAttachmentAccessor
interface of the returned
reader to fetch attachments using OMAttachmentAccessor.getDataHandler(String)
. There
is no reason anymore to do so:OMXMLStreamReader.setInlineMTOM(boolean)
is used to disable MTOM inlining,
OMAttachmentAccessor.getDataHandler(String)
must be used to retrieve the binary
content. The fact that this method is deprecated removes the need for this.OMAttachmentAccessor.getDataHandler(String)
to retrieve the binary content. Starting
with 1.2.9 this is no longer be the case: as specified above, the sequence of events is
independent of the state of the object model and the value of the cache
parameter, and all binary content is reported through the
DataHandlerReader
extension.OMAttachmentAccessor.getDataHandler(String)
doesn't give access to the attachments in the SwA case (neither in 1.2.9 nor in previous
versions).
Code making any of these assumptions should be fixed, so that only XMLStreamReader
and DataHandlerReader
are used (and if
necessary, XOPEncodingStreamReader
).
getXMLStreamReader
in interface OMContainer
getXMLStreamReader
in class OMElementImpl
cache
- indicates if caching should be enabledXMLStreamReader
representation of this information itempublic XMLStreamReader getXMLStreamReader(boolean cache, OMXMLStreamReaderConfiguration configuration)
OMContainer
OMContainer.getXMLStreamReader(boolean)
, but accepts an OMXMLStreamReaderConfiguration
object that allows to specify additional options and to customize the behavior of the
returned reader.getXMLStreamReader
in interface OMContainer
getXMLStreamReader
in class OMElementImpl
cache
- indicates if caching should be enabledconfiguration
- additional configuration options; see the Javadoc of
OMXMLStreamReaderConfiguration
for more information about the available
optionsXMLStreamReader
representation of this information itempublic XMLStreamReader getXMLStreamReader()
OMContainer
OMContainer.getXMLStreamReader(boolean)
with cache
set to
true
.getXMLStreamReader
in interface OMContainer
getXMLStreamReader
in class OMElementImpl
XMLStreamReader
representation of this elementpublic XMLStreamReader getXMLStreamReaderWithoutCaching()
OMContainer
OMContainer.getXMLStreamReader(boolean)
with cache
set to
false
.getXMLStreamReaderWithoutCaching
in interface OMContainer
getXMLStreamReaderWithoutCaching
in class OMElementImpl
XMLStreamReader
representation of this elementpublic void setText(String text)
OMElement
OMText
after the method
returns. If the parameter is null
or an empty string, then the element will have
no children.setText
in interface OMElement
setText
in class OMElementImpl
text
- the new text content for the elementpublic void setText(QName text)
OMElement
QName
. If no matching namespace
declaration for the QName
is in scope, then this method will add one. If the
QName
specifies a namespace URI but no prefix, then a prefix will be generated. If
the element has children, then all these children are detached before the content is set. If
the parameter is not null
, then the element will have a single child of type
OMText
after the method returns. If the parameter is null
, then the
element will have no children.setText
in interface OMElement
setText
in class OMElementImpl
text
- the QName valuepublic String getText()
OMElement
This method iterates over all the text children of the element and concatenates them to a single string. Only direct children will be considered, i.e. the text is not extracted recursively. For example the return value for <element>A<child>B</child>C</element> will be AC.
All whitespace will be preserved.
getText
in interface OMElement
getText
in class OMElementImpl
public Reader getTextAsStream(boolean cache)
OMElement
new StringReader(element.getText())
The difference is that the stream implementation returned by this method is optimized for performance and is guaranteed to have constant memory usage, provided that:
OMElement
, i.e.
cache
is false
or the element is an OMSourcedElement
that
is backed by a non destructive OMDataSource
.
XMLStreamReader
in
the case of an OMSourcedElement
) is non coalescing. Note that this is not the default
in Axiom and it may be necessary to configure the parser with
StAXParserConfiguration.NON_COALESCING
.
getTextAsStream
in interface OMElement
getTextAsStream
in class OMElementImpl
cache
- whether to enable caching when accessing the elementOMElement.getText()
public QName getTextAsQName()
OMElement
QName
. The QName is interpreted in a way
that is compatible with the XML schema specification. In particular, surrounding whitespace
is ignored.getTextAsQName
in interface OMElement
getTextAsQName
in class OMElementImpl
null
if the element is empty or the QName could
not be resolvedpublic void writeTextTo(Writer out, boolean cache) throws IOException
OMElement
Writer
.
If cache
is true, this method has the same effect as the following instruction:
out.write(element.getText())
The difference is that this method is guaranteed to have constant memory usage and is
optimized for performance (with the same restrictions that apply to
OMElement.getTextAsStream(boolean)
).
The method does not call Writer.close()
.
writeTextTo
in interface OMElement
writeTextTo
in class OMElementImpl
out
- the stream to write the content tocache
- whether to enable caching when accessing the elementIOException
- if an error occurs when writing to the streamOMElement.getText()
public String getLocalName()
OMElementImpl
getLocalName
in interface OMNamedInformationItem
getLocalName
in class OMElementImpl
public void setLocalName(String localName)
OMElementImpl
setLocalName
in interface OMNamedInformationItem
setLocalName
in class OMElementImpl
localName
- the new local name of the information itempublic OMNamespace getNamespace() throws OMException
OMNamedInformationItem
getNamespace
in interface OMNamedInformationItem
getNamespace
in class OMElementImpl
null
if the information item
has no namespace. Note that this implies that the method never returns an
OMNamespace
object with both prefix and namespace URI set to the empty
string. In addition, the prefix of the returned OMNamespace
object (if any)
is never null
: if a null
prefix was specified when creating
this information item, then a prefix has been automatically assigned and the assigned
prefix is returned.OMException
public String getPrefix()
OMNamedInformationItem
Node.getPrefix()
(when called on an Element
or Attr
).getPrefix
in interface OMNamedInformationItem
getPrefix
in class OMElementImpl
null
if the information item has
no prefixpublic String getNamespaceURI()
OMNamedInformationItem
Node.getNamespaceURI()
(when called on an
Element
or Attr
).getNamespaceURI
in interface OMNamedInformationItem
getNamespaceURI
in class OMElementImpl
null
if the information
item has no namespacepublic void setNamespace(OMNamespace namespace)
OMElement
setNamespace
in interface OMElement
setNamespace
in class OMElementImpl
namespace
- The new namespace for this element, or null
to remove the namespace
from this element. If an OMNamespace
instance with a null
prefix is given, then a prefix will be generated automatically. In this case, the
generated prefix can be determined using OMNamedInformationItem.getNamespace()
.public void setNamespaceWithNoFindInCurrentScope(OMNamespace namespace)
OMElement
setNamespaceWithNoFindInCurrentScope
in interface OMElement
setNamespaceWithNoFindInCurrentScope
in class OMElementImpl
public QName getQName()
OMElementImpl
getQName
in interface OMNamedInformationItem
getQName
in class OMElementImpl
public String toStringWithConsume() throws XMLStreamException
OMElement
As for OMElement.toString()
, this method may cause high memory consumption for object model
trees containing optimized binary data and should therefore be used with care.
toStringWithConsume
in interface OMElement
toStringWithConsume
in class OMElementImpl
XMLStreamException
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
resolveQName
in class OMElementImpl
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()
OMElement
OMInformationItem.clone(OMCloneOptions)
with default options.cloneOMElement
in interface OMElement
cloneOMElement
in class OMElementImpl
public OMInformationItem clone(OMCloneOptions options)
OMInformationItem
clone
in interface OMInformationItem
clone
in class OMNodeImpl
options
- the options to use when cloning this element and its descendants; for object
models with domain specific extensions (such as SOAP), this may be a subclass of
OMCloneOptions
protected OMElement createClone(OMCloneOptions options, OMContainer targetParent)
createClone
in class OMElementImpl
protected OMSourcedElement createClone(OMCloneOptions options, OMDataSource ds)
public void setLineNumber(int lineNumber)
setLineNumber
in interface OMElement
setLineNumber
in class OMElementImpl
public int getLineNumber()
getLineNumber
in interface OMElement
getLineNumber
in class OMElementImpl
public void discard() throws OMException
OMElementImpl
discard
in interface OMNode
discard
in class OMElementImpl
OMException
public int getType()
OMNode
getType
in interface OMNode
getType
in class OMElementImpl
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
.public void internalSerialize(XMLStreamWriter writer, boolean cache) throws XMLStreamException
OMSerializableImpl
internalSerialize
in interface OMNodeEx
internalSerialize
in class OMElementImpl
cache
- indicates if caching should be enabledXMLStreamException
public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException
OMSerializable
OMSerializable.serialize(XMLStreamWriter, boolean)
with cache
set to
true
.serialize
in interface OMSerializable
serialize
in class OMSerializableImpl
XMLStreamException
public void serialize(OutputStream output) throws XMLStreamException
OMElement
This method will always serialize the infoset as plain XML. In particular, any OMText
containing optimized binary will be inlined using base64 encoding.
serialize
in interface OMContainer
serialize
in interface OMElement
serialize
in interface OMNode
serialize
in class OMSerializableImpl
output
- the byte stream to write the serialized infoset toXMLStreamException
public void serialize(Writer writer) throws XMLStreamException
OMElement
This method will always serialize the infoset as plain XML. In particular, any OMText
containing optimized binary will be inlined using base64 encoding.
serialize
in interface OMContainer
serialize
in interface OMElement
serialize
in interface OMNode
serialize
in class OMSerializableImpl
writer
- the character stream to write the serialized infoset toXMLStreamException
public void serialize(OutputStream output, OMOutputFormat format) throws XMLStreamException
OMElement
The format of the output is controlled by the provided OMOutputFormat
object. In
particular, OMOutputFormat.setDoOptimize(boolean)
can be used to instruct this method
to produce an XOP/MTOM encoded MIME message.
serialize
in interface OMContainer
serialize
in interface OMElement
serialize
in interface OMNode
serialize
in class OMSerializableImpl
output
- the byte stream to write the serialized infoset toformat
- the output format to useXMLStreamException
public void serialize(Writer writer, OMOutputFormat format) throws XMLStreamException
OMElement
serialize
in interface OMContainer
serialize
in interface OMElement
serialize
in interface OMNode
serialize
in class OMSerializableImpl
writer
- the character stream to write the serialized infoset toformat
- the output format to useXMLStreamException
public void serializeAndConsume(XMLStreamWriter xmlWriter) throws XMLStreamException
OMSerializable
OMSerializable.serialize(XMLStreamWriter, boolean)
with cache
set to
false
.serializeAndConsume
in interface OMSerializable
serializeAndConsume
in class OMSerializableImpl
XMLStreamException
public void serializeAndConsume(OutputStream output) throws XMLStreamException
OMElement
This method will always serialize the infoset as plain XML. In particular, any OMText
containing optimized binary will be inlined using base64 encoding.
serializeAndConsume
in interface OMContainer
serializeAndConsume
in interface OMElement
serializeAndConsume
in interface OMNode
serializeAndConsume
in class OMSerializableImpl
output
- the byte stream to write the serialized infoset toXMLStreamException
public void serializeAndConsume(Writer writer) throws XMLStreamException
OMElement
This method will always serialize the infoset as plain XML. In particular, any OMText
containing optimized binary will be inlined using base64 encoding.
serializeAndConsume
in interface OMContainer
serializeAndConsume
in interface OMElement
serializeAndConsume
in interface OMNode
serializeAndConsume
in class OMSerializableImpl
writer
- the character stream to write the serialized infoset toXMLStreamException
public void serializeAndConsume(OutputStream output, OMOutputFormat format) throws XMLStreamException
OMElement
The format of the output is controlled by the provided OMOutputFormat
object. In
particular, OMOutputFormat.setDoOptimize(boolean)
can be used to instruct this method
to produce an XOP/MTOM encoded MIME message.
serializeAndConsume
in interface OMContainer
serializeAndConsume
in interface OMElement
serializeAndConsume
in interface OMNode
serializeAndConsume
in class OMSerializableImpl
output
- the byte stream to write the serialized infoset toformat
- the output format to useXMLStreamException
public void serializeAndConsume(Writer writer, OMOutputFormat format) throws XMLStreamException
OMElement
serializeAndConsume
in interface OMContainer
serializeAndConsume
in interface OMElement
serializeAndConsume
in interface OMNode
serializeAndConsume
in class OMSerializableImpl
writer
- the character stream to write the serialized infoset toformat
- the output format to useXMLStreamException
public void addChild(OMNode omNode)
OMContainer
addChild
in interface OMContainer
addChild
in class OMElementImpl
omNode
- the node to be added to this containerpublic void addChild(OMNode omNode, boolean fromBuilder)
addChild
in interface OMContainerEx
addChild
in class OMElementImpl
public Iterator getChildrenWithName(QName elementQName)
OMElementImpl
getChildrenWithName
in interface OMContainer
getChildrenWithName
in class OMElementImpl
elementQName
- The QName specifying namespace and local name to match.OMElement
items that match the given QNamepublic Iterator getChildrenWithLocalName(String localName)
OMContainer
getChildrenWithLocalName
in interface OMContainer
getChildrenWithLocalName
in class OMElementImpl
OMElement
items that match the given localNamepublic Iterator getChildrenWithNamespaceURI(String uri)
OMContainer
getChildrenWithNamespaceURI
in interface OMContainer
getChildrenWithNamespaceURI
in class OMElementImpl
OMElement
items that match the given uripublic OMElement getFirstChildWithName(QName elementQName) throws OMException
OMElementImpl
getFirstChildWithName
in interface OMContainer
getFirstChildWithName
in class OMElementImpl
elementQName
- The QName to use for matching.qname
criteria, or null
if none is found.OMException
- If an error occurs during deferred parsing.OMContainer.getChildrenWithName(QName)
public Iterator getChildren()
OMElementImpl
getChildren
in interface OMContainer
getChildren
in class OMElementImpl
OMContainer.getFirstChildWithName(javax.xml.namespace.QName)
,
OMContainer.getChildrenWithName(javax.xml.namespace.QName)
public Iterator getDescendants(boolean includeSelf)
OMContainer
getDescendants
in interface OMContainer
getDescendants
in class OMElementImpl
includeSelf
- true
if the iterator should also return the container itself;
false
if the first item returned by the iterator should be the first
child of the containerpublic OMNode getFirstOMChild()
OMElementImpl
getFirstOMChild
in interface OMContainer
getFirstOMChild
in class OMElementImpl
public OMNode getFirstOMChildIfAvailable()
IParentNode
OMSerializable.isComplete()
may return false
when called on the child.
In contrast to OMContainer.getFirstOMChild()
, this method will never modify
the state of the underlying parser.getFirstOMChildIfAvailable
in interface IParentNode
getFirstOMChildIfAvailable
in class OMElementImpl
null
if the container has no children or
the builder has not yet started to build the first childpublic OMNode getLastKnownOMChild()
getLastKnownOMChild
in interface IContainer
getLastKnownOMChild
in class OMElementImpl
public OMNode detach() throws OMException
OMElementImpl
detach
in interface OMNode
detach
in class OMElementImpl
OMException
- If a node is not complete, the detach can trigger further parsing, which may
cause an exception.public OMNode getNextOMSibling() throws OMException
OMNodeImpl
getNextOMSibling
in interface OMNode
getNextOMSibling
in class OMNodeImpl
OMException
public OMNode getNextOMSiblingIfAvailable()
OMNodeEx
OMSerializable.isComplete()
may return false
when called on the sibling.
In contrast to OMNode.getNextOMSibling()
, this method will never modify
the state of the underlying parser.getNextOMSiblingIfAvailable
in interface OMNodeEx
getNextOMSiblingIfAvailable
in class OMNodeImpl
null
if the node has no next sibling or
the builder has not yet started to build the next siblingpublic int getState()
getState
in interface IParentNode
getState
in class OMElementImpl
public boolean isComplete()
OMSerializable
isComplete
in interface IParentNode
isComplete
in interface OMSerializable
isComplete
in class OMElementImpl
public String toString()
OMElement
This method produces the same result as OMContainer.serialize(Writer)
. In particular,
the element is always serialized as plain XML and OMText
nodes containing optimized
binary data are always inlined using base64 encoding. Since the output is accumulated into a
single string object, this may result in high memory consumption. Therefore this method
should be used with care.
toString
in interface OMElement
toString
in class OMElementImpl
public void buildWithAttachments()
OMNodeImpl
buildWithAttachments
in interface OMNode
buildWithAttachments
in class OMElementImpl
public void build() throws OMException
OMSerializable
build
in interface OMSerializable
build
in class OMElementImpl
OMException
public OMDataSource getDataSource()
getDataSource
in interface OMSourcedElement
public OMDataSource setDataSource(OMDataSource dataSource)
setDataSource
in interface OMSourcedElement
dataSource
- new OMDataSourcepublic void setComplete(boolean value)
setComplete
in interface OMContainerEx
setComplete
in interface OMNodeEx
setComplete
in class OMElementImpl
public void discarded()
discarded
in interface OMContainerEx
discarded
in class OMElementImpl
public SAXSource getSAXSource(boolean cache)
OMContainer
SAXSource
representation for this node. This method can be used to integrate
Axiom with APIs and third party libraries that don't support StAX. In particular it can be
used with the Transformer
API.
The returned object supports all events defined by ContentHandler
and
LexicalHandler
. DTDHandler
and DeclHandler
are not supported.
If the node is an element and has a parent which is not a document, care is taken to properly
generate ContentHandler.startPrefixMapping(String, String)
and
ContentHandler.endPrefixMapping(String)
events also for namespace mappings declared
on the ancestors of the element. To understand why this is important, consider the following
example:
<root xmlns:ns="urn:ns"><element attr="ns:someThing"/><root>
In that case, to correctly interpret the attribute value, the SAX content handler must be aware of the namespace mapping for the ns prefix, even if the serialization starts only at the child element.
getSAXSource
in interface OMContainer
getSAXSource
in class OMElementImpl
cache
- Indicates if caching should be enabled. If set to false
, the returned
SAXSource
may only be used once, and using it may have the side effect of
consuming the original content of this node.SAXSource
representation of this elementpublic Object getObject(Class dataSourceClass)
OMSourcedElement
OMDataSource
of the type specified by the
dataSourceClass
parameter (in the sense of Class.isInstance(Object)
).
OMDataSourceExt.getObject()
method returns a non null value on the configured
data source.
OMSourcedElement.isExpanded()
returns
false
), but the implementation may use additional mechanisms to detect changes
after expansion of the element.
getObject
in interface OMSourcedElement
dataSourceClass
- the expected data source class; must be assignment compatible with
OMDataSourceExt
null
if the conditions specified above are
not satisfiedpublic void removeChildren()
OMContainer
for (Iterator it = container.getChildren(); it.hasNext(); ) { it.next(); it.remove(); }However, the implementation may do this in an optimized way. In particular, if the node is incomplete, it may choose not to instantiate child node that would become unreachable anyway.
removeChildren
in interface OMContainer
removeChildren
in class OMElementImpl
Copyright © 2004–2024 The Apache Software Foundation. All rights reserved.