2 * Copyright (c) 2001-2004 World Wide Web Consortium,
3 * (Massachusetts Institute of Technology, Institut National de
4 * Recherche en Informatique et en Automatique, Keio University). All
5 * Rights Reserved. This program is distributed under the W3C's Software
6 * Intellectual Property License. This program is distributed in the
7 * hope that it will be useful, but WITHOUT ANY WARRANTY; without even
8 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10 * See W3C License http://www.w3.org/Consortium/Legal/ for more details.
14 $Log: DOM4JTestDocumentBuilderFactory.java,v $
15 Revision 1.2 2004/03/11 01:44:21 dom-ts-4
16 Checkstyle fixes (bug 592)
18 Revision 1.1 2002/02/03 07:47:51 dom-ts-4
23 package org.w3c.domts;
25 import java.lang.reflect.Constructor;
26 import java.lang.reflect.InvocationTargetException;
27 import java.lang.reflect.Method;
29 import org.w3c.dom.DOMImplementation;
30 import org.w3c.dom.Document;
31 import org.xml.sax.XMLReader;
34 * This class implements the generic parser and configuation
35 * abstract class for JAXP supporting parsers.
37 public class DOM4JTestDocumentBuilderFactory
38 extends DOMTestDocumentBuilderFactory {
40 private final Object domFactory;
41 private final Object saxReader;
42 private final org.xml.sax.XMLReader xmlReader;
43 private org.w3c.dom.DOMImplementation domImpl;
44 private final Method readMethod;
47 * Creates a JAXP implementation of DOMTestDocumentBuilderFactory.
48 * @param factory null for default JAXP provider. If not null,
49 * factory will be mutated in constructor and should be released
50 * by calling code upon return.
51 * @param XMLReader if null use default XMLReader. If provided,
52 * it may be mutated and should be released by the caller immediately
53 * after the constructor.
54 * @param settings array of settings, may be null.
56 public DOM4JTestDocumentBuilderFactory(DocumentBuilderSetting[] settings) throws
57 DOMTestIncompatibleException {
61 // The following reflection code is trying to accomplish
63 //domFactory = org.dom4j.dom.DOMDocumentFactory.getInstance();
64 //domImpl = (DOMImplementation) domFactory;
65 //saxReader = new org.dom4j.io.SAXReader(domFactory);
66 //xmlReader = saxReader.getXMLReader();
68 ClassLoader classLoader = ClassLoader.getSystemClassLoader();
69 Class domFactoryClass = classLoader.loadClass(
70 "org.dom4j.dom.DOMDocumentFactory");
71 Method getInstance = domFactoryClass.getMethod("getInstance", new Class[] {});
72 domFactory = getInstance.invoke(null, new Object[] {});
73 domImpl = (DOMImplementation) domFactory;
74 Class saxReaderClass = classLoader.loadClass("org.dom4j.io.SAXReader");
75 Constructor saxReaderConstructor = saxReaderClass.getConstructor(
76 new Class[] {classLoader.loadClass("org.dom4j.DocumentFactory")});
77 saxReader = saxReaderConstructor.newInstance(new Object[] {domFactory});
79 Method getReaderMethod = saxReaderClass.getMethod("getXMLReader",
81 xmlReader = (XMLReader) getReaderMethod.invoke(saxReader, new Object[0]);
83 readMethod = saxReaderClass.getMethod("read", new Class[] {java.net.URL.class});
85 catch (InvocationTargetException ex) {
86 throw new DOMTestIncompatibleException(ex.getTargetException(), null);
88 catch (Exception ex) {
89 throw new DOMTestIncompatibleException(ex, null);
92 // TODO: Process settings
96 public DOMTestDocumentBuilderFactory newInstance(DocumentBuilderSetting[]
97 newSettings) throws DOMTestIncompatibleException {
98 if (newSettings == null) {
101 DocumentBuilderSetting[] mergedSettings = mergeSettings(newSettings);
102 return new DOM4JTestDocumentBuilderFactory(mergedSettings);
105 public Document load(java.net.URL url) throws DOMTestLoadException {
107 throw new NullPointerException("url");
109 if (saxReader == null) {
110 throw new NullPointerException("saxReader");
113 return (org.w3c.dom.Document) readMethod.invoke(saxReader,
116 catch (InvocationTargetException ex) {
117 ex.getTargetException().printStackTrace();
118 throw new DOMTestLoadException(ex.getTargetException());
120 catch (Exception ex) {
121 ex.printStackTrace();
122 throw new DOMTestLoadException(ex);
126 public DOMImplementation getDOMImplementation() {
130 public boolean hasFeature(String feature, String version) {
131 return domImpl.hasFeature(feature, version);
134 public boolean isCoalescing() {
138 public boolean isExpandEntityReferences() {
142 public boolean isIgnoringElementContentWhitespace() {
146 public boolean isNamespaceAware() {
150 public boolean isValidating() {