1 /* 2 * Copyright (c) 2000, 2019, 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 package org.xml.sax.helpers; 27 28 import jdk.xml.internal.SecuritySupport; 29 30 /** 31 * Java-specific class for dynamically loading SAX parsers. 32 * 33 * <p><strong>Note:</strong> This class is designed to work with the now-deprecated 34 * SAX1 {@link org.xml.sax.Parser Parser} class. SAX2 applications should use 35 * {@link org.xml.sax.helpers.XMLReaderFactory XMLReaderFactory} instead.</p> 36 * 37 * <p>ParserFactory is not part of the platform-independent definition 38 * of SAX; it is an additional convenience class designed 39 * specifically for Java XML application writers. SAX applications 40 * can use the static methods in this class to allocate a SAX parser 41 * dynamically at run-time based either on the value of the 42 * `org.xml.sax.parser' system property or on a string containing the class 43 * name.</p> 44 * 45 * <p>Note that the application still requires an XML parser that 46 * implements SAX1.</p> 47 * 48 * @deprecated This class works with the deprecated 49 * {@link org.xml.sax.Parser Parser} 50 * interface. 51 * @since 1.4, SAX 1.0 52 * @author David Megginson 53 * @version 2.0.1 (sax2r2) 54 */ 55 @SuppressWarnings( "deprecation" ) 56 @Deprecated(since="1.5") 57 public class ParserFactory { 58 59 /** 60 * Private null constructor. 61 */ 62 private ParserFactory () 63 { 64 } 65 66 67 /** 68 * Create a new SAX parser using the `org.xml.sax.parser' system property. 69 * 70 * <p>The named class must exist and must implement the 71 * {@link org.xml.sax.Parser Parser} interface.</p> 72 * 73 * @exception java.lang.NullPointerException There is no value 74 * for the `org.xml.sax.parser' system property. 75 * @exception java.lang.ClassNotFoundException The SAX parser 76 * class was not found (check your CLASSPATH). 77 * @exception IllegalAccessException The SAX parser class was 78 * found, but you do not have permission to load 79 * it. 80 * @exception InstantiationException The SAX parser class was 81 * found but could not be instantiated. 82 * @exception java.lang.ClassCastException The SAX parser class 83 * was found and instantiated, but does not implement 84 * org.xml.sax.Parser. 85 * @see #makeParser(java.lang.String) 86 * @see org.xml.sax.Parser 87 */ 88 public static org.xml.sax.Parser makeParser () 89 throws ClassNotFoundException, 90 IllegalAccessException, 91 InstantiationException, 92 NullPointerException, 93 ClassCastException 94 { 95 String className = SecuritySupport.getSystemProperty("org.xml.sax.parser"); 96 if (className == null) { 97 throw new NullPointerException("No value for sax.parser property"); 98 } else { 99 return makeParser(className); 100 } 101 } 102 103 104 /** 105 * Create a new SAX parser object using the class name provided. 106 * 107 * <p>The named class must exist and must implement the 108 * {@link org.xml.sax.Parser Parser} interface.</p> 109 * 110 * @param className A string containing the name of the 111 * SAX parser class. 112 * @exception java.lang.ClassNotFoundException The SAX parser 113 * class was not found (check your CLASSPATH). 114 * @exception IllegalAccessException The SAX parser class was 115 * found, but you do not have permission to load 116 * it. 117 * @exception InstantiationException The SAX parser class was 118 * found but could not be instantiated. 119 * @exception java.lang.ClassCastException The SAX parser class 120 * was found and instantiated, but does not implement 121 * org.xml.sax.Parser. 122 * @see #makeParser() 123 * @see org.xml.sax.Parser 124 */ 125 public static org.xml.sax.Parser makeParser (String className) 126 throws ClassNotFoundException, 127 IllegalAccessException, 128 InstantiationException, 129 ClassCastException 130 { 131 return NewInstance.newInstance (org.xml.sax.Parser.class, 132 SecuritySupport.getClassLoader(), className); 133 } 134 135 }