FileDocCategorySizeDatePackage
DOM4JTestDocumentBuilderFactory.javaAPI DocAndroid 1.5 API5023Wed May 06 22:41:04 BST 2009org.w3c.domts

DOM4JTestDocumentBuilderFactory

public class DOM4JTestDocumentBuilderFactory extends DOMTestDocumentBuilderFactory
This class implements the generic parser and configuation abstract class for JAXP supporting parsers.

Fields Summary
private final Object
domFactory
private final Object
saxReader
private final XMLReader
xmlReader
private DOMImplementation
domImpl
private final Method
readMethod
Constructors Summary
public DOM4JTestDocumentBuilderFactory(DocumentBuilderSetting[] settings)
Creates a JAXP implementation of DOMTestDocumentBuilderFactory.

param
factory null for default JAXP provider. If not null, factory will be mutated in constructor and should be released by calling code upon return.
param
XMLReader if null use default XMLReader. If provided, it may be mutated and should be released by the caller immediately after the constructor.
param
settings array of settings, may be null.

    super(settings);
    try {
      //
      //   The following reflection code is trying to accomplish
      //
      //domFactory = org.dom4j.dom.DOMDocumentFactory.getInstance();
      //domImpl = (DOMImplementation) domFactory;
      //saxReader = new org.dom4j.io.SAXReader(domFactory);
      //xmlReader = saxReader.getXMLReader();

      ClassLoader classLoader = ClassLoader.getSystemClassLoader();
      Class domFactoryClass = classLoader.loadClass(
          "org.dom4j.dom.DOMDocumentFactory");
      Method getInstance = domFactoryClass.getMethod("getInstance", new Class[] {});
      domFactory = getInstance.invoke(null, new Object[] {});
      domImpl = (DOMImplementation) domFactory;
      Class saxReaderClass = classLoader.loadClass("org.dom4j.io.SAXReader");
      Constructor saxReaderConstructor = saxReaderClass.getConstructor(
          new Class[] {classLoader.loadClass("org.dom4j.DocumentFactory")});
      saxReader = saxReaderConstructor.newInstance(new Object[] {domFactory});

      Method getReaderMethod = saxReaderClass.getMethod("getXMLReader",
          new Class[] {});
      xmlReader = (XMLReader) getReaderMethod.invoke(saxReader, new Object[0]);

      readMethod = saxReaderClass.getMethod("read", new Class[] {java.net.URL.class});
    }
    catch (InvocationTargetException ex) {
      throw new DOMTestIncompatibleException(ex.getTargetException(), null);
    }
    catch (Exception ex) {
      throw new DOMTestIncompatibleException(ex, null);
    }
    //
    //   TODO: Process settings
    //
  
Methods Summary
public org.w3c.dom.DOMImplementationgetDOMImplementation()

    return domImpl;
  
public booleanhasFeature(java.lang.String feature, java.lang.String version)

    return domImpl.hasFeature(feature, version);
  
public booleanisCoalescing()

    return false;
  
public booleanisExpandEntityReferences()

    return false;
  
public booleanisIgnoringElementContentWhitespace()

    return false;
  
public booleanisNamespaceAware()

    return true;
  
public booleanisValidating()

    return false;
  
public org.w3c.dom.Documentload(java.net.URL url)

    if (url == null) {
      throw new NullPointerException("url");
    }
    if (saxReader == null) {
      throw new NullPointerException("saxReader");
    }
    try {
      return (org.w3c.dom.Document) readMethod.invoke(saxReader,
          new Object[] {url});
    }
    catch (InvocationTargetException ex) {
      ex.getTargetException().printStackTrace();
      throw new DOMTestLoadException(ex.getTargetException());
    }
    catch (Exception ex) {
      ex.printStackTrace();
      throw new DOMTestLoadException(ex);
    }
  
public DOMTestDocumentBuilderFactorynewInstance(DocumentBuilderSetting[] newSettings)

    if (newSettings == null) {
      return this;
    }
    DocumentBuilderSetting[] mergedSettings = mergeSettings(newSettings);
    return new DOM4JTestDocumentBuilderFactory(mergedSettings);