00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00057
00058
00059
00060
00061
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
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