KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thaiopensource > xml > sax > Jaxp11XMLReaderCreator


1 package com.thaiopensource.xml.sax;
2
3 import javax.xml.parsers.SAXParserFactory JavaDoc;
4 import javax.xml.parsers.ParserConfigurationException JavaDoc;
5 import org.xml.sax.XMLReader JavaDoc;
6 import org.xml.sax.SAXException JavaDoc;
7
8 import com.thaiopensource.xml.sax.XMLReaderCreator;
9
10 /**
11  * An <code>XMLReaderCreator</code> that uses JAXP 1.1 to create <code>XMLReader</code>s.
12  * An instance of this class is <em>not</em> safe for concurrent access by multiple threads.
13  *
14  * @see javax.xml.parsers.SAXParserFactory
15  * @author <a HREF="mailto:jjc@jclark.com">James Clark</a>
16  */

17 public class Jaxp11XMLReaderCreator implements XMLReaderCreator {
18     
19   private final SAXParserFactory JavaDoc factory;
20
21   /**
22    * Default constructor.
23    */

24   public Jaxp11XMLReaderCreator() {
25     factory = SAXParserFactory.newInstance();
26     factory.setNamespaceAware(true);
27     factory.setValidating(false);
28   }
29
30   public XMLReader JavaDoc createXMLReader() throws SAXException JavaDoc {
31     try {
32       return factory.newSAXParser().getXMLReader();
33     }
34     catch (ParserConfigurationException JavaDoc e) {
35       throw new SAXException JavaDoc(e);
36     }
37   }
38 }
39
Popular Tags