Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/org/xml/sax/helpers/ParserFactory.java
48576 views
1
/*
2
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. 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. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* 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 org.xml.sax.Parser;
34
35
36
/**
37
* Java-specific class for dynamically loading SAX parsers.
38
*
39
* <blockquote>
40
* <em>This module, both source code and documentation, is in the
41
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
42
* See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
43
* for further information.
44
* </blockquote>
45
*
46
* <p><strong>Note:</strong> This class is designed to work with the now-deprecated
47
* SAX1 {@link org.xml.sax.Parser Parser} class. SAX2 applications should use
48
* {@link org.xml.sax.helpers.XMLReaderFactory XMLReaderFactory} instead.</p>
49
*
50
* <p>ParserFactory is not part of the platform-independent definition
51
* of SAX; it is an additional convenience class designed
52
* specifically for Java XML application writers. SAX applications
53
* can use the static methods in this class to allocate a SAX parser
54
* dynamically at run-time based either on the value of the
55
* `org.xml.sax.parser' system property or on a string containing the class
56
* name.</p>
57
*
58
* <p>Note that the application still requires an XML parser that
59
* implements SAX1.</p>
60
*
61
* @deprecated This class works with the deprecated
62
* {@link org.xml.sax.Parser Parser}
63
* interface.
64
* @since SAX 1.0
65
* @author David Megginson
66
* @version 2.0.1 (sax2r2)
67
*/
68
public class ParserFactory {
69
private static SecuritySupport ss = new SecuritySupport();
70
71
/**
72
* Private null constructor.
73
*/
74
private ParserFactory ()
75
{
76
}
77
78
79
/**
80
* Create a new SAX parser using the `org.xml.sax.parser' system property.
81
*
82
* <p>The named class must exist and must implement the
83
* {@link org.xml.sax.Parser Parser} interface.</p>
84
*
85
* @exception java.lang.NullPointerException There is no value
86
* for the `org.xml.sax.parser' system property.
87
* @exception java.lang.ClassNotFoundException The SAX parser
88
* class was not found (check your CLASSPATH).
89
* @exception IllegalAccessException The SAX parser class was
90
* found, but you do not have permission to load
91
* it.
92
* @exception InstantiationException The SAX parser class was
93
* found but could not be instantiated.
94
* @exception java.lang.ClassCastException The SAX parser class
95
* was found and instantiated, but does not implement
96
* org.xml.sax.Parser.
97
* @see #makeParser(java.lang.String)
98
* @see org.xml.sax.Parser
99
*/
100
public static Parser makeParser ()
101
throws ClassNotFoundException,
102
IllegalAccessException,
103
InstantiationException,
104
NullPointerException,
105
ClassCastException
106
{
107
String className = ss.getSystemProperty("org.xml.sax.parser");
108
if (className == null) {
109
throw new NullPointerException("No value for sax.parser property");
110
} else {
111
return makeParser(className);
112
}
113
}
114
115
116
/**
117
* Create a new SAX parser object using the class name provided.
118
*
119
* <p>The named class must exist and must implement the
120
* {@link org.xml.sax.Parser Parser} interface.</p>
121
*
122
* @param className A string containing the name of the
123
* SAX parser class.
124
* @exception java.lang.ClassNotFoundException The SAX parser
125
* class was not found (check your CLASSPATH).
126
* @exception IllegalAccessException The SAX parser class was
127
* found, but you do not have permission to load
128
* it.
129
* @exception InstantiationException The SAX parser class was
130
* found but could not be instantiated.
131
* @exception java.lang.ClassCastException The SAX parser class
132
* was found and instantiated, but does not implement
133
* org.xml.sax.Parser.
134
* @see #makeParser()
135
* @see org.xml.sax.Parser
136
*/
137
public static Parser makeParser (String className)
138
throws ClassNotFoundException,
139
IllegalAccessException,
140
InstantiationException,
141
ClassCastException
142
{
143
return (Parser) NewInstance.newInstance (
144
ss.getContextClassLoader(), className);
145
}
146
147
}
148
149