Home | History | Annotate | Download | only in domts
      1 /*
      2  * Copyright (c) 2001-2003 World Wide Web Consortium,
      3  * (Massachusetts Institute of Technology, Institut National de
      4  * Recherche en Informatique et en Automatique, Keio University). All
      5  * Rights Reserved. This program is distributed under the W3C's Software
      6  * Intellectual Property License. This program is distributed in the
      7  * hope that it will be useful, but WITHOUT ANY WARRANTY; without even
      8  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
      9  * PURPOSE.
     10  * See W3C License http://www.w3.org/Consortium/Legal/ for more details.
     11  */
     12 
     13 /*
     14   $Log: XalanDOMTestDocumentBuilderFactory.java,v $
     15   Revision 1.2  2004/03/11 01:44:21  dom-ts-4
     16   Checkstyle fixes (bug 592)
     17 
     18   Revision 1.1  2003/04/24 05:02:05  dom-ts-4
     19   Xalan-J support for L3 XPath
     20   http://www.w3.org/Bugs/Public/show_bug.cgi?id=191
     21 
     22   Revision 1.1  2002/02/03 07:47:51  dom-ts-4
     23   More missing files
     24 
     25  */
     26 
     27 package org.w3c.domts;
     28 
     29 import java.lang.reflect.Constructor;
     30 
     31 import javax.xml.parsers.DocumentBuilderFactory;
     32 
     33 import org.w3c.dom.Document;
     34 
     35 /**
     36  *
     37  *   This class uses Xalan-J to add XPath support
     38  *       to the current JAXP DOM implementation
     39  */
     40 public class XalanDOMTestDocumentBuilderFactory
     41     extends JAXPDOMTestDocumentBuilderFactory {
     42 
     43   /**
     44    * Creates a JAXP implementation of DOMTestDocumentBuilderFactory.
     45    * @param factory null for default JAXP provider.  If not null,
     46    * factory will be mutated in constructor and should be released
     47    * by calling code upon return.
     48    * @param settings array of settings, may be null.
     49    */
     50   public XalanDOMTestDocumentBuilderFactory(
     51       DocumentBuilderFactory baseFactory,
     52       DocumentBuilderSetting[] settings) throws DOMTestIncompatibleException {
     53     super(baseFactory, settings);
     54   }
     55 
     56   protected DOMTestDocumentBuilderFactory createInstance(DocumentBuilderFactory
     57       newFactory,
     58       DocumentBuilderSetting[] mergedSettings) throws
     59       DOMTestIncompatibleException {
     60     return new XalanDOMTestDocumentBuilderFactory(newFactory, mergedSettings);
     61   }
     62 
     63   /**
     64    *  Creates XPath evaluator
     65    *  @param doc DOM document, may not be null
     66    */
     67   public Object createXPathEvaluator(Document doc) {
     68     try {
     69       Class xpathClass = Class.forName(
     70           "org.apache.xpath.domapi.XPathEvaluatorImpl");
     71       Constructor constructor = xpathClass.getConstructor(new Class[] {Document.class});
     72       return constructor.newInstance(new Object[] {doc});
     73     }
     74     catch (Exception ex) {
     75     }
     76     return doc;
     77   }
     78 
     79 }
     80