FileDocCategorySizeDatePackage
StAXSource.javaAPI DocGlassfish v2 API10390Fri May 04 22:30:28 BST 2007com.sun.enterprise.jbi.serviceengine.util

StAXSource

public class StAXSource extends SAXSource
A JAXP {@link javax.xml.transform.Source} implementation that wraps the specified {@link javax.xml.stream.XMLStreamReader} or {@link javax.xml.stream.XMLEventReader} for use by applications that expext a {@link javax.xml.transform.Source}.

The fact that StAXSource derives from SAXSource is an implementation detail. Thus in general applications are strongly discouraged from accessing methods defined on SAXSource. In particular:

  • The setXMLReader and setInputSource methods shall never be called.
  • The XMLReader object obtained by the getXMLReader method shall be used only for parsing the InputSource object returned by the getInputSource method.
  • The InputSource object obtained by the getInputSource method shall be used only for being parsed by the XMLReader object returned by the getXMLReader method.

Example:

// create a StAXSource
XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new FileReader(args[0]));
Source staxSource = new StAXSource(reader);

// createa StreamResult
Result streamResult = new StreamResult(System.out);

// run the transform
TransformerFactory.newInstance().newTransformer().transform(staxSource, streamResult);
author
Ryan.Shoemaker@Sun.COM
version
1.0

Fields Summary
private final XMLStreamReaderToContentHandler
reader
private XMLFilterImpl
repeater
private final XMLReader
pseudoParser
Constructors Summary
public StAXSource(XMLStreamReader reader, boolean eagerQuit)
Creates a new {@link javax.xml.transform.Source} for the given {@link XMLStreamReader}. The XMLStreamReader must be pointing at either a {@link javax.xml.stream.XMLStreamConstants#START_DOCUMENT} or {@link javax.xml.stream.XMLStreamConstants#START_ELEMENT} event.

param
reader XMLStreamReader that will be exposed as a Source
throws
IllegalArgumentException iff the reader is null
throws
IllegalStateException iff the reader is not pointing at either a START_DOCUMENT or START_ELEMENT event


                                                                 
         
        if( reader == null )
            throw new IllegalArgumentException();

        int eventType = reader.getEventType();
        if (!(eventType == XMLStreamConstants.START_DOCUMENT)
            && !(eventType == XMLStreamConstants.START_ELEMENT)) {
            throw new IllegalStateException();
        }

        this.reader = new XMLStreamReaderToContentHandler(reader,repeater,eagerQuit);

        super.setXMLReader(pseudoParser);
        // pass a dummy InputSource. We don't care
        super.setInputSource(new InputSource());
    
Methods Summary