Commit 22b0c4e1 authored by Lukas Jungmann's avatar Lukas Jungmann
Browse files

added impl lookup through properties passed to JAXBContext.newInstance

Signed-off-by: default avatarLukas Jungmann <lukas.jungmann@oracle.com>
parent 2c22f9e5
...@@ -302,6 +302,18 @@ class ContextFinder { ...@@ -302,6 +302,18 @@ class ContextFinder {
String factoryName = classNameFromSystemProperties(); String factoryName = classNameFromSystemProperties();
if (factoryName != null) return newInstance(contextPath, contextPathClasses, factoryName, classLoader, properties); if (factoryName != null) return newInstance(contextPath, contextPathClasses, factoryName, classLoader, properties);
Object factory = properties.get(factoryId);
if (factory != null) {
if (factory instanceof String) {
factoryName = (String) factory;
} else {
throw new JAXBException(Messages.format(Messages.ILLEGAL_CAST, factory.getClass().getName(), "String"));
}
}
if (factoryName != null) {
return newInstance(contextPath, contextPathClasses, factoryName, classLoader, properties);
}
JAXBContextFactory obj = ServiceLoaderUtil.firstByServiceLoader( JAXBContextFactory obj = ServiceLoaderUtil.firstByServiceLoader(
JAXBContextFactory.class, logger, EXCEPTION_HANDLER); JAXBContextFactory.class, logger, EXCEPTION_HANDLER);
...@@ -332,6 +344,18 @@ class ContextFinder { ...@@ -332,6 +344,18 @@ class ContextFinder {
String factoryClassName = classNameFromSystemProperties(); String factoryClassName = classNameFromSystemProperties();
if (factoryClassName != null) return newInstance(classes, properties, factoryClassName); if (factoryClassName != null) return newInstance(classes, properties, factoryClassName);
Object ctxFactory = properties.get(JAXBContext.JAXB_CONTEXT_FACTORY);
if (ctxFactory != null) {
if (ctxFactory instanceof String) {
factoryClassName = (String) ctxFactory;
} else {
throw new JAXBException(Messages.format(Messages.ILLEGAL_CAST, ctxFactory.getClass().getName(), "String"));
}
}
if (factoryClassName != null) {
return newInstance(classes, properties, factoryClassName);
}
JAXBContextFactory factory = JAXBContextFactory factory =
ServiceLoaderUtil.firstByServiceLoader(JAXBContextFactory.class, logger, EXCEPTION_HANDLER); ServiceLoaderUtil.firstByServiceLoader(JAXBContextFactory.class, logger, EXCEPTION_HANDLER);
......
/* /*
* Copyright (c) 2003, 2021 Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2022 Oracle and/or its affiliates. All rights reserved.
* *
* This program and the accompanying materials are made available under the * This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at * terms of the Eclipse Distribution License v. 1.0, which is available at
...@@ -179,6 +179,11 @@ import java.util.Map; ...@@ -179,6 +179,11 @@ import java.util.Map;
* factory class. This phase of the look up enables per-JVM override of the Jakarta XML Binding implementation. * factory class. This phase of the look up enables per-JVM override of the Jakarta XML Binding implementation.
* *
* <li> * <li>
* If the property {@link #JAXB_CONTEXT_FACTORY} exists in the {@code Map<String, ?>} passed to {@link #newInstance(Class[], Map)}
* or to {@link #newInstance(String, ClassLoader, Map)}, then its value is assumed to be the fully qualified provider factory class name.
* This phase of the look up enables context sensitive selection of the Jakarta XML Binding implementation.
*
* <li>
* Provider of {@link jakarta.xml.bind.JAXBContextFactory} is loaded using the service-provider loading * Provider of {@link jakarta.xml.bind.JAXBContextFactory} is loaded using the service-provider loading
* facilities, defined by the {@link java.util.ServiceLoader} class, to attempt * facilities, defined by the {@link java.util.ServiceLoader} class, to attempt
* to locate and load an implementation of the service using the {@linkplain * to locate and load an implementation of the service using the {@linkplain
...@@ -365,8 +370,8 @@ public abstract class JAXBContext { ...@@ -365,8 +370,8 @@ public abstract class JAXBContext {
* @param classLoader * @param classLoader
* This class loader will be used to locate the implementation classes. * This class loader will be used to locate the implementation classes.
* @param properties * @param properties
* provider-specific properties. Can be null, which means the same thing as passing * provider-specific or provider selection-specific properties.
* in an empty map. * Can be null, which means the same thing as passing in an empty map.
* *
* @return a new instance of a {@code JAXBContext} * @return a new instance of a {@code JAXBContext}
* @throws JAXBException if an error was encountered while creating the * @throws JAXBException if an error was encountered while creating the
...@@ -559,8 +564,8 @@ public abstract class JAXBContext { ...@@ -559,8 +564,8 @@ public abstract class JAXBContext {
* Can be empty, in which case a {@link JAXBContext} that only knows about * Can be empty, in which case a {@link JAXBContext} that only knows about
* spec-defined classes will be returned. * spec-defined classes will be returned.
* @param properties * @param properties
* provider-specific properties. Can be null, which means the same thing as passing * provider-specific or provider selection-specific properties.
* in an empty map. * Can be null, which means the same thing as passing in an empty map.
* *
* @return * @return
* A new instance of a {@code JAXBContext}. * A new instance of a {@code JAXBContext}.
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
through `jaxb.properties` file, `jakarta.xml.bind.context.factory` and through `jaxb.properties` file, `jakarta.xml.bind.context.factory` and
`jakarta.xml.bind.JAXBContext` properties and `/META-INF/services/jakarta.xml.bind.JAXBContext` `jakarta.xml.bind.JAXBContext` properties and `/META-INF/services/jakarta.xml.bind.JAXBContext`
resource file resource file
* added Jakarta XML Binding implementation lookup through the properties `Map`
passed to `JAXBContext.newInstance` methods
* dropped requirement on compatibility with JAXB 1.0 * dropped requirement on compatibility with JAXB 1.0
=== Changes in Version 3 === Changes in Version 3
......
// //
// Copyright (c) 2020 Contributors to the Eclipse Foundation // Copyright (c) 2020, 2022 Contributors to the Eclipse Foundation
// //
== The Binding Framework == The Binding Framework
...@@ -796,6 +796,11 @@ specified (first successful resolution applies): ...@@ -796,6 +796,11 @@ specified (first successful resolution applies):
then its value is assumed to be the provider factory class. This phase then its value is assumed to be the provider factory class. This phase
of the look up enables per-JVM override of the Jakarta XML Binding implementation. of the look up enables per-JVM override of the Jakarta XML Binding implementation.
. If the property `jakarta.xml.bind.JAXBContextFactory` exists in the `Map<String, ?>`
passed to `JAXBContext.newInstance(Class[], Map)` or to `JAXBContext.newInstance(String, ClassLoader, Map)`,
then its value is assumed to be the fully qualified provider factory class name.
This phase of the look up enables context sensitive selection of the Jakarta XML Binding implementation.
. Provider of `jakarta.xml.bind.JAXBContextFactory` is loaded . Provider of `jakarta.xml.bind.JAXBContextFactory` is loaded
using the service-provider loading facilities, as defined by using the service-provider loading facilities, as defined by
Java SE Platform, to attempt to locate and load Java SE Platform, to attempt to locate and load
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment