/* * Copyright (c) 2001 World Wide Web Consortium, * (Massachusetts Institute of Technology, Institut National de * Recherche en Informatique et en Automatique, Keio University). All * Rights Reserved. This program is distributed under the W3C's Software * Intellectual Property License. This program is distributed in the * hope that it will be useful, but WITHOUT ANY WARRANTY; without even * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. * See W3C License http://www.w3.org/Consortium/Legal/ for more details. */ package org.w3c.dom; /** *
* DOMImplementationFactory
provides a static method to get a
* reference to a DOMImplementation. The actual class to be returned by
* getDOMImplementation
can be specified by the application or the
* implementation, depending on the context, through the Java system property
* "org.w3c.dom.DOMImplementation". In addition, an implementation can provide
* its own version of this class, with the same class name and package name,
* in order to set the default name to the desired value.
*
* Because the DOM only defines interfaces, applications have to rely on some * "proprietary" API to start from. Typically, a Java application starts with * a line of code such as: *
DOMImplementation impl = org.apache.xerces.dom.DOMImplementationImpl.getDOMImplementation();* * *
* With DOMImplementationFactory, the first line of an application * typically becomes something like: *
DOMImplementation impl = DOMImplementationFactory.getDOMImplementation();* * *
* See also the Document Object Model (DOM) Level 3 Core Specification. *
* ** Since there is no language independent way of "bootstrapping" a DOM implementation, * this section describes a solution for Java. Hopefully, similar solutions could be * defined for other language bindings. *
* ** Disclaimer: this is an unofficial test version of DOMImplementationFactory. *
* * @see DOMImplementation */ public abstract class DOMImplementationFactory { // The system property to specify the DOMImplementation class name. private static String property = "org.w3c.dom.DOMImplementation"; // The default DOMImplementation class name to use. private static String defaultImpl = "NO DEFAULT IMPLEMENTATION SET"; /** * Returns a DOMImplementation **/ public static DOMImplementation getDOMImplementation() throws ClassNotFoundException, InstantiationException, IllegalAccessException, ClassCastException { // Retrieve the system property String impl; try { impl = System.getProperty(property, defaultImpl); } catch (SecurityException e) { // fallback on default implementation in case of security pb impl = defaultImpl; } // Attempt to load, instantiate and return the implementation class return (DOMImplementation) Class.forName(impl).newInstance(); } }