Package org.apache.axiom.om.impl.builder
Class StAXBuilder
java.lang.Object
org.apache.axiom.om.impl.builder.StAXBuilder
- All Implemented Interfaces:
OMXMLParserWrapper
- Direct Known Subclasses:
StAXOMBuilder
OM should be able to be built from any data source. And the model it builds may be a SOAP
specific one or just an XML model. This class will give some common functionality of OM Building
from StAX.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected booleanprotected booleanField cacheprotected Stringprotected CustomBuilderprotected Mapprotected DataHandlerReaderReference to theDataHandlerReaderextension of the parser, ornullif the parser doesn't support this extension.protected OMDocumentprotected booleanField doneprotected intElement level is the depth of the element.protected OMNodeField lastNodeprotected intprotected OMFactoryField omfactoryprotected XMLStreamReaderField parserprotected booleanField parserAccessedprotected ExceptionStores exceptions thrown by the parser. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedInit() *must* be called after creating the builder using this constructor.protectedStAXBuilder(XMLStreamReader parser) Constructor StAXBuilder.protectedStAXBuilder(OMFactory ombuilderFactory, XMLStreamReader parser) Constructor StAXBuilder.protectedStAXBuilder(OMFactory ombuilderFactory, XMLStreamReader parser, String characterEncoding) Constructor StAXBuilder. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close this builder.protected abstract OMNodeThis method is called with the XMLStreamConstants.START_ELEMENT event.protected OMNodecreateOMText(int textType) Method createOMText.voidMethod discard.intMethod getAttributeCount.getAttributeName(int arg) Method getAttributeName.getAttributeNamespace(int arg) Method getAttributeNamespace.getAttributePrefix(int arg) Method getAttributePrefix.shortReturns the type of the builder.Returns the encoding style of the XML dataprotected CustomBuildergetCustomBuilder(String namespace, String localPart) Return CustomBuilder associated with the namespace/localPartGet the document being built by this builder.getName()Method getName.Method getNamespace.intMethod getNamespaceCount.getNamespacePrefix(int index) Method getNamespacePrefix.getNamespaceUri(int index) Method getNamespaceUri.Get the underlyingXMLStreamReaderused by this builder.Method getPrefix.getReaderProperty(String name) Get the value of a feature/property from the underlying XMLStreamReader implementation without accessing the XMLStreamReader.Method getRegisteredContentHandler.getText()Method getText.voidinit(InputStream inputStream, String charSetEncoding, String url, String contentType) Deprecated.Not used anywherebooleanisCache()booleanisClosed()booleanMethod isCompleted.abstract intnext()Forwards the parser one step further, if parser is not completed yet.protected voidprocessAttributes(OMElement node) Method processAttributes.protected abstract voidMethod processNamespaceData.registerCustomBuilder(QName qName, int maxDepth, CustomBuilder customBuilder) Register a CustomBuilder associated with the indicated QName.registerCustomBuilderForPayload(CustomBuilder customBuilder) Register a CustomBuilder for a payload.voidMethod registerExternalContentHandler.voidreleaseParserOnClose(boolean value) Indicate if the parser resource should be release when closed.voidMethod reset.voidsetCache(boolean b) Method setCache.voidsetOMBuilderFactory(OMFactory ombuilderFactory) Method setOMBuilderFactory.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.axiom.om.OMXMLParserWrapper
getDocumentElement, getDocumentElement
-
Field Details
-
parser
Field parser -
omfactory
Field omfactory -
lastNode
Field lastNode -
done
protected boolean doneField done -
cache
protected boolean cacheField cache -
parserAccessed
protected boolean parserAccessedField parserAccessed -
document
-
charEncoding
-
_isClosed
protected boolean _isClosed -
_releaseParserOnClose
protected boolean _releaseParserOnClose -
customBuilderForPayload
-
customBuilders
-
maxDepthForCustomBuilders
protected int maxDepthForCustomBuilders -
dataHandlerReader
Reference to theDataHandlerReaderextension of the parser, ornullif the parser doesn't support this extension. -
elementLevel
protected int elementLevelElement level is the depth of the element. The root element (i.e. envelope) is defined as 1. -
parserException
Stores exceptions thrown by the parser. Used to avoid accessing the parser again after is has thrown a parse exception.
-
-
Constructor Details
-
StAXBuilder
Constructor StAXBuilder. This constructor is used if the parser is at the beginning (START_DOCUMENT).- Parameters:
ombuilderFactory-parser-
-
StAXBuilder
Constructor StAXBuilder. This constructor is used if the parser is not at the START_DOCUMENT.- Parameters:
ombuilderFactory-parser-characterEncoding-
-
StAXBuilder
Constructor StAXBuilder.- Parameters:
parser-
-
StAXBuilder
protected StAXBuilder()Init() *must* be called after creating the builder using this constructor.
-
-
Method Details
-
init
public void init(InputStream inputStream, String charSetEncoding, String url, String contentType) throws OMException Deprecated.Not used anywhere- Throws:
OMException
-
setOMBuilderFactory
Method setOMBuilderFactory.- Parameters:
ombuilderFactory-
-
processNamespaceData
Method processNamespaceData.- Parameters:
node-
-
processAttributes
Method processAttributes.- Parameters:
node-
-
createOMText
Method createOMText.- Returns:
- Returns OMNode.
- Throws:
OMException
-
reset
Method reset.- Parameters:
node-- Throws:
OMException
-
discard
Method discard.- Specified by:
discardin interfaceOMXMLParserWrapper- Parameters:
element-- Throws:
OMException
-
getText
Method getText.- Returns:
- Returns String.
- Throws:
OMException
-
getNamespace
Method getNamespace.- Returns:
- Returns String.
- Throws:
OMException
-
getNamespaceCount
Method getNamespaceCount.- Returns:
- Returns int.
- Throws:
OMException
-
getNamespacePrefix
Method getNamespacePrefix.- Parameters:
index-- Returns:
- Returns String.
- Throws:
OMException
-
getNamespaceUri
Method getNamespaceUri.- Parameters:
index-- Returns:
- Returns String.
- Throws:
OMException
-
setCache
public void setCache(boolean b) Method setCache.- Specified by:
setCachein interfaceOMXMLParserWrapper- Parameters:
b-
-
isCache
public boolean isCache()- Specified by:
isCachein interfaceOMXMLParserWrapper- Returns:
- true if caching
-
getName
Method getName.- Returns:
- Returns String.
- Throws:
OMException
-
getPrefix
Method getPrefix.- Returns:
- Returns String.
- Throws:
OMException
-
getAttributeCount
Method getAttributeCount.- Returns:
- Returns int.
- Throws:
OMException
-
getAttributeNamespace
Method getAttributeNamespace.- Parameters:
arg-- Returns:
- Returns String.
- Throws:
OMException
-
getAttributeName
Method getAttributeName.- Parameters:
arg-- Returns:
- Returns String.
- Throws:
OMException
-
getAttributePrefix
Method getAttributePrefix.- Parameters:
arg-- Returns:
- Returns String.
- Throws:
OMException
-
getParser
Get the underlyingXMLStreamReaderused by this builder. Note that for this type of builder, accessing the underlying parser implies that can no longer be used, and any attempt to callnext()will result in an exception.- Specified by:
getParserin interfaceOMXMLParserWrapper- Returns:
- The
XMLStreamReaderobject used by this builder. Note that the constraints described in the Javadoc of thereaderparameter of theCustomBuilder.create(String, String, OMContainer, XMLStreamReader, OMFactory)method also apply to the stream reader returned by this method, i.e.:- The caller should use
XOPUtils.getXOPEncodedStream(XMLStreamReader)to get an XOP encoded stream from the return value. - To get access to the bare StAX parser implementation, the caller should use
XMLStreamReaderUtils.getOriginalXMLStreamReader(XMLStreamReader).
- The caller should use
- Throws:
IllegalStateException- if the parser has already been accessed
-
isCompleted
public boolean isCompleted()Method isCompleted.- Specified by:
isCompletedin interfaceOMXMLParserWrapper- Returns:
- Returns boolean.
-
createOMElement
This method is called with the XMLStreamConstants.START_ELEMENT event.- Returns:
- Returns OMNode.
- Throws:
OMException
-
next
Forwards the parser one step further, if parser is not completed yet. If this is called after parser is done, then throw an OMException. If the cache is set to false, then returns the event, *without* building the OM tree. If the cache is set to true, then handles all the events within this, and builds the object structure appropriately and returns the event.- Specified by:
nextin interfaceOMXMLParserWrapper- Returns:
- Returns int.
- Throws:
OMException
-
registerCustomBuilder
Register a CustomBuilder associated with the indicated QName. The CustomBuilder will be used when an element of that qname is encountered.- Parameters:
qName-maxDepth- indicate the maximum depth that this qname will be found. (root = 0)customBuilder-- Returns:
- replaced CustomBuilder or null
-
registerCustomBuilderForPayload
Register a CustomBuilder for a payload. The payload is defined as the elements inside a SOAPBody or the document element of a REST message.- Parameters:
customBuilder-- Returns:
- replaced CustomBuilder or null
-
getCustomBuilder
Return CustomBuilder associated with the namespace/localPart- Parameters:
namespace-localPart-- Returns:
- CustomBuilder or null
-
getBuilderType
public short getBuilderType()Description copied from interface:OMXMLParserWrapperReturns the type of the builder. Can be eitherOMConstants.PUSH_TYPE_BUILDERorOMConstants.PULL_TYPE_BUILDER.- Specified by:
getBuilderTypein interfaceOMXMLParserWrapper- Returns:
- Returns short.
-
registerExternalContentHandler
Method registerExternalContentHandler.- Specified by:
registerExternalContentHandlerin interfaceOMXMLParserWrapper- Parameters:
obj-
-
getRegisteredContentHandler
Method getRegisteredContentHandler.- Specified by:
getRegisteredContentHandlerin interfaceOMXMLParserWrapper- Returns:
- Returns Object.
-
getDocument
Description copied from interface:OMXMLParserWrapperGet the document being built by this builder.- Specified by:
getDocumentin interfaceOMXMLParserWrapper- Returns:
- the
OMDocumentinstance
-
getCharsetEncoding
-
getLastNode
-
close
public void close()Description copied from interface:OMXMLParserWrapperClose this builder. This method frees the resources associated with this builder. In particular, it releases the resources held by the underlying parser. This method does not close the underlying input source.- Specified by:
closein interfaceOMXMLParserWrapper
-
getReaderProperty
Get the value of a feature/property from the underlying XMLStreamReader implementation without accessing the XMLStreamReader. https://issues.apache.org/jira/browse/WSCOMMONS-155- Parameters:
name-- Returns:
- TODO
- Throws:
IllegalArgumentException
-
getCharacterEncoding
Returns the encoding style of the XML data- Specified by:
getCharacterEncodingin interfaceOMXMLParserWrapper- Returns:
- the character encoding, defaults to "UTF-8"
-
isClosed
public boolean isClosed()- Returns:
- if parser is closed
-
releaseParserOnClose
public void releaseParserOnClose(boolean value) Indicate if the parser resource should be release when closed.- Parameters:
value- boolean
-