author | joehw |
Thu, 21 Dec 2017 17:08:05 -0800 | |
changeset 48412 | d4412e380f6b |
parent 47312 | d4f959806fe9 |
permissions | -rw-r--r-- |
12005 | 1 |
/* |
45853
bfa06be36a17
8181154: Fix lint warnings in JAXP repo: deprecation
joehw
parents:
42806
diff
changeset
|
2 |
* Copyright (c) 2003, 2017, 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.parsers; |
|
27 |
||
28 |
import java.io.File; |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
29 |
import java.security.AccessController; |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
30 |
import java.security.PrivilegedAction; |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
31 |
import java.util.Iterator; |
12458 | 32 |
import java.util.Properties; |
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
33 |
import java.util.ServiceConfigurationError; |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
34 |
import java.util.ServiceLoader; |
42806
35843e3d5ef1
8146271: File system contention in debug print via XPathFactory.newInstance
aefimov
parents:
27574
diff
changeset
|
35 |
import java.util.function.Supplier; |
47312 | 36 |
import jdk.xml.internal.SecuritySupport; |
12005 | 37 |
|
38 |
/** |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
39 |
* <p>Implements pluggable Parsers.</p> |
12005 | 40 |
* |
41 |
* <p>This class is duplicated for each JAXP subpackage so keep it in |
|
42 |
* sync. It is package private for secure class loading.</p> |
|
43 |
* |
|
48412 | 44 |
* @author Santiago PericasGeertsen |
12005 | 45 |
*/ |
46 |
class FactoryFinder { |
|
16953 | 47 |
private static final String DEFAULT_PACKAGE = "com.sun.org.apache.xerces.internal"; |
12005 | 48 |
/** |
49 |
* Internal debug flag. |
|
50 |
*/ |
|
51 |
private static boolean debug = false; |
|
52 |
||
53 |
/** |
|
27574 | 54 |
* Cache for properties in java.home/conf/jaxp.properties |
12005 | 55 |
*/ |
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
56 |
private static final Properties cacheProps = new Properties(); |
12005 | 57 |
|
58 |
/** |
|
27574 | 59 |
* Flag indicating if properties from java.home/conf/jaxp.properties |
12005 | 60 |
* have been cached. |
61 |
*/ |
|
12458 | 62 |
static volatile boolean firstTime = true; |
12005 | 63 |
|
64 |
// Define system property "jaxp.debug" to get output |
|
65 |
static { |
|
66 |
// Use try/catch block to support applets, which throws |
|
67 |
// SecurityException out of this code. |
|
68 |
try { |
|
47312 | 69 |
String val = SecuritySupport.getSystemProperty("jaxp.debug"); |
12005 | 70 |
// Allow simply setting the prop to turn on debug |
71 |
debug = val != null && !"false".equals(val); |
|
72 |
} |
|
73 |
catch (SecurityException se) { |
|
74 |
debug = false; |
|
75 |
} |
|
76 |
} |
|
77 |
||
42806
35843e3d5ef1
8146271: File system contention in debug print via XPathFactory.newInstance
aefimov
parents:
27574
diff
changeset
|
78 |
private static void dPrint(Supplier<String> msgGen) { |
12005 | 79 |
if (debug) { |
42806
35843e3d5ef1
8146271: File system contention in debug print via XPathFactory.newInstance
aefimov
parents:
27574
diff
changeset
|
80 |
System.err.println("JAXP: " + msgGen.get()); |
12005 | 81 |
} |
82 |
} |
|
83 |
||
84 |
/** |
|
85 |
* Attempt to load a class using the class loader supplied. If that fails |
|
86 |
* and fall back is enabled, the current (i.e. bootstrap) class loader is |
|
87 |
* tried. |
|
88 |
* |
|
89 |
* If the class loader supplied is <code>null</code>, first try using the |
|
90 |
* context class loader followed by the current (i.e. bootstrap) class |
|
91 |
* loader. |
|
12458 | 92 |
* |
93 |
* Use bootstrap classLoader if cl = null and useBSClsLoader is true |
|
12005 | 94 |
*/ |
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
95 |
static private Class<?> getProviderClass(String className, ClassLoader cl, |
12458 | 96 |
boolean doFallback, boolean useBSClsLoader) throws ClassNotFoundException |
12005 | 97 |
{ |
98 |
try { |
|
99 |
if (cl == null) { |
|
12458 | 100 |
if (useBSClsLoader) { |
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
101 |
return Class.forName(className, false, FactoryFinder.class.getClassLoader()); |
12458 | 102 |
} else { |
47312 | 103 |
cl = SecuritySupport.getContextClassLoader(); |
12458 | 104 |
if (cl == null) { |
105 |
throw new ClassNotFoundException(); |
|
106 |
} |
|
107 |
else { |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
108 |
return Class.forName(className, false, cl); |
12458 | 109 |
} |
12005 | 110 |
} |
111 |
} |
|
112 |
else { |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
113 |
return Class.forName(className, false, cl); |
12005 | 114 |
} |
115 |
} |
|
116 |
catch (ClassNotFoundException e1) { |
|
117 |
if (doFallback) { |
|
118 |
// Use current class loader - should always be bootstrap CL |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
119 |
return Class.forName(className, false, FactoryFinder.class.getClassLoader()); |
12005 | 120 |
} |
121 |
else { |
|
122 |
throw e1; |
|
123 |
} |
|
124 |
} |
|
125 |
} |
|
126 |
||
127 |
/** |
|
128 |
* Create an instance of a class. Delegates to method |
|
129 |
* <code>getProviderClass()</code> in order to load the class. |
|
130 |
* |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
131 |
* @param type Base class / Service interface of the factory to |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
132 |
* instantiate. |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
133 |
* |
12005 | 134 |
* @param className Name of the concrete class corresponding to the |
135 |
* service provider |
|
136 |
* |
|
12458 | 137 |
* @param cl <code>ClassLoader</code> used to load the factory class. If <code>null</code> |
138 |
* current <code>Thread</code>'s context classLoader is used to load the factory class. |
|
12005 | 139 |
* |
140 |
* @param doFallback True if the current ClassLoader should be tried as |
|
141 |
* a fallback if the class is not found using cl |
|
142 |
*/ |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
143 |
static <T> T newInstance(Class<T> type, String className, ClassLoader cl, |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
144 |
boolean doFallback) |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
145 |
throws FactoryConfigurationError |
12005 | 146 |
{ |
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
147 |
return newInstance(type, className, cl, doFallback, false); |
12458 | 148 |
} |
149 |
||
150 |
/** |
|
151 |
* Create an instance of a class. Delegates to method |
|
152 |
* <code>getProviderClass()</code> in order to load the class. |
|
153 |
* |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
154 |
* @param type Base class / Service interface of the factory to |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
155 |
* instantiate. |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
156 |
* |
12458 | 157 |
* @param className Name of the concrete class corresponding to the |
158 |
* service provider |
|
159 |
* |
|
160 |
* @param cl <code>ClassLoader</code> used to load the factory class. If <code>null</code> |
|
161 |
* current <code>Thread</code>'s context classLoader is used to load the factory class. |
|
162 |
* |
|
163 |
* @param doFallback True if the current ClassLoader should be tried as |
|
164 |
* a fallback if the class is not found using cl |
|
165 |
* |
|
166 |
* @param useBSClsLoader True if cl=null actually meant bootstrap classLoader. This parameter |
|
167 |
* is needed since DocumentBuilderFactory/SAXParserFactory defined null as context classLoader. |
|
168 |
*/ |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
169 |
static <T> T newInstance(Class<T> type, String className, ClassLoader cl, |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
170 |
boolean doFallback, boolean useBSClsLoader) |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
171 |
throws FactoryConfigurationError |
12458 | 172 |
{ |
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
173 |
assert type != null; |
16953 | 174 |
// make sure we have access to restricted packages |
175 |
if (System.getSecurityManager() != null) { |
|
176 |
if (className != null && className.startsWith(DEFAULT_PACKAGE)) { |
|
177 |
cl = null; |
|
178 |
useBSClsLoader = true; |
|
179 |
} |
|
180 |
} |
|
181 |
||
12005 | 182 |
try { |
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
183 |
Class<?> providerClass = getProviderClass(className, cl, doFallback, useBSClsLoader); |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
184 |
if (!type.isAssignableFrom(providerClass)) { |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
185 |
throw new ClassCastException(className + " cannot be cast to " + type.getName()); |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
186 |
} |
45853
bfa06be36a17
8181154: Fix lint warnings in JAXP repo: deprecation
joehw
parents:
42806
diff
changeset
|
187 |
Object instance = providerClass.getConstructor().newInstance(); |
42806
35843e3d5ef1
8146271: File system contention in debug print via XPathFactory.newInstance
aefimov
parents:
27574
diff
changeset
|
188 |
final ClassLoader clD = cl; |
35843e3d5ef1
8146271: File system contention in debug print via XPathFactory.newInstance
aefimov
parents:
27574
diff
changeset
|
189 |
dPrint(()->"created new instance of " + providerClass + |
35843e3d5ef1
8146271: File system contention in debug print via XPathFactory.newInstance
aefimov
parents:
27574
diff
changeset
|
190 |
" using ClassLoader: " + clD); |
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
191 |
return type.cast(instance); |
12005 | 192 |
} |
193 |
catch (ClassNotFoundException x) { |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
194 |
throw new FactoryConfigurationError(x, |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
195 |
"Provider " + className + " not found"); |
12005 | 196 |
} |
197 |
catch (Exception x) { |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
198 |
throw new FactoryConfigurationError(x, |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
199 |
"Provider " + className + " could not be instantiated: " + x); |
12005 | 200 |
} |
201 |
} |
|
202 |
||
203 |
/** |
|
204 |
* Finds the implementation Class object in the specified order. Main |
|
205 |
* entry point. |
|
206 |
* @return Class object of factory, never null |
|
207 |
* |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
208 |
* @param type Base class / Service interface of the |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
209 |
* factory to find. |
12005 | 210 |
* @param fallbackClassName Implementation class name, if nothing else |
211 |
* is found. Use null to mean no fallback. |
|
212 |
* |
|
213 |
* Package private so this code can be shared. |
|
214 |
*/ |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
215 |
static <T> T find(Class<T> type, String fallbackClassName) |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
216 |
throws FactoryConfigurationError |
12005 | 217 |
{ |
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
218 |
final String factoryId = type.getName(); |
42806
35843e3d5ef1
8146271: File system contention in debug print via XPathFactory.newInstance
aefimov
parents:
27574
diff
changeset
|
219 |
dPrint(()->"find factoryId =" + factoryId); |
12005 | 220 |
|
221 |
// Use the system property first |
|
222 |
try { |
|
47312 | 223 |
String systemProp = SecuritySupport.getSystemProperty(factoryId); |
12005 | 224 |
if (systemProp != null) { |
42806
35843e3d5ef1
8146271: File system contention in debug print via XPathFactory.newInstance
aefimov
parents:
27574
diff
changeset
|
225 |
dPrint(()->"found system property, value=" + systemProp); |
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
226 |
return newInstance(type, systemProp, null, true); |
12005 | 227 |
} |
228 |
} |
|
229 |
catch (SecurityException se) { |
|
230 |
if (debug) se.printStackTrace(); |
|
231 |
} |
|
232 |
||
27574 | 233 |
// try to read from $java.home/conf/jaxp.properties |
12005 | 234 |
try { |
235 |
if (firstTime) { |
|
236 |
synchronized (cacheProps) { |
|
237 |
if (firstTime) { |
|
47312 | 238 |
String configFile = SecuritySupport.getSystemProperty("java.home") + File.separator + |
27574 | 239 |
"conf" + File.separator + "jaxp.properties"; |
12005 | 240 |
File f = new File(configFile); |
241 |
firstTime = false; |
|
47312 | 242 |
if (SecuritySupport.doesFileExist(f)) { |
42806
35843e3d5ef1
8146271: File system contention in debug print via XPathFactory.newInstance
aefimov
parents:
27574
diff
changeset
|
243 |
dPrint(()->"Read properties file "+f); |
47312 | 244 |
cacheProps.load(SecuritySupport.getFileInputStream(f)); |
12005 | 245 |
} |
246 |
} |
|
247 |
} |
|
248 |
} |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
249 |
final String factoryClassName = cacheProps.getProperty(factoryId); |
12005 | 250 |
|
251 |
if (factoryClassName != null) { |
|
42806
35843e3d5ef1
8146271: File system contention in debug print via XPathFactory.newInstance
aefimov
parents:
27574
diff
changeset
|
252 |
dPrint(()->"found in ${java.home}/conf/jaxp.properties, value=" + factoryClassName); |
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
253 |
return newInstance(type, factoryClassName, null, true); |
12005 | 254 |
} |
255 |
} |
|
256 |
catch (Exception ex) { |
|
257 |
if (debug) ex.printStackTrace(); |
|
258 |
} |
|
259 |
||
260 |
// Try Jar Service Provider Mechanism |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
261 |
T provider = findServiceProvider(type); |
12005 | 262 |
if (provider != null) { |
263 |
return provider; |
|
264 |
} |
|
265 |
if (fallbackClassName == null) { |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
266 |
throw new FactoryConfigurationError( |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
267 |
"Provider for " + factoryId + " cannot be found"); |
12005 | 268 |
} |
269 |
||
42806
35843e3d5ef1
8146271: File system contention in debug print via XPathFactory.newInstance
aefimov
parents:
27574
diff
changeset
|
270 |
dPrint(()->"loaded from fallback value: " + fallbackClassName); |
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
271 |
return newInstance(type, fallbackClassName, null, true); |
12005 | 272 |
} |
273 |
||
274 |
/* |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
275 |
* Try to find provider using the ServiceLoader API |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
276 |
* |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
277 |
* @param type Base class / Service interface of the factory to find. |
12005 | 278 |
* |
279 |
* @return instance of provider class if found or null |
|
280 |
*/ |
|
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
281 |
private static <T> T findServiceProvider(final Class<T> type) { |
12005 | 282 |
try { |
17264
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
283 |
return AccessController.doPrivileged(new PrivilegedAction<T>() { |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
284 |
public T run() { |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
285 |
final ServiceLoader<T> serviceLoader = ServiceLoader.load(type); |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
286 |
final Iterator<T> iterator = serviceLoader.iterator(); |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
287 |
if (iterator.hasNext()) { |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
288 |
return iterator.next(); |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
289 |
} else { |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
290 |
return null; |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
291 |
} |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
292 |
} |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
293 |
}); |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
294 |
} catch(ServiceConfigurationError e) { |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
295 |
// It is not possible to wrap an error directly in |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
296 |
// FactoryConfigurationError - so we need to wrap the |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
297 |
// ServiceConfigurationError in a RuntimeException. |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
298 |
// The alternative would be to modify the logic in |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
299 |
// FactoryConfigurationError to allow setting a |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
300 |
// Throwable as the cause, but that could cause |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
301 |
// compatibility issues down the road. |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
302 |
final RuntimeException x = new RuntimeException( |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
303 |
"Provider for " + type + " cannot be created", e); |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
304 |
final FactoryConfigurationError error = |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
305 |
new FactoryConfigurationError(x, x.getMessage()); |
3aff554ad461
8005954: JAXP Plugability Layer should use java.util.ServiceLoader
dfuchs
parents:
16953
diff
changeset
|
306 |
throw error; |
12005 | 307 |
} |
308 |
} |
|
309 |
||
310 |
} |