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 {
String factoryName = classNameFromSystemProperties();
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.class, logger, EXCEPTION_HANDLER);
......@@ -332,6 +344,18 @@ class ContextFinder {
String factoryClassName = classNameFromSystemProperties();
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 =
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
* terms of the Eclipse Distribution License v. 1.0, which is available at
......@@ -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.
*
* <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
* facilities, defined by the {@link java.util.ServiceLoader} class, to attempt
* to locate and load an implementation of the service using the {@linkplain
......@@ -365,8 +370,8 @@ public abstract class JAXBContext {
* @param classLoader
* This class loader will be used to locate the implementation classes.
* @param properties
* provider-specific properties. Can be null, which means the same thing as passing
* in an empty map.
* provider-specific or provider selection-specific properties.
* Can be null, which means the same thing as passing in an empty map.
*
* @return a new instance of a {@code JAXBContext}
* @throws JAXBException if an error was encountered while creating the
......@@ -559,8 +564,8 @@ public abstract class JAXBContext {
* Can be empty, in which case a {@link JAXBContext} that only knows about
* spec-defined classes will be returned.
* @param properties
* provider-specific properties. Can be null, which means the same thing as passing
* in an empty map.
* provider-specific or provider selection-specific properties.
* Can be null, which means the same thing as passing in an empty map.
*
* @return
* A new instance of a {@code JAXBContext}.
......
......@@ -14,6 +14,8 @@
through `jaxb.properties` file, `jakarta.xml.bind.context.factory` and
`jakarta.xml.bind.JAXBContext` properties and `/META-INF/services/jakarta.xml.bind.JAXBContext`
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
=== Changes in Version 3
......
//
// Copyright (c) 2020 Contributors to the Eclipse Foundation
// Copyright (c) 2020, 2022 Contributors to the Eclipse Foundation
//
== The Binding Framework
......@@ -796,6 +796,11 @@ specified (first successful resolution applies):
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.
. 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
using the service-provider loading facilities, as defined by
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