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/04/14 18:13:24 UTC

[sis] branch geoapi-4.0 updated (9252ad9e1d -> 7ccfb5a03b)

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 9252ad9e1d First draft of World File reader as a wrapper around standard Java Image I/O.
     new 5b53df22a7 `MetadataSource.lookup(…)` should verify if the metadata record exists (otherwise the `catch (MetadataStoreException)` blocks are ineffective).
     new a8fcd7a9fe Implement `probleContent(…)` for World File data store. Fix documentation in other implementations of `probleContent(…)`.
     new 7ccfb5a03b Fix a hole in localization of `GridExtent` string representation. This is necessary for platform-independent tests.

The 3 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:
 .../org/apache/sis/coverage/grid/GridExtent.java   |  11 +-
 .../org/apache/sis/metadata/sql/Dispatcher.java    |   6 +-
 .../apache/sis/metadata/sql/MetadataSource.java    | 114 ++++++++++++++-------
 .../apache/sis/metadata/sql/TableHierarchy.java    |   4 +
 .../sis/storage/landsat/LandsatStoreProvider.java  |   2 +-
 .../apache/sis/storage/landsat/MetadataReader.java |   4 +-
 .../apache/sis/storage/geotiff/GeoTiffStore.java   |   2 +-
 .../sis/storage/geotiff/GeoTiffStoreProvider.java  |  11 +-
 .../apache/sis/storage/netcdf/MetadataReader.java  |   2 +-
 .../sis/storage/netcdf/NetcdfStoreProvider.java    |  11 +-
 .../apache/sis/storage/sql/SQLStoreProvider.java   |   2 +-
 .../internal/storage/DocumentedStoreProvider.java  |  45 ++++----
 .../sis/internal/storage/MetadataBuilder.java      |  22 ++--
 .../apache/sis/internal/storage/ascii/Store.java   |   2 +-
 .../sis/internal/storage/ascii/StoreProvider.java  |  12 ++-
 .../org/apache/sis/internal/storage/csv/Store.java |   2 +-
 .../sis/internal/storage/csv/StoreProvider.java    |  12 ++-
 .../sis/internal/storage/folder/StoreProvider.java |   4 +-
 .../sis/internal/storage/image/FormatFilter.java   |  42 +++++++-
 .../apache/sis/internal/storage/image/Store.java   |   7 +-
 .../sis/internal/storage/image/StoreProvider.java  |  36 ++++++-
 .../sis/internal/storage/wkt/StoreProvider.java    |  20 ++--
 .../sis/internal/storage/xml/AbstractProvider.java |  13 +--
 .../org/apache/sis/storage/DataStoreProvider.java  |   8 +-
 .../internal/storage/wkt/StoreProviderTest.java    |   2 +-
 25 files changed, 262 insertions(+), 134 deletions(-)


[sis] 03/03: Fix a hole in localization of `GridExtent` string representation. This is necessary for platform-independent tests.

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 7ccfb5a03bbe78135ef1f2e5ac5285e74a1f00d3
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Thu Apr 14 20:12:39 2022 +0200

    Fix a hole in localization of `GridExtent` string representation.
    This is necessary for platform-independent tests.
---
 .../main/java/org/apache/sis/coverage/grid/GridExtent.java    | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridExtent.java b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
index 90430252dc..935149a81c 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
@@ -26,6 +26,7 @@ import java.io.IOException;
 import java.io.UncheckedIOException;
 import java.awt.Rectangle;
 import org.opengis.util.FactoryException;
+import org.opengis.util.InternationalString;
 import org.opengis.geometry.Envelope;
 import org.opengis.geometry.DirectPosition;
 import org.opengis.metadata.spatial.DimensionNameType;
@@ -1610,8 +1611,14 @@ public class GridExtent implements GridEnvelope, LenientComparable, Serializable
         final TableAppender table = new TableAppender(out, "");
         final int dimension = getDimension();
         for (int i=0; i<dimension; i++) {
-            CharSequence name;
-            if ((types == null) || (name = Types.getCodeTitle(types[i])) == null) {
+            String name = null;
+            if (types != null) {
+                final InternationalString title = Types.getCodeTitle(types[i]);
+                if (title != null) {
+                    name = title.toString(vocabulary.getLocale());
+                }
+            }
+            if (name == null) {
                 name = vocabulary.getString(Vocabulary.Keys.Dimension_1, i);
             }
             final long lower = coordinates[i];


[sis] 01/03: `MetadataSource.lookup(…)` should verify if the metadata record exists (otherwise the `catch (MetadataStoreException)` blocks are ineffective).

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 5b53df22a7eb2eb00be4849c3b311ff1bae1d6f7
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Thu Apr 14 16:06:40 2022 +0200

    `MetadataSource.lookup(…)` should verify if the metadata record exists
    (otherwise the `catch (MetadataStoreException)` blocks are ineffective).
---
 .../org/apache/sis/metadata/sql/Dispatcher.java    |   6 +-
 .../apache/sis/metadata/sql/MetadataSource.java    | 114 ++++++++++++++-------
 .../apache/sis/metadata/sql/TableHierarchy.java    |   4 +
 .../apache/sis/storage/landsat/MetadataReader.java |   4 +-
 .../apache/sis/storage/geotiff/GeoTiffStore.java   |   2 +-
 .../apache/sis/storage/netcdf/MetadataReader.java  |   2 +-
 .../internal/storage/DocumentedStoreProvider.java  |  45 ++++----
 .../sis/internal/storage/MetadataBuilder.java      |  22 ++--
 .../apache/sis/internal/storage/ascii/Store.java   |   2 +-
 .../org/apache/sis/internal/storage/csv/Store.java |   2 +-
 .../apache/sis/internal/storage/image/Store.java   |   2 +-
 11 files changed, 124 insertions(+), 81 deletions(-)

diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/Dispatcher.java b/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/Dispatcher.java
index 9eb83a9151..63a15907e4 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/Dispatcher.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/Dispatcher.java
@@ -56,7 +56,7 @@ import org.apache.sis.internal.util.Numerics;
  *
  * @author  Touraïvane (IRD)
  * @author  Martin Desruisseaux (IRD, Geomatys)
- * @version 1.0
+ * @version 1.2
  * @since   0.8
  * @module
  */
@@ -83,7 +83,7 @@ final class Dispatcher implements InvocationHandler {
      * have different {@code preferredIndex} values even if their {@link CachedStatement#type} value is the same,
      * since their {@link #identifier} values are different.</div>
      */
-    byte preferredIndex;
+    int preferredIndex;
 
     /**
      * The metadata instance where to store the property (column) values, or {@code null} if not yet created.
@@ -266,7 +266,7 @@ final class Dispatcher implements InvocationHandler {
                                     hasValue |= (fetchValue(info, impl.getMethod(dep)) != null);
                                 }
                                 if (hasValue) {
-                                    cache = this.cache;             // Created by recursive 'invoke(…)' call above.
+                                    cache = this.cache;             // Created by recursive `invoke(…)` call above.
                                     if (cache != null) {
                                         synchronized (cache) {
                                             value = method.invoke(cache);             // Attempt a new computation.
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java b/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java
index 269d2c570e..4cf0c3509c 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java
@@ -110,7 +110,7 @@ import org.apache.sis.util.iso.Types;
  *
  * @author  Touraïvane (IRD)
  * @author  Martin Desruisseaux (IRD, Geomatys)
- * @version 1.1
+ * @version 1.2
  * @since   0.8
  * @module
  */
@@ -193,7 +193,7 @@ public class MetadataSource implements AutoCloseable {
      *     }
      * }
      *
-     * @see #take(Class, int)
+     * @see #prepareStatement(Class, String, int)
      * @see #recycle(CachedStatement, int)
      */
     private final CachedStatement[] statements;
@@ -332,7 +332,7 @@ public class MetadataSource implements AutoCloseable {
                 }
                 /*
                  * If the error is transient or has a transient cause, we will not save MetadataFallback.INSTANCE
-                 * in the 'instance' field. The intent is to try again next time this method will be invoked, in
+                 * in the `instance` field. The intent is to try again next time this method will be invoked, in
                  * case the transient error has disappeared.
                  */
                 for (Throwable cause = e; cause != null; cause = cause.getCause()) {
@@ -508,13 +508,17 @@ public class MetadataSource implements AutoCloseable {
     }
 
     /**
-     * Returns a statement that can be reused for the given interface, or {@code null} if none.
+     * Returns a statement that can be reused for performing queries on the table for the specified interface.
+     * Callers must invoke this method in a block synchronized on {@code this}.
      *
      * @param  type            the interface for which to reuse a prepared statement.
+     * @param  tableName       value of {@code getTableName(type)}, or {@code null} for computing by this method.
      * @param  preferredIndex  index in the cache array where to search first. This is only a hint for increasing
      *         the chances to find quickly a {@code CachedStatement} instance for the right type and identifier.
      */
-    private CachedStatement take(final Class<?> type, final int preferredIndex) {
+    private CachedStatement prepareStatement(final Class<?> type, String tableName, final int preferredIndex)
+            throws SQLException
+    {
         assert Thread.holdsLock(this);
         if (preferredIndex >= 0 && preferredIndex < statements.length) {
             final CachedStatement statement = statements[preferredIndex];
@@ -530,7 +534,14 @@ public class MetadataSource implements AutoCloseable {
                 return statement;
             }
         }
-        return null;
+        if (tableName == null) {
+            tableName = getTableName(type);
+        }
+        final SQLBuilder helper = helper();
+        final String query = helper.clear().append("SELECT * FROM ")
+                .appendIdentifier(schema, tableName).append(" WHERE ")
+                .appendIdentifier(ID_COLUMN).append("=?").toString();
+        return new CachedStatement(type, connection().prepareStatement(query), logFilter);
     }
 
     /**
@@ -548,7 +559,7 @@ public class MetadataSource implements AutoCloseable {
             while (statements[preferredIndex] != null) {
                 if (++preferredIndex >= statements.length) {
                     /*
-                     * If we reach this point, this means that the 'statements' pool has reached its maximal capacity.
+                     * If we reach this point, this means that the `statements` pool has reached its maximal capacity.
                      * Loop again on all statements in order to find the oldest one. We will close that old statement
                      * and cache the given one instead.
                      */
@@ -837,26 +848,64 @@ public class MetadataSource implements AutoCloseable {
      * @param  identifier  the identifier of the record for the metadata entity to be created.
      *                     This is usually the primary key of the record to search for.
      * @return an implementation of the required interface, or the code list element.
-     * @throws MetadataStoreException if a SQL query failed.
+     * @throws MetadataStoreException if a SQL query failed or if the metadata has not been found.
      */
     public <T> T lookup(final Class<T> type, final String identifier) throws MetadataStoreException {
         ArgumentChecks.ensureNonNull("type", type);
         ArgumentChecks.ensureNonEmpty("identifier", identifier);
+        return type.cast(lookup(type, identifier, true));
+    }
+
+    /**
+     * Implementation of public {@link #lookup(Class, String)} method.
+     *
+     * <h4>Deferred database access</h4>
+     * This method may or may not query the database immediately, at implementation choice.
+     * It the database is not queried immediately, invalid identifiers may not be detected
+     * during this method invocation. Instead, an invalid identifier may be detected only
+     * when a getter method is invoked on the returned metadata object. In such case,
+     * an {@link org.apache.sis.util.collection.BackingStoreException} will be thrown
+     * at getter method invocation time.
+     *
+     * @param  type        the interface to implement or the {@link ControlledVocabulary} type.
+     * @param  identifier  the identifier of the record for the metadata entity to be created.
+     * @param  verify      whether to check for record existence.
+     * @return an implementation of the required interface, or the code list element.
+     * @throws MetadataStoreException if a SQL query failed or if the metadata has not been found.
+     */
+    private Object lookup(final Class<?> type, final String identifier, boolean verify) throws MetadataStoreException {
         Object value;
         if (ControlledVocabulary.class.isAssignableFrom(type)) {
             value = getCodeList(type, identifier);
         } else {
             final CacheKey key = new CacheKey(type, identifier);
             /*
-             * IMPLEMENTATION NOTE: be careful to not invoke any method that may synchronize on 'this'
-             * inside the block synchronized on 'pool'.
+             * IMPLEMENTATION NOTE: be careful to not invoke any method that may synchronize on `this`
+             * inside a block synchronized on `pool` (implicit synchronization of `pool` method calls).
              */
-            synchronized (pool) {
-                value = pool.get(key);
-                if (value == null && type.isInterface()) {
-                    value = Proxy.newProxyInstance(classloader,
-                            new Class<?>[] {type, MetadataProxy.class}, new Dispatcher(identifier, this));
-                    pool.put(key, value);
+            value = pool.get(key);
+            if (value == null && type.isInterface()) {
+                final Dispatcher toSearch = new Dispatcher(identifier, this);
+                value = Proxy.newProxyInstance(classloader, new Class<?>[] {type, MetadataProxy.class}, toSearch);
+                if (verify) try {
+                    /*
+                     * If the caller asked to verify whether the record exists, perform a query now.
+                     * We trivially request the identifier, so the `getValue(…)` result should be
+                     * the identifier itself (this is not verified). If the record does not exist,
+                     * a `MetadataStoreException` is thrown by `getValue(…)`.
+                     */
+                    synchronized (this) {
+                        final Class<?> subType = TableHierarchy.subType(type, identifier);
+                        CachedStatement result = prepareStatement(subType, null, toSearch.preferredIndex);
+                        result.getValue(identifier, ID_COLUMN);               // Check record existence.
+                        toSearch.preferredIndex = recycle(result, toSearch.preferredIndex);
+                    }
+                } catch (SQLException e) {
+                    throw new MetadataStoreException(Errors.format(Errors.Keys.DatabaseError_2, type, identifier), e);
+                }
+                final Object replacement = pool.putIfAbsent(key, value);
+                if (replacement != null) {
+                    value = replacement;
                 }
             }
             /*
@@ -908,12 +957,14 @@ public class MetadataSource implements AutoCloseable {
 
     /**
      * Invoked by {@link MetadataProxy} for fetching an attribute value from a table.
+     * It the database table does not contains a column for the property, this method returns {@code null}.
+     * A {@code null} value may also mean that the column exists but contains an SQL {@code NULL} value.
      *
      * @param  info      the interface type (together with cached information).
      *                   This is mapped to the table name in the database.
      * @param  method    the method invoked. This is mapped to the column name in the database.
      * @param  toSearch  contains the identifier and preferred index of the record to search.
-     * @return the value of the requested attribute.
+     * @return the value of the requested attribute, or {@code null} if none.
      * @throws SQLException if the SQL query failed.
      * @throws MetadataStoreException if a value was not found or can not be converted to the expected type.
      */
@@ -922,7 +973,7 @@ public class MetadataSource implements AutoCloseable {
     {
         /*
          * If the identifier is prefixed with a table name as in "{Organisation}identifier",
-         * the name between bracket is a subtype of the given 'type' argument.
+         * the name between bracket is a subtype of the given `type` argument.
          */
         final Class<?> type           = TableHierarchy.subType(info.getMetadataType(), toSearch.identifier);
         final Class<?> returnType     = method.getReturnType();
@@ -940,17 +991,10 @@ public class MetadataSource implements AutoCloseable {
             } else {
                 /*
                  * Prepares the statement and executes the SQL query in this synchronized block.
-                 * Note that the usage of 'result' must stay inside this synchronized block
+                 * Note that the usage of `result` must stay inside this synchronized block
                  * because we can not assume that JDBC connections are thread-safe.
                  */
-                CachedStatement result = take(type, Byte.toUnsignedInt(toSearch.preferredIndex));
-                if (result == null) {
-                    final SQLBuilder helper = helper();
-                    final String query = helper.clear().append("SELECT * FROM ")
-                            .appendIdentifier(schema, tableName).append(" WHERE ")
-                            .appendIdentifier(ID_COLUMN).append("=?").toString();
-                    result = new CachedStatement(type, connection().prepareStatement(query), logFilter);
-                }
+                CachedStatement result = prepareStatement(type, tableName, toSearch.preferredIndex);
                 value = result.getValue(toSearch.identifier, columnName);
                 isArray = (value instanceof java.sql.Array);
                 if (isArray) {
@@ -958,7 +1002,7 @@ public class MetadataSource implements AutoCloseable {
                     value = array.getArray();
                     array.free();
                 }
-                toSearch.preferredIndex = (byte) recycle(result, Byte.toUnsignedInt(toSearch.preferredIndex));
+                toSearch.preferredIndex = recycle(result, toSearch.preferredIndex);
             }
         }
         /*
@@ -971,7 +1015,7 @@ public class MetadataSource implements AutoCloseable {
                 Object element = Array.get(value, i);
                 if (element != null) {
                     if (isMetadata) {
-                        element = lookup(elementType, element.toString());
+                        element = lookup(elementType, element.toString(), false);
                     } else try {
                         element = info.convert(elementType, element);
                     } catch (UnconvertibleObjectException e) {
@@ -987,13 +1031,13 @@ public class MetadataSource implements AutoCloseable {
             }
         }
         /*
-         * Now converts the value to its final type. To be strict, we should convert null values into empty collections
-         * if the return type is a collection type. But we leave this task to the caller (which is the Dispatcher class)
-         * for making easier to detect when a value is absent, for allowing Dispatcher to manage its cache.
+         * Now convert the value to its final type. To be strict, we should convert null values to empty collections
+         * if the return type is a collection type. But we leave this task to the caller (which is the `Dispatcher`)
+         * for making easier to detect when a value is absent, for allowing `Dispatcher` to manage its cache.
          */
         if (value != null) {
             if (isMetadata) {
-                value = lookup(elementType, value.toString());
+                value = lookup(elementType, value.toString(), false);
             } else try {
                 value = info.convert(elementType, value);
             } catch (UnconvertibleObjectException e) {
@@ -1045,7 +1089,7 @@ public class MetadataSource implements AutoCloseable {
             enumeration = EnumSet.noneOf((Class) elementType);
         } else {
             /*
-             * If 'returnType' is Collection.class, do not copy into a Set since a List
+             * If `returnType` is Collection.class, do not copy into a Set since a List
              * is probably good enough. Copy only if a Set is explicitly requested.
              */
             if (Set.class.isAssignableFrom(returnType)) {
@@ -1185,7 +1229,7 @@ public class MetadataSource implements AutoCloseable {
             isCloseScheduled = true;
         } else {
             // No more prepared statements.
-            final Connection c = this.connection;
+            final Connection c = connection;
             connection = null;
             helper = null;
             closeQuietly(c);
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/TableHierarchy.java b/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/TableHierarchy.java
index bd8c757bf9..d362793ca4 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/TableHierarchy.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/TableHierarchy.java
@@ -112,6 +112,10 @@ final class TableHierarchy {
      * For example if the given type is {@code Party.class} and the given identifier is
      * {@code "{Organisation}EPSG"}, then this method returns {@code Organisation.class}.
      * Otherwise this method returns {@code type} unchanged.
+     *
+     * @param  type        base metadata type.
+     * @param  identifier  primary key in the database.
+     * @return actual type of the metadata object.
      */
     static Class<?> subType(Class<?> type, final String identifier) {
         if (identifier.charAt(0) == TYPE_OPEN) {
diff --git a/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/landsat/MetadataReader.java b/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/landsat/MetadataReader.java
index 4b0f2be036..411542f275 100644
--- a/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/landsat/MetadataReader.java
+++ b/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/landsat/MetadataReader.java
@@ -476,8 +476,8 @@ final class MetadataReader extends MetadataBuilder {
             case "OUTPUT_FORMAT": {
                 String name = value;
                 if (Constants.GEOTIFF.equalsIgnoreCase(name)) try {
-                    name = Constants.GEOTIFF;               // Because 'metadata.setFormat(…)' is case-sensitive.
-                    setFormat(name);
+                    name = Constants.GEOTIFF;       // Because `metadata.setPredefinedFormat(…)` is case-sensitive.
+                    setPredefinedFormat(name);
                     break;
                 } catch (MetadataStoreException e) {
                     warning(key, null, e);
diff --git a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStore.java b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStore.java
index 783f177233..d0a2c77d26 100644
--- a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStore.java
+++ b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStore.java
@@ -285,7 +285,7 @@ public class GeoTiffStore extends DataStore implements Aggregate {
      */
     final void setFormatInfo(final MetadataBuilder builder) {
         try {
-            builder.setFormat(Constants.GEOTIFF);
+            builder.setPredefinedFormat(Constants.GEOTIFF);
         } catch (MetadataStoreException e) {
             builder.addFormatName(Constants.GEOTIFF);
             listeners.warning(e);
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
index 92fe35edd9..15c099b14b 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
@@ -666,7 +666,7 @@ split:  while ((start = CharSequences.skipLeadingWhitespaces(value, start, lengt
         final String[] format = decoder.getFormatDescription();
         String id = format[0];
         if (NetcdfStoreProvider.NAME.equalsIgnoreCase(id)) try {
-            setFormat(NetcdfStoreProvider.NAME);
+            setPredefinedFormat(NetcdfStoreProvider.NAME);
             id = null;
         } catch (MetadataStoreException e) {
             // Will add `id` at the end of this method.
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/DocumentedStoreProvider.java b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/DocumentedStoreProvider.java
index 3e27da39ea..0ea7a4eb80 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/DocumentedStoreProvider.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/DocumentedStoreProvider.java
@@ -31,7 +31,7 @@ import org.apache.sis.internal.system.Modules;
  * The primary key in the {@code MD_Format} table must be the name given at construction time.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.2
  * @since   0.8
  * @module
  */
@@ -43,11 +43,11 @@ public abstract class DocumentedStoreProvider extends URIDataStore.Provider {
     private final String name;
 
     /**
-     * {@code true} if the call to {@link #getFormat()} caught an exception. In such case,
-     * we log a warning only the first time and use a finer logging level the other times.
-     * The intent is to avoid polluting the logs with too many warnings.
+     * The format, created when first requested.
+     *
+     * @see #getFormat(StoreListeners)
      */
-    private volatile boolean logged;
+    private transient Format format;
 
     /**
      * Creates a new provider.
@@ -88,29 +88,24 @@ public abstract class DocumentedStoreProvider extends URIDataStore.Provider {
      * @param  listeners  where to report the warning in case of error, or {@code null} if none.
      * @return a description of the data format.
      */
-    public final Format getFormat(final StoreListeners listeners) {
-        /*
-         * Note: this method does not cache the format because such caching is already done by MetadataSource.
-         */
-        if (name != null) try {
-            return MetadataSource.getProvided().lookup(Format.class, name);
-        } catch (MetadataStoreException e) {
-            if (listeners != null) {
-                listeners.warning(e);
-            } else {
-                final Level level;
-                if (!logged) {
-                    logged = true;      // Not atomic - not a big deal if we use warning level twice.
-                    level = Level.WARNING;
-                } else {
-                    level = Level.FINE;
-                }
-                final LogRecord record = Resources.forLocale(null).getLogRecord(level,
+    public final synchronized Format getFormat(final StoreListeners listeners) {
+        if (format == null) {
+            if (name != null) try {
+                return format = MetadataSource.getProvided().lookup(Format.class, name);
+            } catch (MetadataStoreException e) {
+                final LogRecord record = Resources.forLocale(null).getLogRecord(Level.WARNING,
                         Resources.Keys.CanNotGetCommonMetadata_2, getShortName(), e.getLocalizedMessage());
+                record.setSourceClassName(getClass().getCanonicalName());
+                record.setSourceMethodName("getFormat");
                 record.setLoggerName(Modules.STORAGE);
-                Logging.log(getClass(), "getFormat", record);
+                if (listeners != null) {
+                    listeners.warning(record);
+                } else {
+                    Logging.getLogger(Modules.STORAGE).log(record);
+                }
             }
+            format = super.getFormat();
         }
-        return super.getFormat();
+        return format;
     }
 }
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
index 2e83572902..dac07899b8 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
@@ -1008,7 +1008,7 @@ public class MetadataBuilder {
      *
      * {@preformat java
      *     try {
-     *         metadata.setFormat("MyFormat");
+     *         metadata.setPredefinedFormat("MyFormat");
      *     } catch (MetadataStoreException e) {
      *         metadata.addFormatName("MyFormat");
      *         listeners.warning(null, e);
@@ -1023,7 +1023,7 @@ public class MetadataBuilder {
      * @see #addCompression(CharSequence)
      * @see #addFormatName(CharSequence)
      */
-    public final void setFormat(final String abbreviation) throws MetadataStoreException {
+    public final void setPredefinedFormat(final String abbreviation) throws MetadataStoreException {
         if (abbreviation != null && abbreviation.length() != 0) {
             if (format == null) {
                 format = MetadataSource.getProvided().lookup(Format.class, abbreviation);
@@ -3089,12 +3089,12 @@ parse:      for (int i = 0; i < length;) {
      *   <li>{@code metadata/identificationInfo/resourceFormat/formatSpecificationCitation/alternateTitle}</li>
      * </ul>
      *
-     * If this method is used together with {@link #setFormat(String)},
-     * then {@code setFormat} should be invoked <strong>before</strong> this method.
+     * If this method is used together with {@link #setPredefinedFormat(String)},
+     * then {@code setPredefinedFormat(…)} should be invoked <strong>before</strong> this method.
      *
      * @param value  the format name, or {@code null} for no-operation.
      *
-     * @see #setFormat(String)
+     * @see #setPredefinedFormat(String)
      * @see #setFormatEdition(CharSequence)
      * @see #addCompression(CharSequence)
      */
@@ -3119,12 +3119,12 @@ parse:      for (int i = 0; i < length;) {
      *   <li>{@code metadata/identificationInfo/resourceFormat/formatSpecificationCitation/edition}</li>
      * </ul>
      *
-     * If this method is used together with {@link #setFormat(String)},
-     * then {@code setFormat} should be invoked <strong>before</strong> this method.
+     * If this method is used together with {@link #setPredefinedFormat(String)},
+     * then {@code setPredefinedFormat(…)} should be invoked <strong>before</strong> this method.
      *
      * @param value  the format edition, or {@code null} for no-operation.
      *
-     * @see #setFormat(String)
+     * @see #setPredefinedFormat(String)
      * @see #addFormatName(CharSequence)
      */
     public final void setFormatEdition(final CharSequence value) {
@@ -3148,12 +3148,12 @@ parse:      for (int i = 0; i < length;) {
      *   <li>{@code metadata/identificationInfo/resourceFormat/fileDecompressionTechnique}</li>
      * </ul>
      *
-     * If this method is used together with {@link #setFormat(String)},
-     * then {@code setFormat} should be invoked <strong>before</strong> this method.
+     * If this method is used together with {@link #setPredefinedFormat(String)},
+     * then {@code setPredefinedFormat(…)} should be invoked <strong>before</strong> this method.
      *
      * @param value  the compression name, or {@code null} for no-operation.
      *
-     * @see #setFormat(String)
+     * @see #setPredefinedFormat(String)
      * @see #addFormatName(CharSequence)
      */
     public final void addCompression(final CharSequence value) {
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ascii/Store.java b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ascii/Store.java
index 2409b120e0..ead3dceeca 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ascii/Store.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ascii/Store.java
@@ -332,7 +332,7 @@ cellsize:       if (value != null) {
             readHeader();
             final MetadataBuilder builder = new MetadataBuilder();
             try {
-                builder.setFormat("ASCGRD");
+                builder.setPredefinedFormat("ASCGRD");
             } catch (MetadataStoreException e) {
                 builder.addFormatName(StoreProvider.NAME);
                 listeners.warning(e);
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/Store.java b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/Store.java
index 0398172c9e..7580d9ce41 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/Store.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/Store.java
@@ -640,7 +640,7 @@ final class Store extends URIDataStore implements FeatureSet {
             final MetadataBuilder builder = new MetadataBuilder();
             final String format = (timeEncoding != null) && hasTrajectories ? StoreProvider.MOVING : StoreProvider.NAME;
             try {
-                builder.setFormat(format);
+                builder.setPredefinedFormat(format);
             } catch (MetadataStoreException e) {
                 builder.addFormatName(format);
                 listeners.warning(e);
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/Store.java b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/Store.java
index 299b1db493..148c7f50d7 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/Store.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/Store.java
@@ -344,7 +344,7 @@ loop:   for (int convention=0;; convention++) {
             final MetadataBuilder builder = new MetadataBuilder();
             final String format = reader().getFormatName();
             try {
-                builder.setFormat(format);
+                builder.setPredefinedFormat(format);
             } catch (MetadataStoreException e) {
                 builder.addFormatName(format);
                 listeners.warning(Level.FINE, null, e);


[sis] 02/03: Implement `probleContent(…)` for World File data store. Fix documentation in other implementations of `probleContent(…)`.

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 a8fcd7a9fe484ee32c9fbcc275e3303517f5d997
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Thu Apr 14 20:11:28 2022 +0200

    Implement `probleContent(…)` for World File data store.
    Fix documentation in other implementations of `probleContent(…)`.
---
 .../sis/storage/landsat/LandsatStoreProvider.java  |  2 +-
 .../sis/storage/geotiff/GeoTiffStoreProvider.java  | 11 +++---
 .../sis/storage/netcdf/NetcdfStoreProvider.java    | 11 +++---
 .../apache/sis/storage/sql/SQLStoreProvider.java   |  2 +-
 .../sis/internal/storage/ascii/StoreProvider.java  | 12 ++++---
 .../sis/internal/storage/csv/StoreProvider.java    | 12 ++++---
 .../sis/internal/storage/folder/StoreProvider.java |  4 +--
 .../sis/internal/storage/image/FormatFilter.java   | 42 +++++++++++++++++++++-
 .../apache/sis/internal/storage/image/Store.java   |  5 ++-
 .../sis/internal/storage/image/StoreProvider.java  | 36 +++++++++++++++++--
 .../sis/internal/storage/wkt/StoreProvider.java    | 20 +++++------
 .../sis/internal/storage/xml/AbstractProvider.java | 13 +++----
 .../org/apache/sis/storage/DataStoreProvider.java  |  8 ++---
 .../internal/storage/wkt/StoreProviderTest.java    |  2 +-
 14 files changed, 129 insertions(+), 51 deletions(-)

diff --git a/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/landsat/LandsatStoreProvider.java b/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/landsat/LandsatStoreProvider.java
index 448b3968b6..7be9c50b39 100644
--- a/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/landsat/LandsatStoreProvider.java
+++ b/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/landsat/LandsatStoreProvider.java
@@ -198,7 +198,7 @@ public class LandsatStoreProvider extends DataStoreProvider {
      * that there appears to be a reasonable chance of success based on a brief inspection of the storage header.
      *
      * @return {@link ProbeResult#SUPPORTED} if the given storage seems to be readable as a Landsat file.
-     * @throws DataStoreException if an I/O or SQL error occurred.
+     * @throws DataStoreException if an I/O error occurred.
      */
     @Override
     public ProbeResult probeContent(final StorageConnector connector) throws DataStoreException {
diff --git a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStoreProvider.java b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStoreProvider.java
index f59ec4d1e7..5059e7b55b 100644
--- a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStoreProvider.java
+++ b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStoreProvider.java
@@ -95,13 +95,14 @@ public class GeoTiffStoreProvider extends DataStoreProvider {
     }
 
     /**
-     * Returns {@link ProbeResult#SUPPORTED} if the given storage appears to be supported by {@link GeoTiffStore}.
-     * Returning {@code SUPPORTED} from this method does not guarantee that reading or writing will succeed,
-     * only that there appears to be a reasonable chance of success based on a brief inspection of the
-     * {@linkplain StorageConnector#getStorage() storage object} or contents.
+     * Returns the MIME type if the given storage appears to be supported by {@link GeoTiffStore}.
+     * A {@linkplain ProbeResult#isSupported() supported} status does not guarantee that reading
+     * or writing will succeed, only that there appears to be a reasonable chance of success
+     * based on a brief inspection of the file header.
      *
      * @param  connector  information about the storage (URL, stream, <i>etc</i>).
-     * @return {@code SUPPORTED} if the given storage seems to be usable by {@code GeoTiffStore} instances.
+     * @return a {@linkplain ProbeResult#isSupported() supported} status with the MIME type
+     *         if the given storage seems to be readable by {@code GeoTiffStore} instances.
      * @throws DataStoreException if an I/O error occurred.
      */
     @Override
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStoreProvider.java b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStoreProvider.java
index 7dd23ac87a..033d126fd4 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStoreProvider.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStoreProvider.java
@@ -176,13 +176,14 @@ public class NetcdfStoreProvider extends DataStoreProvider {
     }
 
     /**
-     * Returns {@link ProbeResult#SUPPORTED} if the given storage appears to be supported by {@link NetcdfStore}.
-     * Returning {@code SUPPORTED} from this method does not guarantee that reading or writing will succeed,
-     * only that there appears to be a reasonable chance of success based on a brief inspection of the
-     * {@linkplain StorageConnector#getStorage() storage object} or contents.
+     * Returns the MIME type if the given storage appears to be supported by {@link NetcdfStore}.
+     * A {@linkplain ProbeResult#isSupported() supported} status does not guarantee that reading
+     * or writing will succeed, only that there appears to be a reasonable chance of success
+     * based on a brief inspection of the file header.
      *
      * @param  connector  information about the storage (URL, stream, {@link ucar.nc2.NetcdfFile} instance, <i>etc</i>).
-     * @return {@code SUPPORTED} if the given storage seems to be usable by {@code NetcdfStore} instances.
+     * @return a {@linkplain ProbeResult#isSupported() supported} status with the MIME type
+     *         if the given storage seems to be readable by {@code NetcdfStore} instances.
      * @throws DataStoreException if an I/O error occurred.
      */
     @Override
diff --git a/storage/sis-sqlstore/src/main/java/org/apache/sis/storage/sql/SQLStoreProvider.java b/storage/sis-sqlstore/src/main/java/org/apache/sis/storage/sql/SQLStoreProvider.java
index 8761c3a615..156289fb09 100644
--- a/storage/sis-sqlstore/src/main/java/org/apache/sis/storage/sql/SQLStoreProvider.java
+++ b/storage/sis-sqlstore/src/main/java/org/apache/sis/storage/sql/SQLStoreProvider.java
@@ -175,7 +175,7 @@ public class SQLStoreProvider extends DataStoreProvider {
      *
      * @param  connector  information about the storage (data source).
      * @return {@code SUPPORTED} if the given storage seems to be usable by {@code SQLStore} instances.
-     * @throws DataStoreException if an I/O error occurred.
+     * @throws DataStoreException if an SQL error occurred.
      */
     @Override
     public ProbeResult probeContent(final StorageConnector connector) throws DataStoreException {
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ascii/StoreProvider.java b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ascii/StoreProvider.java
index a77dbaf7de..7e625150c9 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ascii/StoreProvider.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ascii/StoreProvider.java
@@ -69,12 +69,14 @@ public final class StoreProvider extends PRJDataStore.Provider {
     }
 
     /**
-     * Returns {@link ProbeResult#SUPPORTED} if the given storage appears to be supported by ASCII Grid {@link Store}.
-     * Returning {@code SUPPORTED} from this method does not guarantee that reading or writing will succeed, only
-     * that there appears to be a reasonable chance of success based on a brief inspection of the storage header.
+     * Returns the MIME type if the given storage appears to be supported by ASCII Grid {@link Store}.
+     * A {@linkplain ProbeResult#isSupported() supported} status does not guarantee that reading
+     * or writing will succeed, only that there appears to be a reasonable chance of success
+     * based on a brief inspection of the file header.
      *
-     * @return {@link ProbeResult#SUPPORTED} if the given storage seems to be readable as an ASCII Grid file.
-     * @throws DataStoreException if an I/O or SQL error occurred.
+     * @return a {@linkplain ProbeResult#isSupported() supported} status with the MIME type
+     *         if the given storage seems to be readable as an ASCII Grid file.
+     * @throws DataStoreException if an I/O error occurred.
      */
     @Override
     public ProbeResult probeContent(StorageConnector connector) throws DataStoreException {
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/StoreProvider.java b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/StoreProvider.java
index b6ada7275d..d6a3db371a 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/StoreProvider.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/StoreProvider.java
@@ -143,12 +143,14 @@ public final class StoreProvider extends URIDataStore.Provider {
     }
 
     /**
-     * Returns {@link ProbeResult#SUPPORTED} if the given storage appears to be supported by CSV {@link Store}.
-     * Returning {@code SUPPORTED} from this method does not guarantee that reading or writing will succeed, only
-     * that there appears to be a reasonable chance of success based on a brief inspection of the storage header.
+     * Returns the MIME type if the given storage appears to be supported by CSV {@link Store}.
+     * A {@linkplain ProbeResult#isSupported() supported} status does not guarantee that reading
+     * or writing will succeed, only that there appears to be a reasonable chance of success
+     * based on a brief inspection of the file header.
      *
-     * @return {@link ProbeResult#SUPPORTED} if the given storage seems to be readable as a CSV file.
-     * @throws DataStoreException if an I/O or SQL error occurred.
+     * @return a {@linkplain ProbeResult#isSupported() supported} status with the MIME type
+     *         if the given storage seems to be readable as a CSV file.
+     * @throws DataStoreException if an I/O error occurred.
      */
     @Override
     public ProbeResult probeContent(final StorageConnector connector) throws DataStoreException {
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/folder/StoreProvider.java b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/folder/StoreProvider.java
index 2f81fac1c2..f3906223b4 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/folder/StoreProvider.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/folder/StoreProvider.java
@@ -146,10 +146,10 @@ public final class StoreProvider extends DataStoreProvider {
      * Returns {@link ProbeResult#SUPPORTED} if the given storage appears to be a folder.
      * Returning {@code SUPPORTED} from this method does not guarantee that reading or writing will succeed,
      * only that there appears to be a reasonable chance of success based on a brief inspection of the storage
-     * header.
+     * characteristics.
      *
      * @return {@link ProbeResult#SUPPORTED} if the given storage seems to be readable as a folder.
-     * @throws DataStoreException if an I/O or SQL error occurred.
+     * @throws DataStoreException if an I/O error occurred.
      */
     @Override
     public ProbeResult probeContent(StorageConnector connector) throws DataStoreException {
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/FormatFilter.java b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/FormatFilter.java
index 603852c9ab..610c34eed0 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/FormatFilter.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/FormatFilter.java
@@ -17,6 +17,7 @@
 package org.apache.sis.internal.storage.image;
 
 import java.util.Map;
+import java.util.Set;
 import java.util.Iterator;
 import java.util.function.Function;
 import java.net.URI;
@@ -119,6 +120,44 @@ enum FormatFilter {
         }
     }
 
+    /**
+     * Finds a provider for the given input, or returns {@code null} if none.
+     *
+     * @param  identifier  the property value to use as a filtering criterion, or {@code null} if none.
+     * @param  connector   provider of the input to be given to the {@code canDecodeInput(…)} method.
+     * @param  done        initially empty set to be populated with providers tested by this method.
+     * @return the provider for the given input, or {@code null} if none was found.
+     * @throws DataStoreException if an error occurred while opening a stream from the storage connector.
+     * @throws IOException if an error occurred while creating the image reader instance.
+     */
+    final ImageReaderSpi findProvider(final String identifier, final StorageConnector connector, final Set<ImageReaderSpi> done)
+            throws IOException, DataStoreException
+    {
+        final Iterator<ImageReaderSpi> it = FormatFilter.SUFFIX.getServiceProviders(ImageReaderSpi.class, identifier);
+        while (it.hasNext()) {
+            final ImageReaderSpi provider = it.next();
+            if (done.add(provider)) {
+                for (final Class<?> type : provider.getInputTypes()) {
+                    if (Classes.isAssignableToAny(type, VALID_INPUTS)) {
+                        final Object input = connector.getStorageAs(type);
+                        if (input != null) {
+                            /*
+                             * We do not try to mark/reset the input because it should be done
+                             * by `canDecodeInput(…)` as per Image I/O contract. Doing our own
+                             * mark/reset may interfere with the `canDecodeInput(…)` marks.
+                             */
+                            if (provider.canDecodeInput(input)) {
+                                return provider;
+                            }
+                            break;          // Skip other input types, try the next provider.
+                        }
+                    }
+                }
+            }
+        }
+        return null;
+    }
+
     /**
      * Creates a new reader for the given input. Caller needs to invoke this method with an initially empty
      * {@code deferred} map, which will be populated by this method. Providers associated to {@code TRUE}
@@ -126,7 +165,7 @@ enum FormatFilter {
      * This is intentionally not done automatically by {@link StorageConnector}.
      *
      * @param  identifier  the property value to use as a filtering criterion, or {@code null} if none.
-     * @param  input       the input to be given to the new reader instance.
+     * @param  connector   provider of the input to be given to the new reader instance.
      * @param  deferred    initially empty map to be populated with providers tested by this method.
      * @return the new image reader instance with its input initialized, or {@code null} if none was found.
      * @throws DataStoreException if an error occurred while opening a stream from the storage connector.
@@ -149,6 +188,7 @@ enum FormatFilter {
                                 reader.setInput(input, false, true);
                                 return reader;
                             }
+                            break;        // Skip other input types, try the next provider.
                         } else if (type == ImageInputStream.class) {
                             deferred.put(provider, Boolean.TRUE);
                         }
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/Store.java b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/Store.java
index 148c7f50d7..1a5510b1fc 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/Store.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/Store.java
@@ -342,7 +342,10 @@ loop:   for (int convention=0;; convention++) {
     public synchronized Metadata getMetadata() throws DataStoreException {
         if (metadata == null) try {
             final MetadataBuilder builder = new MetadataBuilder();
-            final String format = reader().getFormatName();
+            String format = reader().getFormatName();
+            if (format.equalsIgnoreCase("tif")) {
+                format = "TIFF";
+            }
             try {
                 builder.setPredefinedFormat(format);
             } catch (MetadataStoreException e) {
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/StoreProvider.java b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/StoreProvider.java
index 795e6fe4bb..435264a72d 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/StoreProvider.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/StoreProvider.java
@@ -16,13 +16,17 @@
  */
 package org.apache.sis.internal.storage.image;
 
+import java.util.Set;
+import java.util.HashSet;
 import java.io.IOException;
+import javax.imageio.spi.ImageReaderSpi;
 import org.apache.sis.storage.DataStore;
 import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.storage.StorageConnector;
 import org.apache.sis.internal.storage.Capability;
 import org.apache.sis.internal.storage.StoreMetadata;
 import org.apache.sis.internal.storage.PRJDataStore;
+import org.apache.sis.internal.storage.io.IOUtilities;
 import org.apache.sis.storage.ProbeResult;
 
 
@@ -74,8 +78,36 @@ public final class StoreProvider extends PRJDataStore.Provider {
         }
     }
 
+    /**
+     * Returns the MIME type if the image file is recognized by an Image I/O reader.
+     * A {@linkplain ProbeResult#isSupported() supported} status does not guarantee that reading
+     * or writing will succeed, only that there appears to be a reasonable chance of success
+     * based on a brief inspection of the file header.
+     *
+     * @return a {@linkplain ProbeResult#isSupported() supported} status with the MIME type
+     *         if the given storage seems to be readable as an image.
+     * @throws DataStoreException if an I/O error occurred.
+     */
     @Override
-    public ProbeResult probeContent(StorageConnector connector) throws DataStoreException {
-        throw new UnsupportedOperationException("Not supported yet.");
+    public ProbeResult probeContent(final StorageConnector connector) throws DataStoreException {
+        final Set<ImageReaderSpi> deferred = new HashSet<>();
+        final String suffix = IOUtilities.extension(connector.getStorage());
+        ImageReaderSpi provider;
+        try {
+            provider = FormatFilter.SUFFIX.findProvider(suffix, connector, deferred);
+            if (provider == null) {
+                provider = FormatFilter.SUFFIX.findProvider(null, connector, deferred);
+                if (provider == null) {
+                    return ProbeResult.UNSUPPORTED_STORAGE;
+                }
+            }
+        } catch (IOException e) {
+            throw new DataStoreException(e);
+        }
+        final String[] types = provider.getMIMETypes();
+        if (types != null && types.length != 0) {
+            return new ProbeResult(true, types[0], null);
+        }
+        return ProbeResult.SUPPORTED;
     }
 }
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/StoreProvider.java b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/StoreProvider.java
index c8534e3d4a..c95ab0f519 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/StoreProvider.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/StoreProvider.java
@@ -47,11 +47,6 @@ public final class StoreProvider extends URIDataStore.Provider {
      */
     static final String NAME = "WKT";
 
-    /**
-     * The {@value} MIME type.
-     */
-    public static final String MIME_TYPE = "application/wkt";
-
     /**
      * The object to use for verifying if the first keyword is a WKT one.
      * This object contains the set of recognized WKT keywords.
@@ -139,7 +134,7 @@ public final class StoreProvider extends URIDataStore.Provider {
                     }
                 }
                 if (keywords.contains(String.valueOf(keyword, 0, length))) {
-                    return new ProbeResult(true, MIME_TYPE, Version.valueOf(version));
+                    return new ProbeResult(true, null, Version.valueOf(version));
                 }
             }
             return ProbeResult.UNSUPPORTED_STORAGE;
@@ -163,13 +158,14 @@ public final class StoreProvider extends URIDataStore.Provider {
     }
 
     /**
-     * Returns {@link ProbeResult#SUPPORTED} if the given storage appears to be supported by WKT {@link Store}.
-     * Returning {@code SUPPORTED} from this method does not guarantee that reading or writing will succeed,
-     * only that there appears to be a reasonable chance of success based on a brief inspection of the storage
-     * header.
+     * Returns WKT version if the given storage appears to be supported by WKT {@link Store}.
+     * A {@linkplain ProbeResult#isSupported() supported} status does not guarantee that reading
+     * or writing will succeed, only that there appears to be a reasonable chance of success
+     * based on a brief inspection of the file header.
      *
-     * @return {@link ProbeResult#SUPPORTED} if the given storage seems to be readable as a WKT file.
-     * @throws DataStoreException if an I/O or SQL error occurred.
+     * @return a {@linkplain ProbeResult#isSupported() supported} status with the WKT version
+     *         if the given storage seems to be readable as a WKT string.
+     * @throws DataStoreException if an I/O error occurred.
      */
     @Override
     public ProbeResult probeContent(final StorageConnector connector) throws DataStoreException {
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/AbstractProvider.java b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/AbstractProvider.java
index e0e646a275..101afc143e 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/AbstractProvider.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/AbstractProvider.java
@@ -98,13 +98,14 @@ public abstract class AbstractProvider extends DocumentedStoreProvider {
     }
 
     /**
-     * Returns {@link ProbeResult#SUPPORTED} if the given storage appears to be supported by the data store.
-     * Returning {@code SUPPORTED} from this method does not guarantee that reading or writing will succeed,
-     * only that there appears to be a reasonable chance of success based on a brief inspection of the storage
-     * header.
+     * Returns the MIME type if the given storage appears to be supported by the data store.
+     * A {@linkplain ProbeResult#isSupported() supported} status does not guarantee that reading
+     * or writing will succeed, only that there appears to be a reasonable chance of success
+     * based on a brief inspection of the file header.
      *
-     * @return {@link ProbeResult#SUPPORTED} if the given storage seems to be readable as a XML file.
-     * @throws DataStoreException if an I/O or SQL error occurred.
+     * @return a {@linkplain ProbeResult#isSupported() supported} status with the MIME type
+     *         if the given storage seems to be readable as a XML file.
+     * @throws DataStoreException if an I/O error occurred.
      */
     @Override
     public ProbeResult probeContent(final StorageConnector connector) throws DataStoreException {
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreProvider.java b/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreProvider.java
index e2e9e96d7b..0a6daee728 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreProvider.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreProvider.java
@@ -239,8 +239,8 @@ public abstract class DataStoreProvider {
      * with the format. The most typical return values are:
      *
      * <ul>
-     *   <li>{@link ProbeResult#SUPPORTED} if the {@code DataStore}s created by this provider
-     *       can open the given storage.</li>
+     *   <li>{@link ProbeResult#SUPPORTED} or another instance with {@linkplain ProbeResult#isSupported() supported}
+     *       status if the {@code DataStore}s created by this provider can open the given storage.</li>
      *   <li>{@link ProbeResult#UNSUPPORTED_STORAGE} if the given storage does not appear to be in a format
      *       supported by this {@code DataStoreProvider}.</li>
      * </ul>
@@ -259,8 +259,8 @@ public abstract class DataStoreProvider {
      * </div>
      *
      * @param  connector  information about the storage (URL, stream, JDBC connection, <i>etc</i>).
-     * @return {@link ProbeResult#SUPPORTED} if the given storage seems to be readable by the {@code DataStore}
-     *         instances created by this provider.
+     * @return a {@linkplain ProbeResult#isSupported() supported} status if the given storage
+     *         seems to be readable by the {@code DataStore} instances created by this provider.
      * @throws DataStoreException if an I/O or SQL error occurred. The error shall be unrelated to the logical
      *         structure of the storage.
      */
diff --git a/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/wkt/StoreProviderTest.java b/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/wkt/StoreProviderTest.java
index ba74e61df7..f0067145b9 100644
--- a/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/wkt/StoreProviderTest.java
+++ b/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/wkt/StoreProviderTest.java
@@ -83,7 +83,7 @@ public final strictfp class StoreProviderTest extends TestCase {
         c.closeAllExcept(null);
         assertEquals("isSupported", isSupported, r.isSupported());
         if (isSupported) {
-            assertEquals("mimeType", "application/wkt", r.getMimeType());
+            assertNull  ("mimeType", r.getMimeType());
             assertEquals("version", version, r.getVersion().getMajor());
         }
     }