Skip to content

Commit e7b5f04

Browse files
Roman Grigoriadilukasj
Roman Grigoriadi
authored andcommitted
Non Java SE default context factory for JDK's > 8
Signed-off-by: Roman Grigoriadi <roman.grigoriadi@oracle.com>
1 parent 27d259c commit e7b5f04

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

jaxb-api/src/main/java/javax/xml/bind/ContextFinder.java

+4-19
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,6 @@
3838
*/
3939
class ContextFinder {
4040

41-
/**
42-
* When JAXB is in J2SE, rt.jar has to have a JAXB implementation.
43-
* However, rt.jar cannot have META-INF/services/javax.xml.bind.JAXBContext
44-
* because if it has, it will take precedence over any file that applications have
45-
* in their jar files.
46-
*
47-
* <p>
48-
* When the user bundles his own JAXB implementation, we'd like to use it, and we
49-
* want the platform default to be used only when there's no other JAXB provider.
50-
*
51-
* <p>
52-
* For this reason, we have to hard-code the class name into the API.
53-
*/
54-
private static final String PLATFORM_DEFAULT_FACTORY_CLASS = "com.sun.xml.internal.bind.v2.ContextFactory";
55-
5641
// previous value of JAXBContext.JAXB_CONTEXT_FACTORY, using also this to ensure backwards compatibility
5742
private static final String JAXB_CONTEXT_FACTORY_DEPRECATED = "javax.xml.bind.context.factory";
5843

@@ -140,7 +125,7 @@ static JAXBContext newInstance(String contextPath,
140125
Map properties) throws JAXBException {
141126

142127
try {
143-
Class spFactory = ServiceLoaderUtil.safeLoadClass(className, PLATFORM_DEFAULT_FACTORY_CLASS, classLoader);
128+
Class spFactory = ServiceLoaderUtil.safeLoadClass(className, ModuleUtil.DEFAULT_FACTORY_CLASS, classLoader);
144129
return newInstance(contextPath, contextPathClasses, spFactory, classLoader, properties);
145130
} catch (ClassNotFoundException x) {
146131
throw new JAXBException(Messages.format(Messages.DEFAULT_PROVIDER_NOT_FOUND), x);
@@ -242,7 +227,7 @@ static JAXBContext newInstance(Class[] classes, Map properties, String className
242227

243228
Class spi;
244229
try {
245-
spi = ServiceLoaderUtil.safeLoadClass(className, PLATFORM_DEFAULT_FACTORY_CLASS, getContextClassLoader());
230+
spi = ServiceLoaderUtil.safeLoadClass(className, ModuleUtil.DEFAULT_FACTORY_CLASS, getContextClassLoader());
246231
} catch (ClassNotFoundException e) {
247232
throw new JAXBException(Messages.format(Messages.DEFAULT_PROVIDER_NOT_FOUND), e);
248233
}
@@ -330,7 +315,7 @@ static JAXBContext find(String factoryId,
330315

331316
// else no provider found
332317
logger.fine("Trying to create the platform default provider");
333-
return newInstance(contextPath, contextPathClasses, PLATFORM_DEFAULT_FACTORY_CLASS, classLoader, properties);
318+
return newInstance(contextPath, contextPathClasses, ModuleUtil.DEFAULT_FACTORY_CLASS, classLoader, properties);
334319
}
335320

336321
static JAXBContext find(Class<?>[] classes, Map<String, ?> properties) throws JAXBException {
@@ -387,7 +372,7 @@ static JAXBContext find(Class<?>[] classes, Map<String, ?> properties) throws JA
387372

388373
// else no provider found
389374
logger.fine("Trying to create the platform default provider");
390-
return newInstance(classes, properties, PLATFORM_DEFAULT_FACTORY_CLASS);
375+
return newInstance(classes, properties, ModuleUtil.DEFAULT_FACTORY_CLASS);
391376
}
392377

393378

jaxb-api/src/main/java/javax/xml/bind/ModuleUtil.java

+15
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@
2020
*/
2121
class ModuleUtil {
2222

23+
/**
24+
* When JAXB is in J2SE, rt.jar has to have a JAXB implementation.
25+
* However, rt.jar cannot have META-INF/services/javax.xml.bind.JAXBContext
26+
* because if it has, it will take precedence over any file that applications have
27+
* in their jar files.
28+
*
29+
* <p>
30+
* When the user bundles his own JAXB implementation, we'd like to use it, and we
31+
* want the platform default to be used only when there's no other JAXB provider.
32+
*
33+
* <p>
34+
* For this reason, we have to hard-code the class name into the API.
35+
*/
36+
static final String DEFAULT_FACTORY_CLASS = "com.sun.xml.internal.bind.v2.ContextFactory";
37+
2338
/**
2439
* Resolves classes from context path.
2540
* Only one class per package is needed to access its {@link java.lang.Module}

jaxb-api/src/main/mr-jar/javax/xml/bind/ModuleUtil.java

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ class ModuleUtil {
2929

3030
private static Logger logger = Logger.getLogger("javax.xml.bind");
3131

32+
/**
33+
* JAXB-RI default context factory.
34+
*/
35+
static final String DEFAULT_FACTORY_CLASS = "com.sun.xml.bind.v2.ContextFactory";
36+
3237
/**
3338
* Resolves classes from context path.
3439
* Only one class per package is needed to access its {@link java.lang.Module}

0 commit comments

Comments
 (0)