2 // http://www.saxproject.org
3 // No warranty; no copyright -- use this as you will.
4 // $Id: ParserFactory.java,v 1.1 2004/12/23 22:38:42 mark Exp $
6 package org.xml.sax.helpers;
8 import java.lang.ClassNotFoundException;
9 import java.lang.IllegalAccessException;
10 import java.lang.InstantiationException;
11 import java.lang.SecurityException;
12 import java.lang.ClassCastException;
14 import org.xml.sax.Parser;
18 * Java-specific class for dynamically loading SAX parsers.
21 * <em>This module, both source code and documentation, is in the
22 * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
23 * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
24 * for further information.
27 * <p><strong>Note:</strong> This class is designed to work with the now-deprecated
28 * SAX1 {@link org.xml.sax.Parser Parser} class. SAX2 applications should use
29 * {@link org.xml.sax.helpers.XMLReaderFactory XMLReaderFactory} instead.</p>
31 * <p>ParserFactory is not part of the platform-independent definition
32 * of SAX; it is an additional convenience class designed
33 * specifically for Java XML application writers. SAX applications
34 * can use the static methods in this class to allocate a SAX parser
35 * dynamically at run-time based either on the value of the
36 * `org.xml.sax.parser' system property or on a string containing the class
39 * <p>Note that the application still requires an XML parser that
40 * implements SAX1.</p>
42 * @deprecated This class works with the deprecated
43 * {@link org.xml.sax.Parser Parser}
46 * @author David Megginson
47 * @version 2.0.1 (sax2r2)
49 public class ParserFactory {
53 * Private null constructor.
55 private ParserFactory ()
61 * Create a new SAX parser using the `org.xml.sax.parser' system property.
63 * <p>The named class must exist and must implement the
64 * {@link org.xml.sax.Parser Parser} interface.</p>
66 * @exception java.lang.NullPointerException There is no value
67 * for the `org.xml.sax.parser' system property.
68 * @exception java.lang.ClassNotFoundException The SAX parser
69 * class was not found (check your CLASSPATH).
70 * @exception IllegalAccessException The SAX parser class was
71 * found, but you do not have permission to load
73 * @exception InstantiationException The SAX parser class was
74 * found but could not be instantiated.
75 * @exception java.lang.ClassCastException The SAX parser class
76 * was found and instantiated, but does not implement
78 * @see #makeParser(java.lang.String)
79 * @see org.xml.sax.Parser
81 public static Parser makeParser ()
82 throws ClassNotFoundException,
83 IllegalAccessException,
84 InstantiationException,
88 String className = System.getProperty("org.xml.sax.parser");
89 if (className == null) {
90 throw new NullPointerException("No value for sax.parser property");
92 return makeParser(className);
98 * Create a new SAX parser object using the class name provided.
100 * <p>The named class must exist and must implement the
101 * {@link org.xml.sax.Parser Parser} interface.</p>
103 * @param className A string containing the name of the
105 * @exception java.lang.ClassNotFoundException The SAX parser
106 * class was not found (check your CLASSPATH).
107 * @exception IllegalAccessException The SAX parser class was
108 * found, but you do not have permission to load
110 * @exception InstantiationException The SAX parser class was
111 * found but could not be instantiated.
112 * @exception java.lang.ClassCastException The SAX parser class
113 * was found and instantiated, but does not implement
114 * org.xml.sax.Parser.
116 * @see org.xml.sax.Parser
118 public static Parser makeParser (String className)
119 throws ClassNotFoundException,
120 IllegalAccessException,
121 InstantiationException,
124 return (Parser) NewInstance.newInstance (
125 NewInstance.getClassLoader (), className);