KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > xpath > XPathFactoryImpl


1 package net.sf.saxon.xpath;
2
3 import net.sf.saxon.Configuration;
4 import net.sf.saxon.om.NamespaceConstant;
5
6 import javax.xml.XMLConstants JavaDoc;
7 import javax.xml.xpath.*;
8
9 /**
10  * Saxon implementation of the JAXP 1.3 XPathFactory
11  */

12 public class XPathFactoryImpl extends XPathFactory {
13
14     private Configuration config = new Configuration();
15     private XPathVariableResolver variableResolver;
16     private XPathFunctionResolver functionResolver;
17
18     /**
19      * Test whether a given object model is supported. Returns true if the object model
20      * is the Saxon object model, DOM, JDOM, or XOM
21      * @param model The URI identifying the object model.
22      * @return true if the object model is one of
23      * {@link NamespaceConstant#OBJECT_MODEL_SAXON},
24      * {@link XPathConstants#DOM_OBJECT_MODEL},
25      * {@link NamespaceConstant#OBJECT_MODEL_JDOM}, or
26      * {@link NamespaceConstant#OBJECT_MODEL_XOM}
27      */

28     public boolean isObjectModelSupported(String JavaDoc model) {
29         if (model.equals(NamespaceConstant.OBJECT_MODEL_SAXON)) return true;
30         if (model.equals(XPathConstants.DOM_OBJECT_MODEL)) return true;
31         if (model.equals(NamespaceConstant.OBJECT_MODEL_JDOM)) return true;
32         if (model.equals(NamespaceConstant.OBJECT_MODEL_XOM)) return true;
33         return false;
34     }
35
36     /**
37      * Set a feature of this XPath implementation. The only feature currently
38      * recognized is {@link XMLConstants#FEATURE_SECURE_PROCESSING}
39      * @param feature a URI identifying the feature
40      * @param b true to set the feature on, false to set it off
41      * @throws XPathFactoryConfigurationException if the feature name is not recognized
42      */

43
44     public void setFeature(String JavaDoc feature, boolean b) throws XPathFactoryConfigurationException {
45         if (feature.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
46             config.setAllowExternalFunctions(!b);
47         } else {
48             throw new XPathFactoryConfigurationException("Unknown feature: " + feature);
49         }
50     }
51
52     /**
53      * Get a feature of this XPath implementation. The only feature currently
54      * recognized is {@link XMLConstants#FEATURE_SECURE_PROCESSING}
55      * @param feature a URI identifying the feature
56      * @return true if the feature is on, false if it is off
57      * @throws XPathFactoryConfigurationException if the feature name is not recognized
58      */

59
60     public boolean getFeature(String JavaDoc feature) throws XPathFactoryConfigurationException {
61         if (feature.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
62             return !config.isAllowExternalFunctions();
63         } else {
64             throw new XPathFactoryConfigurationException("Unknown feature: " + feature);
65         }
66     }
67
68     /**
69      * Set a resolver for XPath variables. This will be used to obtain the value of
70      * any variable referenced in an XPath expression. The variable resolver must be allocated
71      * before the expression is compiled, but it will only be called when the expression
72      * is evaluated.
73      * @param xPathVariableResolver The object used to resolve references to variables.
74      */

75     public void setXPathVariableResolver(XPathVariableResolver xPathVariableResolver) {
76         variableResolver = xPathVariableResolver;
77     }
78
79     /**
80      * Set a resolver for XPath functions. This will be used to obtain an implementation
81      * of any external function referenced in an XPath expression. This is not required for
82      * system functions, Saxon extension functions, constructor functions named after types,
83      * or extension functions bound using a namespace that maps to a Java class.
84      * @param xPathFunctionResolver The object used to resolve references to external functions.
85      */

86
87     public void setXPathFunctionResolver(XPathFunctionResolver xPathFunctionResolver) {
88         functionResolver = xPathFunctionResolver;
89     }
90
91     /**
92      * Create an XPath evaluator
93      * @return an XPath object, which can be used to compile and execute XPath expressions.
94      */

95     public XPath newXPath() {
96         XPathEvaluator xpath = new XPathEvaluator(config);
97         xpath.setXPathFunctionResolver(functionResolver);
98         xpath.setXPathVariableResolver(variableResolver);
99         //config.registerStandardObjectModels();
100
return xpath;
101     }
102
103
104
105 }
106
107 //
108
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
109
// you may not use this file except in compliance with the License. You may obtain a copy of the
110
// License at http://www.mozilla.org/MPL/
111
//
112
// Software distributed under the License is distributed on an "AS IS" basis,
113
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
114
// See the License for the specific language governing rights and limitations under the License.
115
//
116
// The Original Code is: all this file.
117
//
118
// The Initial Developer of the Original Code is Michael H. Kay.
119
//
120
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
121
//
122
// Contributor(s):
123
//
Popular Tags