Top Description Fields Constructors Methods
org.codehaus.stax2.ri

public Class Stax2ReaderAdapter

extends StreamReaderDelegate
implements XMLStreamReader2, AttributeInfo, DTDInfo, LocationInfo
Class Inheritance
All Implemented Interfaces
org.codehaus.stax2.LocationInfo, org.codehaus.stax2.DTDInfo, org.codehaus.stax2.AttributeInfo, org.codehaus.stax2.XMLStreamReader2, org.codehaus.stax2.validation.Validatable, org.codehaus.stax2.typed.TypedXMLStreamReader, javax.xml.stream.XMLStreamReader, javax.xml.stream.XMLStreamConstants
Imports
java.io.IOException, .Writer, java.math.BigDecimal, .BigInteger, javax.xml.namespace.NamespaceContext, .QName, javax.xml.stream.*, javax.xml.stream.util.StreamReaderDelegate, org.codehaus.stax2.typed.Base64Variant, .Base64Variants, .TypedArrayDecoder, .TypedValueDecoder, .TypedXMLStreamException, org.codehaus.stax2.ri.Stax2Util, org.codehaus.stax2.ri.typed.StringBase64Decoder, .ValueDecoderFactory, org.codehaus.stax2.*, org.codehaus.stax2.validation.*

This adapter implements parts of XMLStreamReader2, the extended stream reader defined by Stax2 extension, by wrapping a vanilla Stax 1.0 XMLStreamReader implementation.

Note: the implementation is incomplete as-is, since not all features needed are accessible via basic Stax 1.0 interface. As such, two main use cases for this wrapper are:

Author
Tatu Saloranta

Field Summary

Modifier and TypeField and Description
protected StringBase64Decoder
_base64Decoder

Lazily-constructed decoder object for decoding base64 encoded binary content.

protected ValueDecoderFactory
_decoderFactory

Factory used for constructing decoders we need for typed access

protected int
_depth

Number of open (start) elements currently.

protected String
_typedContent

Content temporarily cached to be used for decoding typed content that is in chunked mode (int/long/float/double arrays, base64 encoded binary data)

pack-priv static final int
private static final int
protected static final int

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
protected StringBase64Decoder
protected TypedXMLStreamException
_constructTypeException(IllegalArgumentException
Problem as reported by converter
iae
,
String
Lexical value (element content, attribute value) that could not be converted succesfully.
lexicalValue
)

Method called to wrap or convert given conversion-fail exception into a full TypedXMLStreamException,

protected TypedXMLStreamException
protected ValueDecoderFactory
protected int
private final boolean
checkExpand(TypedArrayDecoder tad)

Internal method used to see if we can expand the buffer that the array decoder has.

public void
closeCompletely()

Implements org.codehaus.stax2.XMLStreamReader2.closeCompletely.

Method similar to javax.xml.stream.XMLStreamReader#close, except that this method also does close the underlying input source if it has not yet been closed.
public int
public void
getAttributeAs(int index, TypedValueDecoder tvd)

Implements org.codehaus.stax2.typed.TypedXMLStreamReader.getAttributeAs.

Generic access method that can be used for efficient decoding of additional types not support natively by the typed stream reader.
public int
getAttributeAsArray(int index, TypedArrayDecoder tad)

Implements org.codehaus.stax2.typed.TypedXMLStreamReader.getAttributeAsArray.

Method that allows reading contents of an attribute as an array of whitespace-separate tokens, decoded using specified decoder.
public byte[]
getAttributeAsBinary(int
The attribute's index as returned by getAttributeIndex(String, String).
index
)

Implements org.codehaus.stax2.typed.TypedXMLStreamReader.getAttributeAsBinary.

Read an attribute value as a byte array.
public byte[]
public boolean
getAttributeAsBoolean(int
The attribute's index as returned by getAttributeIndex(String, String)
index
)

Implements org.codehaus.stax2.typed.TypedXMLStreamReader.getAttributeAsBoolean.

Read an attribute value as a boolean.

public BigDecimal
public double
public double[]
public float
public float[]
public int
getAttributeAsInt(int
The attribute's index as returned by getAttributeIndex(String, String)
index
)

Implements org.codehaus.stax2.typed.TypedXMLStreamReader.getAttributeAsInt.

Read an attribute value as a boolean.

public int[]
getAttributeAsIntArray(int
The attribute's index as returned by getAttributeIndex(String, String).
index
)

Implements org.codehaus.stax2.typed.TypedXMLStreamReader.getAttributeAsIntArray.

Read an attribute content as an int array.

public BigInteger
public long
getAttributeAsLong(int
The attribute's index as returned by getAttributeIndex(String, String)
index
)

Implements org.codehaus.stax2.typed.TypedXMLStreamReader.getAttributeAsLong.

Read an attribute value as a boolean.

public long[]
public QName
public int
getAttributeIndex(String
The attribute's namespace URI. Values of null and "" are considered the same, i.e. "no namespace" (or "empty" namespace)
namespaceURI
,
String
The attribute's local name.
localName
)

Implements org.codehaus.stax2.typed.TypedXMLStreamReader.getAttributeIndex.

Returns the index of the attribute whose local name is localName and URI is namespaceURI or -1 if no such attribute exists.
public AttributeInfo
getAttributeInfo()

Implements org.codehaus.stax2.XMLStreamReader2.getAttributeInfo.

Method that can be called to get additional information about attributes related to the current start element, as well as related DTD-based information if available.
public XMLStreamLocation2
getCurrentLocation()

Implements org.codehaus.stax2.LocationInfo.getCurrentLocation.

A method that returns the current location of the stream reader at the input source.
public int

Returns:

Number of open elements in the stack; 0 when parser is in prolog/epilog, 1 inside root element and so on.
getDepth
()

Implements org.codehaus.stax2.XMLStreamReader2.getDepth.

Method that returns the number of open elements in the stack; 0 when the reader is in prolog/epilog, 1 inside root element (including when pointing at the root element itself) and so on.
public DTDInfo
getDTDInfo()

Implements org.codehaus.stax2.XMLStreamReader2.getDTDInfo.

Method that can be called to get information about DOCTYPE declaration that the reader is currently pointing to, if the reader has parsed it.
public String

Returns:

Internal subset portion of the DOCTYPE declaration, if any; empty String if none
getDTDInternalSubset
()

Implements org.codehaus.stax2.DTDInfo.getDTDInternalSubset.

public String
public String
public String
public void
getElementAs(TypedValueDecoder tvd)

Implements org.codehaus.stax2.typed.TypedXMLStreamReader.getElementAs.

Generic decoding method that can be used for efficient decoding of additional types not support natively by the typed stream reader.
public byte[]
getElementAsBinary()

Implements org.codehaus.stax2.typed.TypedXMLStreamReader.getElementAsBinary.

Convenience method that can be used similar to read binary content instead of readElementAsBinary, in cases where neither performance nor memory usage is a big concern.
public byte[]
getElementAsBinary(Base64Variant
Base64 variant content is in; needed to decode alternative variants ("modified base64")
v
)

Implements org.codehaus.stax2.typed.TypedXMLStreamReader.getElementAsBinary.

Convenience method that can be used similar to read binary content instead of readElementAsBinary, in cases where neither performance nor memory usage is a big concern.
public boolean
public BigDecimal
public double
getElementAsDouble()

Implements org.codehaus.stax2.typed.TypedXMLStreamReader.getElementAsDouble.

Read an element content as a 64-bit floating point value.

public float
getElementAsFloat()

Implements org.codehaus.stax2.typed.TypedXMLStreamReader.getElementAsFloat.

Read an element content as a 32-bit floating point value.

public int
getElementAsInt()

Implements org.codehaus.stax2.typed.TypedXMLStreamReader.getElementAsInt.

Read an element content as a 32-bit integer.

public BigInteger
public long
getElementAsLong()

Implements org.codehaus.stax2.typed.TypedXMLStreamReader.getElementAsLong.

Read an element content as a 64-bit integer.

public QName
public String
getElementText()

Overrides javax.xml.stream.util.StreamReaderDelegate.getElementText.

Implements javax.xml.stream.XMLStreamReader.getElementText.

Reads the content of a text-only element, an exception is thrown if this is not a text-only element.
public long
getEndingByteOffset()

Implements org.codehaus.stax2.LocationInfo.getEndingByteOffset.

Method that can be used to get exact byte offset (number of bytes read from the stream right before getting to this location) in the stream that is pointed to by this reader, right after the end of the current event.
public long
getEndingCharOffset()

Implements org.codehaus.stax2.LocationInfo.getEndingCharOffset.

Method that can be used to get exact character offset (number of chars read from the stream right before getting to this location) in the stream that is pointed to by this reader, right after the end of the current event.
public final XMLStreamLocation2
getEndLocation()

Implements org.codehaus.stax2.LocationInfo.getEndLocation.

An optional method that either returns the location object that points the ending position of the current event, or null if implementation does not keep track of it (some may return only start location; and some no location at all).
public Object
getFeature(String
Name of the feature of which value to get
name
)

Implements org.codehaus.stax2.XMLStreamReader2.getFeature.

Deprecated
Method that can be used to get per-reader values; both generic ones (names for which are defined as constants in this class), and implementation dependant ones.
public int
getIdAttributeIndex()

Implements org.codehaus.stax2.AttributeInfo.getIdAttributeIndex.

Returns the index of the id attribute (attribute with any name, type ID from DTD) of current (start) element, if any.
public final LocationInfo
getLocationInfo()

Implements org.codehaus.stax2.XMLStreamReader2.getLocationInfo.

Location information is always accessible, for this reader.
public NamespaceContext
getNonTransientNamespaceContext()

Implements org.codehaus.stax2.XMLStreamReader2.getNonTransientNamespaceContext.

This method returns a namespace context object that contains information identical to that returned by javax.xml.stream.XMLStreamReader#getNamespaceContext(), but one that is not transient.
public int
getNotationAttributeIndex()

Implements org.codehaus.stax2.AttributeInfo.getNotationAttributeIndex.

Returns the index of the notation attribute (attribute with any name, type NOTATION from DTD) of current (start) element, if any.
public String
getPrefixedName()

Implements org.codehaus.stax2.XMLStreamReader2.getPrefixedName.

This method returns "prefix-qualified" name of the current element.
public Object
public DTDValidationSchema
public long
getStartingByteOffset()

Implements org.codehaus.stax2.LocationInfo.getStartingByteOffset.

Method that can be used to get exact byte offset (number of bytes read from the stream right before getting to this location) in the stream that is pointed to by this reader, right before the start of the current event.
public long
getStartingCharOffset()

Implements org.codehaus.stax2.LocationInfo.getStartingCharOffset.

Method that can be used to get exact character offset (number of chars read from the stream right before getting to this location) in the stream that is pointed to by this reader, right before the start of the current event.
public XMLStreamLocation2
getStartLocation()

Implements org.codehaus.stax2.LocationInfo.getStartLocation.

An optional method that either returns the location object that points the starting position of the current event, or null if implementation does not keep track of it (some may return only end location; and some no location at all).
public int
getText(Writer
Writer to use for writing textual contents
w
,
boolean
If true, reader has to preserve contents so that further calls to getText will return proper conntets. If false, reader is allowed to skip creation of such copies: this can improve performance, but it also means that further calls to getText is not guaranteed to return meaningful data.
preserveContents
)

Implements org.codehaus.stax2.XMLStreamReader2.getText.

Method similar to getText(), except that it just uses provided Writer to write all textual content, and that it works for wider range of event types.
public boolean
isEmptyElement()

Implements org.codehaus.stax2.XMLStreamReader2.isEmptyElement.

Alas, there is no way to find this out via Stax 1.0, so this implementation always returns false.
public boolean
isPropertySupported(String name)

Implements org.codehaus.stax2.XMLStreamReader2.isPropertySupported.

Method similar to javax.xml.stream.XMLInputFactory#isPropertySupported, used to determine whether a property is supported by the Reader instance.
public int
next()

Overrides javax.xml.stream.util.StreamReaderDelegate.next.

Implements javax.xml.stream.XMLStreamReader.next.

Get next parsing event - a processor may return all contiguous character data in a single chunk, or it may split it into several chunks.
public int
readElementAsArray(TypedArrayDecoder tad)

Implements org.codehaus.stax2.typed.TypedXMLStreamReader.readElementAsArray.

Read an element content as an array of tokens.
public int
readElementAsBinary(byte[] resultBuffer, int offset, int maxLength)

Implements org.codehaus.stax2.typed.TypedXMLStreamReader.readElementAsBinary.

public int
readElementAsBinary(byte[]
Array in which to copy decoded bytes.
resultBuffer
,
int
Starting offset of the first decoded byte within result buffer
offset
,
int
Maximum number of bytes to decode with this call
maxLength
,
Base64Variant v)

Implements org.codehaus.stax2.typed.TypedXMLStreamReader.readElementAsBinary.

Read element content as decoded byte sequence; possibly only reading a fragment of all element content.
public int
public int
public int
readElementAsIntArray(int[]
The array in which to copy the ints.
value
,
int
The index in the array from which copying starts.
from
,
int
The maximun number of ints to copy. Minimum value is 1; others an IllegalArgumentException is thrown
length
)

Implements org.codehaus.stax2.typed.TypedXMLStreamReader.readElementAsIntArray.

Read an element content as an int array.
public int
public void
setFeature(String
Name of the feature to set
name
,
Object
Value to set feature to.
value
)

Implements org.codehaus.stax2.XMLStreamReader2.setFeature.

Deprecated
Method that can be used to set per-reader features such as configuration settings; both generic ones (names for which are defined as constants in this class), and implementation dependant ones.
public boolean
setProperty(String
Name of the property to set
name
,
Object
Value to set property to.
value
)

Implements org.codehaus.stax2.XMLStreamReader2.setProperty.

Method that can be used to set per-reader properties; a subset of properties one can set via matching org.codehaus.stax2.XMLInputFactory2 instance.
public ValidationProblemHandler
setValidationProblemHandler(ValidationProblemHandler
Handler to install, if non null; if null, indicates that the default (implementation-specific) handling should be used
h
)

Implements org.codehaus.stax2.validation.Validatable.setValidationProblemHandler.

Method that application can call to define a custom handler for validation problems encountered during validation process.
public void
skipElement()

Implements org.codehaus.stax2.XMLStreamReader2.skipElement.

Method that will skip all the contents of the element that the stream currently points to.
public XMLValidator
stopValidatingAgainst(XMLValidationSchema schema)

Implements org.codehaus.stax2.validation.Validatable.stopValidatingAgainst.

Method that can be called by application to stop validating output against a schema, for which validateAgainst was called earlier.
public XMLValidator
stopValidatingAgainst(XMLValidator validator)

Implements org.codehaus.stax2.validation.Validatable.stopValidatingAgainst.

Method that can be called by application to stop validating output using specified validator.
protected void
protected void
protected void
public XMLValidator
validateAgainst(XMLValidationSchema schema)

Implements org.codehaus.stax2.validation.Validatable.validateAgainst.

Method that will construct a XMLValidator instance from the given schema (unless a validator for that schema has already been added), initialize it if necessary, and make validatable object (reader, writer) call appropriate validation methods from this point on until the end of the document (that is, it's not scoped with sub-trees), or until validator is removed by an explicit call to stopValidatingAgainst.
public static XMLStreamReader2
wrapIfNecessary(XMLStreamReader sr)

Method that should be used to add dynamic support for XMLStreamReader2.

Inherited from javax.xml.stream.util.StreamReaderDelegate:
closegetAttributeCountgetAttributeLocalNamegetAttributeNamegetAttributeNamespacegetAttributePrefixgetAttributeTypegetAttributeValuegetAttributeValuegetCharacterEncodingSchemegetEncodinggetEventTypegetLocalNamegetLocationgetNamegetNamespaceContextgetNamespaceCountgetNamespacePrefixgetNamespaceURIgetNamespaceURIgetNamespaceURIgetParentgetPIDatagetPITargetgetPrefixgetPropertygetTextgetTextCharactersgetTextCharactersgetTextLengthgetTextStartgetVersionhasNamehasNexthasTextisAttributeSpecifiedisCharactersisEndElementisStandaloneisStartElementisWhiteSpacenextTagrequiresetParentstandaloneSet