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 22378d7a3fe223c5501b1ca0647097a1d7b7b15d
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Sun Feb 23 12:46:55 2025 +0100

    Consolidation of previous commit: regroup in the same class all the fields 
used for creating the identifier.
---
 .../apache/sis/storage/geotiff/GeoTiffStore.java   | 27 ++++++++++++++--------
 .../sis/storage/geotiff/ImageFileDirectory.java    |  2 +-
 .../sis/storage/geotiff/MultiResolutionImage.java  |  2 +-
 .../org/apache/sis/storage/geotiff/Reader.java     | 12 ++--------
 .../org/apache/sis/storage/geotiff/Writer.java     |  2 +-
 5 files changed, 22 insertions(+), 23 deletions(-)

diff --git 
a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/GeoTiffStore.java
 
b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/GeoTiffStore.java
index 360332cd75..5abdde61d1 100644
--- 
a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/GeoTiffStore.java
+++ 
b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/GeoTiffStore.java
@@ -72,6 +72,7 @@ import org.apache.sis.util.privy.Constants;
 import org.apache.sis.util.privy.ListOfUnknownSize;
 import org.apache.sis.util.collection.BackingStoreException;
 import org.apache.sis.util.collection.TreeTable;
+import org.apache.sis.util.iso.DefaultNameFactory;
 import org.apache.sis.util.iso.DefaultNameSpace;
 import org.apache.sis.util.resources.Errors;
 
@@ -149,14 +150,20 @@ public class GeoTiffStore extends DataStore implements 
Aggregate {
      */
     final Path path;
 
+    /**
+     * The factory to use for creating image identifiers.
+     */
+    final NameFactory nameFactory;
+
     /**
      * The data store identifier created from the filename, or {@code null} if 
none.
      * Defined as a namespace for use as the scope of children resources (the 
images).
      * This is created when first needed.
      *
      * <h4>Design note</h4>
-     * We do not create this field in the constructor because its creation 
invokes
-     * the user-overrideable {@link #customize(int, GenericName)} method.
+     * We do not create this field in the constructor because this value can 
be provided by
+     * the user-specified {@link #customizer}, which would receive a reference 
to {@code this}
+     * before its construction is completed.
      *
      * @see #namespace()
      */
@@ -245,6 +252,7 @@ public class GeoTiffStore extends DataStore implements 
Aggregate {
     {
         super(parent, provider, connector, hidden);
         this.hidden = hidden;
+        nameFactory = DefaultNameFactory.provider();
 
         @SuppressWarnings("LocalVariableHidesMemberVariable")
         final SchemaModifier customizer = 
connector.getOption(SchemaModifier.OPTION_KEY);
@@ -277,22 +285,21 @@ public class GeoTiffStore extends DataStore implements 
Aggregate {
      * This method must be invoked inside a block synchronized on {@code this}.
      */
     private NameSpace namespace() {
-        @SuppressWarnings("LocalVariableHidesMemberVariable")
-        final Reader reader = this.reader;
-        if (!isNamespaceSet && reader != null) {
-            final NameFactory f = reader.nameFactory;
+        assert Thread.holdsLock(this);
+        if (!isNamespaceSet && (reader != null || writer != null)) {
             GenericName name = null;
             /*
              * We test `location != null` because if the location was not 
convertible to URI,
              * then the string representation is probably a class name, which 
is not useful.
              */
             if (location != null) {
-                String filename = 
IOUtilities.filenameWithoutExtension(reader.input.filename);
-                name = f.createLocalName(null, filename);
+                String filename = (reader != null ? reader.input : 
writer.output).filename;
+                filename = IOUtilities.filenameWithoutExtension(filename);
+                name = nameFactory.createLocalName(null, filename);
             }
             name = customizer.customize(new SchemaModifier.Source(this), name);
             if (name != null) {
-                namespace = f.createNameSpace(name, null);
+                namespace = nameFactory.createNameSpace(name, null);
             }
             isNamespaceSet = true;
         }
@@ -307,7 +314,7 @@ public class GeoTiffStore extends DataStore implements 
Aggregate {
      * @return a name in the scope of this store.
      */
     final GenericName createLocalName(final String tip) {
-        return reader.nameFactory.createLocalName(namespace(), tip);
+        return nameFactory.createLocalName(namespace(), tip);
     }
 
     /**
diff --git 
a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/ImageFileDirectory.java
 
b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/ImageFileDirectory.java
index 61a7cc4850..c6cc20ebec 100644
--- 
a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/ImageFileDirectory.java
+++ 
b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/ImageFileDirectory.java
@@ -506,7 +506,7 @@ final class ImageFileDirectory extends DataCube {
      * @param  overview  1 for the first overview, 2 for the next one, etc.
      */
     final void setOverviewIdentifier(final NameSpace base, final int overview) 
{
-        identifier = reader.nameFactory.createLocalName(base, "overview-" + 
overview);
+        identifier = reader.store.nameFactory.createLocalName(base, 
"overview-" + overview);
     }
 
     /**
diff --git 
a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/MultiResolutionImage.java
 
b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/MultiResolutionImage.java
index 21717f1f15..ee2258510f 100644
--- 
a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/MultiResolutionImage.java
+++ 
b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/MultiResolutionImage.java
@@ -142,7 +142,7 @@ final class MultiResolutionImage extends 
GridResourceWrapper implements StoreRes
             if (namespace == null) {
                 final ImageFileDirectory base = levels[0];
                 // Identifier should never be empty (see 
`DataCube.getIdentifier()` contract).
-                namespace = 
base.reader.nameFactory.createNameSpace(base.getIdentifier().get(), null);
+                namespace = 
base.reader.store.nameFactory.createNameSpace(base.getIdentifier().get(), null);
             }
             dir.setOverviewIdentifier(namespace, index);
         }
diff --git 
a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/Reader.java
 
b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/Reader.java
index 77f641d19d..0c61acaca9 100644
--- 
a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/Reader.java
+++ 
b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/Reader.java
@@ -24,7 +24,6 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.io.IOException;
 import java.nio.ByteOrder;
-import org.opengis.util.NameFactory;
 import org.apache.sis.io.stream.ChannelDataInput;
 import org.apache.sis.storage.GridCoverageResource;
 import org.apache.sis.storage.DataStoreException;
@@ -34,7 +33,6 @@ import org.apache.sis.storage.geotiff.base.Resources;
 import org.apache.sis.storage.geotiff.base.Tags;
 import org.apache.sis.storage.geotiff.reader.Type;
 import org.apache.sis.storage.geotiff.reader.XMLMetadata;
-import org.apache.sis.util.iso.DefaultNameFactory;
 import org.apache.sis.util.resources.Errors;
 
 
@@ -133,11 +131,6 @@ final class Reader extends IOBase {
      */
     private boolean deferredNeedsSort;
 
-    /**
-     * The factory to use for creating image identifiers.
-     */
-    final NameFactory nameFactory;
-
     /**
      * Creates a new GeoTIFF reader which will read data from the given input.
      * The input must be at the beginning of the GeoTIFF file.
@@ -147,9 +140,8 @@ final class Reader extends IOBase {
      */
     Reader(final GeoTiffStore store, final ChannelDataInput input) throws 
IOException, DataStoreException {
         super(store);
-        this.input       = input;
-        this.doneIFD     = new HashSet<>();
-        this.nameFactory = DefaultNameFactory.provider();
+        this.input   = input;
+        this.doneIFD = new HashSet<>();
         /*
          * A TIFF file begins with either "II" (0x4949) or "MM" (0x4D4D) 
characters.
          * Those characters identify the byte order. Note that we do not need 
to care
diff --git 
a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/Writer.java
 
b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/Writer.java
index d657f0ab60..f14d7db097 100644
--- 
a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/Writer.java
+++ 
b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/Writer.java
@@ -131,7 +131,7 @@ final class Writer extends IOBase implements Flushable {
     /**
      * The stream where to write the data.
      */
-    private final ChannelDataOutput output;
+    final ChannelDataOutput output;
 
     /**
      * Whether the lengths and offsets shall be written as 64-bits integers 
instead of 32-bits integers.

Reply via email to