You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2022/12/10 20:49:40 UTC

[sis] branch geoapi-4.0 updated (c33f347075 -> ee6b293e6b)

This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a change to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git


    from c33f347075 Rename `JDK9` as `JDK17` since it is now a placeholder for methods defined after Java 11.
     new 11293da0ed Rollback two changes from last commit where the order of elements in the `Set` matter.
     new ee6b293e6b Remove reference to JAXB internal implementation, which is not provided anymore.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../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 --
 .../internal/referencing/CoordinateOperations.java |  5 +-
 .../java/org/apache/sis/io/wkt/WKTDictionary.java  |  3 +-
 .../apache/sis/internal/util/CollectionsExt.java   | 24 ++++++++--
 .../org/apache/sis/internal/util/package-info.java |  2 +-
 10 files changed, 55 insertions(+), 98 deletions(-)


[sis] 01/02: Rollback two changes from last commit where the order of elements in the `Set` matter.

Posted by de...@apache.org.
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 11293da0ed384e3707eafeaf43fc8b958c9e2928
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Sat Dec 10 21:43:20 2022 +0100

    Rollback two changes from last commit where the order of elements in the `Set` matter.
---
 .../internal/referencing/CoordinateOperations.java |  5 +++--
 .../java/org/apache/sis/io/wkt/WKTDictionary.java  |  3 ++-
 .../apache/sis/internal/util/CollectionsExt.java   | 24 +++++++++++++++++++---
 .../org/apache/sis/internal/util/package-info.java |  2 +-
 4 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/CoordinateOperations.java b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/CoordinateOperations.java
index 018b5db1c0..7fcd3a1eae 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/CoordinateOperations.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/CoordinateOperations.java
@@ -41,6 +41,7 @@ import org.apache.sis.internal.metadata.NameToIdentifier;
 import org.apache.sis.internal.system.DefaultFactories;
 import org.apache.sis.internal.system.Modules;
 import org.apache.sis.internal.system.SystemListener;
+import org.apache.sis.internal.util.CollectionsExt;
 import org.apache.sis.internal.util.Numerics;
 import org.apache.sis.util.Deprecable;
 import org.apache.sis.util.collection.Containers;
@@ -51,7 +52,7 @@ import org.apache.sis.util.collection.Containers;
  * until first needed. Contains also utility methods related to coordinate operations.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.1
+ * @version 1.4
  * @since   0.7
  * @module
  */
@@ -292,7 +293,7 @@ public final class CoordinateOperations extends SystemListener {
             indices[i] = dim;
             r &= ~(1L << dim);
         }
-        final Set<Integer> dimensions = Set.of(indices);
+        final Set<Integer> dimensions = CollectionsExt.immutableSet(true, indices);
         if (useCache) {
             synchronized (CACHE) {
                 final Set<Integer> existing = CACHE[(int) changes];
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/WKTDictionary.java b/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/WKTDictionary.java
index a3397abd62..04268b3420 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/WKTDictionary.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/WKTDictionary.java
@@ -149,6 +149,7 @@ public class WKTDictionary extends GeodeticAuthorityFactory {
     /**
      * Code spaces of authority codes recognized by this factory.
      * This set is computed from the {@code "ID[…]"} elements found in WKT definitions.
+     * Code spaces are sorted with most frequently used space first.
      *
      * @see #getCodeSpaces()
      */
@@ -882,7 +883,7 @@ public class WKTDictionary extends GeodeticAuthorityFactory {
     public Set<String> getCodeSpaces() {
         lock.readLock().lock();
         try {
-            return Set.copyOf(codespaces);
+            return CollectionsExt.copyPreserveOrder(codespaces);
         } finally {
             lock.readLock().unlock();
         }
diff --git a/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java b/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java
index 81f8edc66a..566185a50d 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java
@@ -49,7 +49,7 @@ import static org.apache.sis.util.collection.Containers.hashMapCapacity;
  * bit tedious to explain, which is another indication that they should not be in public API.
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
- * @version 1.1
+ * @version 1.4
  * @since   0.3
  * @module
  */
@@ -335,14 +335,14 @@ public final class CollectionsExt extends Static {
      * sense of {@link Object#equals(Object)}, then only the last instance of the duplicated
      * values will be included in the returned set.
      *
+     * <p>This method differs from {@link Set#of(Object...)} in that it preserves element order.</p>
+     *
      * @param  <E>          the type of array elements.
      * @param  excludeNull  {@code true} for excluding the {@code null} element from the returned set.
      * @param  array        the array to copy in a set. May be {@code null} or contain null elements.
      * @return a set containing the array elements, or {@code null} if the given array was null.
      *
      * @see Collections#unmodifiableSet(Set)
-     *
-     * @todo Consider replacing by {@code Set.of(...)} in JDK9.
      */
     @SafeVarargs
     @SuppressWarnings("fallthrough")
@@ -691,6 +691,24 @@ public final class CollectionsExt extends Static {
         return list;
     }
 
+    /**
+     * Returns a unmodifiable copy of the given set, preserving order.
+     *
+     * @param  <E>   the type of elements.
+     * @param  set   the set to copy, or {@code null}.
+     * @return a copy of the given set, or {@code null} if the given set was null.
+     */
+    public static <E> Set<E> copyPreserveOrder(final Set<E> set) {
+        if (set == null) {
+            return null;
+        }
+        switch (set.size()) {
+            case 0:  return Collections.emptySet();
+            case 1:  return Collections.singleton(set.iterator().next());
+            default: return Collections.unmodifiableSet(new LinkedHashSet<>(set));
+        }
+    }
+
     /**
      * Returns a clone of the given set. This method is only intended to avoid the "unchecked cast" warning.
      *
diff --git a/core/sis-utility/src/main/java/org/apache/sis/internal/util/package-info.java b/core/sis-utility/src/main/java/org/apache/sis/internal/util/package-info.java
index 0146bec0dd..f384a4c31e 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/internal/util/package-info.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/internal/util/package-info.java
@@ -30,7 +30,7 @@
  * so some serialized classes still exist in this package.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.3
+ * @version 1.4
  * @since   0.3
  * @module
  */


[sis] 02/02: Remove reference to JAXB internal implementation, which is not provided anymore.

Posted by de...@apache.org.
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 <ma...@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"));