summaryrefslogtreecommitdiffstats
path: root/dom/src/test/java/org/w3c/domts/XalanDOMTestDocumentBuilderFactory.java
blob: cb60658a28bd6a23453cde2aa9365b4f702c60bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * Copyright (c) 2001-2003 World Wide Web Consortium,
 * (Massachusetts Institute of Technology, Institut National de
 * Recherche en Informatique et en Automatique, Keio University). All
 * Rights Reserved. This program is distributed under the W3C's Software
 * Intellectual Property License. This program is distributed in the
 * hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE.
 * See W3C License http://www.w3.org/Consortium/Legal/ for more details.
 */

/*
  $Log: XalanDOMTestDocumentBuilderFactory.java,v $
  Revision 1.2  2004/03/11 01:44:21  dom-ts-4
  Checkstyle fixes (bug 592)

  Revision 1.1  2003/04/24 05:02:05  dom-ts-4
  Xalan-J support for L3 XPath
  http://www.w3.org/Bugs/Public/show_bug.cgi?id=191

  Revision 1.1  2002/02/03 07:47:51  dom-ts-4
  More missing files

 */

package org.w3c.domts;

import java.lang.reflect.Constructor;

import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;

/**
 *
 *   This class uses Xalan-J to add XPath support
 *       to the current JAXP DOM implementation
 */
public class XalanDOMTestDocumentBuilderFactory
    extends JAXPDOMTestDocumentBuilderFactory {

  /**
   * 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.
   */
  public XalanDOMTestDocumentBuilderFactory(
      DocumentBuilderFactory baseFactory,
      DocumentBuilderSetting[] settings) throws DOMTestIncompatibleException {
    super(baseFactory, settings);
  }

  protected DOMTestDocumentBuilderFactory createInstance(DocumentBuilderFactory
      newFactory,
      DocumentBuilderSetting[] mergedSettings) throws
      DOMTestIncompatibleException {
    return new XalanDOMTestDocumentBuilderFactory(newFactory, mergedSettings);
  }

  /**
   *  Creates XPath evaluator
   *  @param doc DOM document, may not be null
   */
  public Object createXPathEvaluator(Document doc) {
    try {
      Class xpathClass = Class.forName(
          "org.apache.xpath.domapi.XPathEvaluatorImpl");
      Constructor constructor = xpathClass.getConstructor(new Class[] {Document.class});
      return constructor.newInstance(new Object[] {doc});
    }
    catch (Exception ex) {
    }
    return doc;
  }

}