Package org.jibx.v2
Interface XmlReader
public interface XmlReader
XML reader interface used for input to the unmarshalling code. This interface allows easy substitution of different
parsers or other input sources.
- Author:
- Dennis M. Sosnoski
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
-
Method Summary
Modifier and TypeMethodDescriptionBuild current parse input position description.boolean
checkStartTag
(String name) Advance to a start or end tag, and check if it is the named start tag in the implicit namespace.boolean
checkStartTag
(String ns, String name) Advance to a start or end tag, and verify it is the named start tag.byte[]
Convert abyte[]
value from the current source selection using base64Binary encoding.Convert aBigDecimal
value from the current source selection.Convert aBigInteger
value from the current source selection.Convert aBoolean
value from the current source selection.long
Convert aboolean
value from the current source selection.Convert aDate
value from the current source selection.Convert aFloat
value from the current source selection.long
Convert afloat
value from the current source selection.Convert anInteger
value from the current source selection.int
Convert anint
value from the current source selection.Convert aLong
value from the current source selection.long
Convert along
value from the current source selection.Convert aString
value from the current source selection.createElementInstance
(String root, XmlReader rdr, Object inst) Creat instance of class for element name.createTypeInstance
(String dflt, XmlReader rdr, Object inst) Validate instance of class for type name.getAttributeCollapsed
(int index) Read a required text attribute value from the current start tag with whitespace collapsed.int
Get the number of attributes of the current start tag.int
getAttributeIndex
(String name) Get the index of a no-namespace attribute from the current start tag.int
getAttributeIndex
(String ns, String name) Get the index of an attribute from 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.getAttributeText
(int index) Get a required text attribute value from the current start tag.Get the unmarshalling context associated with this reader.int
Get current source column number.Get document name.Get current element text.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.Read an optional text attribute value from the current start tag.getOptionalAttributeText
(String ns, String name) Read an optional text attribute value from the current start tag.Get element prefix from the current start or end tag.Read a required text attribute value from the current start tag.getRequiredAttributeText
(String ns, String name) Read a required text attribute value from the current start tag.getText()
Get current text.Get the current validation context for this 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.void
Push a validation context on this reader.readText()
Read current element text.void
Advance to the next start or end tag, and verify it is the close tag for the current open element.boolean
requireStartTag
(String name) Advance to a start or end tag, and verify it is the named start tag in the implicit namespace.boolean
requireStartTag
(String ns, String name) Advance to a start or end tag, and verify it is the named start tag.void
selectAttribute
(int index) Select an attribute value from the current start tag as text for conversion.boolean
Select an optional no-namespace attribute value from the current start tag as text for conversion.boolean
selectOptionalAttribute
(String ns, String name) Select an optional attribute value from the current start tag as text for conversion.void
Select a required no-namespace attribute value from the current start tag as text for conversion.void
selectRequiredAttribute
(String ns, String name) Select a required attribute value from the current start tag as text for conversion.void
Select the current text content for conversion.Set the implicit namespace used for elements unless otherwise specified.
-
Field Details
-
START_DOCUMENT
static final int START_DOCUMENT- See Also:
-
END_DOCUMENT
static final int END_DOCUMENT- See Also:
-
START_TAG
static final int START_TAG- See Also:
-
END_TAG
static final int END_TAG- See Also:
-
TEXT
static final int TEXT- See Also:
-
CDSECT
static final int CDSECT- See Also:
-
ENTITY_REF
static final int ENTITY_REF- See Also:
-
IGNORABLE_WHITESPACE
static final int IGNORABLE_WHITESPACE- See Also:
-
PROCESSING_INSTRUCTION
static final int PROCESSING_INSTRUCTION- See Also:
-
COMMENT
static final int COMMENT- See Also:
-
DOCDECL
static final int DOCDECL- See Also:
-
-
Method Details
-
getValidationContext
ValidationContext getValidationContext()Get the current validation context for this reader. The validation context is used both for tracking problems, and to determine the appropriate handling when a problem occurs.- Returns:
- context
-
pushValidationContext
Push a validation context on this reader. The supplied validation context is popped after processing the end tag for the current element.- Parameters:
vctx
- context
-
getBindingContext
UnmarshallingContext getBindingContext()Get the unmarshalling context associated with this reader. The unmarshalling context tracks higher-level information about the conversion of XML into a Java object structure.- Returns:
- context
-
buildPositionString
String buildPositionString()Build current parse input position description.- Returns:
- text description of current parse position
-
nextToken
Advance to next parse event of input document.- Returns:
- parse event type code
- Throws:
JiBXException
- if error reading or parsing document
-
next
Advance to next binding component of input document. This is a higher-level operation thannextToken()
, which consolidates text content and ignores parse events for components such as comments and PIs.- Returns:
- parse event type code
- Throws:
JiBXException
- if error reading or parsing document
-
getEventType
Gets the current parse event type, without changing the current parse state.- Returns:
- parse event type code
- Throws:
JiBXException
- if error parsing document
-
getName
String getName()Get element name from the current start or end tag.- Returns:
- local name if namespace handling enabled, full name if namespace handling disabled
- Throws:
IllegalStateException
- if not at a start or end tag (optional)
-
getNamespace
String getNamespace()Get element namespace from the current start or end tag.- Returns:
- namespace URI if namespace handling enabled and element is in a namespace, empty string otherwise
- Throws:
IllegalStateException
- if not at a start or end tag (optional)
-
getPrefix
String getPrefix()Get element prefix from the current start or end tag.- Returns:
- prefix text (
null
if no prefix) - Throws:
IllegalStateException
- if not at a start or end tag
-
setImplicitNamespace
Set the implicit namespace used for elements unless otherwise specified.- Parameters:
ns
- namespace URI for element (may be the empty string for the no-namespace namespace)- Returns:
- prior implicit namespace
-
requireStartTag
Advance to a start or end tag, and verify it is the named start tag in the implicit namespace.- Parameters:
name
- element name- Returns:
true
if tag found,false
if not (recoverable error case)- Throws:
JiBXException
- on unrecoverable error
-
requireStartTag
Advance to a start or end tag, and verify it is the named start tag.- Parameters:
ns
- namespace URI for element (may be the empty string for the no-namespace namespace)name
- element name- Returns:
true
if tag found,false
if not (exception not thrown)- Throws:
JiBXException
- on unrecoverable error
-
checkStartTag
Advance to a start or end tag, and check if it is the named start tag in the implicit namespace.- Parameters:
name
- element name- Returns:
true
if match,false
if not- Throws:
JiBXException
- on unrecoverable error
-
checkStartTag
Advance to a start or end tag, and verify it is the named start tag.- Parameters:
ns
- namespace URI for element (may be the empty string for the no-namespace namespace)name
- element name- Returns:
true
if match,false
if not- Throws:
JiBXException
- on unrecoverable error
-
requireEndTag
Advance to the next start or end tag, and verify it is the close tag for the current open element.- Throws:
JiBXException
- on unrecoverable error
-
getElementText
Get current element text. This is only valid with an open start tag, and reads past the text content of the element, leaving the reader positioned on the next element start or end tag following the text.- Returns:
- text for current element (may be
null
, in the case of a recoverable error) - Throws:
IllegalStateException
- if not at a start tagJiBXException
- on unrecoverable error
-
getText
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.- Returns:
- text for current event (may be
null
, in the case of a recoverable error) - Throws:
JiBXException
- on unrecoverable error
-
getAttributeCount
int getAttributeCount()Get the number of attributes of the current start tag.- Returns:
- number of attributes
- Throws:
IllegalStateException
- if not at a start tag (optional)
-
getAttributeName
Get an attribute name from the current start tag.- Parameters:
index
- attribute index- Returns:
- local name if namespace handling enabled, full name if namespace handling disabled
- Throws:
IllegalStateException
- if not at a start tag or invalid index
-
getAttributeNamespace
Get an attribute namespace from the current start tag.- Parameters:
index
- attribute index- Returns:
- namespace URI if namespace handling enabled and attribute is in a namespace, empty string otherwise
- Throws:
IllegalStateException
- if not at a start tag or invalid index
-
getAttributePrefix
Get an attribute prefix from the current start tag.- Parameters:
index
- attribute index- Returns:
- prefix for attribute (
null
if no prefix present) - Throws:
IllegalStateException
- if not at a start tag or invalid index
-
getAttributeIndex
Get the index of a no-namespace attribute from the current start tag.- Parameters:
name
- attribute name- Returns:
- attribute index (
-1
if not found) - Throws:
IllegalStateException
- if not at a start tag
-
getAttributeIndex
Get the index of an attribute from the current start tag.- Parameters:
ns
- namespace URI for attribute (may be the empty string for the no-namespace namespace)name
- attribute name- Returns:
- attribute index (
-1
if not found) - Throws:
IllegalStateException
- if not at a start tag
-
getAttributeText
Get a required text attribute value from the current start tag.- Parameters:
index
- attribute index (error if negative)- Returns:
- value text (may be
null
, in the case of a recoverable error) - Throws:
IllegalStateException
- if not at a start tag or invalid indexJiBXException
- on unrecoverable error
-
getAttributeCollapsed
Read a required text attribute value from the current start tag with whitespace collapsed.- Parameters:
index
- attribute index (error if negative)- Returns:
- value text (may be
null
, in the case of a recoverable error) - Throws:
IllegalStateException
- if not at a start tag or invalid indexJiBXException
- on unrecoverable error
-
getOptionalAttributeText
Read an optional text attribute value from the current start tag.- Parameters:
name
- attribute name- Returns:
- value text,
null
if attribute not present - Throws:
IllegalStateException
- if not at a start tag or invalid index
-
getOptionalAttributeText
Read an optional text attribute value from the current start tag.- Parameters:
ns
- namespace URI for attribute (may be the empty string for the no-namespace namespace)name
- attribute name- Returns:
- value text,
null
if attribute not present - Throws:
IllegalStateException
- if not at a start tag or invalid index
-
getRequiredAttributeText
Read a required text attribute value from the current start tag.- Parameters:
name
- attribute name- Returns:
- value text,
null
if attribute not present and recoverable error - Throws:
JiBXException
- if attribute not present and unrecoverable errorIllegalStateException
- if not at a start tag or invalid index
-
getRequiredAttributeText
Read a required text attribute value from the current start tag.- Parameters:
ns
- namespace URI for attribute (may be the empty string for the no-namespace namespace)name
- attribute name- Returns:
- value text,
null
if attribute not present and recoverable error - Throws:
JiBXException
- if attribute not present and unrecoverable errorIllegalStateException
- if not at a start tag or invalid index
-
selectText
Select the current text content for conversion.- Throws:
JiBXException
- on unrecoverable error
-
selectAttribute
Select an attribute value from the current start tag as text for conversion.- Parameters:
index
- attribute index (error if negative)- Throws:
IllegalStateException
- if not at a start tag or invalid indexJiBXException
- on unrecoverable error
-
selectOptionalAttribute
Select an optional no-namespace attribute value from the current start tag as text for conversion.- Parameters:
name
- attribute name- Returns:
true
if attribute present,false
if not- Throws:
IllegalStateException
- if not at a start tag
-
selectRequiredAttribute
Select a required no-namespace attribute value from the current start tag as text for conversion.- Parameters:
name
- attribute name- Throws:
IllegalStateException
- if not at a start tagJiBXException
- on unrecoverable error
-
selectOptionalAttribute
Select an optional attribute value from the current start tag as text for conversion.- Parameters:
ns
- namespace URI for attribute (may be the empty string for the no-namespace namespace)name
- attribute name- Returns:
true
if attribute present,false
if not- Throws:
IllegalStateException
- if not at a start tag
-
selectRequiredAttribute
Select a required attribute value from the current start tag as text for conversion.- Parameters:
ns
- namespace URI for attribute (may be the empty string for the no-namespace namespace)name
- attribute name- Throws:
IllegalStateException
- if not at a start tagJiBXException
- on unrecoverable error
-
convertString
Convert aString
value from the current source selection. This is an empty conversion, which always just returns the text.- Returns:
- text (
null
if selection missing) - Throws:
JiBXException
- if unrecoverable conversion error
-
convertIntPrimitive
Convert anint
value from the current source selection. This always uses whitespace collapsed processing.- Returns:
- converted value (
0
if selection missing or in error) - Throws:
JiBXException
- if unrecoverable conversion error
-
convertInteger
Convert anInteger
value from the current source selection. This always uses whitespace collapsed processing.- Returns:
- converted value (
null
if selection missing or in error) - Throws:
JiBXException
- if unrecoverable conversion error
-
convertLongPrimitive
Convert along
value from the current source selection. This always uses whitespace collapsed processing.- Returns:
- converted value (
0
if selection missing or in error) - Throws:
JiBXException
- if unrecoverable conversion error
-
convertLong
Convert aLong
value from the current source selection. This always uses whitespace collapsed processing.- Returns:
- converted value (
null
if selection missing or in error) - Throws:
JiBXException
- if unrecoverable conversion error
-
convertFloatPrimitive
Convert afloat
value from the current source selection. This always uses whitespace collapsed processing.- Returns:
- converted value (
0
if selection missing or in error) - Throws:
JiBXException
- if unrecoverable conversion error
-
convertFloat
Convert aFloat
value from the current source selection. This always uses whitespace collapsed processing.- Returns:
- converted value (
null
if selection missing or in error) - Throws:
JiBXException
- if unrecoverable conversion error
-
convertBooleanPrimitive
Convert aboolean
value from the current source selection. This always uses whitespace collapsed processing.- Returns:
- converted value (
false
if selection missing or in error) - Throws:
JiBXException
- if unrecoverable conversion error
-
convertBoolean
Convert aBoolean
value from the current source selection. This always uses whitespace collapsed processing.- Returns:
- converted value (
null
if selection missing or in error) - Throws:
JiBXException
- if unrecoverable conversion error
-
convertBase64
Convert abyte[]
value from the current source selection using base64Binary encoding. This always uses whitespace collapsed processing.- Returns:
- converted value (
null
if selection missing or in error) - Throws:
JiBXException
- if unrecoverable conversion error
-
convertDateTime
Convert aDate
value from the current source selection. This always uses whitespace collapsed processing.- Returns:
- converted value (
null
if selection missing or in error) - Throws:
JiBXException
- if unrecoverable conversion error
-
convertBigDecimal
Convert aBigDecimal
value from the current source selection. This always uses whitespace collapsed processing.- Returns:
- converted value (
null
if selection missing or in error) - Throws:
JiBXException
- if unrecoverable conversion error
-
convertBigInteger
Convert aBigInteger
value from the current source selection. This always uses whitespace collapsed processing.- Returns:
- converted value (
null
if selection missing or in error) - Throws:
JiBXException
- if unrecoverable conversion error
-
readText
String readText()Read current element text. This is only valid with an open start tag, and reads past the corresponding end tag after reading the value.- Returns:
- text for current event
- Throws:
IllegalStateException
- if not at a start tag or invalid index
-
createElementInstance
Creat instance of class for element name. This implements substitution group handling, by checking the current element start tag name against the expected element name, and if they're not the same finding the appropriate class based on the substitution group rooted on the expected element name (which must be a global element name).- Parameters:
root
- global root element name, including namespace URI, in "lname{uri}" formrdr
- readerinst
- supplied instance of root element class or subclass (null
if none)- Returns:
- instance of appropriate class to use for unmarshalling (may be the same as the provided instance)
-
createTypeInstance
Validate instance of class for type name. This implements type substitution handling, by checking for an override xsi:type specification on the current element start tag, and if the type is different from the default finding the appropriate class.- Parameters:
dflt
- global default complexType name, including namespace URI, in "lname{uri}" formrdr
- readerinst
- supplied instance of default type class or subclass (null
if none)- Returns:
- instance of appropriate class to use for unmarshalling (may be the same as the provided instance)
-
getNestingDepth
int getNestingDepth()Get current element nesting depth. The returned depth always includes the current start or end tag (if positioned on a start or end tag).- Returns:
- element nesting depth
-
getNamespaceCount
int getNamespaceCount(int depth) Get number of namespace declarations active at depth.- Parameters:
depth
- element nesting depth- Returns:
- number of namespaces active at depth
- Throws:
IllegalArgumentException
- if invalid depth
-
getNamespaceUri
Get namespace URI.- Parameters:
index
- declaration index- Returns:
- namespace URI
- Throws:
IllegalArgumentException
- if invalid index
-
getNamespacePrefix
Get namespace prefix.- Parameters:
index
- declaration index- Returns:
- namespace prefix,
null
if a default namespace - Throws:
IllegalArgumentException
- if invalid index
-
getDocumentName
String getDocumentName()Get document name.- Returns:
- document name,
null
if not known
-
getLineNumber
int getLineNumber()Get current source line number.- Returns:
- line number from source document,
-1
if line number information not available
-
getColumnNumber
int getColumnNumber()Get current source column number.- Returns:
- column number from source document,
-1
if column number information not available
-
getNamespace
Get namespace URI associated with prefix.- Parameters:
prefix
- to be found- Returns:
- associated URI (
null
if prefix not defined)
-
getInputEncoding
String getInputEncoding()Return the input encoding, if known. This is only valid after parsing of a document has been started.- Returns:
- input encoding (
null
if unknown)
-
isNamespaceAware
boolean isNamespaceAware()Return namespace processing flag.- Returns:
- namespace processing flag (
true
if namespaces are processed by reader,false
if not)
-