org.springframework.util.xml
Class StaxSource

java.lang.Object
  extended by javax.xml.transform.sax.SAXSource
      extended by org.springframework.util.xml.StaxSource
All Implemented Interfaces:
javax.xml.transform.Source

 class StaxSource
extends javax.xml.transform.sax.SAXSource

Implementation of the Source tagging interface for StAX readers. Can be constructed with a XMLEventReader or a XMLStreamReader.

This class is necessary because there is no implementation of Source for StAX Readers in JAXP 1.3. There is a StAXSource in JAXP 1.4 (JDK 1.6), but this class is kept around for back-ward compatibility reasons.

Even though StaxSource extends from SAXSource, calling the methods of SAXSource is not supported. In general, the only supported operation on this class is to use the XMLReader obtained via SAXSource.getXMLReader() to parse the input source obtained via SAXSource.getInputSource(). Calling setXMLReader(XMLReader) or setInputSource(InputSource) will result in UnsupportedOperationExceptions.

Since:
3.0
Author:
Arjen Poutsma
See Also:
XMLEventReader, XMLStreamReader, Transformer

Field Summary
private  javax.xml.stream.XMLEventReader eventReader
           
private  javax.xml.stream.XMLStreamReader streamReader
           
 
Fields inherited from class javax.xml.transform.sax.SAXSource
FEATURE
 
Constructor Summary
StaxSource(javax.xml.stream.XMLEventReader eventReader)
          Constructs a new instance of the StaxSource with the specified XMLEventReader.
StaxSource(javax.xml.stream.XMLStreamReader streamReader)
          Constructs a new instance of the StaxSource with the specified XMLStreamReader.
 
Method Summary
(package private)  javax.xml.stream.XMLEventReader getXMLEventReader()
          Returns the XMLEventReader used by this StaxSource.
(package private)  javax.xml.stream.XMLStreamReader getXMLStreamReader()
          Returns the XMLStreamReader used by this StaxSource.
 void setInputSource(org.xml.sax.InputSource inputSource)
          Throws a UnsupportedOperationException.
 void setXMLReader(org.xml.sax.XMLReader reader)
          Throws a UnsupportedOperationException.
 
Methods inherited from class javax.xml.transform.sax.SAXSource
getInputSource, getSystemId, getXMLReader, setSystemId, sourceToInputSource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

eventReader

private javax.xml.stream.XMLEventReader eventReader

streamReader

private javax.xml.stream.XMLStreamReader streamReader
Constructor Detail

StaxSource

StaxSource(javax.xml.stream.XMLStreamReader streamReader)
Constructs a new instance of the StaxSource with the specified XMLStreamReader. The supplied stream reader must be in XMLStreamConstants.START_DOCUMENT or XMLStreamConstants.START_ELEMENT state.

Parameters:
streamReader - the XMLStreamReader to read from
Throws:
java.lang.IllegalStateException - if the reader is not at the start of a document or element

StaxSource

StaxSource(javax.xml.stream.XMLEventReader eventReader)
Constructs a new instance of the StaxSource with the specified XMLEventReader. The supplied event reader must be in XMLStreamConstants.START_DOCUMENT or XMLStreamConstants.START_ELEMENT state.

Parameters:
eventReader - the XMLEventReader to read from
Throws:
java.lang.IllegalStateException - if the reader is not at the start of a document or element
Method Detail

getXMLEventReader

javax.xml.stream.XMLEventReader getXMLEventReader()
Returns the XMLEventReader used by this StaxSource. If this StaxSource was created with an XMLStreamReader, the result will be null.

Returns:
the StAX event reader used by this source
See Also:
StaxSource(javax.xml.stream.XMLEventReader)

getXMLStreamReader

javax.xml.stream.XMLStreamReader getXMLStreamReader()
Returns the XMLStreamReader used by this StaxSource. If this StaxSource was created with an XMLEventReader, the result will be null.

Returns:
the StAX event reader used by this source
See Also:
StaxSource(javax.xml.stream.XMLEventReader)

setInputSource

public void setInputSource(org.xml.sax.InputSource inputSource)
Throws a UnsupportedOperationException.

Overrides:
setInputSource in class javax.xml.transform.sax.SAXSource
Throws:
java.lang.UnsupportedOperationException - always

setXMLReader

public void setXMLReader(org.xml.sax.XMLReader reader)
Throws a UnsupportedOperationException.

Overrides:
setXMLReader in class javax.xml.transform.sax.SAXSource
Throws:
java.lang.UnsupportedOperationException - always