2 // http://www.saxproject.org
3 // No warranty; no copyright -- use this as you will.
4 // $Id: ParserFactory.java,v 1.7 2002/01/30 20:52:36 dbrownell Exp $
6 package org.xml.sax.helpers;
8 import org.xml.sax.Parser;
12 * Java-specific class for dynamically loading SAX parsers.
15 * <em>This module, both source code and documentation, is in the
16 * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
17 * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
18 * for further information.
21 * <p><strong>Note:</strong> This class is designed to work with the now-deprecated
22 * SAX1 {@link org.xml.sax.Parser Parser} class. SAX2 applications should use
23 * {@link org.xml.sax.helpers.XMLReaderFactory XMLReaderFactory} instead.</p>
25 * <p>ParserFactory is not part of the platform-independent definition
26 * of SAX; it is an additional convenience class designed
27 * specifically for Java XML application writers. SAX applications
28 * can use the static methods in this class to allocate a SAX parser
29 * dynamically at run-time based either on the value of the
30 * `org.xml.sax.parser' system property or on a string containing the class
33 * <p>Note that the application still requires an XML parser that
34 * implements SAX1.</p>
36 * @deprecated This class works with the deprecated
37 * {@link org.xml.sax.Parser Parser}
40 * @author David Megginson
41 * @version 2.0.1 (sax2r2)
43 public class ParserFactory {
47 * Private null constructor.
49 private ParserFactory ()
55 * Create a new SAX parser using the `org.xml.sax.parser' system property.
57 * <p>The named class must exist and must implement the
58 * {@link org.xml.sax.Parser Parser} interface.</p>
60 * @exception java.lang.NullPointerException There is no value
61 * for the `org.xml.sax.parser' system property.
62 * @exception java.lang.ClassNotFoundException The SAX parser
63 * class was not found (check your CLASSPATH).
64 * @exception IllegalAccessException The SAX parser class was
65 * found, but you do not have permission to load
67 * @exception InstantiationException The SAX parser class was
68 * found but could not be instantiated.
69 * @exception java.lang.ClassCastException The SAX parser class
70 * was found and instantiated, but does not implement
72 * @see #makeParser(java.lang.String)
73 * @see org.xml.sax.Parser
75 public static Parser makeParser ()
76 throws ClassNotFoundException,
77 IllegalAccessException,
78 InstantiationException,
82 String className = System.getProperty("org.xml.sax.parser");
83 if (className == null) {
84 throw new NullPointerException("No value for sax.parser property");
86 return makeParser(className);
92 * Create a new SAX parser object using the class name provided.
94 * <p>The named class must exist and must implement the
95 * {@link org.xml.sax.Parser Parser} interface.</p>
97 * @param className A string containing the name of the
99 * @exception java.lang.ClassNotFoundException The SAX parser
100 * class was not found (check your CLASSPATH).
101 * @exception IllegalAccessException The SAX parser class was
102 * found, but you do not have permission to load
104 * @exception InstantiationException The SAX parser class was
105 * found but could not be instantiated.
106 * @exception java.lang.ClassCastException The SAX parser class
107 * was found and instantiated, but does not implement
108 * org.xml.sax.Parser.
110 * @see org.xml.sax.Parser
112 public static Parser makeParser (String className)
113 throws ClassNotFoundException,
114 IllegalAccessException,
115 InstantiationException,
118 return (Parser) NewInstance.newInstance (
119 NewInstance.getClassLoader (), className);