1 // SAX parser factory.
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 $
5 
6 package org.xml.sax.helpers;
7 
8 import org.xml.sax.Parser;
9 
10 
11 /**
12  * Java-specific class for dynamically loading SAX parsers.
13  *
14  * <blockquote>
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.
19  * </blockquote>
20  *
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>
24  *
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
31  * name.</p>
32  *
33  * <p>Note that the application still requires an XML parser that
34  * implements SAX1.</p>
35  *
36  * @deprecated This class works with the deprecated
37  *             {@link org.xml.sax.Parser Parser}
38  *             interface.
39  * @since SAX 1.0
40  * @author David Megginson
41  * @version 2.0.1 (sax2r2)
42  */
43 @Deprecated
44 public class ParserFactory {
45 
46 
47     /**
48      * Private null constructor.
49      */
ParserFactory()50     private ParserFactory ()
51     {
52     }
53 
54 
55     /**
56      * Create a new SAX parser using the `org.xml.sax.parser' system property.
57      *
58      * <p>The named class must exist and must implement the
59      * {@link org.xml.sax.Parser Parser} interface.</p>
60      *
61      * @return the newly created parser.
62      *
63      * @exception java.lang.NullPointerException There is no value
64      *            for the `org.xml.sax.parser' system property.
65      * @exception java.lang.ClassNotFoundException The SAX parser
66      *            class was not found (check your CLASSPATH).
67      * @exception IllegalAccessException The SAX parser class was
68      *            found, but you do not have permission to load
69      *            it.
70      * @exception InstantiationException The SAX parser class was
71      *            found but could not be instantiated.
72      * @exception java.lang.ClassCastException The SAX parser class
73      *            was found and instantiated, but does not implement
74      *            org.xml.sax.Parser.
75      * @see #makeParser(java.lang.String)
76      * @see org.xml.sax.Parser
77      */
makeParser()78     public static Parser makeParser ()
79     throws ClassNotFoundException,
80     IllegalAccessException,
81     InstantiationException,
82     NullPointerException,
83     ClassCastException
84     {
85     String className = System.getProperty("org.xml.sax.parser");
86     if (className == null) {
87         throw new NullPointerException("No value for sax.parser property");
88     } else {
89         return makeParser(className);
90     }
91     }
92 
93 
94     /**
95      * Create a new SAX parser object using the class name provided.
96      *
97      * <p>The named class must exist and must implement the
98      * {@link org.xml.sax.Parser Parser} interface.</p>
99      *
100      * @return the newly created parser.
101      *
102      * @param className A string containing the name of the
103      *                  SAX parser class.
104      * @exception java.lang.ClassNotFoundException The SAX parser
105      *            class was not found (check your CLASSPATH).
106      * @exception IllegalAccessException The SAX parser class was
107      *            found, but you do not have permission to load
108      *            it.
109      * @exception InstantiationException The SAX parser class was
110      *            found but could not be instantiated.
111      * @exception java.lang.ClassCastException The SAX parser class
112      *            was found and instantiated, but does not implement
113      *            org.xml.sax.Parser.
114      * @see #makeParser()
115      * @see org.xml.sax.Parser
116      */
makeParser(String className)117     public static Parser makeParser (String className)
118     throws ClassNotFoundException,
119     IllegalAccessException,
120     InstantiationException,
121     ClassCastException
122     {
123     return (Parser) NewInstance.newInstance (
124         NewInstance.getClassLoader (), className);
125     }
126 
127 }
128 
129