Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/org/xml/sax/helpers/ParserFactory.java
48576 views
/*1* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425// SAX parser factory.26// http://www.saxproject.org27// No warranty; no copyright -- use this as you will.28// $Id: ParserFactory.java,v 1.2 2004/11/03 22:53:09 jsuttor Exp $2930package org.xml.sax.helpers;3132import org.xml.sax.Parser;333435/**36* Java-specific class for dynamically loading SAX parsers.37*38* <blockquote>39* <em>This module, both source code and documentation, is in the40* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>41* See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>42* for further information.43* </blockquote>44*45* <p><strong>Note:</strong> This class is designed to work with the now-deprecated46* SAX1 {@link org.xml.sax.Parser Parser} class. SAX2 applications should use47* {@link org.xml.sax.helpers.XMLReaderFactory XMLReaderFactory} instead.</p>48*49* <p>ParserFactory is not part of the platform-independent definition50* of SAX; it is an additional convenience class designed51* specifically for Java XML application writers. SAX applications52* can use the static methods in this class to allocate a SAX parser53* dynamically at run-time based either on the value of the54* `org.xml.sax.parser' system property or on a string containing the class55* name.</p>56*57* <p>Note that the application still requires an XML parser that58* implements SAX1.</p>59*60* @deprecated This class works with the deprecated61* {@link org.xml.sax.Parser Parser}62* interface.63* @since SAX 1.064* @author David Megginson65* @version 2.0.1 (sax2r2)66*/67public class ParserFactory {68private static SecuritySupport ss = new SecuritySupport();6970/**71* Private null constructor.72*/73private ParserFactory ()74{75}767778/**79* Create a new SAX parser using the `org.xml.sax.parser' system property.80*81* <p>The named class must exist and must implement the82* {@link org.xml.sax.Parser Parser} interface.</p>83*84* @exception java.lang.NullPointerException There is no value85* for the `org.xml.sax.parser' system property.86* @exception java.lang.ClassNotFoundException The SAX parser87* class was not found (check your CLASSPATH).88* @exception IllegalAccessException The SAX parser class was89* found, but you do not have permission to load90* it.91* @exception InstantiationException The SAX parser class was92* found but could not be instantiated.93* @exception java.lang.ClassCastException The SAX parser class94* was found and instantiated, but does not implement95* org.xml.sax.Parser.96* @see #makeParser(java.lang.String)97* @see org.xml.sax.Parser98*/99public static Parser makeParser ()100throws ClassNotFoundException,101IllegalAccessException,102InstantiationException,103NullPointerException,104ClassCastException105{106String className = ss.getSystemProperty("org.xml.sax.parser");107if (className == null) {108throw new NullPointerException("No value for sax.parser property");109} else {110return makeParser(className);111}112}113114115/**116* Create a new SAX parser object using the class name provided.117*118* <p>The named class must exist and must implement the119* {@link org.xml.sax.Parser Parser} interface.</p>120*121* @param className A string containing the name of the122* SAX parser class.123* @exception java.lang.ClassNotFoundException The SAX parser124* class was not found (check your CLASSPATH).125* @exception IllegalAccessException The SAX parser class was126* found, but you do not have permission to load127* it.128* @exception InstantiationException The SAX parser class was129* found but could not be instantiated.130* @exception java.lang.ClassCastException The SAX parser class131* was found and instantiated, but does not implement132* org.xml.sax.Parser.133* @see #makeParser()134* @see org.xml.sax.Parser135*/136public static Parser makeParser (String className)137throws ClassNotFoundException,138IllegalAccessException,139InstantiationException,140ClassCastException141{142return (Parser) NewInstance.newInstance (143ss.getContextClassLoader(), className);144}145146}147148149