Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

DOM4JTestDocumentBuilderFactory.java

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001 World Wide Web Consortium,
00003  * (Massachusetts Institute of Technology, Institut National de
00004  * Recherche en Informatique et en Automatique, Keio University). All
00005  * Rights Reserved. This program is distributed under the W3C's Software
00006  * Intellectual Property License. This program is distributed in the
00007  * hope that it will be useful, but WITHOUT ANY WARRANTY; without even
00008  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00009  * PURPOSE.
00010  * See W3C License http://www.w3.org/Consortium/Legal/ for more details.
00011  */
00012 
00013  /*
00014  $Log: DOM4JTestDocumentBuilderFactory.java,v $
00015  Revision 1.1  2002/02/03 07:47:51  dom-ts-4
00016  More missing files
00017 
00018  */
00019 
00020 package org.w3c.domts;
00021 
00022 import javax.xml.parsers.*;
00023 import org.w3c.dom.*;
00024 import org.w3c.domts.*;
00025 import org.xml.sax.*;
00026 import java.lang.reflect.*;
00027 
00032 public class DOM4JTestDocumentBuilderFactory
00033   extends DOMTestDocumentBuilderFactory {
00034 
00035   private final Object domFactory;
00036   private final Object saxReader;
00037   private final org.xml.sax.XMLReader xmlReader;
00038   private org.w3c.dom.DOMImplementation domImpl;
00039   private final Method readMethod;
00040 
00051   public DOM4JTestDocumentBuilderFactory(DocumentBuilderSetting[] settings)
00052     throws DOMTestIncompatibleException {
00053     super(settings);
00054     try {
00055       //
00056       //   The following reflection code is trying to accomplish
00057       //
00058       //domFactory = org.dom4j.dom.DOMDocumentFactory.getInstance();
00059       //domImpl = (DOMImplementation) domFactory;
00060       //saxReader = new org.dom4j.io.SAXReader(domFactory);
00061       //xmlReader = saxReader.getXMLReader();
00062 
00063       ClassLoader classLoader = ClassLoader.getSystemClassLoader();
00064       Class domFactoryClass = classLoader.loadClass("org.dom4j.dom.DOMDocumentFactory");
00065       Method getInstance = domFactoryClass.getMethod("getInstance", new Class[] {});
00066       domFactory = getInstance.invoke(null,new Object[] {});
00067       domImpl = (DOMImplementation) domFactory;
00068       Class saxReaderClass = classLoader.loadClass("org.dom4j.io.SAXReader");
00069       Constructor saxReaderConstructor = saxReaderClass.getConstructor(
00070         new Class[] { classLoader.loadClass("org.dom4j.DocumentFactory") });
00071       saxReader = saxReaderConstructor.newInstance(new Object[] { domFactory } );
00072 
00073       Method getReaderMethod = saxReaderClass.getMethod("getXMLReader", new Class[] {});
00074       xmlReader = (XMLReader) getReaderMethod.invoke(saxReader, new Object[0]);
00075 
00076       readMethod = saxReaderClass.getMethod("read",new Class[] { java.net.URL.class } );
00077     }
00078     catch(InvocationTargetException ex) {
00079       throw new DOMTestIncompatibleException(ex.getTargetException(),null);
00080     }
00081     catch(Exception ex) {
00082       throw new DOMTestIncompatibleException(ex,null);
00083     }
00084     //
00085     //   TODO: Process settings
00086     //
00087   }
00088 
00089   public DOMTestDocumentBuilderFactory newInstance(DocumentBuilderSetting[] newSettings)
00090     throws DOMTestIncompatibleException {
00091     if(newSettings == null) {
00092       return this;
00093     }
00094     DocumentBuilderSetting[] mergedSettings = mergeSettings(newSettings);
00095     return new DOM4JTestDocumentBuilderFactory(mergedSettings);
00096   }
00097 
00098   public Document load(java.net.URL url) throws DOMTestLoadException {
00099     if(url == null) {
00100         throw new NullPointerException("url");
00101     }
00102     if(saxReader == null) {
00103         throw new NullPointerException("saxReader");
00104     }
00105     try {
00106       return (org.w3c.dom.Document) readMethod.invoke(saxReader, new Object[] { url });
00107     }
00108     catch(InvocationTargetException ex) {
00109       ex.getTargetException().printStackTrace();
00110       throw new DOMTestLoadException(ex.getTargetException());
00111     }
00112     catch(Exception ex) {
00113       ex.printStackTrace();
00114       throw new DOMTestLoadException(ex);
00115     }
00116   }
00117 
00118   public DOMImplementation getDOMImplementation() {
00119     return domImpl;
00120   }
00121 
00122   public boolean hasFeature(String feature, String version) {
00123     return domImpl.hasFeature(feature,version);
00124   }
00125 
00126     public boolean isCoalescing() {
00127       return false;
00128     }
00129 
00130     public boolean isExpandEntityReferences() {
00131       return false;
00132     }
00133 
00134     public boolean isIgnoringElementContentWhitespace() {
00135       return false;
00136     }
00137 
00138     public boolean isNamespaceAware() {
00139       return true;
00140     }
00141 
00142     public boolean isValidating() {
00143       return false;
00144     }
00145 
00146 }
00147 

Generated on Thu Feb 14 19:46:02 2002 for DOM Level 1 Core Test Suite by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001