001    package com.thaiopensource.xml.sax;
002    
003    import javax.xml.parsers.SAXParserFactory;
004    import javax.xml.parsers.ParserConfigurationException;
005    import org.xml.sax.XMLReader;
006    import org.xml.sax.SAXException;
007    
008    import com.thaiopensource.xml.sax.XMLReaderCreator;
009    
010    /**
011     * An <code>XMLReaderCreator</code> that uses JAXP 1.1 to create <code>XMLReader</code>s.
012     * An instance of this class is <em>not</em> safe for concurrent access by multiple threads.
013     *
014     * @see javax.xml.parsers.SAXParserFactory
015     * @author <a href="mailto:jjc@jclark.com">James Clark</a>
016     */
017    public class Jaxp11XMLReaderCreator implements XMLReaderCreator {
018        
019      private final SAXParserFactory factory;
020    
021      /**
022       * Default constructor.
023       */
024      public Jaxp11XMLReaderCreator() {
025        factory = SAXParserFactory.newInstance();
026        factory.setNamespaceAware(true);
027        factory.setValidating(false);
028      }
029    
030      public XMLReader createXMLReader() throws SAXException {
031        try {
032          return factory.newSAXParser().getXMLReader();
033        }
034        catch (ParserConfigurationException e) {
035          throw new SAXException(e);
036        }
037      }
038    }