author | joehw |
Wed, 04 Oct 2017 10:54:18 -0700 | |
changeset 47312 | d4f959806fe9 |
parent 47216 | 71c04702a3d5 |
child 48412 | d4412e380f6b |
permissions | -rw-r--r-- |
12005 | 1 |
/* |
40222
ec0a4bdb7a07
8160069: RuntimeException thrown by XPathFactory::newInstance missing the cause
joehw
parents:
29419
diff
changeset
|
2 |
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. |
12005 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package javax.xml.xpath; |
|
27 |
||
42390
4083bc2c3b5b
8169778: Add new public methods to get new instances of the JAXP factories builtin system-default implementations
dfuchs
parents:
40222
diff
changeset
|
28 |
import com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl; |
47312 | 29 |
import jdk.xml.internal.SecuritySupport; |
42390
4083bc2c3b5b
8169778: Add new public methods to get new instances of the JAXP factories builtin system-default implementations
dfuchs
parents:
40222
diff
changeset
|
30 |
|
12005 | 31 |
/** |
29419
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
32 |
* <p>An {@code XPathFactory} instance can be used to create |
12005 | 33 |
* {@link javax.xml.xpath.XPath} objects.</p> |
34 |
* |
|
35 |
*<p>See {@link #newInstance(String uri)} for lookup mechanism.</p> |
|
36 |
* |
|
37 |
* <p>The {@link XPathFactory} class is not thread-safe. In other words, |
|
38 |
* it is the application's responsibility to ensure that at most |
|
39 |
* one thread is using a {@link XPathFactory} object at any |
|
40 |
* given moment. Implementations are encouraged to mark methods |
|
41 |
* as <code>synchronized</code> to protect themselves from broken clients. |
|
42 |
* |
|
43 |
* <p>{@link XPathFactory} is not re-entrant. While one of the |
|
44 |
* <code>newInstance</code> methods is being invoked, applications |
|
45 |
* may not attempt to recursively invoke a <code>newInstance</code> method, |
|
46 |
* even from the same thread. |
|
47 |
* |
|
48 |
* @author <a href="mailto:Norman.Walsh@Sun.com">Norman Walsh</a> |
|
49 |
* @author <a href="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a> |
|
50 |
* |
|
51 |
* @since 1.5 |
|
52 |
*/ |
|
53 |
public abstract class XPathFactory { |
|
54 |
||
55 |
||
56 |
/** |
|
57 |
* <p>The default property name according to the JAXP spec.</p> |
|
58 |
*/ |
|
59 |
public static final String DEFAULT_PROPERTY_NAME = "javax.xml.xpath.XPathFactory"; |
|
60 |
||
61 |
/** |
|
62 |
* <p>Default Object Model URI.</p> |
|
63 |
*/ |
|
64 |
public static final String DEFAULT_OBJECT_MODEL_URI = "http://java.sun.com/jaxp/xpath/dom"; |
|
65 |
||
66 |
/** |
|
67 |
* <p>Protected constructor as {@link #newInstance()} or {@link #newInstance(String uri)} |
|
68 |
* or {@link #newInstance(String uri, String factoryClassName, ClassLoader classLoader)} |
|
29419
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
69 |
* should be used to create a new instance of an {@code XPathFactory}.</p> |
12005 | 70 |
*/ |
71 |
protected XPathFactory() { |
|
72 |
} |
|
73 |
||
74 |
/** |
|
42390
4083bc2c3b5b
8169778: Add new public methods to get new instances of the JAXP factories builtin system-default implementations
dfuchs
parents:
40222
diff
changeset
|
75 |
* Creates a new instance of the {@code XPathFactory} builtin |
4083bc2c3b5b
8169778: Add new public methods to get new instances of the JAXP factories builtin system-default implementations
dfuchs
parents:
40222
diff
changeset
|
76 |
* system-default implementation. |
4083bc2c3b5b
8169778: Add new public methods to get new instances of the JAXP factories builtin system-default implementations
dfuchs
parents:
40222
diff
changeset
|
77 |
* |
4083bc2c3b5b
8169778: Add new public methods to get new instances of the JAXP factories builtin system-default implementations
dfuchs
parents:
40222
diff
changeset
|
78 |
* @implSpec The {@code XPathFactory} builtin |
4083bc2c3b5b
8169778: Add new public methods to get new instances of the JAXP factories builtin system-default implementations
dfuchs
parents:
40222
diff
changeset
|
79 |
* system-default implementation is only required to support the |
4083bc2c3b5b
8169778: Add new public methods to get new instances of the JAXP factories builtin system-default implementations
dfuchs
parents:
40222
diff
changeset
|
80 |
* {@link #DEFAULT_OBJECT_MODEL_URI default object model}, the |
4083bc2c3b5b
8169778: Add new public methods to get new instances of the JAXP factories builtin system-default implementations
dfuchs
parents:
40222
diff
changeset
|
81 |
* {@linkplain org.w3c.dom W3C DOM}, but may support additional |
4083bc2c3b5b
8169778: Add new public methods to get new instances of the JAXP factories builtin system-default implementations
dfuchs
parents:
40222
diff
changeset
|
82 |
* object models. |
4083bc2c3b5b
8169778: Add new public methods to get new instances of the JAXP factories builtin system-default implementations
dfuchs
parents:
40222
diff
changeset
|
83 |
* |
4083bc2c3b5b
8169778: Add new public methods to get new instances of the JAXP factories builtin system-default implementations
dfuchs
parents:
40222
diff
changeset
|
84 |
* @return A new instance of the {@code XPathFactory} builtin |
4083bc2c3b5b
8169778: Add new public methods to get new instances of the JAXP factories builtin system-default implementations
dfuchs
parents:
40222
diff
changeset
|
85 |
* system-default implementation. |
4083bc2c3b5b
8169778: Add new public methods to get new instances of the JAXP factories builtin system-default implementations
dfuchs
parents:
40222
diff
changeset
|
86 |
* |
4083bc2c3b5b
8169778: Add new public methods to get new instances of the JAXP factories builtin system-default implementations
dfuchs
parents:
40222
diff
changeset
|
87 |
* @since 9 |
4083bc2c3b5b
8169778: Add new public methods to get new instances of the JAXP factories builtin system-default implementations
dfuchs
parents:
40222
diff
changeset
|
88 |
*/ |
4083bc2c3b5b
8169778: Add new public methods to get new instances of the JAXP factories builtin system-default implementations
dfuchs
parents:
40222
diff
changeset
|
89 |
public static XPathFactory newDefaultInstance() { |
4083bc2c3b5b
8169778: Add new public methods to get new instances of the JAXP factories builtin system-default implementations
dfuchs
parents:
40222
diff
changeset
|
90 |
return XPathFactoryImpl.newXPathFactoryNoServiceLoader(); |
4083bc2c3b5b
8169778: Add new public methods to get new instances of the JAXP factories builtin system-default implementations
dfuchs
parents:
40222
diff
changeset
|
91 |
} |
4083bc2c3b5b
8169778: Add new public methods to get new instances of the JAXP factories builtin system-default implementations
dfuchs
parents:
40222
diff
changeset
|
92 |
|
4083bc2c3b5b
8169778: Add new public methods to get new instances of the JAXP factories builtin system-default implementations
dfuchs
parents:
40222
diff
changeset
|
93 |
/** |
29419
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
94 |
* <p>Get a new {@code XPathFactory} instance using the default object model, |
12005 | 95 |
* {@link #DEFAULT_OBJECT_MODEL_URI}, |
96 |
* the W3C DOM.</p> |
|
97 |
* |
|
98 |
* <p>This method is functionally equivalent to:</p> |
|
99 |
* <pre> |
|
100 |
* newInstance(DEFAULT_OBJECT_MODEL_URI) |
|
101 |
* </pre> |
|
102 |
* |
|
103 |
* <p>Since the implementation for the W3C DOM is always available, this method will never fail.</p> |
|
104 |
* |
|
29419
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
105 |
* @return Instance of an {@code XPathFactory}. |
12005 | 106 |
* |
107 |
* @throws RuntimeException When there is a failure in creating an |
|
29419
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
108 |
* {@code XPathFactory} for the default object model. |
12005 | 109 |
*/ |
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
110 |
public static XPathFactory newInstance() { |
12005 | 111 |
|
112 |
try { |
|
40222
ec0a4bdb7a07
8160069: RuntimeException thrown by XPathFactory::newInstance missing the cause
joehw
parents:
29419
diff
changeset
|
113 |
return newInstance(DEFAULT_OBJECT_MODEL_URI); |
ec0a4bdb7a07
8160069: RuntimeException thrown by XPathFactory::newInstance missing the cause
joehw
parents:
29419
diff
changeset
|
114 |
} catch (XPathFactoryConfigurationException e) { |
ec0a4bdb7a07
8160069: RuntimeException thrown by XPathFactory::newInstance missing the cause
joehw
parents:
29419
diff
changeset
|
115 |
throw new RuntimeException( |
ec0a4bdb7a07
8160069: RuntimeException thrown by XPathFactory::newInstance missing the cause
joehw
parents:
29419
diff
changeset
|
116 |
"XPathFactory#newInstance() failed to create an XPathFactory for the default object model: " |
ec0a4bdb7a07
8160069: RuntimeException thrown by XPathFactory::newInstance missing the cause
joehw
parents:
29419
diff
changeset
|
117 |
+ DEFAULT_OBJECT_MODEL_URI |
ec0a4bdb7a07
8160069: RuntimeException thrown by XPathFactory::newInstance missing the cause
joehw
parents:
29419
diff
changeset
|
118 |
+ " with the XPathFactoryConfigurationException: " |
ec0a4bdb7a07
8160069: RuntimeException thrown by XPathFactory::newInstance missing the cause
joehw
parents:
29419
diff
changeset
|
119 |
+ e.getMessage(), e |
ec0a4bdb7a07
8160069: RuntimeException thrown by XPathFactory::newInstance missing the cause
joehw
parents:
29419
diff
changeset
|
120 |
); |
12005 | 121 |
} |
122 |
} |
|
123 |
||
124 |
/** |
|
29419
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
125 |
* <p>Get a new {@code XPathFactory} instance using the specified object model.</p> |
12005 | 126 |
* |
29419
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
127 |
* <p>To find a {@code XPathFactory} object, |
12005 | 128 |
* this method looks the following places in the following order where "the class loader" refers to the context class loader:</p> |
129 |
* <ol> |
|
130 |
* <li> |
|
29419
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
131 |
* <p> |
12005 | 132 |
* If the system property {@link #DEFAULT_PROPERTY_NAME} + ":uri" is present, |
133 |
* where uri is the parameter to this method, then its value is read as a class name. |
|
134 |
* The method will try to create a new instance of this class by using the class loader, |
|
135 |
* and returns it if it is successfully created. |
|
136 |
* </li> |
|
137 |
* <li> |
|
29419
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
138 |
* <p> |
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
139 |
* Use the configuration file "jaxp.properties". The file is in standard |
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
140 |
* {@link java.util.Properties} format and typically located in the |
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
141 |
* conf directory of the Java installation. It contains the fully qualified |
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
142 |
* name of the implementation class with the key being the system property |
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
143 |
* defined above. |
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
144 |
* <p> |
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
145 |
* The jaxp.properties file is read only once by the JAXP implementation |
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
146 |
* and its values are then cached for future use. If the file does not exist |
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
147 |
* when the first attempt is made to read from it, no further attempts are |
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
148 |
* made to check for its existence. It is not possible to change the value |
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
149 |
* of any property in jaxp.properties after it has been read for the first time. |
12005 | 150 |
* </li> |
151 |
* <li> |
|
29419
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
152 |
* <p> |
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
153 |
* Use the service-provider loading facility, defined by the |
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
154 |
* {@link java.util.ServiceLoader} class, to attempt to locate and load an |
20581
65d17ea72da3
8025745: Clarify API documentation of JAXP factories.
dfuchs
parents:
17264
diff
changeset
|
155 |
* implementation of the service using the {@linkplain |
65d17ea72da3
8025745: Clarify API documentation of JAXP factories.
dfuchs
parents:
17264
diff
changeset
|
156 |
* java.util.ServiceLoader#load(java.lang.Class) default loading mechanism}: |
65d17ea72da3
8025745: Clarify API documentation of JAXP factories.
dfuchs
parents:
17264
diff
changeset
|
157 |
* the service-provider loading facility will use the {@linkplain |
65d17ea72da3
8025745: Clarify API documentation of JAXP factories.
dfuchs
parents:
17264
diff
changeset
|
158 |
* java.lang.Thread#getContextClassLoader() current thread's context class loader} |
65d17ea72da3
8025745: Clarify API documentation of JAXP factories.
dfuchs
parents:
17264
diff
changeset
|
159 |
* to attempt to load the service. If the context class |
65d17ea72da3
8025745: Clarify API documentation of JAXP factories.
dfuchs
parents:
17264
diff
changeset
|
160 |
* loader is null, the {@linkplain |
65d17ea72da3
8025745: Clarify API documentation of JAXP factories.
dfuchs
parents:
17264
diff
changeset
|
161 |
* ClassLoader#getSystemClassLoader() system class loader} will be used. |
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
162 |
* <br> |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
163 |
* Each potential service provider is required to implement the method |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
164 |
* {@link #isObjectModelSupported(String objectModel)}. |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
165 |
* The first service provider found that supports the specified object |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
166 |
* model is returned. |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
167 |
* <br> |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
168 |
* In case of {@link java.util.ServiceConfigurationError} an |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
169 |
* {@link XPathFactoryConfigurationException} will be thrown. |
12005 | 170 |
* </li> |
171 |
* <li> |
|
29419
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
172 |
* <p> |
42390
4083bc2c3b5b
8169778: Add new public methods to get new instances of the JAXP factories builtin system-default implementations
dfuchs
parents:
40222
diff
changeset
|
173 |
* Platform default {@code XPathFactory} is located in a platform |
4083bc2c3b5b
8169778: Add new public methods to get new instances of the JAXP factories builtin system-default implementations
dfuchs
parents:
40222
diff
changeset
|
174 |
* specific way. |
4083bc2c3b5b
8169778: Add new public methods to get new instances of the JAXP factories builtin system-default implementations
dfuchs
parents:
40222
diff
changeset
|
175 |
* There must be a {@linkplain #newDefaultInstance() platform default} |
4083bc2c3b5b
8169778: Add new public methods to get new instances of the JAXP factories builtin system-default implementations
dfuchs
parents:
40222
diff
changeset
|
176 |
* {@code XPathFactory} for the W3C DOM, i.e. |
4083bc2c3b5b
8169778: Add new public methods to get new instances of the JAXP factories builtin system-default implementations
dfuchs
parents:
40222
diff
changeset
|
177 |
* {@link #DEFAULT_OBJECT_MODEL_URI}. |
12005 | 178 |
* </li> |
179 |
* </ol> |
|
29419
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
180 |
* <p>If everything fails, an {@code XPathFactoryConfigurationException} will be thrown. |
12005 | 181 |
* |
29419
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
182 |
* <p>Tip for Trouble-shooting: |
12005 | 183 |
* <p>See {@link java.util.Properties#load(java.io.InputStream)} for exactly how a property file is parsed. |
184 |
* In particular, colons ':' need to be escaped in a property file, so make sure the URIs are properly escaped in it. |
|
29419
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
185 |
* For example: |
12005 | 186 |
* <pre> |
187 |
* http\://java.sun.com/jaxp/xpath/dom=org.acme.DomXPathFactory |
|
188 |
* </pre> |
|
189 |
* |
|
190 |
* @param uri Identifies the underlying object model. |
|
191 |
* The specification only defines the URI {@link #DEFAULT_OBJECT_MODEL_URI}, |
|
192 |
* <code>http://java.sun.com/jaxp/xpath/dom</code> for the W3C DOM, |
|
193 |
* the org.w3c.dom package, and implementations are free to introduce other URIs for other object models. |
|
194 |
* |
|
29419
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
195 |
* @return Instance of an {@code XPathFactory}. |
12005 | 196 |
* |
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
197 |
* @throws XPathFactoryConfigurationException If the specified object model |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
198 |
* is unavailable, or if there is a configuration error. |
12005 | 199 |
* @throws NullPointerException If <code>uri</code> is <code>null</code>. |
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
200 |
* @throws IllegalArgumentException If <code>uri</code> is <code>null</code> |
12005 | 201 |
* or <code>uri.length() == 0</code>. |
202 |
*/ |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
203 |
public static XPathFactory newInstance(final String uri) |
12005 | 204 |
throws XPathFactoryConfigurationException { |
205 |
||
206 |
if (uri == null) { |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
207 |
throw new NullPointerException( |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
208 |
"XPathFactory#newInstance(String uri) cannot be called with uri == null"); |
12005 | 209 |
} |
210 |
||
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
211 |
if (uri.length() == 0) { |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
212 |
throw new IllegalArgumentException( |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
213 |
"XPathFactory#newInstance(String uri) cannot be called with uri == \"\""); |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
214 |
} |
12005 | 215 |
|
47312 | 216 |
ClassLoader classLoader = SecuritySupport.getContextClassLoader(); |
12005 | 217 |
|
218 |
if (classLoader == null) { |
|
219 |
//use the current class loader |
|
220 |
classLoader = XPathFactory.class.getClassLoader(); |
|
221 |
} |
|
222 |
||
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
223 |
XPathFactory xpathFactory = new XPathFactoryFinder(classLoader).newFactory(uri); |
12005 | 224 |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
225 |
if (xpathFactory == null) { |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
226 |
throw new XPathFactoryConfigurationException( |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
227 |
"No XPathFactory implementation found for the object model: " |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
228 |
+ uri); |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
229 |
} |
12005 | 230 |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
231 |
return xpathFactory; |
12005 | 232 |
} |
233 |
||
234 |
/** |
|
29419
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
235 |
* <p>Obtain a new instance of a {@code XPathFactory} from a factory class name. {@code XPathFactory} |
12005 | 236 |
* is returned if specified factory class supports the specified object model. |
237 |
* This function is useful when there are multiple providers in the classpath. |
|
238 |
* It gives more control to the application as it can specify which provider |
|
239 |
* should be loaded.</p> |
|
240 |
* |
|
241 |
* |
|
242 |
* <h2>Tip for Trouble-shooting</h2> |
|
243 |
* <p>Setting the <code>jaxp.debug</code> system property will cause |
|
244 |
* this method to print a lot of debug messages |
|
245 |
* to <code>System.err</code> about what it is doing and where it is looking at.</p> |
|
246 |
* |
|
247 |
* <p> If you have problems try:</p> |
|
248 |
* <pre> |
|
249 |
* java -Djaxp.debug=1 YourProgram .... |
|
250 |
* </pre> |
|
251 |
* |
|
252 |
* @param uri Identifies the underlying object model. The specification only defines the URI |
|
253 |
* {@link #DEFAULT_OBJECT_MODEL_URI},<code>http://java.sun.com/jaxp/xpath/dom</code> |
|
254 |
* for the W3C DOM, the org.w3c.dom package, and implementations are free to introduce |
|
255 |
* other URIs for other object models. |
|
256 |
* |
|
257 |
* @param factoryClassName fully qualified factory class name that provides implementation of <code>javax.xml.xpath.XPathFactory</code>. |
|
258 |
* |
|
259 |
* @param classLoader <code>ClassLoader</code> used to load the factory class. If <code>null</code> |
|
260 |
* current <code>Thread</code>'s context classLoader is used to load the factory class. |
|
261 |
* |
|
262 |
* |
|
29419
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
263 |
* @return New instance of a {@code XPathFactory} |
12005 | 264 |
* |
265 |
* @throws XPathFactoryConfigurationException |
|
266 |
* if <code>factoryClassName</code> is <code>null</code>, or |
|
267 |
* the factory class cannot be loaded, instantiated |
|
268 |
* or the factory class does not support the object model specified |
|
269 |
* in the <code>uri</code> parameter. |
|
270 |
* |
|
271 |
* @throws NullPointerException If <code>uri</code> is <code>null</code>. |
|
272 |
* @throws IllegalArgumentException If <code>uri</code> is <code>null</code> |
|
273 |
* or <code>uri.length() == 0</code>. |
|
274 |
* |
|
275 |
* @see #newInstance() |
|
276 |
* @see #newInstance(String uri) |
|
277 |
* |
|
278 |
* @since 1.6 |
|
279 |
*/ |
|
280 |
public static XPathFactory newInstance(String uri, String factoryClassName, ClassLoader classLoader) |
|
281 |
throws XPathFactoryConfigurationException{ |
|
282 |
ClassLoader cl = classLoader; |
|
283 |
||
284 |
if (uri == null) { |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
285 |
throw new NullPointerException( |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
286 |
"XPathFactory#newInstance(String uri) cannot be called with uri == null"); |
12005 | 287 |
} |
288 |
||
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
289 |
if (uri.length() == 0) { |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
290 |
throw new IllegalArgumentException( |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
291 |
"XPathFactory#newInstance(String uri) cannot be called with uri == \"\""); |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
292 |
} |
12005 | 293 |
|
294 |
if (cl == null) { |
|
47312 | 295 |
cl = SecuritySupport.getContextClassLoader(); |
12005 | 296 |
} |
297 |
||
298 |
XPathFactory f = new XPathFactoryFinder(cl).createInstance(factoryClassName); |
|
299 |
||
300 |
if (f == null) { |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
301 |
throw new XPathFactoryConfigurationException( |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
302 |
"No XPathFactory implementation found for the object model: " |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
303 |
+ uri); |
12005 | 304 |
} |
305 |
//if this factory supports the given schemalanguage return this factory else thrown exception |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
306 |
if (f.isObjectModelSupported(uri)) { |
12005 | 307 |
return f; |
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
308 |
} else { |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
309 |
throw new XPathFactoryConfigurationException("Factory " |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
310 |
+ factoryClassName + " doesn't support given " + uri |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
311 |
+ " object model"); |
12005 | 312 |
} |
313 |
||
314 |
} |
|
315 |
||
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
316 |
/** |
29419
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
317 |
* <p>Is specified object model supported by this {@code XPathFactory}?</p> |
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
318 |
* |
29419
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
319 |
* @param objectModel Specifies the object model which the returned {@code XPathFactory} will understand. |
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
320 |
* |
29419
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
321 |
* @return <code>true</code> if {@code XPathFactory} supports <code>objectModel</code>, else <code>false</code>. |
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
322 |
* |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
323 |
* @throws NullPointerException If <code>objectModel</code> is <code>null</code>. |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
324 |
* @throws IllegalArgumentException If <code>objectModel.length() == 0</code>. |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
325 |
*/ |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
326 |
public abstract boolean isObjectModelSupported(String objectModel); |
12005 | 327 |
|
328 |
/** |
|
29419
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
329 |
* <p>Set a feature for this {@code XPathFactory} and |
12005 | 330 |
* <code>XPath</code>s created by this factory.</p> |
331 |
* |
|
332 |
* <p> |
|
333 |
* Feature names are fully qualified {@link java.net.URI}s. |
|
334 |
* Implementations may define their own features. |
|
335 |
* An {@link XPathFactoryConfigurationException} is thrown if this |
|
29419
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
336 |
* {@code XPathFactory} or the <code>XPath</code>s |
12005 | 337 |
* it creates cannot support the feature. |
29419
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
338 |
* It is possible for an {@code XPathFactory} to expose a feature value |
12005 | 339 |
* but be unable to change its state. |
340 |
* </p> |
|
341 |
* |
|
342 |
* <p> |
|
343 |
* All implementations are required to support the {@link javax.xml.XMLConstants#FEATURE_SECURE_PROCESSING} feature. |
|
344 |
* When the feature is <code>true</code>, any reference to an external function is an error. |
|
345 |
* Under these conditions, the implementation must not call the {@link XPathFunctionResolver} |
|
346 |
* and must throw an {@link XPathFunctionException}. |
|
347 |
* </p> |
|
348 |
* |
|
349 |
* @param name Feature name. |
|
350 |
* @param value Is feature state <code>true</code> or <code>false</code>. |
|
351 |
* |
|
29419
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
352 |
* @throws XPathFactoryConfigurationException if this {@code XPathFactory} or the <code>XPath</code>s |
12005 | 353 |
* it creates cannot support this feature. |
354 |
* @throws NullPointerException if <code>name</code> is <code>null</code>. |
|
355 |
*/ |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
356 |
public abstract void setFeature(String name, boolean value) |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
357 |
throws XPathFactoryConfigurationException; |
12005 | 358 |
|
359 |
/** |
|
360 |
* <p>Get the state of the named feature.</p> |
|
361 |
* |
|
362 |
* <p> |
|
363 |
* Feature names are fully qualified {@link java.net.URI}s. |
|
364 |
* Implementations may define their own features. |
|
365 |
* An {@link XPathFactoryConfigurationException} is thrown if this |
|
29419
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
366 |
* {@code XPathFactory} or the <code>XPath</code>s |
12005 | 367 |
* it creates cannot support the feature. |
29419
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
368 |
* It is possible for an {@code XPathFactory} to expose a feature value |
12005 | 369 |
* but be unable to change its state. |
370 |
* </p> |
|
371 |
* |
|
372 |
* @param name Feature name. |
|
373 |
* |
|
374 |
* @return State of the named feature. |
|
375 |
* |
|
376 |
* @throws XPathFactoryConfigurationException if this |
|
29419
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
377 |
* {@code XPathFactory} or the <code>XPath</code>s |
12005 | 378 |
* it creates cannot support this feature. |
379 |
* @throws NullPointerException if <code>name</code> is <code>null</code>. |
|
380 |
*/ |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
381 |
public abstract boolean getFeature(String name) |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
382 |
throws XPathFactoryConfigurationException; |
12005 | 383 |
|
384 |
/** |
|
385 |
* <p>Establish a default variable resolver.</p> |
|
386 |
* |
|
387 |
* <p>Any <code>XPath</code> objects constructed from this factory will use |
|
388 |
* the specified resolver by default.</p> |
|
389 |
* |
|
390 |
* <p>A <code>NullPointerException</code> is thrown if <code>resolver</code> |
|
391 |
* is <code>null</code>.</p> |
|
392 |
* |
|
393 |
* @param resolver Variable resolver. |
|
394 |
* |
|
395 |
* @throws NullPointerException If <code>resolver</code> is |
|
396 |
* <code>null</code>. |
|
397 |
*/ |
|
398 |
public abstract void setXPathVariableResolver(XPathVariableResolver resolver); |
|
399 |
||
400 |
/** |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
401 |
* <p>Establish a default function resolver.</p> |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
402 |
* |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
403 |
* <p>Any <code>XPath</code> objects constructed from this factory will |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
404 |
* use the specified resolver by default.</p> |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
405 |
* |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
406 |
* <p>A <code>NullPointerException</code> is thrown if |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
407 |
* <code>resolver</code> is <code>null</code>.</p> |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
408 |
* |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
409 |
* @param resolver XPath function resolver. |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
410 |
* |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
411 |
* @throws NullPointerException If <code>resolver</code> is |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
412 |
* <code>null</code>. |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
12457
diff
changeset
|
413 |
*/ |
12005 | 414 |
public abstract void setXPathFunctionResolver(XPathFunctionResolver resolver); |
415 |
||
416 |
/** |
|
417 |
* <p>Return a new <code>XPath</code> using the underlying object |
|
29419
534054ee6062
8049378: Examine references to ${java.home}/lib in JAXP
joehw
parents:
28695
diff
changeset
|
418 |
* model determined when the {@code XPathFactory} was instantiated.</p> |
12005 | 419 |
* |
420 |
* @return New instance of an <code>XPath</code>. |
|
421 |
*/ |
|
422 |
public abstract XPath newXPath(); |
|
423 |
} |