This is an automated email from the ASF dual-hosted git repository. desruisseaux pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
commit ee6b293e6b2bc983d8d53cf603ac65e7ea587312 Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Sat Dec 10 21:46:42 2022 +0100 Remove reference to JAXB internal implementation, which is not provided anymore. https://issues.apache.org/jira/browse/SIS-469 --- .../java/org/apache/sis/xml/Implementation.java | 55 +++++----------------- .../java/org/apache/sis/xml/MarshallerPool.java | 4 +- .../src/main/java/org/apache/sis/xml/Pooled.java | 47 +++++------------- .../java/org/apache/sis/xml/PooledTemplate.java | 7 +-- .../main/java/org/apache/sis/xml/package-info.java | 2 +- .../org/apache/sis/xml/MarshallerPoolTest.java | 4 -- 6 files changed, 28 insertions(+), 91 deletions(-) diff --git a/core/sis-metadata/src/main/java/org/apache/sis/xml/Implementation.java b/core/sis-metadata/src/main/java/org/apache/sis/xml/Implementation.java index 0540a60fb6..cd8ae8490a 100644 --- a/core/sis-metadata/src/main/java/org/apache/sis/xml/Implementation.java +++ b/core/sis-metadata/src/main/java/org/apache/sis/xml/Implementation.java @@ -24,18 +24,18 @@ import javax.xml.bind.JAXBContext; * This enumeration allows to set vendor-specific marshaller properties. * * @author Martin Desruisseaux (Geomatys) - * @version 1.0 + * @version 1.4 * @since 0.8 * @module */ enum Implementation { /** - * JAXB implementation bundled in the JDK. + * JAXB implementation provided by Jakarta Glassfish. */ - INTERNAL("com.sun.xml.internal.bind.indentString"), + GLASSFISH("org.glassfish.jaxb.indentString"), /** - * JAXB implementation provided in a separated JAR, used for instance by Glassfish. + * JAXB implementation before JAXB moved to Jakarta. */ ENDORSED("com.sun.xml.bind.indentString"), @@ -45,17 +45,14 @@ enum Implementation { OTHER(null); /** - * The prefix of property names which are provided in external (endorsed) implementation of JAXB. - * This is slightly different than the prefix used by the implementation bundled with the JDK 6, - * which is {@code "com.sun.xml.internal.bind"}. + * The prefix of property names for {@link #ENDORSED} implementation. */ private static final String ENDORSED_PREFIX = "com.sun.xml.bind."; /** - * The prefix of property names which are provided in internal implementation of JAXB - * (the one bundled with the JDK 6). + * The prefix of property names for {@link #GLASSFISH} implementation. */ - private static final String INTERNAL_PREFIX = "com.sun.xml.internal.bind."; + private static final String GLASSFISH_PREFIX = "org.glassfish.jaxb."; /** * The JAXB property for setting the indentation string, or {@code null} if none. @@ -70,22 +67,17 @@ enum Implementation { } /** - * Detects if we are using the endorsed JAXB implementation (the one provided in separated JAR files) - * or the one bundled in JDK. We use the JAXB context package name as a criterion: - * - * <ul> - * <li>JAXB endorsed JAR uses {@code "com.sun.xml.bind.*"}</li> - * <li>JAXB bundled in JDK uses {@code "com.sun.xml.internal.bind.*"}</li> - * </ul> + * Detects the JAXB implementation in use. + * This method uses the JAXB context package name as a criterion. * * @param context the JAXB context for which to detect the implementation. - * @return the implementation, or {@code OTHER} if unknown. + * @return the implementation, or {@link #OTHER} if unknown. */ public static Implementation detect(final JAXBContext context) { if (context != null) { final String classname = context.getClass().getName(); - if (classname.startsWith(INTERNAL_PREFIX)) { - return INTERNAL; + if (classname.startsWith(GLASSFISH_PREFIX)) { + return GLASSFISH; } else if (classname.startsWith(ENDORSED_PREFIX)) { return ENDORSED; } @@ -98,32 +90,11 @@ enum Implementation { * A value of {@code true} does not necessarily mean that the given property is supported, * but that the caller should either support the property or throw an exception. * - * <p>This method excludes the {@code "com.sun.xml.bind.*"} properties if the implementation - * is not {@link #ENDORSED} or {@link #INTERNAL}. We do not distinguish between the endorsed - * and internal namespaces since Apache SIS uses only the endorsed namespace and lets - * {@code org.apache.sis.xml.Pooled} do the conversion to internal namespace if needed.</p> - * * @param key the property key to test. * @return {@code false} if the given property should be silently ignored. */ boolean filterProperty(final String key) { - // We user 'indentKey' as a sentinel value for identifying INTERNAL and ENDORSED cases. + // We user `indentKey` as a sentinel value for identifying a recognized implementation. return (indentKey != null) || !key.startsWith(ENDORSED_PREFIX); } - - /** - * Converts the given key from {@code "com.sun.xml.bind.*"} to {@code "com.sun.xml.internal.bind.*"} namespace. - * This method is invoked when the JAXB implementation is known to be the {@link #INTERNAL} one. We perform this - * conversion for allowing Apache SIS to ignore the difference between internal and endorsed JAXB. - * - * @param key the key that may potentially a endorsed JAXB key. - * @return the key as an internal JAXB key, or the given key unchanged if it is not an endorsed JAXB key. - */ - static String toInternal(String key) { - if (key.startsWith(ENDORSED_PREFIX)) { - final StringBuilder buffer = new StringBuilder(key.length() + 10); - key = buffer.append(INTERNAL_PREFIX).append(key, ENDORSED_PREFIX.length(), key.length()).toString(); - } - return key; - } } diff --git a/core/sis-metadata/src/main/java/org/apache/sis/xml/MarshallerPool.java b/core/sis-metadata/src/main/java/org/apache/sis/xml/MarshallerPool.java index 39d75af171..734550d2f6 100644 --- a/core/sis-metadata/src/main/java/org/apache/sis/xml/MarshallerPool.java +++ b/core/sis-metadata/src/main/java/org/apache/sis/xml/MarshallerPool.java @@ -86,9 +86,7 @@ public class MarshallerPool { protected final JAXBContext context; /** - * {@code INTERNAL} if the JAXB implementation is the one bundled in the JDK, - * {@code ENDORSED} if the TAXB implementation is the endorsed JAXB (Glassfish), or - * {@code null} if unknown. + * The JAXB implementation, or {@code null} if unknown. */ private final Implementation implementation; diff --git a/core/sis-metadata/src/main/java/org/apache/sis/xml/Pooled.java b/core/sis-metadata/src/main/java/org/apache/sis/xml/Pooled.java index 498c394f07..53927dcf9b 100644 --- a/core/sis-metadata/src/main/java/org/apache/sis/xml/Pooled.java +++ b/core/sis-metadata/src/main/java/org/apache/sis/xml/Pooled.java @@ -46,13 +46,12 @@ import org.apache.sis.internal.jaxb.TypeRegistration; /** * Base class of {@link PooledMarshaller} and {@link PooledUnmarshaller}. * This class provides basic service for saving the initial values of (un)marshaller properties, - * in order to reset them to their initial values after usage. This is required in order to allow - * (un)marshaller reuse. In addition this base class translates properties key from JDK 6 names to - * "endorsed JAR" names if needed. + * in order to reset them to their initial values after usage. + * This is required in order to allow (un)marshaller reuse. * * @author Martin Desruisseaux (Geomatys) * @author Cullen Rombach (Image Matters) - * @version 1.1 + * @version 1.4 * @since 0.3 * @module */ @@ -63,16 +62,6 @@ abstract class Pooled { */ private static final String[] SCHEMA_KEYS = {"cat", "gmd", "gmi", "gml"}; - /** - * {@code true} if the JAXB implementation is the one bundled in JDK 6, or {@code false} - * if this is the external implementation provided as a JAR file in the endorsed directory. - * If {@code true}, then an additional {@code "internal"} package name needs to be inserted - * in the property keys. - * - * @see Implementation#toInternal(String) - */ - private final boolean internal; - /** * The initial state of the (un)marshaller. Will be filled only as needed, * often with null values (which must be supported by the map implementation). @@ -103,7 +92,7 @@ abstract class Pooled { /** * The timezone, or {@code null} if unspecified. - * Can be set by the {@link XML#TIMEZONE} property. + * Can be set by the {@link XML#TIMEZONE} property. */ private TimeZone timezone; @@ -164,13 +153,8 @@ abstract class Pooled { /** * Creates a {@link PooledTemplate}. - * - * @param internal {@code true} if the JAXB implementation is the one bundled in JDK 6, - * or {@code false} if this is the external implementation provided as a JAR file - * in the endorsed directory. */ - Pooled(final boolean internal) { - this.internal = internal; + Pooled() { initialProperties = new LinkedHashMap<>(); } @@ -182,7 +166,6 @@ abstract class Pooled { */ Pooled(final Pooled template) { initialProperties = new LinkedHashMap<>(); - internal = template.internal; } /** @@ -230,11 +213,11 @@ abstract class Pooled { } /** - * Resets the given marshaller property to its initial state. This method is invoked - * automatically by the {@link #reset(Pooled)} method. The key is either a {@link String} - * or a {@link Class}. If this is a string, then the value shall be given to the - * {@code setProperty(key, value)} method. Otherwise the value shall be given to - * {@code setFoo(value)} method where {@code "Foo"} is determined from the key. + * Resets the given marshaller property to its initial state. This method is invoked automatically + * by the {@link #reset(Pooled)} method. The key is either a {@link String} or a {@link Class}. + * If this is a string, then the value shall be given to the {@code setProperty(key, value)} method. + * Otherwise the value shall be given to {@code setFoo(value)} method + * where {@code "Foo"} is determined from the key. * * @param key the property to reset. * @param value the initial value to give to the property. @@ -399,9 +382,6 @@ abstract class Pooled { * If we reach this point, the given name is not a SIS property. Try to handle * it as a (un)marshaller-specific property, after saving the previous value. */ - if (internal) { - name = Implementation.toInternal(name); - } if (!initialProperties.containsKey(name) && initialProperties.put(name, getStandardProperty(name)) != null) { // Should never happen, unless on concurrent changes in a backgroung thread. throw new ConcurrentModificationException(name); @@ -434,12 +414,7 @@ abstract class Pooled { return (n != 0) ? ArraysExt.resize(substitutes, n) : null; } case TypeRegistration.ROOT_ADAPTERS: return (rootAdapters != null) ? rootAdapters.clone() : null; - default: { - if (internal) { - name = Implementation.toInternal(name); - } - return getStandardProperty(name); - } + default: return getStandardProperty(name); } } diff --git a/core/sis-metadata/src/main/java/org/apache/sis/xml/PooledTemplate.java b/core/sis-metadata/src/main/java/org/apache/sis/xml/PooledTemplate.java index 71fc08a0d3..5ed42c757b 100644 --- a/core/sis-metadata/src/main/java/org/apache/sis/xml/PooledTemplate.java +++ b/core/sis-metadata/src/main/java/org/apache/sis/xml/PooledTemplate.java @@ -31,7 +31,7 @@ import org.apache.sis.util.resources.Errors; * redoing the conversion every time a new (un)marshaller is requested. * * @author Martin Desruisseaux (Geomatys) - * @version 0.3 + * @version 1.4 * @since 0.3 * @module */ @@ -40,12 +40,9 @@ final class PooledTemplate extends Pooled { * Creates a new template. * * @param properties the properties to be given to JAXB (un)marshallers, or {@code null} if none. - * @param implementation {@link Implementation#INTERNAL} if the JAXB implementation is the one bundled in JDK 6, or - * {@link Implementation#ENDORSED} if this is the external implementation provided as a JAR - * file in the endorsed directory. + * @param implementation the JAXB implementation used. */ PooledTemplate(final Map<String,?> properties, final Implementation implementation) throws PropertyException { - super(implementation == Implementation.INTERNAL); if (properties != null) { for (final Map.Entry<String,?> entry : properties.entrySet()) { final String key = entry.getKey(); diff --git a/core/sis-metadata/src/main/java/org/apache/sis/xml/package-info.java b/core/sis-metadata/src/main/java/org/apache/sis/xml/package-info.java index c35cf0b6f8..4d5fce35b6 100644 --- a/core/sis-metadata/src/main/java/org/apache/sis/xml/package-info.java +++ b/core/sis-metadata/src/main/java/org/apache/sis/xml/package-info.java @@ -59,7 +59,7 @@ * @author Guilhem Legal (Geomatys) * @author Martin Desruisseaux (Geomatys) * @author Cullen Rombach (Image Matters) - * @version 1.3 + * @version 1.4 * @since 0.3 * @module */ diff --git a/core/sis-metadata/src/test/java/org/apache/sis/xml/MarshallerPoolTest.java b/core/sis-metadata/src/test/java/org/apache/sis/xml/MarshallerPoolTest.java index cde97a0758..591816dac7 100644 --- a/core/sis-metadata/src/test/java/org/apache/sis/xml/MarshallerPoolTest.java +++ b/core/sis-metadata/src/test/java/org/apache/sis/xml/MarshallerPoolTest.java @@ -46,10 +46,6 @@ public final strictfp class MarshallerPoolTest extends TestCase { final MarshallerPool pool = new MarshallerPool(JAXBContext.newInstance(new Class<?>[0]), null); final Marshaller marshaller = pool.acquireMarshaller(); assertNotNull(marshaller); - /* - * PooledMarshaller should convert the property name from "com.sun.xml.bind.xmlHeaders" to - * "com.sun.xml.internal.bind.xmlHeaders" if we are running JDK implementation of JAXB. - */ assertNull(marshaller.getProperty("com.sun.xml.bind.xmlHeaders")); marshaller.setProperty("com.sun.xml.bind.xmlHeaders", "<DTD ...>"); assertEquals("<DTD ...>", marshaller.getProperty("com.sun.xml.bind.xmlHeaders"));