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

JAXPDOMTestDocumentBuilderFactory

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

Fields Summary
private DocumentBuilderFactory
factory
private DocumentBuilder
builder
Constructors Summary
public JAXPDOMTestDocumentBuilderFactory(DocumentBuilderFactory baseFactory, 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
settings array of settings, may be null.

    super(settings);
    if (baseFactory == null) {
      factory = DocumentBuilderFactory.newInstance();
    }
    else {
      factory = baseFactory;
    }
    //
    //    apply settings to selected document builder
    //         may throw exception if incompatible
    if (settings != null) {
      for (int i = 0; i < settings.length; i++) {
        settings[i].applySetting(factory);
      }
    }
    try {
      this.builder = factory.newDocumentBuilder();
    }
    catch (ParserConfigurationException ex) {
      throw new DOMTestIncompatibleException(ex, null);
    }
  
Methods Summary
protected DOMTestDocumentBuilderFactorycreateInstance(javax.xml.parsers.DocumentBuilderFactory newFactory, DocumentBuilderSetting[] mergedSettings)

    return new JAXPDOMTestDocumentBuilderFactory(newFactory, mergedSettings);
  
public static DocumentBuilderSetting[]getConfiguration1()

    return new DocumentBuilderSetting[] {
        DocumentBuilderSetting.notCoalescing,
        DocumentBuilderSetting.notExpandEntityReferences,
        DocumentBuilderSetting.notIgnoringElementContentWhitespace,
        DocumentBuilderSetting.notNamespaceAware,
        DocumentBuilderSetting.notValidating};
  
public static DocumentBuilderSetting[]getConfiguration2()

    return new DocumentBuilderSetting[] {
        DocumentBuilderSetting.notCoalescing,
        DocumentBuilderSetting.expandEntityReferences,
        DocumentBuilderSetting.ignoringElementContentWhitespace,
        DocumentBuilderSetting.namespaceAware,
        DocumentBuilderSetting.validating};

  
public org.w3c.dom.DOMImplementationgetDOMImplementation()

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

    return builder.getDOMImplementation().hasFeature(feature, version);
  
public booleanisCoalescing()

    return factory.isCoalescing();
  
public booleanisExpandEntityReferences()

    return factory.isExpandEntityReferences();
  
public booleanisIgnoringElementContentWhitespace()

    return factory.isIgnoringElementContentWhitespace();
  
public booleanisNamespaceAware()

    return factory.isNamespaceAware();
  
public booleanisValidating()

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

    Document doc = null;
    Exception parseException = null;
    try {
      LoadErrorHandler errorHandler = new LoadErrorHandler();
      builder.setErrorHandler(errorHandler);
      doc = builder.parse(url.openStream(), url.toString());
      parseException = errorHandler.getFirstException();
    }
    catch (Exception ex) {
      parseException = ex;
    }
    builder.setErrorHandler(null);
    if (parseException != null) {
      throw new DOMTestLoadException(parseException);
    }
    return doc;
  
public DOMTestDocumentBuilderFactorynewInstance(DocumentBuilderSetting[] newSettings)

    if (newSettings == null) {
      return this;
    }
    DocumentBuilderSetting[] mergedSettings = mergeSettings(newSettings);
    DocumentBuilderFactory newFactory = factory.newInstance();
    return createInstance(newFactory, mergedSettings);