88 * @return Instance of an <code>XPathFactory</code>. |
88 * @return Instance of an <code>XPathFactory</code>. |
89 * |
89 * |
90 * @throws RuntimeException When there is a failure in creating an |
90 * @throws RuntimeException When there is a failure in creating an |
91 * <code>XPathFactory</code> for the default object model. |
91 * <code>XPathFactory</code> for the default object model. |
92 */ |
92 */ |
93 public static final XPathFactory newInstance() { |
93 public static XPathFactory newInstance() { |
94 |
94 |
95 try { |
95 try { |
96 return newInstance(DEFAULT_OBJECT_MODEL_URI); |
96 return newInstance(DEFAULT_OBJECT_MODEL_URI); |
97 } catch (XPathFactoryConfigurationException xpathFactoryConfigurationException) { |
97 } catch (XPathFactoryConfigurationException xpathFactoryConfigurationException) { |
98 throw new RuntimeException( |
98 throw new RuntimeException( |
119 * <li> |
119 * <li> |
120 * ${java.home}/lib/jaxp.properties is read and the value associated with the key being the system property above is looked for. |
120 * ${java.home}/lib/jaxp.properties is read and the value associated with the key being the system property above is looked for. |
121 * If present, the value is processed just like above. |
121 * If present, the value is processed just like above. |
122 * </li> |
122 * </li> |
123 * <li> |
123 * <li> |
124 * The class loader is asked for service provider provider-configuration files matching <code>javax.xml.xpath.XPathFactory</code> |
124 * Use the service-provider loading facilities, defined by the |
125 * in the resource directory META-INF/services. |
125 * {@link java.util.ServiceLoader} class, to attempt to locate and load an |
126 * See the JAR File Specification for file format and parsing rules. |
126 * implementation of the service. |
127 * Each potential service provider is required to implement the method: |
127 * <br> |
128 * <pre> |
128 * Each potential service provider is required to implement the method |
129 * {@link #isObjectModelSupported(String objectModel)} |
129 * {@link #isObjectModelSupported(String objectModel)}. |
130 * </pre> |
130 * The first service provider found that supports the specified object |
131 * The first service provider found in class loader order that supports the specified object model is returned. |
131 * model is returned. |
|
132 * <br> |
|
133 * In case of {@link java.util.ServiceConfigurationError} an |
|
134 * {@link XPathFactoryConfigurationException} will be thrown. |
132 * </li> |
135 * </li> |
133 * <li> |
136 * <li> |
134 * Platform default <code>XPathFactory</code> is located in a platform specific way. |
137 * Platform default <code>XPathFactory</code> is located in a platform specific way. |
135 * There must be a platform default XPathFactory for the W3C DOM, i.e. {@link #DEFAULT_OBJECT_MODEL_URI}. |
138 * There must be a platform default XPathFactory for the W3C DOM, i.e. {@link #DEFAULT_OBJECT_MODEL_URI}. |
136 * </li> |
139 * </li> |
150 * <code>http://java.sun.com/jaxp/xpath/dom</code> for the W3C DOM, |
153 * <code>http://java.sun.com/jaxp/xpath/dom</code> for the W3C DOM, |
151 * the org.w3c.dom package, and implementations are free to introduce other URIs for other object models. |
154 * the org.w3c.dom package, and implementations are free to introduce other URIs for other object models. |
152 * |
155 * |
153 * @return Instance of an <code>XPathFactory</code>. |
156 * @return Instance of an <code>XPathFactory</code>. |
154 * |
157 * |
155 * @throws XPathFactoryConfigurationException If the specified object model is unavailable. |
158 * @throws XPathFactoryConfigurationException If the specified object model |
|
159 * is unavailable, or if there is a configuration error. |
156 * @throws NullPointerException If <code>uri</code> is <code>null</code>. |
160 * @throws NullPointerException If <code>uri</code> is <code>null</code>. |
157 * @throws IllegalArgumentException If <code>uri</code> is <code>null</code> |
161 * @throws IllegalArgumentException If <code>uri</code> is <code>null</code> |
158 * or <code>uri.length() == 0</code>. |
162 * or <code>uri.length() == 0</code>. |
159 */ |
163 */ |
160 public static final XPathFactory newInstance(final String uri) |
164 public static XPathFactory newInstance(final String uri) |
161 throws XPathFactoryConfigurationException { |
165 throws XPathFactoryConfigurationException { |
162 |
166 |
163 if (uri == null) { |
167 if (uri == null) { |
164 throw new NullPointerException( |
168 throw new NullPointerException( |
165 "XPathFactory#newInstance(String uri) cannot be called with uri == null" |
169 "XPathFactory#newInstance(String uri) cannot be called with uri == null"); |
166 ); |
170 } |
167 } |
171 |
168 |
172 if (uri.length() == 0) { |
169 if (uri.length() == 0) { |
173 throw new IllegalArgumentException( |
170 throw new IllegalArgumentException( |
174 "XPathFactory#newInstance(String uri) cannot be called with uri == \"\""); |
171 "XPathFactory#newInstance(String uri) cannot be called with uri == \"\"" |
175 } |
172 ); |
176 |
173 } |
177 ClassLoader classLoader = ss.getContextClassLoader(); |
174 |
|
175 ClassLoader classLoader = ss.getContextClassLoader(); |
|
176 |
178 |
177 if (classLoader == null) { |
179 if (classLoader == null) { |
178 //use the current class loader |
180 //use the current class loader |
179 classLoader = XPathFactory.class.getClassLoader(); |
181 classLoader = XPathFactory.class.getClassLoader(); |
180 } |
182 } |
181 |
183 |
182 XPathFactory xpathFactory = new XPathFactoryFinder(classLoader).newFactory(uri); |
184 XPathFactory xpathFactory = new XPathFactoryFinder(classLoader).newFactory(uri); |
183 |
185 |
184 if (xpathFactory == null) { |
186 if (xpathFactory == null) { |
185 throw new XPathFactoryConfigurationException( |
187 throw new XPathFactoryConfigurationException( |
186 "No XPathFactory implementation found for the object model: " |
188 "No XPathFactory implementation found for the object model: " |
187 + uri |
189 + uri); |
188 ); |
190 } |
189 } |
191 |
190 |
192 return xpathFactory; |
191 return xpathFactory; |
|
192 } |
193 } |
193 |
194 |
194 /** |
195 /** |
195 * <p>Obtain a new instance of a <code>XPathFactory</code> from a factory class name. <code>XPathFactory</code> |
196 * <p>Obtain a new instance of a <code>XPathFactory</code> from a factory class name. <code>XPathFactory</code> |
196 * is returned if specified factory class supports the specified object model. |
197 * is returned if specified factory class supports the specified object model. |
240 public static XPathFactory newInstance(String uri, String factoryClassName, ClassLoader classLoader) |
241 public static XPathFactory newInstance(String uri, String factoryClassName, ClassLoader classLoader) |
241 throws XPathFactoryConfigurationException{ |
242 throws XPathFactoryConfigurationException{ |
242 ClassLoader cl = classLoader; |
243 ClassLoader cl = classLoader; |
243 |
244 |
244 if (uri == null) { |
245 if (uri == null) { |
245 throw new NullPointerException( |
246 throw new NullPointerException( |
246 "XPathFactory#newInstance(String uri) cannot be called with uri == null" |
247 "XPathFactory#newInstance(String uri) cannot be called with uri == null"); |
247 ); |
248 } |
248 } |
249 |
249 |
250 if (uri.length() == 0) { |
250 if (uri.length() == 0) { |
251 throw new IllegalArgumentException( |
251 throw new IllegalArgumentException( |
252 "XPathFactory#newInstance(String uri) cannot be called with uri == \"\""); |
252 "XPathFactory#newInstance(String uri) cannot be called with uri == \"\"" |
253 } |
253 ); |
|
254 } |
|
255 |
254 |
256 if (cl == null) { |
255 if (cl == null) { |
257 cl = ss.getContextClassLoader(); |
256 cl = ss.getContextClassLoader(); |
258 } |
257 } |
259 |
258 |
260 XPathFactory f = new XPathFactoryFinder(cl).createInstance(factoryClassName); |
259 XPathFactory f = new XPathFactoryFinder(cl).createInstance(factoryClassName); |
261 |
260 |
262 if (f == null) { |
261 if (f == null) { |
263 throw new XPathFactoryConfigurationException( |
262 throw new XPathFactoryConfigurationException( |
264 "No XPathFactory implementation found for the object model: " |
263 "No XPathFactory implementation found for the object model: " |
265 + uri |
264 + uri); |
266 ); |
|
267 } |
265 } |
268 //if this factory supports the given schemalanguage return this factory else thrown exception |
266 //if this factory supports the given schemalanguage return this factory else thrown exception |
269 if(f.isObjectModelSupported(uri)){ |
267 if (f.isObjectModelSupported(uri)) { |
270 return f; |
268 return f; |
271 }else{ |
269 } else { |
272 throw new XPathFactoryConfigurationException("Factory " + factoryClassName + " doesn't support given " + uri + " object model"); |
270 throw new XPathFactoryConfigurationException("Factory " |
|
271 + factoryClassName + " doesn't support given " + uri |
|
272 + " object model"); |
273 } |
273 } |
274 |
274 |
275 } |
275 } |
276 |
276 |
277 /** |
277 /** |
278 * <p>Is specified object model supported by this <code>XPathFactory</code>?</p> |
278 * <p>Is specified object model supported by this <code>XPathFactory</code>?</p> |
279 * |
279 * |
280 * @param objectModel Specifies the object model which the returned <code>XPathFactory</code> will understand. |
280 * @param objectModel Specifies the object model which the returned <code>XPathFactory</code> will understand. |
281 * |
281 * |
282 * @return <code>true</code> if <code>XPathFactory</code> supports <code>objectModel</code>, else <code>false</code>. |
282 * @return <code>true</code> if <code>XPathFactory</code> supports <code>objectModel</code>, else <code>false</code>. |
283 * |
283 * |
284 * @throws NullPointerException If <code>objectModel</code> is <code>null</code>. |
284 * @throws NullPointerException If <code>objectModel</code> is <code>null</code>. |
285 * @throws IllegalArgumentException If <code>objectModel.length() == 0</code>. |
285 * @throws IllegalArgumentException If <code>objectModel.length() == 0</code>. |
286 */ |
286 */ |
287 public abstract boolean isObjectModelSupported(String objectModel); |
287 public abstract boolean isObjectModelSupported(String objectModel); |
288 |
288 |
289 /** |
289 /** |
290 * <p>Set a feature for this <code>XPathFactory</code> and |
290 * <p>Set a feature for this <code>XPathFactory</code> and |
291 * <code>XPath</code>s created by this factory.</p> |
291 * <code>XPath</code>s created by this factory.</p> |
292 * |
292 * |
312 * |
312 * |
313 * @throws XPathFactoryConfigurationException if this <code>XPathFactory</code> or the <code>XPath</code>s |
313 * @throws XPathFactoryConfigurationException if this <code>XPathFactory</code> or the <code>XPath</code>s |
314 * it creates cannot support this feature. |
314 * it creates cannot support this feature. |
315 * @throws NullPointerException if <code>name</code> is <code>null</code>. |
315 * @throws NullPointerException if <code>name</code> is <code>null</code>. |
316 */ |
316 */ |
317 public abstract void setFeature(String name, boolean value) |
317 public abstract void setFeature(String name, boolean value) |
318 throws XPathFactoryConfigurationException; |
318 throws XPathFactoryConfigurationException; |
319 |
319 |
320 /** |
320 /** |
321 * <p>Get the state of the named feature.</p> |
321 * <p>Get the state of the named feature.</p> |
322 * |
322 * |
323 * <p> |
323 * <p> |
337 * @throws XPathFactoryConfigurationException if this |
337 * @throws XPathFactoryConfigurationException if this |
338 * <code>XPathFactory</code> or the <code>XPath</code>s |
338 * <code>XPathFactory</code> or the <code>XPath</code>s |
339 * it creates cannot support this feature. |
339 * it creates cannot support this feature. |
340 * @throws NullPointerException if <code>name</code> is <code>null</code>. |
340 * @throws NullPointerException if <code>name</code> is <code>null</code>. |
341 */ |
341 */ |
342 public abstract boolean getFeature(String name) |
342 public abstract boolean getFeature(String name) |
343 throws XPathFactoryConfigurationException; |
343 throws XPathFactoryConfigurationException; |
344 |
344 |
345 /** |
345 /** |
346 * <p>Establish a default variable resolver.</p> |
346 * <p>Establish a default variable resolver.</p> |
347 * |
347 * |
348 * <p>Any <code>XPath</code> objects constructed from this factory will use |
348 * <p>Any <code>XPath</code> objects constructed from this factory will use |
357 * <code>null</code>. |
357 * <code>null</code>. |
358 */ |
358 */ |
359 public abstract void setXPathVariableResolver(XPathVariableResolver resolver); |
359 public abstract void setXPathVariableResolver(XPathVariableResolver resolver); |
360 |
360 |
361 /** |
361 /** |
362 * <p>Establish a default function resolver.</p> |
362 * <p>Establish a default function resolver.</p> |
363 * |
363 * |
364 * <p>Any <code>XPath</code> objects constructed from this factory will |
364 * <p>Any <code>XPath</code> objects constructed from this factory will |
365 * use the specified resolver by default.</p> |
365 * use the specified resolver by default.</p> |
366 * |
366 * |
367 * <p>A <code>NullPointerException</code> is thrown if |
367 * <p>A <code>NullPointerException</code> is thrown if |
368 * <code>resolver</code> is <code>null</code>.</p> |
368 * <code>resolver</code> is <code>null</code>.</p> |
369 * |
369 * |
370 * @param resolver XPath function resolver. |
370 * @param resolver XPath function resolver. |
371 * |
371 * |
372 * @throws NullPointerException If <code>resolver</code> is |
372 * @throws NullPointerException If <code>resolver</code> is |
373 * <code>null</code>. |
373 * <code>null</code>. |
374 */ |
374 */ |
375 public abstract void setXPathFunctionResolver(XPathFunctionResolver resolver); |
375 public abstract void setXPathFunctionResolver(XPathFunctionResolver resolver); |
376 |
376 |
377 /** |
377 /** |
378 * <p>Return a new <code>XPath</code> using the underlying object |
378 * <p>Return a new <code>XPath</code> using the underlying object |
379 * model determined when the <code>XPathFactory</code> was instantiated.</p> |
379 * model determined when the <code>XPathFactory</code> was instantiated.</p> |