Package org.jibx.runtime.impl
Class StAXReaderWrapper
java.lang.Object
org.jibx.runtime.impl.StAXReaderWrapper
- All Implemented Interfaces:
IXMLReader
Wrapper for a StAX parser implementation. This delegates most calls
more or less directly, only adding the required namespace functionality
on top of the StAX API.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String
Accumulated text for return.private final String
Document name.private String
Document encoding (apparently cannot be read after parse done).private IntStack
Namespace definitions in scope at each nesting depth.private GrowableStringArray
Namespace prefixes in scope.private GrowableStringArray
Namespace URIs in scope.(package private) final boolean
Parser processing namespaces flag.private boolean
Accumulated text is processing instruction flag (otherwise content)(package private) int
Current element nesting depth.private final XMLStreamReader
Actual parser.(package private) static final byte[]
Event type code translation array.Fields inherited from interface org.jibx.runtime.IXMLReader
CDSECT, COMMENT, DOCDECL, END_DOCUMENT, END_TAG, ENTITY_REF, IGNORABLE_WHITESPACE, PROCESSING_INSTRUCTION, START_DOCUMENT, START_TAG, TEXT
-
Constructor Summary
ConstructorsConstructorDescriptionStAXReaderWrapper
(XMLStreamReader rdr, String name, boolean nsa) Constructor used by factory. -
Method Summary
Modifier and TypeMethodDescriptionBuild current parse input position description.private void
endTag()
Handle end tag.int
Get the number of attributes of the current start tag.getAttributeName
(int index) Get an attribute name from the current start tag.getAttributeNamespace
(int index) Get an attribute namespace from the current start tag.getAttributePrefix
(int index) Get an attribute prefix from the current start tag.getAttributeValue
(int index) Get an attribute value from the current start tag.getAttributeValue
(String ns, String name) Get an attribute value from the current start tag.int
Get current source column number.Get document name.int
Gets the current parse event type, without changing the current parse state.Return the input encoding, if known.int
Get current source line number.getName()
Get element name from the current start or end tag.Get element namespace from the current start or end tag.getNamespace
(String prefix) Get namespace URI associated with prefix.int
getNamespaceCount
(int depth) Get number of namespace declarations active at depth.getNamespacePrefix
(int index) Get namespace prefix.getNamespaceUri
(int index) Get namespace URI.int
Get current element nesting depth.Get element prefix from the current start or end tag.getText()
Get current text.void
init()
Initialize reader.boolean
Return namespace processing flag.int
next()
Advance to next binding component of input document.int
Advance to next parse event of input document.private void
startTag()
Handle start tag.
-
Field Details
-
s_eventTranslations
static final byte[] s_eventTranslationsEvent type code translation array. Indexed by the StAX event code, it returns the corresponding XML reader event code. -
m_parser
Actual parser. -
m_isNamespaceAware
final boolean m_isNamespaceAwareParser processing namespaces flag. -
m_docName
Document name. -
m_nestingDepth
int m_nestingDepthCurrent element nesting depth. -
m_inScopeCounts
Namespace definitions in scope at each nesting depth. -
m_inScopeUris
Namespace URIs in scope. -
m_inScopePrefixes
Namespace prefixes in scope. -
m_accumulatedText
Accumulated text for return. -
m_isProcessingInstruction
private boolean m_isProcessingInstructionAccumulated text is processing instruction flag (otherwise content) -
m_encoding
Document encoding (apparently cannot be read after parse done).
-
-
Constructor Details
-
StAXReaderWrapper
Constructor used by factory. This checks the parser state, and if positioned at a start tag it initializes the namespace information for that start tag.- Parameters:
rdr
- event readername
- document namensa
- namespace aware flag
-
-
Method Details
-
init
public void init()Initialize reader.- Specified by:
init
in interfaceIXMLReader
-
buildPositionString
Build current parse input position description.- Specified by:
buildPositionString
in interfaceIXMLReader
- Returns:
- text description of current parse position
-
startTag
private void startTag()Handle start tag. This increments the nesting count, and records all namespaces associated with the start tag. -
endTag
private void endTag()Handle end tag. This decrements the nesting count, and deletes all namespaces associated with the start tag. -
nextToken
Description copied from interface:IXMLReader
Advance to next parse event of input document.- Specified by:
nextToken
in interfaceIXMLReader
- Returns:
- parse event type code
- Throws:
JiBXException
- if error reading or parsing document
-
next
Description copied from interface:IXMLReader
Advance to next binding component of input document. This is a higher-level operation thanIXMLReader.nextToken()
, which consolidates text content and ignores parse events for components such as comments and PIs.- Specified by:
next
in interfaceIXMLReader
- Returns:
- parse event type code
- Throws:
JiBXException
- if error reading or parsing document
-
getEventType
Description copied from interface:IXMLReader
Gets the current parse event type, without changing the current parse state.- Specified by:
getEventType
in interfaceIXMLReader
- Returns:
- parse event type code
- Throws:
JiBXException
- if error parsing document
-
getName
Description copied from interface:IXMLReader
Get element name from the current start or end tag.- Specified by:
getName
in interfaceIXMLReader
- Returns:
- local name if namespace handling enabled, full name if namespace handling disabled
-
getNamespace
Description copied from interface:IXMLReader
Get element namespace from the current start or end tag.- Specified by:
getNamespace
in interfaceIXMLReader
- Returns:
- namespace URI if namespace handling enabled and element is in a namespace, empty string otherwise
-
getPrefix
Description copied from interface:IXMLReader
Get element prefix from the current start or end tag.- Specified by:
getPrefix
in interfaceIXMLReader
- Returns:
- prefix text (
null
if no prefix)
-
getAttributeCount
public int getAttributeCount()Description copied from interface:IXMLReader
Get the number of attributes of the current start tag.- Specified by:
getAttributeCount
in interfaceIXMLReader
- Returns:
- number of attributes
-
getAttributeName
Description copied from interface:IXMLReader
Get an attribute name from the current start tag.- Specified by:
getAttributeName
in interfaceIXMLReader
- Parameters:
index
- attribute index- Returns:
- local name if namespace handling enabled, full name if namespace handling disabled
-
getAttributeNamespace
Description copied from interface:IXMLReader
Get an attribute namespace from the current start tag.- Specified by:
getAttributeNamespace
in interfaceIXMLReader
- Parameters:
index
- attribute index- Returns:
- namespace URI if namespace handling enabled and attribute is in a namespace, empty string otherwise
-
getAttributePrefix
Description copied from interface:IXMLReader
Get an attribute prefix from the current start tag.- Specified by:
getAttributePrefix
in interfaceIXMLReader
- Parameters:
index
- attribute index- Returns:
- prefix for attribute (
null
if no prefix present)
-
getAttributeValue
Description copied from interface:IXMLReader
Get an attribute value from the current start tag.- Specified by:
getAttributeValue
in interfaceIXMLReader
- Parameters:
index
- attribute index- Returns:
- value text
-
getAttributeValue
Description copied from interface:IXMLReader
Get an attribute value from the current start tag.- Specified by:
getAttributeValue
in interfaceIXMLReader
- Parameters:
ns
- namespace URI for expected attribute (may benull
or the empty string for the empty namespace)name
- attribute name expected- Returns:
- attribute value text, or
null
if missing
-
getText
Description copied from interface:IXMLReader
Get current text. When positioned on a TEXT event this returns the actual text; for CDSECT it returns the text inside the CDATA section; for COMMENT, DOCDECL, or PROCESSING_INSTRUCTION it returns the text inside the structure.- Specified by:
getText
in interfaceIXMLReader
- Returns:
- text for current event
-
getNestingDepth
public int getNestingDepth()Description copied from interface:IXMLReader
Get current element nesting depth. The returned depth always includes the current start or end tag (if positioned on a start or end tag).- Specified by:
getNestingDepth
in interfaceIXMLReader
- Returns:
- element nesting depth
-
getNamespaceCount
public int getNamespaceCount(int depth) Description copied from interface:IXMLReader
Get number of namespace declarations active at depth.- Specified by:
getNamespaceCount
in interfaceIXMLReader
- Parameters:
depth
- element nesting depth- Returns:
- number of namespaces active at depth
-
getNamespaceUri
Description copied from interface:IXMLReader
Get namespace URI.- Specified by:
getNamespaceUri
in interfaceIXMLReader
- Parameters:
index
- declaration index- Returns:
- namespace URI
-
getNamespacePrefix
Description copied from interface:IXMLReader
Get namespace prefix.- Specified by:
getNamespacePrefix
in interfaceIXMLReader
- Parameters:
index
- declaration index- Returns:
- namespace prefix,
null
if a default namespace
-
getDocumentName
Description copied from interface:IXMLReader
Get document name.- Specified by:
getDocumentName
in interfaceIXMLReader
- Returns:
- document name,
null
if not known
-
getLineNumber
public int getLineNumber()Description copied from interface:IXMLReader
Get current source line number.- Specified by:
getLineNumber
in interfaceIXMLReader
- Returns:
- line number from source document,
-1
if line number information not available
-
getColumnNumber
public int getColumnNumber()Description copied from interface:IXMLReader
Get current source column number.- Specified by:
getColumnNumber
in interfaceIXMLReader
- Returns:
- column number from source document,
-1
if column number information not available
-
getNamespace
Description copied from interface:IXMLReader
Get namespace URI associated with prefix.- Specified by:
getNamespace
in interfaceIXMLReader
- Parameters:
prefix
- namespace prefix to be matched (null
for default namespace)- Returns:
- associated URI (
null
if prefix not defined)
-
getInputEncoding
Description copied from interface:IXMLReader
Return the input encoding, if known. This is only valid after parsing of a document has been started.- Specified by:
getInputEncoding
in interfaceIXMLReader
- Returns:
- input encoding (
null
if unknown)
-
isNamespaceAware
public boolean isNamespaceAware()Description copied from interface:IXMLReader
Return namespace processing flag.- Specified by:
isNamespaceAware
in interfaceIXMLReader
- Returns:
- namespace processing flag (
true
if namespaces are processed by reader,false
if not)
-