All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.xml.sax.helpers.NewInstance Maven / Gradle / Ivy

Go to download

Xerces2 is the next generation of high performance, fully compliant XML parsers in the Apache Xerces family. This new version of Xerces introduces the Xerces Native Interface (XNI), a complete framework for building parser components and configurations that is extremely modular and easy to program. The Apache Xerces2 parser is the reference implementation of XNI but other parser components, configurations, and parsers can be written using the Xerces Native Interface. For complete design and implementation documents, refer to the XNI Manual. Xerces2 is a fully conforming XML Schema 1.0 processor. A partial experimental implementation of the XML Schema 1.1 Structures and Datatypes Working Drafts (December 2009) and an experimental implementation of the XML Schema Definition Language (XSD): Component Designators (SCD) Candidate Recommendation (January 2010) are provided for evaluation. For more information, refer to the XML Schema page. Xerces2 also provides a complete implementation of the Document Object Model Level 3 Core and Load/Save W3C Recommendations and provides a complete implementation of the XML Inclusions (XInclude) W3C Recommendation. It also provides support for OASIS XML Catalogs v1.1. Xerces2 is able to parse documents written according to the XML 1.1 Recommendation, except that it does not yet provide an option to enable normalization checking as described in section 2.13 of this specification. It also handles namespaces according to the XML Namespaces 1.1 Recommendation, and will correctly serialize XML 1.1 documents if the DOM level 3 load/save APIs are in use.

The newest version!
// NewInstance.java - create a new instance of a class by name.
// http://www.saxproject.org
// Written by Edwin Goei, [email protected]
// and by David Brownell, [email protected]
// NO WARRANTY!  This class is in the Public Domain.
// $Id: NewInstance.java 670295 2008-06-22 01:46:43Z mrglavas $

package org.xml.sax.helpers;

/**
 * Create a new instance of a class by name.
 *
 * 
* This module, both source code and documentation, is in the * Public Domain, and comes with NO WARRANTY. * See http://www.saxproject.org * for further information. *
* *

This class contains a static method for creating an instance of a * class from an explicit class name. It tries to use the thread's context * ClassLoader if possible and falls back to using * Class.forName(String). It also takes into account JDK 1.2+'s * AccessController mechanism for performing its actions.

* *

This code is designed to compile and run on JDK version 1.1 and later * including versions of Java 2.

* *

This is not the NewInstance accompanying SAX 2.0.2; it * represents many fixes to that code. * * @author Edwin Goei, David Brownell * @version 2.0.1 (sax2r2) */ class NewInstance { // constants // governs whether, if we fail in finding a class even // when given a classloader, we'll make a last-ditch attempt // to use the current classloader. private static final boolean DO_FALLBACK = true; /** * Creates a new instance of the specified class name * * Package private so this code is not exposed at the API level. */ static Object newInstance (ClassLoader classLoader, String className) throws ClassNotFoundException, IllegalAccessException, InstantiationException { Class driverClass; if (classLoader == null) { // XXX Use the bootstrap ClassLoader. There is no way to // load a class using the bootstrap ClassLoader that works // in both JDK 1.1 and Java 2. However, this should still // work b/c the following should be true: // // (cl == null) iff current ClassLoader == null // // Thus Class.forName(String) will use the current // ClassLoader which will be the bootstrap ClassLoader. driverClass = Class.forName(className); } else { try { driverClass = classLoader.loadClass(className); } catch (ClassNotFoundException x) { if (DO_FALLBACK) { // Fall back to current classloader classLoader = NewInstance.class.getClassLoader(); if (classLoader != null) { driverClass = classLoader.loadClass(className); } else { driverClass = Class.forName(className); } } else { throw x; } } } Object instance = driverClass.newInstance(); return instance; } /** * Figure out which ClassLoader to use. For JDK 1.2 and later use * the context ClassLoader. */ static ClassLoader getClassLoader () { // Figure out which ClassLoader to use for loading the provider // class. If there is a Context ClassLoader then use it. ClassLoader cl = SecuritySupport.getContextClassLoader(); if (cl == null) { // Assert: we are on JDK 1.1 or we have no Context ClassLoader // so use the current ClassLoader cl = NewInstance.class.getClassLoader(); } return cl; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy