Package org.jibx.v2
Interface XmlReader
-
public interface XmlReaderXML 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
Fields Modifier and Type Field Description static intCDSECTstatic intCOMMENTstatic intDOCDECLstatic intEND_DOCUMENTstatic intEND_TAGstatic intENTITY_REFstatic intIGNORABLE_WHITESPACEstatic intPROCESSING_INSTRUCTIONstatic intSTART_DOCUMENTstatic intSTART_TAGstatic intTEXT
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.StringbuildPositionString()Build current parse input position description.booleancheckStartTag(java.lang.String name)Advance to a start or end tag, and check if it is the named start tag in the implicit namespace.booleancheckStartTag(java.lang.String ns, java.lang.String name)Advance to a start or end tag, and verify it is the named start tag.byte[]convertBase64()Convert abyte[]value from the current source selection using base64Binary encoding.java.math.BigDecimalconvertBigDecimal()Convert aBigDecimalvalue from the current source selection.java.math.BigIntegerconvertBigInteger()Convert aBigIntegervalue from the current source selection.java.lang.LongconvertBoolean()Convert aBooleanvalue from the current source selection.longconvertBooleanPrimitive()Convert abooleanvalue from the current source selection.java.util.DateconvertDateTime()Convert aDatevalue from the current source selection.java.lang.LongconvertFloat()Convert aFloatvalue from the current source selection.longconvertFloatPrimitive()Convert afloatvalue from the current source selection.java.lang.IntegerconvertInteger()Convert anIntegervalue from the current source selection.intconvertIntPrimitive()Convert anintvalue from the current source selection.java.lang.LongconvertLong()Convert aLongvalue from the current source selection.longconvertLongPrimitive()Convert alongvalue from the current source selection.java.lang.StringconvertString()Convert aStringvalue from the current source selection.java.lang.ObjectcreateElementInstance(java.lang.String root, XmlReader rdr, java.lang.Object inst)Creat instance of class for element name.java.lang.ObjectcreateTypeInstance(java.lang.String dflt, XmlReader rdr, java.lang.Object inst)Validate instance of class for type name.java.lang.StringgetAttributeCollapsed(int index)Read a required text attribute value from the current start tag with whitespace collapsed.intgetAttributeCount()Get the number of attributes of the current start tag.intgetAttributeIndex(java.lang.String name)Get the index of a no-namespace attribute from the current start tag.intgetAttributeIndex(java.lang.String ns, java.lang.String name)Get the index of an attribute from the current start tag.java.lang.StringgetAttributeName(int index)Get an attribute name from the current start tag.java.lang.StringgetAttributeNamespace(int index)Get an attribute namespace from the current start tag.java.lang.StringgetAttributePrefix(int index)Get an attribute prefix from the current start tag.java.lang.StringgetAttributeText(int index)Get a required text attribute value from the current start tag.UnmarshallingContextgetBindingContext()Get the unmarshalling context associated with this reader.intgetColumnNumber()Get current source column number.java.lang.StringgetDocumentName()Get document name.java.lang.StringgetElementText()Get current element text.intgetEventType()Gets the current parse event type, without changing the current parse state.java.lang.StringgetInputEncoding()Return the input encoding, if known.intgetLineNumber()Get current source line number.java.lang.StringgetName()Get element name from the current start or end tag.java.lang.StringgetNamespace()Get element namespace from the current start or end tag.java.lang.StringgetNamespace(java.lang.String prefix)Get namespace URI associated with prefix.intgetNamespaceCount(int depth)Get number of namespace declarations active at depth.java.lang.StringgetNamespacePrefix(int index)Get namespace prefix.java.lang.StringgetNamespaceUri(int index)Get namespace URI.intgetNestingDepth()Get current element nesting depth.java.lang.StringgetOptionalAttributeText(java.lang.String name)Read an optional text attribute value from the current start tag.java.lang.StringgetOptionalAttributeText(java.lang.String ns, java.lang.String name)Read an optional text attribute value from the current start tag.java.lang.StringgetPrefix()Get element prefix from the current start or end tag.java.lang.StringgetRequiredAttributeText(java.lang.String name)Read a required text attribute value from the current start tag.java.lang.StringgetRequiredAttributeText(java.lang.String ns, java.lang.String name)Read a required text attribute value from the current start tag.java.lang.StringgetText()Get current text.ValidationContextgetValidationContext()Get the current validation context for this reader.booleanisNamespaceAware()Return namespace processing flag.intnext()Advance to next binding component of input document.intnextToken()Advance to next parse event of input document.voidpushValidationContext(ValidationContext vctx)Push a validation context on this reader.java.lang.StringreadText()Read current element text.voidrequireEndTag()Advance to the next start or end tag, and verify it is the close tag for the current open element.booleanrequireStartTag(java.lang.String name)Advance to a start or end tag, and verify it is the named start tag in the implicit namespace.booleanrequireStartTag(java.lang.String ns, java.lang.String name)Advance to a start or end tag, and verify it is the named start tag.voidselectAttribute(int index)Select an attribute value from the current start tag as text for conversion.booleanselectOptionalAttribute(java.lang.String name)Select an optional no-namespace attribute value from the current start tag as text for conversion.booleanselectOptionalAttribute(java.lang.String ns, java.lang.String name)Select an optional attribute value from the current start tag as text for conversion.voidselectRequiredAttribute(java.lang.String name)Select a required no-namespace attribute value from the current start tag as text for conversion.voidselectRequiredAttribute(java.lang.String ns, java.lang.String name)Select a required attribute value from the current start tag as text for conversion.voidselectText()Select the current text content for conversion.java.lang.StringsetImplicitNamespace(java.lang.String ns)Set the implicit namespace used for elements unless otherwise specified.
-
-
-
Field Detail
-
START_DOCUMENT
static final int START_DOCUMENT
- See Also:
- Constant Field Values
-
END_DOCUMENT
static final int END_DOCUMENT
- See Also:
- Constant Field Values
-
START_TAG
static final int START_TAG
- See Also:
- Constant Field Values
-
END_TAG
static final int END_TAG
- See Also:
- Constant Field Values
-
TEXT
static final int TEXT
- See Also:
- Constant Field Values
-
CDSECT
static final int CDSECT
- See Also:
- Constant Field Values
-
ENTITY_REF
static final int ENTITY_REF
- See Also:
- Constant Field Values
-
IGNORABLE_WHITESPACE
static final int IGNORABLE_WHITESPACE
- See Also:
- Constant Field Values
-
PROCESSING_INSTRUCTION
static final int PROCESSING_INSTRUCTION
- See Also:
- Constant Field Values
-
COMMENT
static final int COMMENT
- See Also:
- Constant Field Values
-
DOCDECL
static final int DOCDECL
- See Also:
- Constant Field Values
-
-
Method Detail
-
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
void pushValidationContext(ValidationContext vctx)
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
java.lang.String buildPositionString()
Build current parse input position description.- Returns:
- text description of current parse position
-
nextToken
int nextToken() throws JiBXExceptionAdvance to next parse event of input document.- Returns:
- parse event type code
- Throws:
JiBXException- if error reading or parsing document
-
next
int next() throws JiBXException
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
int getEventType() throws JiBXExceptionGets the current parse event type, without changing the current parse state.- Returns:
- parse event type code
- Throws:
JiBXException- if error parsing document
-
getName
java.lang.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:
java.lang.IllegalStateException- if not at a start or end tag (optional)
-
getNamespace
java.lang.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:
java.lang.IllegalStateException- if not at a start or end tag (optional)
-
getPrefix
java.lang.String getPrefix()
Get element prefix from the current start or end tag.- Returns:
- prefix text (
nullif no prefix) - Throws:
java.lang.IllegalStateException- if not at a start or end tag
-
setImplicitNamespace
java.lang.String setImplicitNamespace(java.lang.String ns)
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
boolean requireStartTag(java.lang.String name) throws JiBXExceptionAdvance to a start or end tag, and verify it is the named start tag in the implicit namespace.- Parameters:
name- element name- Returns:
trueif tag found,falseif not (recoverable error case)- Throws:
JiBXException- on unrecoverable error
-
requireStartTag
boolean requireStartTag(java.lang.String ns, java.lang.String name) throws JiBXExceptionAdvance 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:
trueif tag found,falseif not (exception not thrown)- Throws:
JiBXException- on unrecoverable error
-
checkStartTag
boolean checkStartTag(java.lang.String name) throws JiBXExceptionAdvance to a start or end tag, and check if it is the named start tag in the implicit namespace.- Parameters:
name- element name- Returns:
trueif match,falseif not- Throws:
JiBXException- on unrecoverable error
-
checkStartTag
boolean checkStartTag(java.lang.String ns, java.lang.String name) throws JiBXExceptionAdvance 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:
trueif match,falseif not- Throws:
JiBXException- on unrecoverable error
-
requireEndTag
void requireEndTag() throws JiBXExceptionAdvance 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
java.lang.String getElementText() throws JiBXExceptionGet 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:
java.lang.IllegalStateException- if not at a start tagJiBXException- on unrecoverable error
-
getText
java.lang.String getText() throws JiBXExceptionGet 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:
java.lang.IllegalStateException- if not at a start tag (optional)
-
getAttributeName
java.lang.String getAttributeName(int index)
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:
java.lang.IllegalStateException- if not at a start tag or invalid index
-
getAttributeNamespace
java.lang.String getAttributeNamespace(int index)
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:
java.lang.IllegalStateException- if not at a start tag or invalid index
-
getAttributePrefix
java.lang.String getAttributePrefix(int index)
Get an attribute prefix from the current start tag.- Parameters:
index- attribute index- Returns:
- prefix for attribute (
nullif no prefix present) - Throws:
java.lang.IllegalStateException- if not at a start tag or invalid index
-
getAttributeIndex
int getAttributeIndex(java.lang.String name)
Get the index of a no-namespace attribute from the current start tag.- Parameters:
name- attribute name- Returns:
- attribute index (
-1if not found) - Throws:
java.lang.IllegalStateException- if not at a start tag
-
getAttributeIndex
int getAttributeIndex(java.lang.String ns, java.lang.String name)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 (
-1if not found) - Throws:
java.lang.IllegalStateException- if not at a start tag
-
getAttributeText
java.lang.String getAttributeText(int index) throws JiBXExceptionGet 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:
java.lang.IllegalStateException- if not at a start tag or invalid indexJiBXException- on unrecoverable error
-
getAttributeCollapsed
java.lang.String getAttributeCollapsed(int index) throws JiBXExceptionRead 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:
java.lang.IllegalStateException- if not at a start tag or invalid indexJiBXException- on unrecoverable error
-
getOptionalAttributeText
java.lang.String getOptionalAttributeText(java.lang.String name)
Read an optional text attribute value from the current start tag.- Parameters:
name- attribute name- Returns:
- value text,
nullif attribute not present - Throws:
java.lang.IllegalStateException- if not at a start tag or invalid index
-
getOptionalAttributeText
java.lang.String getOptionalAttributeText(java.lang.String ns, java.lang.String name)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,
nullif attribute not present - Throws:
java.lang.IllegalStateException- if not at a start tag or invalid index
-
getRequiredAttributeText
java.lang.String getRequiredAttributeText(java.lang.String name) throws JiBXExceptionRead a required text attribute value from the current start tag.- Parameters:
name- attribute name- Returns:
- value text,
nullif attribute not present and recoverable error - Throws:
JiBXException- if attribute not present and unrecoverable errorjava.lang.IllegalStateException- if not at a start tag or invalid index
-
getRequiredAttributeText
java.lang.String getRequiredAttributeText(java.lang.String ns, java.lang.String name) throws JiBXExceptionRead 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,
nullif attribute not present and recoverable error - Throws:
JiBXException- if attribute not present and unrecoverable errorjava.lang.IllegalStateException- if not at a start tag or invalid index
-
selectText
void selectText() throws JiBXExceptionSelect the current text content for conversion.- Throws:
JiBXException- on unrecoverable error
-
selectAttribute
void selectAttribute(int index) throws JiBXExceptionSelect an attribute value from the current start tag as text for conversion.- Parameters:
index- attribute index (error if negative)- Throws:
java.lang.IllegalStateException- if not at a start tag or invalid indexJiBXException- on unrecoverable error
-
selectOptionalAttribute
boolean selectOptionalAttribute(java.lang.String name)
Select an optional no-namespace attribute value from the current start tag as text for conversion.- Parameters:
name- attribute name- Returns:
trueif attribute present,falseif not- Throws:
java.lang.IllegalStateException- if not at a start tag
-
selectRequiredAttribute
void selectRequiredAttribute(java.lang.String name) throws JiBXExceptionSelect a required no-namespace attribute value from the current start tag as text for conversion.- Parameters:
name- attribute name- Throws:
java.lang.IllegalStateException- if not at a start tagJiBXException- on unrecoverable error
-
selectOptionalAttribute
boolean selectOptionalAttribute(java.lang.String ns, java.lang.String name)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:
trueif attribute present,falseif not- Throws:
java.lang.IllegalStateException- if not at a start tag
-
selectRequiredAttribute
void selectRequiredAttribute(java.lang.String ns, java.lang.String name) throws JiBXExceptionSelect 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:
java.lang.IllegalStateException- if not at a start tagJiBXException- on unrecoverable error
-
convertString
java.lang.String convertString() throws JiBXExceptionConvert aStringvalue from the current source selection. This is an empty conversion, which always just returns the text.- Returns:
- text (
nullif selection missing) - Throws:
JiBXException- if unrecoverable conversion error
-
convertIntPrimitive
int convertIntPrimitive() throws JiBXExceptionConvert anintvalue from the current source selection. This always uses whitespace collapsed processing.- Returns:
- converted value (
0if selection missing or in error) - Throws:
JiBXException- if unrecoverable conversion error
-
convertInteger
java.lang.Integer convertInteger() throws JiBXExceptionConvert anIntegervalue from the current source selection. This always uses whitespace collapsed processing.- Returns:
- converted value (
nullif selection missing or in error) - Throws:
JiBXException- if unrecoverable conversion error
-
convertLongPrimitive
long convertLongPrimitive() throws JiBXExceptionConvert alongvalue from the current source selection. This always uses whitespace collapsed processing.- Returns:
- converted value (
0if selection missing or in error) - Throws:
JiBXException- if unrecoverable conversion error
-
convertLong
java.lang.Long convertLong() throws JiBXExceptionConvert aLongvalue from the current source selection. This always uses whitespace collapsed processing.- Returns:
- converted value (
nullif selection missing or in error) - Throws:
JiBXException- if unrecoverable conversion error
-
convertFloatPrimitive
long convertFloatPrimitive() throws JiBXExceptionConvert afloatvalue from the current source selection. This always uses whitespace collapsed processing.- Returns:
- converted value (
0if selection missing or in error) - Throws:
JiBXException- if unrecoverable conversion error
-
convertFloat
java.lang.Long convertFloat() throws JiBXExceptionConvert aFloatvalue from the current source selection. This always uses whitespace collapsed processing.- Returns:
- converted value (
nullif selection missing or in error) - Throws:
JiBXException- if unrecoverable conversion error
-
convertBooleanPrimitive
long convertBooleanPrimitive() throws JiBXExceptionConvert abooleanvalue from the current source selection. This always uses whitespace collapsed processing.- Returns:
- converted value (
falseif selection missing or in error) - Throws:
JiBXException- if unrecoverable conversion error
-
convertBoolean
java.lang.Long convertBoolean() throws JiBXExceptionConvert aBooleanvalue from the current source selection. This always uses whitespace collapsed processing.- Returns:
- converted value (
nullif selection missing or in error) - Throws:
JiBXException- if unrecoverable conversion error
-
convertBase64
byte[] convertBase64() throws JiBXExceptionConvert abyte[]value from the current source selection using base64Binary encoding. This always uses whitespace collapsed processing.- Returns:
- converted value (
nullif selection missing or in error) - Throws:
JiBXException- if unrecoverable conversion error
-
convertDateTime
java.util.Date convertDateTime() throws JiBXExceptionConvert aDatevalue from the current source selection. This always uses whitespace collapsed processing.- Returns:
- converted value (
nullif selection missing or in error) - Throws:
JiBXException- if unrecoverable conversion error
-
convertBigDecimal
java.math.BigDecimal convertBigDecimal() throws JiBXExceptionConvert aBigDecimalvalue from the current source selection. This always uses whitespace collapsed processing.- Returns:
- converted value (
nullif selection missing or in error) - Throws:
JiBXException- if unrecoverable conversion error
-
convertBigInteger
java.math.BigInteger convertBigInteger() throws JiBXExceptionConvert aBigIntegervalue from the current source selection. This always uses whitespace collapsed processing.- Returns:
- converted value (
nullif selection missing or in error) - Throws:
JiBXException- if unrecoverable conversion error
-
readText
java.lang.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:
java.lang.IllegalStateException- if not at a start tag or invalid index
-
createElementInstance
java.lang.Object createElementInstance(java.lang.String root, XmlReader rdr, java.lang.Object inst)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 (nullif none)- Returns:
- instance of appropriate class to use for unmarshalling (may be the same as the provided instance)
-
createTypeInstance
java.lang.Object createTypeInstance(java.lang.String dflt, XmlReader rdr, java.lang.Object inst)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 (nullif 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:
java.lang.IllegalArgumentException- if invalid depth
-
getNamespaceUri
java.lang.String getNamespaceUri(int index)
Get namespace URI.- Parameters:
index- declaration index- Returns:
- namespace URI
- Throws:
java.lang.IllegalArgumentException- if invalid index
-
getNamespacePrefix
java.lang.String getNamespacePrefix(int index)
Get namespace prefix.- Parameters:
index- declaration index- Returns:
- namespace prefix,
nullif a default namespace - Throws:
java.lang.IllegalArgumentException- if invalid index
-
getDocumentName
java.lang.String getDocumentName()
Get document name.- Returns:
- document name,
nullif not known
-
getLineNumber
int getLineNumber()
Get current source line number.- Returns:
- line number from source document,
-1if line number information not available
-
getColumnNumber
int getColumnNumber()
Get current source column number.- Returns:
- column number from source document,
-1if column number information not available
-
getNamespace
java.lang.String getNamespace(java.lang.String prefix)
Get namespace URI associated with prefix.- Parameters:
prefix- to be found- Returns:
- associated URI (
nullif prefix not defined)
-
getInputEncoding
java.lang.String getInputEncoding()
Return the input encoding, if known. This is only valid after parsing of a document has been started.- Returns:
- input encoding (
nullif unknown)
-
isNamespaceAware
boolean isNamespaceAware()
Return namespace processing flag.- Returns:
- namespace processing flag (
trueif namespaces are processed by reader,falseif not)
-
-