Main Page Packages Class Hierarchy Compound List File List Compound Members

# DOMTestDocumentBuilderFactory.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: DOMTestDocumentBuilderFactory.java,v $
    00015  Revision 1.4  2002/02/03 04:22:35  dom-ts-4
    00016  DOM4J and Batik support added.
    00017  Rework of parser settings
    00018
    00019  Revision 1.3  2002/01/30 07:08:44  dom-ts-4
    00020  Update for GNUJAXP
    00021
    00022  Revision 1.2  2001/08/22 22:12:49  dom-ts-4
    00023  Now passing all tests with default settings
    00024
    00025  Revision 1.1  2001/07/23 04:52:20  dom-ts-4
    00026  Initial test running using JUnit.
    00027
    00028  */
    00029
    00030 package org.w3c.domts;
    00031
    00032 import javax.xml.parsers.*;
    00033 import org.w3c.dom.*;
    00034 import org.w3c.domts.*;
    00035 import java.lang.reflect.*;
    00036 import java.util.*;
    00037 import org.xml.sax.*;
    00047 public abstract class DOMTestDocumentBuilderFactory {
    00051   private final DocumentBuilderSetting[] settings;
    00052
    00053
    00058   public DOMTestDocumentBuilderFactory(DocumentBuilderSetting[] settings)
    00059     throws DOMTestIncompatibleException {
    00060     if(settings == null) {
    00061         this.settings = new DocumentBuilderSetting[0];
    00062     }
    00063     else {
    00064         this.settings = (DocumentBuilderSetting[]) settings.clone();
    00065     }
    00066   }
    00067
    00074   public abstract DOMTestDocumentBuilderFactory newInstance(DocumentBuilderSetting[] settings)
    00075     throws DOMTestIncompatibleException;
    00076
    00077   public abstract DOMImplementation getDOMImplementation();
    00078
    00079   public abstract boolean hasFeature(String feature,String version);
    00080
    00081   public abstract Document load(java.net.URL url) throws DOMTestLoadException;
    00082
    00089   protected DocumentBuilderSetting[] mergeSettings(DocumentBuilderSetting[] newSettings)
    00090   {
    00091       if(newSettings == null) {
    00092         return (DocumentBuilderSetting[]) settings.clone();
    00093       }
    00094       List mergedSettings = new ArrayList(settings.length + newSettings.length);
    00095       //
    00096       //    all new settings are respected
    00097       //
    00098       for(int i = 0; i < newSettings.length; i++) {
    00099         mergedSettings.add(newSettings[i]);
    00100       }
    00101       //
    00102       //    for all previous settings, take only those that
    00103       //       do not conflict with existing settings
    00104       for(int i = 0; i < settings.length; i++) {
    00105         DocumentBuilderSetting setting = settings[i];
    00106         boolean hasConflict = false;
    00107         for(int j = 0; j < newSettings.length; j++) {
    00108           DocumentBuilderSetting newSetting = newSettings[j];
    00109           if(newSetting.hasConflict(setting) || setting.hasConflict(newSetting)) {
    00110             hasConflict = true;
    00111             break;
    00112           }
    00113         }
    00114         if(!hasConflict) {
    00115           mergedSettings.add(setting);
    00116         }
    00117       }
    00118
    00119       DocumentBuilderSetting[] mergedArray =
    00120         new DocumentBuilderSetting[mergedSettings.size()];
    00121       for(int i = 0; i < mergedSettings.size(); i++) {
    00122         mergedArray[i] = (DocumentBuilderSetting) mergedSettings.get(i);
    00123       }
    00124       return mergedArray;
    00125     }
    00126
    00127
    00128     public String addExtension(String testFileName) {
    00129         return testFileName + ".xml";
    00130     }
    00131
    00132     public abstract boolean isCoalescing();
    00133
    00134     public abstract boolean isExpandEntityReferences();
    00135
    00136     public abstract boolean isIgnoringElementContentWhitespace();
    00137
    00138     public abstract boolean isNamespaceAware();
    00139
    00140     public abstract boolean isValidating();
    00141
    00147   public final DocumentBuilderSetting[] getActualSettings() {
    00148
    00149     DocumentBuilderSetting[] allSettings = new DocumentBuilderSetting[] {
    00150       DocumentBuilderSetting.coalescing,
    00151       DocumentBuilderSetting.expandEntityReferences,
    00152       DocumentBuilderSetting.hasNullString,
    00153       DocumentBuilderSetting.ignoringElementContentWhitespace,
    00154       DocumentBuilderSetting.namespaceAware,
    00155       DocumentBuilderSetting.signed,
    00156       DocumentBuilderSetting.validating,
    00157       DocumentBuilderSetting.notCoalescing,
    00158       DocumentBuilderSetting.notExpandEntityReferences,
    00159       DocumentBuilderSetting.notHasNullString,
    00160       DocumentBuilderSetting.notIgnoringElementContentWhitespace,
    00161       DocumentBuilderSetting.notNamespaceAware,
    00162       DocumentBuilderSetting.notSigned,
    00163       DocumentBuilderSetting.notValidating
    00164       };
    00165
    00166       List list = new ArrayList(allSettings.length /2);
    00167       for(int i = 0; i < allSettings.length; i++) {
    00168         if(allSettings[i].hasSetting(this)) {
    00169           list.add(allSettings[i]);
    00170         }
    00171       }
    00172       DocumentBuilderSetting[] settings = new DocumentBuilderSetting[list.size()];
    00173       for(int i = 0; i < settings.length; i++) {
    00174         settings[i] = (DocumentBuilderSetting) list.get(i);
    00175       }
    00176       return settings;
    00177   }
    00178
    00179 }
    00180