KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xml > sax > helpers > ParserFactory


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.1.24.1 2004/05/01 08:34:46 jsuttor Exp $
5

6 package org.xml.sax.helpers;
7
8 import java.lang.ClassNotFoundException JavaDoc;
9 import java.lang.IllegalAccessException JavaDoc;
10 import java.lang.InstantiationException JavaDoc;
11 import java.lang.SecurityException JavaDoc;
12 import java.lang.ClassCastException JavaDoc;
13
14 import org.xml.sax.Parser JavaDoc;
15
16
17 /**
18  * Java-specific class for dynamically loading SAX parsers.
19  *
20  * <blockquote>
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.
25  * </blockquote>
26  *
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>
30  *
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
37  * name.</p>
38  *
39  * <p>Note that the application still requires an XML parser that
40  * implements SAX1.</p>
41  *
42  * @deprecated This class works with the deprecated
43  * {@link org.xml.sax.Parser Parser}
44  * interface.
45  * @since SAX 1.0
46  * @author David Megginson
47  * @version 2.0.1 (sax2r2)
48  */

49 public class ParserFactory {
50     
51     
52     /**
53      * Private null constructor.
54      */

55     private ParserFactory ()
56     {
57     }
58     
59     
60     /**
61      * Create a new SAX parser using the `org.xml.sax.parser' system property.
62      *
63      * <p>The named class must exist and must implement the
64      * {@link org.xml.sax.Parser Parser} interface.</p>
65      *
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
72      * it.
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
77      * org.xml.sax.Parser.
78      * @see #makeParser(java.lang.String)
79      * @see org.xml.sax.Parser
80      */

81     public static Parser JavaDoc makeParser ()
82     throws ClassNotFoundException JavaDoc,
83     IllegalAccessException JavaDoc,
84     InstantiationException JavaDoc,
85     NullPointerException JavaDoc,
86     ClassCastException JavaDoc
87     {
88     String JavaDoc className = System.getProperty("org.xml.sax.parser");
89     if (className == null) {
90         throw new NullPointerException JavaDoc("No value for sax.parser property");
91     } else {
92         return makeParser(className);
93     }
94     }
95     
96     
97     /**
98      * Create a new SAX parser object using the class name provided.
99      *
100      * <p>The named class must exist and must implement the
101      * {@link org.xml.sax.Parser Parser} interface.</p>
102      *
103      * @param className A string containing the name of the
104      * SAX parser class.
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
109      * it.
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.
115      * @see #makeParser()
116      * @see org.xml.sax.Parser
117      */

118     public static Parser JavaDoc makeParser (String JavaDoc className)
119     throws ClassNotFoundException JavaDoc,
120     IllegalAccessException JavaDoc,
121     InstantiationException JavaDoc,
122     ClassCastException JavaDoc
123     {
124     return (Parser JavaDoc) NewInstance.newInstance (
125         NewInstance.getClassLoader (), className);
126     }
127     
128 }
129
130
Popular Tags