6
|
1 |
/*
|
|
2 |
* Copyright 2000-2005 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
// SAX parser factory.
|
|
27 |
// http://www.saxproject.org
|
|
28 |
// No warranty; no copyright -- use this as you will.
|
|
29 |
// $Id: ParserFactory.java,v 1.2 2004/11/03 22:53:09 jsuttor Exp $
|
|
30 |
|
|
31 |
package org.xml.sax.helpers;
|
|
32 |
|
|
33 |
import java.lang.ClassNotFoundException;
|
|
34 |
import java.lang.IllegalAccessException;
|
|
35 |
import java.lang.InstantiationException;
|
|
36 |
import java.lang.SecurityException;
|
|
37 |
import java.lang.ClassCastException;
|
|
38 |
|
|
39 |
import org.xml.sax.Parser;
|
|
40 |
|
|
41 |
|
|
42 |
/**
|
|
43 |
* Java-specific class for dynamically loading SAX parsers.
|
|
44 |
*
|
|
45 |
* <blockquote>
|
|
46 |
* <em>This module, both source code and documentation, is in the
|
|
47 |
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
|
|
48 |
* See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
|
|
49 |
* for further information.
|
|
50 |
* </blockquote>
|
|
51 |
*
|
|
52 |
* <p><strong>Note:</strong> This class is designed to work with the now-deprecated
|
|
53 |
* SAX1 {@link org.xml.sax.Parser Parser} class. SAX2 applications should use
|
|
54 |
* {@link org.xml.sax.helpers.XMLReaderFactory XMLReaderFactory} instead.</p>
|
|
55 |
*
|
|
56 |
* <p>ParserFactory is not part of the platform-independent definition
|
|
57 |
* of SAX; it is an additional convenience class designed
|
|
58 |
* specifically for Java XML application writers. SAX applications
|
|
59 |
* can use the static methods in this class to allocate a SAX parser
|
|
60 |
* dynamically at run-time based either on the value of the
|
|
61 |
* `org.xml.sax.parser' system property or on a string containing the class
|
|
62 |
* name.</p>
|
|
63 |
*
|
|
64 |
* <p>Note that the application still requires an XML parser that
|
|
65 |
* implements SAX1.</p>
|
|
66 |
*
|
|
67 |
* @deprecated This class works with the deprecated
|
|
68 |
* {@link org.xml.sax.Parser Parser}
|
|
69 |
* interface.
|
|
70 |
* @since SAX 1.0
|
|
71 |
* @author David Megginson
|
|
72 |
*/
|
|
73 |
public class ParserFactory {
|
|
74 |
|
|
75 |
|
|
76 |
/**
|
|
77 |
* Private null constructor.
|
|
78 |
*/
|
|
79 |
private ParserFactory ()
|
|
80 |
{
|
|
81 |
}
|
|
82 |
|
|
83 |
|
|
84 |
/**
|
|
85 |
* Create a new SAX parser using the `org.xml.sax.parser' system property.
|
|
86 |
*
|
|
87 |
* <p>The named class must exist and must implement the
|
|
88 |
* {@link org.xml.sax.Parser Parser} interface.</p>
|
|
89 |
*
|
|
90 |
* @exception java.lang.NullPointerException There is no value
|
|
91 |
* for the `org.xml.sax.parser' system property.
|
|
92 |
* @exception java.lang.ClassNotFoundException The SAX parser
|
|
93 |
* class was not found (check your CLASSPATH).
|
|
94 |
* @exception IllegalAccessException The SAX parser class was
|
|
95 |
* found, but you do not have permission to load
|
|
96 |
* it.
|
|
97 |
* @exception InstantiationException The SAX parser class was
|
|
98 |
* found but could not be instantiated.
|
|
99 |
* @exception java.lang.ClassCastException The SAX parser class
|
|
100 |
* was found and instantiated, but does not implement
|
|
101 |
* org.xml.sax.Parser.
|
|
102 |
* @see #makeParser(java.lang.String)
|
|
103 |
* @see org.xml.sax.Parser
|
|
104 |
*/
|
|
105 |
public static Parser makeParser ()
|
|
106 |
throws ClassNotFoundException,
|
|
107 |
IllegalAccessException,
|
|
108 |
InstantiationException,
|
|
109 |
NullPointerException,
|
|
110 |
ClassCastException
|
|
111 |
{
|
|
112 |
String className = System.getProperty("org.xml.sax.parser");
|
|
113 |
if (className == null) {
|
|
114 |
throw new NullPointerException("No value for sax.parser property");
|
|
115 |
} else {
|
|
116 |
return makeParser(className);
|
|
117 |
}
|
|
118 |
}
|
|
119 |
|
|
120 |
|
|
121 |
/**
|
|
122 |
* Create a new SAX parser object using the class name provided.
|
|
123 |
*
|
|
124 |
* <p>The named class must exist and must implement the
|
|
125 |
* {@link org.xml.sax.Parser Parser} interface.</p>
|
|
126 |
*
|
|
127 |
* @param className A string containing the name of the
|
|
128 |
* SAX parser class.
|
|
129 |
* @exception java.lang.ClassNotFoundException The SAX parser
|
|
130 |
* class was not found (check your CLASSPATH).
|
|
131 |
* @exception IllegalAccessException The SAX parser class was
|
|
132 |
* found, but you do not have permission to load
|
|
133 |
* it.
|
|
134 |
* @exception InstantiationException The SAX parser class was
|
|
135 |
* found but could not be instantiated.
|
|
136 |
* @exception java.lang.ClassCastException The SAX parser class
|
|
137 |
* was found and instantiated, but does not implement
|
|
138 |
* org.xml.sax.Parser.
|
|
139 |
* @see #makeParser()
|
|
140 |
* @see org.xml.sax.Parser
|
|
141 |
*/
|
|
142 |
public static Parser makeParser (String className)
|
|
143 |
throws ClassNotFoundException,
|
|
144 |
IllegalAccessException,
|
|
145 |
InstantiationException,
|
|
146 |
ClassCastException
|
|
147 |
{
|
|
148 |
return (Parser) NewInstance.newInstance (
|
|
149 |
NewInstance.getClassLoader (), className);
|
|
150 |
}
|
|
151 |
|
|
152 |
}
|