public class OMDocumentImpl extends OMSerializableImpl implements OMDocument, IContainer
Modifier and Type | Field and Description |
---|---|
protected OMXMLParserWrapper |
builder |
protected String |
charSetEncoding
Field charSetEncoding Default : UTF-8
|
protected OMNode |
firstChild
Field firstChild
|
protected String |
isStandalone |
protected OMNode |
lastChild
Field lastChild
|
protected int |
state |
protected String |
xmlEncoding |
protected String |
xmlVersion
Field xmlVersion
|
factory
XML_10, XML_11
COMPLETE, DISCARDED, INCOMPLETE
Constructor and Description |
---|
OMDocumentImpl(OMFactory factory)
Create a
OMDocument given the OMFactory |
OMDocumentImpl(OMXMLParserWrapper parserWrapper,
OMFactory factory)
Create the
OMDocument with the factory |
Modifier and Type | Method and Description |
---|---|
void |
addChild(OMNode child)
Adds the given node as the last child of this container.
|
void |
addChild(OMNode omNode,
boolean fromBuilder) |
void |
build()
Builds itself.
|
OMInformationItem |
clone(OMCloneOptions options)
Clone this information item.
|
protected OMDocument |
createClone(OMCloneOptions options) |
void |
discarded() |
OMXMLParserWrapper |
getBuilder()
Returns the builder object.
|
String |
getCharsetEncoding()
Get the character set encoding scheme.
|
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.
|
Iterator |
getDescendants(boolean includeSelf)
Get an iterator over all descendants of the container.
|
OMElement |
getFirstChildWithName(QName elementQName)
Method getFirstChildWithName.
|
OMNode |
getFirstOMChild()
Method getFirstOMChild.
|
OMNode |
getFirstOMChildIfAvailable()
Get the first child if it is available.
|
OMNode |
getLastKnownOMChild() |
OMElement |
getOMDocumentElement()
Get the document element.
|
SAXSource |
getSAXSource(boolean cache)
Get a
SAXSource representation for this node. |
int |
getState() |
String |
getXMLEncoding()
Get the charset encoding of this document as specified in the XML declaration.
|
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.
|
String |
getXMLVersion()
Returns the XML version.
|
void |
internalSerialize(XMLStreamWriter writer)
Serializes the document with cache.
|
void |
internalSerialize(XMLStreamWriter writer,
boolean cache)
Serializes the node.
|
protected void |
internalSerialize(XMLStreamWriter writer,
boolean cache,
boolean includeXMLDeclaration) |
void |
internalSerializeAndConsume(XMLStreamWriter writer)
Serializes the document with the XML declaration.
|
boolean |
isComplete()
Indicates whether parser has parsed this information item completely or not.
|
String |
isStandalone()
XML standalone value.
|
void |
removeChildren()
Remove all children from this container.
|
void |
setCharsetEncoding(String charEncoding)
Sets the character set encoding scheme to be used.
|
void |
setComplete(boolean complete)
Method setComplete.
|
void |
setFirstChild(OMNode firstChild)
Method setFirstChild.
|
void |
setLastChild(OMNode omNode)
Forcefully set the last child
|
void |
setOMDocumentElement(OMElement documentElement)
Set the document element of the XML document.
|
void |
setStandalone(String isStandalone) |
void |
setXMLEncoding(String encoding)
Set the charset encoding for the XML declaration of this document.
|
void |
setXMLVersion(String xmlVersion)
Sets the XML version.
|
close, getOMFactory, serialize, serialize, serialize, serialize, serialize, serialize, serializeAndConsume, serializeAndConsume, serializeAndConsume, serializeAndConsume, serializeAndConsume
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
serialize, serialize, serialize, serialize, serializeAndConsume, serializeAndConsume, serializeAndConsume, serializeAndConsume
close, serialize, serialize, serializeAndConsume
getOMFactory
protected OMXMLParserWrapper builder
protected int state
protected OMNode firstChild
protected OMNode lastChild
protected String charSetEncoding
protected String xmlVersion
protected String xmlEncoding
protected String isStandalone
public OMDocumentImpl(OMFactory factory)
OMDocument
given the OMFactory
factory
- The OMFactory
that created this instacepublic OMDocumentImpl(OMXMLParserWrapper parserWrapper, OMFactory factory)
OMDocument
with the factoryparserWrapper
- factory
- public OMXMLParserWrapper getBuilder()
OMContainer
getBuilder
in interface IParentNode
getBuilder
in interface OMContainer
getBuilder
in class OMSerializableImpl
public OMElement getOMDocumentElement()
OMDocument
getOMDocumentElement
in interface OMDocument
null
if the document doesn't have any children
of type OMElement
public void setOMDocumentElement(OMElement documentElement)
OMDocument
setOMDocumentElement
in interface OMDocument
documentElement
- the new document element; must not be null
public int getState()
getState
in interface IParentNode
public boolean isComplete()
OMSerializable
isComplete
in interface IParentNode
isComplete
in interface OMSerializable
public void setComplete(boolean complete)
setComplete
in interface OMContainerEx
setComplete
in class OMSerializableImpl
state
- public void discarded()
discarded
in interface OMContainerEx
public void addChild(OMNode child)
OMContainer
addChild
in interface OMContainer
child
- the node to be added to this containerpublic void addChild(OMNode omNode, boolean fromBuilder)
addChild
in interface OMContainerEx
public Iterator getChildren()
getChildren
in interface OMContainer
OMContainer.getFirstChildWithName(javax.xml.namespace.QName)
,
OMContainer.getChildrenWithName(javax.xml.namespace.QName)
public Iterator getDescendants(boolean includeSelf)
OMContainer
getDescendants
in interface OMContainer
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 Iterator getChildrenWithName(QName elementQName)
getChildrenWithName
in interface OMContainer
elementQName
- OMException
public Iterator getChildrenWithLocalName(String localName)
OMContainer
getChildrenWithLocalName
in interface OMContainer
OMElement
items that match the given localNamepublic Iterator getChildrenWithNamespaceURI(String uri)
OMContainer
getChildrenWithNamespaceURI
in interface OMContainer
OMElement
items that match the given uripublic OMNode getFirstOMChild()
getFirstOMChild
in interface OMContainer
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
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
public OMElement getFirstChildWithName(QName elementQName) throws OMException
getFirstChildWithName
in interface OMContainer
elementQName
- OMException
OMContainer.getChildrenWithName(QName)
public void setFirstChild(OMNode firstChild)
setFirstChild
in interface IContainer
firstChild
- public void setLastChild(OMNode omNode)
setLastChild
in interface IContainer
omNode
- public String getCharsetEncoding()
OMDocument
null
when it is not known, such as
when the document was created in memory or from a character stream.getCharsetEncoding
in interface OMDocument
null
if the encoding is not
knownpublic void setCharsetEncoding(String charEncoding)
OMDocument
setCharsetEncoding
in interface OMDocument
public String isStandalone()
OMDocument
isStandalone
in interface OMDocument
public void setStandalone(String isStandalone)
setStandalone
in interface OMDocument
public String getXMLVersion()
OMDocument
getXMLVersion
in interface OMDocument
public void setXMLVersion(String xmlVersion)
OMDocument
setXMLVersion
in interface OMDocument
OMDocument.XML_10
,
OMDocument.XML_11
public String getXMLEncoding()
OMDocument
getXMLEncoding
in interface OMDocument
null
if the
document didn't have an XML declaration or if the encoding
attribute was
not specified in the XML declarationpublic void setXMLEncoding(String encoding)
OMDocument
setXMLEncoding
in interface OMDocument
encoding
- the value of the encoding
attribute of the XML declarationpublic void internalSerialize(XMLStreamWriter writer, boolean cache) throws XMLStreamException
OMSerializableImpl
internalSerialize
in class OMSerializableImpl
XMLStreamException
protected void internalSerialize(XMLStreamWriter writer, boolean cache, boolean includeXMLDeclaration) throws XMLStreamException
XMLStreamException
public void internalSerializeAndConsume(XMLStreamWriter writer) throws XMLStreamException
XMLStreamException
public void internalSerialize(XMLStreamWriter writer) throws XMLStreamException
XMLStreamException
public XMLStreamReader getXMLStreamReader()
OMContainer
OMContainer.getXMLStreamReader(boolean)
with cache
set to
true
.getXMLStreamReader
in interface OMContainer
XMLStreamReader
representation of this elementpublic XMLStreamReader getXMLStreamReaderWithoutCaching()
OMContainer
OMContainer.getXMLStreamReader(boolean)
with cache
set to
false
.getXMLStreamReaderWithoutCaching
in interface OMContainer
XMLStreamReader
representation of this elementpublic 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
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
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 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
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 void build()
OMSerializable
build
in interface OMSerializable
public 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
public OMInformationItem clone(OMCloneOptions options)
OMInformationItem
clone
in interface OMInformationItem
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 OMDocument createClone(OMCloneOptions options)
Copyright © 2004–2018 The Apache Software Foundation. All rights reserved.