< prev index next >

src/java.xml/share/classes/org/xml/sax/helpers/XMLReaderFactory.java

Print this page


   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


 149 
 150         // 4. Distro-specific fallback
 151         if (className == null) {
 152             return new com.sun.org.apache.xerces.internal.parsers.SAXParser();
 153         }
 154 
 155         return loadClass (cl, className);
 156     }
 157 
 158 
 159     /**
 160      * Attempt to create an XML reader from a class name.
 161      *
 162      * <p>Given a class name, this method attempts to load
 163      * and instantiate the class as an XML reader.
 164      *
 165      * <p>Note that this method will not be usable in environments where
 166      * the caller (perhaps an applet) is not permitted to load classes
 167      * dynamically.
 168      *

 169      * @return A new XML reader.
 170      * @exception org.xml.sax.SAXException If the class cannot be
 171      *            loaded, instantiated, and cast to XMLReader.
 172      * @see #createXMLReader()
 173      */
 174     public static XMLReader createXMLReader (String className)
 175         throws SAXException
 176     {
 177         return loadClass (SecuritySupport.getClassLoader(), className);
 178     }
 179 
 180     private static XMLReader loadClass (ClassLoader loader, String className)
 181     throws SAXException
 182     {
 183         try {
 184             return NewInstance.newInstance (XMLReader.class, loader, className);
 185         } catch (ClassNotFoundException e1) {
 186             throw new SAXException("SAX2 driver class " + className +
 187                                    " not found", e1);
 188         } catch (IllegalAccessException e2) {


   1 /*
   2  * Copyright (c) 2000, 2020, 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


 149 
 150         // 4. Distro-specific fallback
 151         if (className == null) {
 152             return new com.sun.org.apache.xerces.internal.parsers.SAXParser();
 153         }
 154 
 155         return loadClass (cl, className);
 156     }
 157 
 158 
 159     /**
 160      * Attempt to create an XML reader from a class name.
 161      *
 162      * <p>Given a class name, this method attempts to load
 163      * and instantiate the class as an XML reader.
 164      *
 165      * <p>Note that this method will not be usable in environments where
 166      * the caller (perhaps an applet) is not permitted to load classes
 167      * dynamically.
 168      *
 169      * @param className a class name
 170      * @return A new XML reader.
 171      * @exception org.xml.sax.SAXException If the class cannot be
 172      *            loaded, instantiated, and cast to XMLReader.
 173      * @see #createXMLReader()
 174      */
 175     public static XMLReader createXMLReader (String className)
 176         throws SAXException
 177     {
 178         return loadClass (SecuritySupport.getClassLoader(), className);
 179     }
 180 
 181     private static XMLReader loadClass (ClassLoader loader, String className)
 182     throws SAXException
 183     {
 184         try {
 185             return NewInstance.newInstance (XMLReader.class, loader, className);
 186         } catch (ClassNotFoundException e1) {
 187             throw new SAXException("SAX2 driver class " + className +
 188                                    " not found", e1);
 189         } catch (IllegalAccessException e2) {


< prev index next >