-// XMLReaderFactory.java - factory for creating a new reader.\r
-// Written by David Megginson, sax@megginson.com\r
-// NO WARRANTY! This class is in the Public Domain.\r
-\r
-// $Id: XMLReaderFactory.java,v 1.1 2000/10/02 02:43:20 sboag Exp $\r
-\r
-package org.xml.sax.helpers;\r
-import org.xml.sax.Parser;\r
-import org.xml.sax.XMLReader;\r
-import org.xml.sax.SAXException;\r
-\r
-\r
-/**\r
- * Factory for creating an XML reader.\r
- *\r
- * <blockquote>\r
- * <em>This module, both source code and documentation, is in the\r
- * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>\r
- * </blockquote>\r
- *\r
- * <p>This class contains static methods for creating an XML reader\r
- * from an explicit class name, or for creating an XML reader based\r
- * on the value of the <code>org.xml.sax.driver</code> system \r
- * property:</p>\r
- *\r
- * <pre>\r
- * try {\r
- * XMLReader myReader = XMLReaderFactory.createXMLReader();\r
- * } catch (SAXException e) {\r
- * System.err.println(e.getMessage());\r
- * }\r
- * </pre>\r
- *\r
- * <p>Note that these methods will not be usable in environments where\r
- * system properties are not accessible or where the application or\r
- * applet is not permitted to load classes dynamically.</p>\r
- *\r
- * <p><strong>Note to implementors:</strong> SAX implementations in specialized\r
- * environments may replace this class with a different one optimized for the\r
- * environment, as long as its method signatures remain the same.</p>\r
- *\r
- * @since SAX 2.0\r
- * @author David Megginson, \r
- * <a href="mailto:sax@megginson.com">sax@megginson.com</a>\r
- * @version 2.0\r
- * @see org.xml.sax.XMLReader\r
- */\r
-final public class XMLReaderFactory\r
-{\r
-\r
- /**\r
- * Private constructor.\r
- *\r
- * <p>This constructor prevents the class from being instantiated.</p>\r
- */\r
- private XMLReaderFactory ()\r
- {\r
- }\r
-\r
-\r
- /**\r
- * Attempt to create an XML reader from a system property.\r
- *\r
- * <p>This method uses the value of the system property\r
- * "org.xml.sax.driver" as the full name of a Java class\r
- * and tries to instantiate that class as a SAX2 \r
- * XMLReader.</p>\r
- *\r
- * <p>Note that many Java interpreters allow system properties\r
- * to be specified on the command line.</p>\r
- *\r
- * @return A new XMLReader.\r
- * @exception org.xml.sax.SAXException If the value of the\r
- * "org.xml.sax.driver" system property is null,\r
- * or if the class cannot be loaded and instantiated.\r
- * @see #createXMLReader(java.lang.String)\r
- */\r
- public static XMLReader createXMLReader ()\r
- throws SAXException\r
- {\r
- String className = System.getProperty("org.xml.sax.driver");\r
- if (className == null) {\r
- Parser parser;\r
- try {\r
- parser = ParserFactory.makeParser();\r
- } catch (Exception e) {\r
- parser = null;\r
- }\r
- if (parser == null) {\r
- throw new\r
- SAXException("System property org.xml.sax.driver not specified");\r
- } else {\r
- return new ParserAdapter(parser);\r
- }\r
- } else {\r
- return createXMLReader(className);\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Attempt to create an XML reader from a class name.\r
- *\r
- * <p>Given a class name, this method attempts to load\r
- * and instantiate the class as an XML reader.</p>\r
- *\r
- * @return A new XML reader.\r
- * @exception org.xml.sax.SAXException If the class cannot be\r
- * loaded, instantiated, and cast to XMLReader.\r
- * @see #createXMLReader()\r
- */\r
- public static XMLReader createXMLReader (String className)\r
- throws SAXException\r
- {\r
- try {\r
- return (XMLReader)(Class.forName(className).newInstance());\r
- } catch (ClassNotFoundException e1) {\r
- throw new SAXException("SAX2 driver class " + className +\r
- " not found", e1);\r
- } catch (IllegalAccessException e2) {\r
- throw new SAXException("SAX2 driver class " + className +\r
- " found but cannot be loaded", e2);\r
- } catch (InstantiationException e3) {\r
- throw new SAXException("SAX2 driver class " + className +\r
- " loaded but cannot be instantiated (no empty public constructor?)",\r
- e3);\r
- } catch (ClassCastException e4) {\r
- throw new SAXException("SAX2 driver class " + className +\r
- " does not implement XMLReader", e4);\r
- }\r
- \r
- }\r
-\r
-}\r
-\r
-// end of XMLReaderFactory.java\r