FileDocCategorySizeDatePackage
StAXSource.javaAPI DocJava SE 6 API8827Tue Jun 10 00:27:14 BST 2008javax.xml.transform.stax

StAXSource

public class StAXSource extends Object implements Source

Acts as a holder for an XML {@link Source} in the form of a StAX reader,i.e. {@link XMLStreamReader} or {@link XMLEventReader}. StAXSource can be used in all cases that accept a Source, e.g. {@link javax.xml.transform.Transformer}, {@link javax.xml.validation.Validator} which accept Source as input.

StAXSources are consumed during processing and are not reusable.

author
Neeraj Bajaj
author
Jeff Suttor
version
$Revision: 1.4 $, $Date: 2006/04/24 13:42:27 $
see
JSR 173: Streaming API for XML
see
XMLStreamReader
see
XMLEventReader
since
1.6

Fields Summary
public static final String
FEATURE
If {@link javax.xml.transform.TransformerFactory#getFeature(String name)} returns true when passed this value as an argument, the Transformer supports Source input of this type.
private XMLEventReader
xmlEventReader

XMLEventReader to be used for source input.

private XMLStreamReader
xmlStreamReader

XMLStreamReader to be used for source input.

private String
systemId

System identifier of source input.

Constructors Summary
public StAXSource(XMLEventReader xmlEventReader)

Creates a new instance of a StAXSource by supplying an {@link XMLEventReader}.

XMLEventReader must be a non-null reference.

XMLEventReader must be in {@link XMLStreamConstants#START_DOCUMENT} or {@link XMLStreamConstants#START_ELEMENT} state.

param
xmlEventReader XMLEventReader used to create this StAXSource.
throws
XMLStreamException If xmlEventReader access throws an Exception.
throws
IllegalArgumentException If xmlEventReader == null.
throws
IllegalStateException If xmlEventReader is not in XMLStreamConstants.START_DOCUMENT or XMLStreamConstants.START_ELEMENT state.


                                                                                
       
          

        if (xmlEventReader == null) {
            throw new IllegalArgumentException(
                    "StAXSource(XMLEventReader) with XMLEventReader == null");
        }

        // TODO: This is ugly ...
        // there is no way to know the current position(event) of
        // XMLEventReader.  peek() is the only way to know the next event.
        // The next event on the input stream should be
        // XMLStreamConstants.START_DOCUMENT or
        // XMLStreamConstants.START_ELEMENT.
        XMLEvent event = xmlEventReader.peek();
        int eventType = event.getEventType();
        if (eventType != XMLStreamConstants.START_DOCUMENT
                && eventType != XMLStreamConstants.START_ELEMENT) {
            throw new IllegalStateException(
                "StAXSource(XMLEventReader) with XMLEventReader "
                + "not in XMLStreamConstants.START_DOCUMENT or "
                + "XMLStreamConstants.START_ELEMENT state");
        }

        this.xmlEventReader = xmlEventReader;
        systemId = event.getLocation().getSystemId();
    
public StAXSource(XMLStreamReader xmlStreamReader)

Creates a new instance of a StAXSource by supplying an {@link XMLStreamReader}.

XMLStreamReader must be a non-null reference.

XMLStreamReader must be in {@link XMLStreamConstants#START_DOCUMENT} or {@link XMLStreamConstants#START_ELEMENT} state.

param
xmlStreamReader XMLStreamReader used to create this StAXSource.
throws
IllegalArgumentException If xmlStreamReader == null.
throws
IllegalStateException If xmlStreamReader is not in XMLStreamConstants.START_DOCUMENT or XMLStreamConstants.START_ELEMENT state.


        if (xmlStreamReader == null) {
            throw new IllegalArgumentException(
                    "StAXSource(XMLStreamReader) with XMLStreamReader == null");
        }

        int eventType = xmlStreamReader.getEventType();
        if (eventType != XMLStreamConstants.START_DOCUMENT
                && eventType != XMLStreamConstants.START_ELEMENT) {
            throw new IllegalStateException(
                    "StAXSource(XMLStreamReader) with XMLStreamReader"
                    + "not in XMLStreamConstants.START_DOCUMENT or "
                    + "XMLStreamConstants.START_ELEMENT state");
        }

        this.xmlStreamReader = xmlStreamReader;
        systemId = xmlStreamReader.getLocation().getSystemId();
    
Methods Summary
public java.lang.StringgetSystemId()

Get the system identifier used by this StAXSource.

The XMLStreamReader or XMLEventReader used to construct this StAXSource is queried to determine the system identifier of the XML source.

The system identifier may be null or an empty "" String.

return
System identifier used by this StAXSource.


        return systemId;
    
public javax.xml.stream.XMLEventReadergetXMLEventReader()

Get the XMLEventReader used by this StAXSource.

XMLEventReader will be null. if this StAXSource was created with a XMLStreamReader.

return
XMLEventReader used by this StAXSource.


        return xmlEventReader;
    
public javax.xml.stream.XMLStreamReadergetXMLStreamReader()

Get the XMLStreamReader used by this StAXSource.

XMLStreamReader will be null if this StAXSource was created with a XMLEventReader.

return
XMLStreamReader used by this StAXSource.


        return xmlStreamReader;
    
public voidsetSystemId(java.lang.String systemId)

In the context of a StAXSource, it is not appropriate to explicitly set the system identifier. The XMLStreamReader or XMLEventReader used to construct this StAXSource determines the system identifier of the XML source.

An {@link UnsupportedOperationException} is always thrown by this method.

param
systemId Ignored.
throws
UnsupportedOperationException Is always thrown by this method.


        throw new UnsupportedOperationException(
                "StAXSource#setSystemId(systemId) cannot set the "
                + "system identifier for a StAXSource");