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
|
factoryXML_10, XML_11COMPLETE, 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, serializeAndConsumeclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitserialize, serialize, serialize, serialize, serializeAndConsume, serializeAndConsume, serializeAndConsume, serializeAndConsumeclose, serialize, serialize, serializeAndConsumegetOMFactoryprotected 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 OMFactoryfactory - The OMFactory that created this instacepublic OMDocumentImpl(OMXMLParserWrapper parserWrapper, OMFactory factory)
OMDocument with the factoryparserWrapper - factory - public OMXMLParserWrapper getBuilder()
OMContainergetBuilder in interface IParentNodegetBuilder in interface OMContainergetBuilder in class OMSerializableImplpublic OMElement getOMDocumentElement()
OMDocumentgetOMDocumentElement in interface OMDocumentnull if the document doesn't have any children
of type OMElementpublic void setOMDocumentElement(OMElement documentElement)
OMDocumentsetOMDocumentElement in interface OMDocumentdocumentElement - the new document element; must not be nullpublic int getState()
getState in interface IParentNodepublic boolean isComplete()
OMSerializableisComplete in interface IParentNodeisComplete in interface OMSerializablepublic void setComplete(boolean complete)
setComplete in interface OMContainerExsetComplete in class OMSerializableImplstate - public void discarded()
discarded in interface OMContainerExpublic void addChild(OMNode child)
OMContaineraddChild in interface OMContainerchild - the node to be added to this containerpublic void addChild(OMNode omNode, boolean fromBuilder)
addChild in interface OMContainerExpublic Iterator getChildren()
getChildren in interface OMContainerOMContainer.getFirstChildWithName(javax.xml.namespace.QName),
OMContainer.getChildrenWithName(javax.xml.namespace.QName)public Iterator getDescendants(boolean includeSelf)
OMContainergetDescendants in interface OMContainerincludeSelf - 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 OMContainerelementQName - OMExceptionpublic Iterator getChildrenWithLocalName(String localName)
OMContainergetChildrenWithLocalName in interface OMContainerOMElement items that match the given localNamepublic Iterator getChildrenWithNamespaceURI(String uri)
OMContainergetChildrenWithNamespaceURI in interface OMContainerOMElement items that match the given uripublic OMNode getFirstOMChild()
getFirstOMChild in interface OMContainerpublic OMNode getFirstOMChildIfAvailable()
IParentNodeOMSerializable.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 IParentNodenull if the container has no children or
the builder has not yet started to build the first childpublic OMNode getLastKnownOMChild()
getLastKnownOMChild in interface IContainerpublic OMElement getFirstChildWithName(QName elementQName) throws OMException
getFirstChildWithName in interface OMContainerelementQName - OMExceptionOMContainer.getChildrenWithName(QName)public void setFirstChild(OMNode firstChild)
setFirstChild in interface IContainerfirstChild - public void setLastChild(OMNode omNode)
setLastChild in interface IContaineromNode - public String getCharsetEncoding()
OMDocumentnull when it is not known, such as
when the document was created in memory or from a character stream.getCharsetEncoding in interface OMDocumentnull if the encoding is not
knownpublic void setCharsetEncoding(String charEncoding)
OMDocumentsetCharsetEncoding in interface OMDocumentpublic String isStandalone()
OMDocumentisStandalone in interface OMDocumentpublic void setStandalone(String isStandalone)
setStandalone in interface OMDocumentpublic String getXMLVersion()
OMDocumentgetXMLVersion in interface OMDocumentpublic void setXMLVersion(String xmlVersion)
OMDocumentsetXMLVersion in interface OMDocumentOMDocument.XML_10,
OMDocument.XML_11public String getXMLEncoding()
OMDocumentgetXMLEncoding in interface OMDocumentnull 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)
OMDocumentsetXMLEncoding in interface OMDocumentencoding - the value of the encoding attribute of the XML declarationpublic void internalSerialize(XMLStreamWriter writer, boolean cache) throws XMLStreamException
OMSerializableImplinternalSerialize in class OMSerializableImplXMLStreamExceptionprotected void internalSerialize(XMLStreamWriter writer, boolean cache, boolean includeXMLDeclaration) throws XMLStreamException
XMLStreamExceptionpublic void internalSerializeAndConsume(XMLStreamWriter writer) throws XMLStreamException
XMLStreamExceptionpublic void internalSerialize(XMLStreamWriter writer) throws XMLStreamException
XMLStreamExceptionpublic XMLStreamReader getXMLStreamReader()
OMContainerOMContainer.getXMLStreamReader(boolean) with cache set to
true.getXMLStreamReader in interface OMContainerXMLStreamReader representation of this elementpublic XMLStreamReader getXMLStreamReaderWithoutCaching()
OMContainerOMContainer.getXMLStreamReader(boolean) with cache set to
false.getXMLStreamReaderWithoutCaching in interface OMContainerXMLStreamReader representation of this elementpublic XMLStreamReader getXMLStreamReader(boolean cache)
OMContainerXMLStreamReader 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 OMContainercache - indicates if caching should be enabledXMLStreamReader representation of this information itempublic XMLStreamReader getXMLStreamReader(boolean cache, OMXMLStreamReaderConfiguration configuration)
OMContainerOMContainer.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 OMContainercache - 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)
OMContainerSAXSource 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 OMContainercache - 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()
OMSerializablebuild in interface OMSerializablepublic 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 OMContainerpublic OMInformationItem clone(OMCloneOptions options)
OMInformationItemclone in interface OMInformationItemoptions - 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
OMCloneOptionsprotected OMDocument createClone(OMCloneOptions options)
Copyright © 2004–2024 The Apache Software Foundation. All rights reserved.