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 2024/04/04 15:00:02 UTC
(sis) 01/02: Resolve deprecation warnings about `AuthorityFactory.getDescriptionText(String)`.
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 194ed455ba61b6d5596b8bb501719a594dfb0d86
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Thu Apr 4 14:53:45 2024 +0200
Resolve deprecation warnings about `AuthorityFactory.getDescriptionText(String)`.
---
.../sis/openoffice/ReferencingFunctions.java | 4 +-
.../main/org/apache/sis/io/wkt/WKTDictionary.java | 20 ++++--
.../org/apache/sis/referencing/DisplayName.java | 84 ++++++++++++++++++++++
.../apache/sis/referencing/IdentifiedObjects.java | 24 ++++++-
.../referencing/factory/AuthorityFactoryProxy.java | 22 +++---
.../factory/CommonAuthorityFactory.java | 30 ++++----
.../factory/ConcurrentAuthorityFactory.java | 11 +--
.../factory/GeodeticAuthorityFactory.java | 41 ++++++++---
.../factory/IdentifiedObjectFinder.java | 4 +-
.../factory/MultiAuthoritiesFactory.java | 14 ++--
.../referencing/factory/sql/AuthorityCodes.java | 8 +--
.../referencing/factory/sql/EPSGDataAccess.java | 37 ++++++----
.../sis/referencing/factory/sql/package-info.java | 2 +-
.../sis/referencing/internal/EPSGFactoryProxy.java | 8 ++-
.../org/apache/sis/io/wkt/WKTDictionaryTest.java | 20 ++++--
.../sis/referencing/AuthorityFactoriesTest.java | 17 +++--
.../factory/CommonAuthorityFactoryTest.java | 18 +++--
.../factory/MultiAuthoritiesFactoryTest.java | 2 +-
.../referencing/factory/sql/EPSGFactoryTest.java | 12 ++--
.../report/CoordinateReferenceSystems.java | 2 +-
.../org/apache/sis/storage/netcdf/base/Axis.java | 2 +-
.../apache/sis/storage/netcdf/base/Linearizer.java | 5 +-
.../main/org/apache/sis/storage/wkt/Store.java | 5 +-
.../apache/sis/gui/referencing/AuthorityCodes.java | 3 +-
24 files changed, 293 insertions(+), 102 deletions(-)
diff --git a/endorsed/src/org.apache.sis.openoffice/main/org/apache/sis/openoffice/ReferencingFunctions.java b/endorsed/src/org.apache.sis.openoffice/main/org/apache/sis/openoffice/ReferencingFunctions.java
index 5221e076d8..2701a8bf28 100644
--- a/endorsed/src/org.apache.sis.openoffice/main/org/apache/sis/openoffice/ReferencingFunctions.java
+++ b/endorsed/src/org.apache.sis.openoffice/main/org/apache/sis/openoffice/ReferencingFunctions.java
@@ -173,8 +173,8 @@ public class ReferencingFunctions extends CalcAddins implements XReferencing {
if (object != null) {
return object.getName().getCode();
}
- // In Apache SIS implementation, 'getDescriptionText' returns the name.
- name = CRS.getAuthorityFactory(null).getDescriptionText(codeOrPath);
+ // In Apache SIS implementation, `getDescriptionText(…)` returns the identified object name.
+ name = CRS.getAuthorityFactory(null).getDescriptionText(IdentifiedObject.class, codeOrPath).orElse(null);
} catch (Exception exception) {
return getLocalizedMessage(exception);
}
diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/WKTDictionary.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/WKTDictionary.java
index d64321c788..fdbf241c8a 100644
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/WKTDictionary.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/WKTDictionary.java
@@ -23,6 +23,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Objects;
+import java.util.Optional;
import java.util.stream.Stream;
import java.util.function.Predicate;
import java.util.function.Consumer;
@@ -38,6 +39,7 @@ import org.opengis.util.InternationalString;
import org.opengis.metadata.citation.Citation;
import org.opengis.referencing.IdentifiedObject;
import org.opengis.referencing.NoSuchAuthorityCodeException;
+import org.apache.sis.referencing.IdentifiedObjects;
import org.apache.sis.referencing.factory.GeodeticAuthorityFactory;
import org.apache.sis.referencing.factory.FactoryDataException;
import org.apache.sis.referencing.privy.ReferencingUtilities;
@@ -128,7 +130,7 @@ import org.opengis.metadata.Identifier;
* {@link org.apache.sis.referencing.factory.sql.EPSGFactory}.
*
* @author Martin Desruisseaux (Geomatys)
- * @version 1.1
+ * @version 1.5
* @since 1.1
*/
public class WKTDictionary extends GeodeticAuthorityFactory {
@@ -957,25 +959,31 @@ public class WKTDictionary extends GeodeticAuthorityFactory {
/**
* Gets a description of the object corresponding to a code.
*
+ * @param type the type of object for which to get a description.
* @param code value allocated by authority.
* @return a description of the object, or {@code null} if {@code null} if none.
* @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
* @throws FactoryException if the query failed for some other reason.
+ *
+ * @since 1.5
*/
@Override
- public InternationalString getDescriptionText(final String code) throws FactoryException {
- final String text;
+ public Optional<InternationalString> getDescriptionText(Class<? extends IdentifiedObject> type, final String code)
+ throws FactoryException
+ {
+ final InternationalString name;
final Object value = getOrCreate(code, false);
if (value instanceof IdentifiedObject) {
- text = ((IdentifiedObject) value).getName().getCode();
+ name = IdentifiedObjects.getDisplayName((IdentifiedObject) value);
} else {
- text = String.valueOf(value);
+ final String text = String.valueOf(value);
if (!(value instanceof StoredTree)) {
// Exception message saved in a previous invocation of `getOrCreate(…)`.
throw new FactoryException(text);
}
+ name = new SimpleInternationalString(text);
}
- return new SimpleInternationalString(text);
+ return Optional.ofNullable(name);
}
/**
diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/DisplayName.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/DisplayName.java
new file mode 100644
index 0000000000..7c2df264c4
--- /dev/null
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/DisplayName.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.referencing;
+
+import java.util.Locale;
+import java.io.Serializable;
+import org.opengis.referencing.IdentifiedObject;
+import org.apache.sis.util.AbstractInternationalString;
+
+
+/**
+ * Name of an identified object in specified locale.
+ * This class is serializable if the identified object is serializable.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @version 1.5
+ * @since 1.5
+ */
+final class DisplayName extends AbstractInternationalString implements Serializable {
+ /**
+ * For cross-version compatibility.
+ */
+ private static final long serialVersionUID = 8061637252049031838L;
+
+ /**
+ * The object for which to provide a display name.
+ */
+ @SuppressWarnings("serial") // Most Apache SIS implementations are serializable.
+ private final IdentifiedObject object;
+
+ /**
+ * Creates a new display name.
+ *
+ * @param object the object for which to provide a display name.
+ */
+ DisplayName(final IdentifiedObject object) {
+ this.object = object;
+ }
+
+ /**
+ * Returns the display name in the given locale.
+ *
+ * @param locale the desired locale for the string to be returned.
+ * @return the string in the given locale if available, or in an
+ * implementation-dependent fallback locale otherwise.
+ */
+ @Override
+ public String toString(final Locale locale) {
+ return IdentifiedObjects.getDisplayName(object, locale);
+ }
+
+ /**
+ * Returns a hash code value for this international string.
+ */
+ @Override
+ public int hashCode() {
+ return object.hashCode() ^ (int) serialVersionUID;
+ }
+
+ /**
+ * Compares this international string with the given object for equality.
+ *
+ * @param obj the object to compare with this international string.
+ * @return whether the two object are equal.
+ */
+ @Override
+ public boolean equals(final Object obj) {
+ return (obj instanceof DisplayName) && object.equals(((DisplayName) obj).object);
+ }
+}
diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/IdentifiedObjects.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/IdentifiedObjects.java
index ffe186657b..5a374cdaef 100644
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/IdentifiedObjects.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/IdentifiedObjects.java
@@ -62,7 +62,7 @@ import org.opengis.referencing.ObjectDomain;
*
* @author Martin Desruisseaux (IRD, Geomatys)
* @author Guilhem Legal (Geomatys)
- * @version 1.4
+ * @version 1.5
*
* @see CRS
* @see org.apache.sis.geometry.Envelopes
@@ -368,7 +368,8 @@ public final class IdentifiedObjects extends Static {
}
/**
- * Returns a name that can be used for display purpose. This method checks the non-blank
+ * Returns a name that can be used for display purposes.
+ * This method checks the non-blank
* {@linkplain AbstractIdentifiedObject#getName() name},
* {@linkplain AbstractIdentifiedObject#getAlias() alias} or
* {@linkplain AbstractIdentifiedObject#getIdentifiers() identifier}, in that order.
@@ -382,9 +383,28 @@ public final class IdentifiedObjects extends Static {
* its {@link GenericName#toInternationalString() toInternationalString()} method will be used.</p>
*
* @param object the identified object, or {@code null}.
+ * @return a name for human reading, or {@code null} if the given object is null.
+ *
+ * @see #getDisplayName(IdentifiedObject, Locale)
+ *
+ * @since 1.5
+ */
+ public static InternationalString getDisplayName(final IdentifiedObject object) {
+ return (object == null) ? null : new DisplayName(object);
+ }
+
+ /**
+ * Returns a name that can be used for display purposes in the specified locale.
+ * Invoking this method is equivalent to invoking {@code getDisplayName(object).toString(locale)},
+ * except that the {@code object} argument can be null and the creation of an intermediate
+ * {@link InternationalString} object is avoided.
+ *
+ * @param object the identified object, or {@code null}.
* @param locale the locale for the name to return, or {@code null} for the default.
* @return a name for human reading, or {@code null} if none were found.
*
+ * @see #getDisplayName(IdentifiedObject)
+ *
* @since 1.1
*/
public static String getDisplayName(final IdentifiedObject object, final Locale locale) {
diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/AuthorityFactoryProxy.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/AuthorityFactoryProxy.java
index d1a3b4e3b2..4f7a0b5c3d 100644
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/AuthorityFactoryProxy.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/AuthorityFactoryProxy.java
@@ -35,11 +35,11 @@ import org.apache.sis.util.privy.Strings;
/**
* Delegates object creations to one of the {@code create} methods in a backing {@code AuthorityFactory}.
- * It is possible to use the generic {@link AuthorityFactory#createObject(String)} method instead of this class,
- * but some factories are more efficient when we use the most specific {@code create} method.
+ * It is possible to use the generic {@link GeodeticAuthorityFactory#createObject(String)} method instead of this class,
+ * but the former is ambiguous and some factories are more efficient when we use the most specific {@code create} method.
* For example, when using a {@linkplain org.apache.sis.referencing.factory.sql.EPSGDataAccess},
* invoking {@link GeodeticAuthorityFactory#createProjectedCRS(String)} instead of
- * {@code AuthorityFactory.createObject(String)} method reduce the number of tables to be queried.
+ * {@code createObject(String)} method reduce the number of tables to be queried.
*
* <p>This class is useful when the same {@code create} method need to be invoked often, but is unknown at compile time.
* It may also be used as a workaround for authority factories that do not implement the {@code createObject(String)}
@@ -172,17 +172,20 @@ abstract class AuthorityFactoryProxy<T> {
abstract T createFromAPI(AuthorityFactory factory, String code) throws FactoryException;
/**
- * The proxy for the {@link GeodeticAuthorityFactory#getDescriptionText(String)} method.
+ * The proxy for the {@link GeodeticAuthorityFactory#getDescriptionText(Class, String)} method.
+ *
+ * @param classe the type of object for which to get a description.
*/
- static final AuthorityFactoryProxy<InternationalString> DESCRIPTION =
- new AuthorityFactoryProxy<InternationalString>(InternationalString.class, AuthorityFactoryIdentifier.ANY) {
+ static final AuthorityFactoryProxy<InternationalString> description(final Class<? extends IdentifiedObject> classe) {
+ return new AuthorityFactoryProxy<InternationalString>(InternationalString.class, AuthorityFactoryIdentifier.ANY) {
@Override InternationalString createFromAPI(AuthorityFactory factory, String code) throws FactoryException {
- return factory.getDescriptionText(code);
+ return factory.getDescriptionText(classe, code).orElse(null);
}
@Override AuthorityFactoryProxy<InternationalString> specialize(String typeName) {
return this;
}
- };
+ };
+ }
/**
* The proxy for the {@link GeodeticAuthorityFactory#createObject(String)} method.
@@ -587,8 +590,7 @@ abstract class AuthorityFactoryProxy<T> {
PARAMETER,
UNIT,
EXTENT,
- OBJECT,
- DESCRIPTION
+ OBJECT
};
/**
diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/CommonAuthorityFactory.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/CommonAuthorityFactory.java
index f59ba79dc0..76a29a557f 100644
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/CommonAuthorityFactory.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/CommonAuthorityFactory.java
@@ -22,13 +22,12 @@ import java.util.List;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Collections;
+import java.util.Optional;
import java.util.Objects;
import javax.measure.Unit;
import javax.measure.quantity.Length;
import org.opengis.util.FactoryException;
import org.opengis.util.InternationalString;
-import org.opengis.util.GenericName;
-import org.opengis.metadata.Identifier;
import org.opengis.metadata.citation.Citation;
import org.opengis.referencing.IdentifiedObject;
import org.opengis.referencing.NoSuchAuthorityCodeException;
@@ -42,16 +41,17 @@ import org.opengis.referencing.crs.TemporalCRS;
import org.opengis.referencing.crs.SingleCRS;
import org.opengis.referencing.cs.CartesianCS;
import org.apache.sis.referencing.CommonCRS;
+import org.apache.sis.referencing.IdentifiedObjects;
+import org.apache.sis.referencing.cs.CoordinateSystems;
import org.apache.sis.referencing.operation.provider.TransverseMercator.Zoner;
import org.apache.sis.referencing.privy.GeodeticObjectBuilder;
import org.apache.sis.referencing.internal.Resources;
import org.apache.sis.metadata.iso.citation.Citations;
import org.apache.sis.util.SimpleInternationalString;
import org.apache.sis.util.privy.Constants;
-import org.apache.sis.measure.Units;
-import org.apache.sis.referencing.cs.CoordinateSystems;
import org.apache.sis.util.logging.Logging;
import org.apache.sis.util.resources.Errors;
+import org.apache.sis.measure.Units;
/**
@@ -206,7 +206,7 @@ import org.apache.sis.util.resources.Errors;
* switching to polar stereographic projections for high latitudes.</p>
*
* @author Martin Desruisseaux (IRD, Geomatys)
- * @version 1.3
+ * @version 1.5
*
* @see CommonCRS
*
@@ -237,7 +237,7 @@ public class CommonAuthorityFactory extends GeodeticAuthorityFactory implements
* Names of objects in the AUTO(2) namespace for codes from 42001 to 42005 inclusive.
* Those names are defined in annexes B.7 to B.11 of WMS 1.3 specification.
*
- * @see #getDescriptionText(String)
+ * @see #getDescriptionText(Class, String)
*/
private static final String[] PROJECTION_NAMES = {
"WGS 84 / Auto UTM",
@@ -409,19 +409,24 @@ public class CommonAuthorityFactory extends GeodeticAuthorityFactory implements
* <tr><td>{@code AUTO2:42001,1,-100,45}</td> <td>WGS 84 / UTM zone 47N</td></tr>
* </table>
*
+ * @param type the type of object for which to get a description.
* @param code value in the CRS or AUTO(2) code space.
* @return a description of the object.
* @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
* @throws FactoryException if an error occurred while fetching the description.
+ *
+ * @since 1.5
*/
@Override
- public InternationalString getDescriptionText(final String code) throws FactoryException {
+ public Optional<InternationalString> getDescriptionText(final Class<? extends IdentifiedObject> type, final String code)
+ throws FactoryException
+ {
final CommonAuthorityCode parsed = new CommonAuthorityCode(code);
if (parsed.isNumeric && parsed.isParameterless()) {
/*
* For codes in the "AUTO(2)" namespace without parameters, we cannot rely on the default implementation
* because it would fail to create the ProjectedCRS instance. Instead, we return a generic description.
- * Note that we do not execute this block if parametes were specified. If there are parameters,
+ * Note that we do not execute this block if parameters were specified. If there are parameters,
* then we instead rely on the default implementation for a more accurate description text.
* Note also that we do not restrict to "AUTOx" namespaces because erroneous namespaces exist
* in practice and the numerical codes are non-ambiguous (at least in current version).
@@ -434,19 +439,14 @@ public class CommonAuthorityFactory extends GeodeticAuthorityFactory implements
}
final int i = codeValue - FIRST_PROJECTION_CODE;
if (i >= 0 && i < PROJECTION_NAMES.length) {
- return new SimpleInternationalString(PROJECTION_NAMES[i]);
+ return Optional.of(new SimpleInternationalString(PROJECTION_NAMES[i]));
}
}
/*
* Fallback on fetching the full CRS, then request its name.
* It will include the parsing of parameters if any.
*/
- final Identifier name = createCoordinateReferenceSystem(code, parsed).getName();
- if (name instanceof GenericName) {
- return ((GenericName) name).tip().toInternationalString();
- } else {
- return new SimpleInternationalString(name.getCode());
- }
+ return Optional.ofNullable(IdentifiedObjects.getDisplayName(createCoordinateReferenceSystem(code, parsed)));
}
/**
diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/ConcurrentAuthorityFactory.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/ConcurrentAuthorityFactory.java
index 739f775e5e..f32cffccf1 100644
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/ConcurrentAuthorityFactory.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/ConcurrentAuthorityFactory.java
@@ -20,6 +20,7 @@ import java.util.Set;
import java.util.Map;
import java.util.List;
import java.util.Deque;
+import java.util.Optional;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.LinkedList;
@@ -96,7 +97,7 @@ import org.apache.sis.system.Shutdown;
* Subclasses should select the interfaces that they choose to implement.
*
* @author Martin Desruisseaux (IRD, Geomatys)
- * @version 1.4
+ * @version 1.5
*
* @param <DAO> the type of factory used as Data Access Object (DAO).
*
@@ -794,7 +795,7 @@ public abstract class ConcurrentAuthorityFactory<DAO extends GeodeticAuthorityFa
* The default implementation performs the following steps:
* <ol>
* <li>get an instance of the Data Access Object,</li>
- * <li>delegate to its {@link GeodeticAuthorityFactory#getDescriptionText(String)} method,</li>
+ * <li>delegate to its {@link GeodeticAuthorityFactory#getDescriptionText(Class, String)} method,</li>
* <li>release the Data Access Object.</li>
* </ol>
*
@@ -803,14 +804,16 @@ public abstract class ConcurrentAuthorityFactory<DAO extends GeodeticAuthorityFa
* corresponding to the specified {@code code} has no description.
* @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
* @throws FactoryException if the query failed for some other reason.
+ *
+ * @since 1.5
*/
@Override
- public InternationalString getDescriptionText(final String code)
+ public Optional<InternationalString> getDescriptionText(Class<? extends IdentifiedObject> type, String code)
throws NoSuchAuthorityCodeException, FactoryException
{
final DAO factory = getDataAccess();
try {
- return factory.getDescriptionText(code);
+ return factory.getDescriptionText(type, code);
} finally {
release("getDescriptionText", InternationalString.class, code);
}
diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/GeodeticAuthorityFactory.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/GeodeticAuthorityFactory.java
index b6a2d18e12..981f93e539 100644
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/GeodeticAuthorityFactory.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/GeodeticAuthorityFactory.java
@@ -17,6 +17,7 @@
package org.apache.sis.referencing.factory;
import java.util.Set;
+import java.util.Optional;
import java.util.logging.Logger;
import javax.measure.Unit;
import org.opengis.referencing.*;
@@ -32,10 +33,10 @@ import org.opengis.util.FactoryException;
import org.opengis.util.InternationalString;
import org.apache.sis.metadata.iso.citation.Citations;
import org.apache.sis.system.Loggers;
-import org.apache.sis.util.SimpleInternationalString;
import org.apache.sis.util.CharSequences;
import org.apache.sis.util.Classes;
import org.apache.sis.util.privy.Constants;
+import org.apache.sis.referencing.IdentifiedObjects;
import org.apache.sis.referencing.AbstractIdentifiedObject;
import org.apache.sis.referencing.privy.ReferencingUtilities;
import org.apache.sis.util.iso.AbstractFactory;
@@ -151,20 +152,43 @@ public abstract class GeodeticAuthorityFactory extends AbstractFactory implement
* The description can be used for example in a combo box in a graphical user interface.
*
* <h4>Default implementation</h4>
- * The default implementation invokes {@link #createObject(String)} for the given code
- * and returns the {@linkplain AbstractIdentifiedObject#getName() object name}.
- * This may be costly since it involves a full object creation.
+ * The default implementation invokes {@link #createObject(Class, String)} for the given class and code,
+ * then returns the {@linkplain IdentifiedObjects#getDisplayName(IdentifiedObject) display name} of the object.
+ * This implementation may be costly because it involves a full object creation.
* Subclasses are encouraged to provide a more efficient implementation if they can.
*
+ * @param type the type of object for which to get a description.
* @param code value allocated by authority.
- * @return a description of the object, or {@code null} if the object
- * corresponding to the specified {@code code} has no description.
+ * @return a description of the object, or empty if the object exists but has no description.
* @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
* @throws FactoryException if an error occurred while fetching the description.
+ *
+ * @since 1.5
*/
@Override
- public InternationalString getDescriptionText(final String code) throws FactoryException {
- return new SimpleInternationalString(createObject(code).getName().getCode());
+ public Optional<InternationalString> getDescriptionText(Class<? extends IdentifiedObject> type, String code)
+ throws FactoryException
+ {
+ return Optional.ofNullable(IdentifiedObjects.getDisplayName(createObject(type, code)));
+ }
+
+ /**
+ * Returns an object of the specified type from a code. This implementation forwards
+ * the method call to the most specialized methods determined by the given type.
+ *
+ * @param <T> the compile-time value of the {@code type} argument.
+ * @param type the type of object to create.
+ * @param code value allocated by authority.
+ * @return the object for the given code.
+ * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+ * @throws FactoryException if the object creation failed for some other reason.
+ *
+ * @since 1.5
+ */
+ public final <T extends IdentifiedObject> T createObject(final Class<T> type, final String code)
+ throws NoSuchAuthorityCodeException, FactoryException
+ {
+ return cast(type, (IdentifiedObject) AuthorityFactoryProxy.getInstance(type).create(this, code), code);
}
/**
@@ -188,6 +212,7 @@ public abstract class GeodeticAuthorityFactory extends AbstractFactory implement
* @see org.apache.sis.referencing.AbstractIdentifiedObject
*/
@Override
+ @SuppressWarnings("deprecation")
public abstract IdentifiedObject createObject(String code) throws NoSuchAuthorityCodeException, FactoryException;
/**
diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/IdentifiedObjectFinder.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/IdentifiedObjectFinder.java
index 7ca72b494f..280e655457 100644
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/IdentifiedObjectFinder.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/IdentifiedObjectFinder.java
@@ -292,8 +292,8 @@ public class IdentifiedObjectFinder {
*
* <ul>
* <li>If the specified object contains {@linkplain AbstractIdentifiedObject#getIdentifiers() identifiers}
- * associated to the same authority as the factory, then those identifiers are used for
- * {@linkplain GeodeticAuthorityFactory#createObject(String) creating objects} to be tested.</li>
+ * associated to the same authority as the factory, then those identifiers are used for creating the
+ * objects to be compared by calls to a {@code create<Type>(String)} method.</li>
* <li>If the authority factory can create objects from their {@linkplain AbstractIdentifiedObject#getName() name}
* in addition of identifiers, then the name and {@linkplain AbstractIdentifiedObject#getAlias() aliases} are
* used for creating objects to be tested.</li>
diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java
index 86b7a4eec9..ca2bcea3de 100644
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java
@@ -16,6 +16,7 @@
*/
package org.apache.sis.referencing.factory;
+import java.util.Optional;
import java.util.ServiceLoader;
import java.util.Collections;
import java.util.Collection;
@@ -868,13 +869,18 @@ public class MultiAuthoritiesFactory extends GeodeticAuthorityFactory implements
* <li>{@code http://www.opengis.net/gml/srs/}<var>authority</var>{@code .xml#}<var>code</var></li>
* </ul>
*
- * @return a description of the object, or {@code null} if the object
- * corresponding to the specified {@code code} has no description.
+ * @param type the type of object for which to get a description.
+ * @param code value allocated by authority.
+ * @return a description of the object, or empty if the object corresponding to the specified code has no description.
* @throws FactoryException if an error occurred while fetching the description.
+ *
+ * @since 1.5
*/
@Override
- public InternationalString getDescriptionText(final String code) throws FactoryException {
- return create(AuthorityFactoryProxy.DESCRIPTION, code);
+ public Optional<InternationalString> getDescriptionText(Class<? extends IdentifiedObject> type, String code)
+ throws FactoryException
+ {
+ return Optional.ofNullable(create(AuthorityFactoryProxy.description(type), code));
}
/**
diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/AuthorityCodes.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/AuthorityCodes.java
index 69cb4dd813..a226b0cad9 100644
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/AuthorityCodes.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/AuthorityCodes.java
@@ -254,7 +254,7 @@ final class AuthorityCodes extends AbstractMap<String,String> implements Seriali
/**
* Returns the object name associated to the given authority code, or {@code null} if none.
* If there is no name for the {@linkplain #type} of object being queried, then this method
- * returns the code itself.
+ * returns {@code null}.
*
* @param code the code for which to get the description. May be a string or an integer.
* @return the description for the given code, or {@code null} if none.
@@ -279,9 +279,9 @@ final class AuthorityCodes extends AbstractMap<String,String> implements Seriali
sql[ONE] = null; // Not needed anymore.
}
statement.setInt(1, n);
- try (ResultSet results = statement.executeQuery()) {
- while (results.next()) {
- String name = results.getString(1);
+ try (ResultSet r = statement.executeQuery()) {
+ while (r.next()) {
+ String name = r.getString(1);
if (name != null) {
return name;
}
diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
index c8dfceab68..8f17efbc4d 100644
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
@@ -30,6 +30,7 @@ import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import java.util.Objects;
+import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.LogRecord;
@@ -159,7 +160,7 @@ import org.opengis.metadata.Identifier;
* @author Matthias Basler
* @author Andrea Aime (TOPP)
* @author Johann Sorel (Geomatys)
- * @version 1.4
+ * @version 1.5
*
* @see <a href="https://sis.apache.org/tables/CoordinateReferenceSystems.html">List of authority codes</a>
*
@@ -541,12 +542,12 @@ addURIs: for (int i=0; ; i++) {
* Returns a map of EPSG authority codes as keys and object names as values.
* The cautions documented in {@link #getAuthorityCodes(Class)} apply also to this map.
*
- * @todo We may need to give some public access to this map if callers need descriptions
- * for other kinds of object than CRS. Current {@link #getDescriptionText(String)}
- * implementation selects CRS if the same code is used by many kinds of objects.
+ * @param type the spatial reference objects type (may be {@code Object.class}).
+ * @return the map of authority codes associated to their names. May be an empty map.
+ * @throws FactoryException if access to the underlying database failed.
*
* @see #getAuthorityCodes(Class)
- * @see #getDescriptionText(String)
+ * @see #getDescriptionText(Class, String)
*/
private synchronized Map<String,String> getCodeMap(final Class<?> type) throws SQLException {
CloseableReference reference = authorityCodes.get(type);
@@ -627,18 +628,24 @@ addURIs: for (int i=0; ; i++) {
* Gets a description of the object corresponding to a code.
* This method returns the object name in a lightweight manner, without creating the full {@link IdentifiedObject}.
*
+ * @param type the type of object for which to get a description.
* @param code value allocated by authority.
- * @return the object name, or {@code null} if the object corresponding to the specified {@code code} has no name.
- * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
+ * @return the object name, or empty if none.
* @throws FactoryException if the query failed for some other reason.
+ *
+ * @since 1.5
*/
@Override
- public InternationalString getDescriptionText(final String code) throws NoSuchAuthorityCodeException, FactoryException {
+ public Optional<InternationalString> getDescriptionText(final Class<? extends IdentifiedObject> type, final String code)
+ throws FactoryException
+ {
try {
for (final TableInfo table : TableInfo.EPSG) {
- final String text = getCodeMap(table.type).get(code);
- if (text != null) {
- return (table.nameColumn != null) ? new SimpleInternationalString(text) : null;
+ if (table.nameColumn != null && type.isAssignableFrom(table.type)) {
+ final String text = getCodeMap(table.type).get(code);
+ if (text != null) {
+ return Optional.of(new SimpleInternationalString(text));
+ }
}
}
} catch (SQLException exception) {
@@ -646,7 +653,7 @@ addURIs: for (int i=0; ; i++) {
} catch (BackingStoreException exception) { // Cause is SQLException.
throw new FactoryException(exception.getLocalizedMessage(), exception.getCause());
}
- throw noSuchAuthorityCode(IdentifiedObject.class, code);
+ return Optional.empty();
}
/**
@@ -686,7 +693,7 @@ addURIs: for (int i=0; ; i++) {
/**
* Converts EPSG codes or EPSG names to the numerical identifiers (the primary keys).
- * This method could be seen as the converse of above {@link #getDescriptionText(String)} method.
+ * This method can be seen as the converse of above {@link #getDescriptionText(Class, String)} method.
*
* @param table the table where the code should appears, or {@code null} if {@code codeColumn} is null.
* @param codeColumn the column name for the codes, or {@code null} if none.
@@ -1233,8 +1240,8 @@ codes: for (int i=0; i<codes.length; i++) {
* for example {@link #createCoordinateReferenceSystem(String)}, {@link #createDatum(String)}, <i>etc.</i>
* until a successful one is found.
*
- * <p><strong>Note that this method may be ambiguous</strong> since the same EPSG code can be used for different
- * kinds of objects. This method throws an exception if it detects an ambiguity on a <em>best-effort</em> basis.
+ * <p><strong>Note that this method may be ambiguous</strong> because the same EPSG code can be used for different
+ * kinds of objects. This method throws an exception on a <em>best-effort</em> basis if it detects an ambiguity.
* It is recommended to invoke the most specific {@code createFoo(String)} method when the desired type is known,
* both for performance reason and for avoiding ambiguity.</p>
*
diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/package-info.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/package-info.java
index 31db366080..5bf31094cb 100644
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/package-info.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/package-info.java
@@ -83,7 +83,7 @@
* @author Jody Garnett (Refractions)
* @author Didier Richard (IGN)
* @author John Grange
- * @version 1.4
+ * @version 1.5
*
* @see org.apache.sis.metadata.sql
*
diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/EPSGFactoryProxy.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/EPSGFactoryProxy.java
index b4419ca81a..d6eaeb701f 100644
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/EPSGFactoryProxy.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/EPSGFactoryProxy.java
@@ -17,6 +17,7 @@
package org.apache.sis.referencing.internal;
import java.util.Set;
+import java.util.Optional;
import org.opengis.metadata.citation.Citation;
import org.opengis.referencing.AuthorityFactory;
import org.opengis.referencing.IdentifiedObject;
@@ -58,11 +59,14 @@ public abstract class EPSGFactoryProxy implements AuthorityFactory {
}
@Override
- public final InternationalString getDescriptionText(String code) throws FactoryException {
- return factory().getDescriptionText(code);
+ public final Optional<InternationalString> getDescriptionText(Class<? extends IdentifiedObject> type, String code)
+ throws FactoryException
+ {
+ return factory().getDescriptionText(type, code);
}
@Override
+ @SuppressWarnings("deprecation")
public final IdentifiedObject createObject(String code) throws FactoryException {
return factory().createObject(code);
}
diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTDictionaryTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTDictionaryTest.java
index e46ccd6f0b..d937e32a3d 100644
--- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTDictionaryTest.java
+++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTDictionaryTest.java
@@ -150,8 +150,8 @@ public final class WKTDictionaryTest extends TestCase {
* Test descriptions before CRS creation.
* Implementation fetches them from `StoredTree` instances.
*/
- assertEquals("North_Pole_Stereographic", factory.getDescriptionText("ESRI::102018").toString());
- assertEquals("South_Pole_Stereographic", factory.getDescriptionText("ESRI::102021").toString());
+ assertDescriptionEquals("North_Pole_Stereographic", factory, "ESRI::102018");
+ assertDescriptionEquals("South_Pole_Stereographic", factory, "ESRI::102021");
/*
* Tests CRS creation.
*/
@@ -163,8 +163,8 @@ public final class WKTDictionaryTest extends TestCase {
* Test descriptions after CRS creation.
* Implementation fetches them from `IdentifiedObject` instances.
*/
- assertEquals("North_Pole_Stereographic", factory.getDescriptionText("ESRI::102018").toString());
- assertEquals("South_Pole_Stereographic", factory.getDescriptionText("ESRI::102021").toString());
+ assertDescriptionEquals("North_Pole_Stereographic", factory, "ESRI::102018");
+ assertDescriptionEquals("South_Pole_Stereographic", factory, "ESRI::102021");
/*
* Test creation of CRS having errors.
* - Verify error index.
@@ -173,11 +173,23 @@ public final class WKTDictionaryTest extends TestCase {
verifyErroneousCRS(factory, "E2", 42);
}
+ /**
+ * Asserts that the description is equal to the expected value.
+ *
+ * @param expected the expected description.
+ * @param factory the factory to use for fetching the description.
+ * @param code the code of the object for which to fetch the description.
+ */
+ private static void assertDescriptionEquals(String expected, WKTDictionary factory, String code) throws FactoryException {
+ assertEquals(expected, factory.getDescriptionText(IdentifiedObject.class, code).orElseThrow().toString());
+ }
+
/**
* Verifies that there is no duplicated nodes in the {@link StoredTree}s.
* When a WKT element is repeated often (e.g. "AngleUnit["Degree", 0.0174532925199433]]"),
* only one {@link org.apache.sis.io.wkt.StoredTree.Node} instance should be created and shared by all trees.
*/
+ @SuppressWarnings("overloads") // Ambiguous `andThen(…)` method is not used by this test.
private static final class SharedValuesCheck implements Consumer<Object>, BiFunction<Integer,Integer,Integer> {
/**
* Counter of number of occurrences of each instance. Keys may be {@link String},
diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/AuthorityFactoriesTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/AuthorityFactoriesTest.java
index 501b05bf8c..7b24a3965d 100644
--- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/AuthorityFactoriesTest.java
+++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/AuthorityFactoriesTest.java
@@ -77,18 +77,27 @@ public final class AuthorityFactoriesTest extends TestCaseWithLogs {
}
/**
- * Tests {@link CRSAuthorityFactory#getDescriptionText(String)}.
+ * Tests {@link CRSAuthorityFactory#getDescriptionText(Class, String)}.
*
* @throws FactoryException if the EPSG:4326 name cannot be obtained.
*/
@Test
public void testGetDescriptionText() throws FactoryException {
- final CRSAuthorityFactory factory = AuthorityFactories.ALL;
- assertEquals("WGS 84", factory.getDescriptionText("EPSG:4326").toString());
- assertEquals("WGS 84", factory.getDescriptionText("urn:ogc:def:crs:epsg::4326").toString());
+ assertDescriptionEquals("WGS 84", "EPSG:4326");
+ assertDescriptionEquals("WGS 84", "urn:ogc:def:crs:epsg::4326");
loggings.assertNoUnexpectedLog();
}
+ /**
+ * Asserts that the description is equal to the expected value.
+ *
+ * @param expected the expected description.
+ * @param code the code of the object for which to fetch the description.
+ */
+ private void assertDescriptionEquals(String expected, String code) throws FactoryException {
+ assertEquals(expected, AuthorityFactories.ALL.getDescriptionText(IdentifiedObject.class, code).orElseThrow().toString());
+ }
+
/**
* Tests creation of {@code CRS:84} from various codes.
*
diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/factory/CommonAuthorityFactoryTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/factory/CommonAuthorityFactoryTest.java
index e21daa6b2b..08182cb292 100644
--- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/factory/CommonAuthorityFactoryTest.java
+++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/factory/CommonAuthorityFactoryTest.java
@@ -130,15 +130,25 @@ public final class CommonAuthorityFactoryTest extends TestCase {
}
/**
- * Tests {@link CommonAuthorityFactory#getDescriptionText(String)}.
+ * Tests {@link CommonAuthorityFactory#getDescriptionText(Class, String)}.
*
* @throws FactoryException if an error occurred while creating a CRS.
*/
@Test
public void testDescription() throws FactoryException {
- assertEquals("WGS 84", factory.getDescriptionText("CRS:84").toString());
- assertEquals("WGS 84 / Auto UTM", factory.getDescriptionText("AUTO:42001").toString());
- assertEquals("WGS 84 / UTM zone 10S", factory.getDescriptionText("AUTO:42001,-124,-10").toString());
+ assertDescriptionEquals("WGS 84", "CRS:84");
+ assertDescriptionEquals("WGS 84 / Auto UTM", "AUTO:42001");
+ assertDescriptionEquals("WGS 84 / UTM zone 10S", "AUTO:42001,-124,-10");
+ }
+
+ /**
+ * Asserts that the description is equal to the expected value.
+ *
+ * @param expected the expected description.
+ * @param code the code of the object for which to fetch the description.
+ */
+ private void assertDescriptionEquals(String expected, String code) throws FactoryException {
+ assertEquals(expected, factory.getDescriptionText(CoordinateReferenceSystem.class, code).orElseThrow().toString());
}
/**
diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/factory/MultiAuthoritiesFactoryTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/factory/MultiAuthoritiesFactoryTest.java
index f1576ffbcb..e57be20fd2 100644
--- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/factory/MultiAuthoritiesFactoryTest.java
+++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/factory/MultiAuthoritiesFactoryTest.java
@@ -192,7 +192,7 @@ public final class MultiAuthoritiesFactoryTest extends TestCaseWithLogs {
assertSame(HardCodedDatum.SPHERE, factory.createGeodeticDatum("MOCK: 0:6047"));
assertSame(Extents .WORLD, factory.createExtent ("MOCK: 2.3 : 1262"));
assertSame(Units .METRE, factory.createUnit (" MoCK : : 9001 "));
- assertEquals("Greenwich", factory.getDescriptionText("MOCK:8901").toString());
+ assertEquals("Greenwich", factory.getDescriptionText(IdentifiedObject.class, "MOCK:8901").get().toString());
var e = assertThrows(NoSuchAuthorityFactoryException.class,
() -> factory.createGeodeticDatum("MOCK2:4326"),
diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/factory/sql/EPSGFactoryTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/factory/sql/EPSGFactoryTest.java
index 2350ce52b4..3cc0a49e78 100644
--- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/factory/sql/EPSGFactoryTest.java
+++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/factory/sql/EPSGFactoryTest.java
@@ -710,18 +710,18 @@ public final class EPSGFactoryTest extends TestCaseWithLogs {
}
/**
- * Tests the {@link EPSGDataAccess#getDescriptionText(String)} method.
+ * Tests the {@link EPSGDataAccess#getDescriptionText(class, String)} method.
*
* @throws FactoryException if an error occurred while querying the factory.
*/
@Test
public void testDescriptionText() throws FactoryException {
final EPSGFactory factory = dataEPSG.factory();
- assertEquals("World Geodetic System 1984", factory.getDescriptionText( "6326").toString(Locale.US));
- assertEquals("Mean Sea Level", factory.getDescriptionText( "5100").toString(Locale.US));
- assertEquals("NTF (Paris) / Nord France", factory.getDescriptionText("27591").toString(Locale.US));
- assertEquals("NTF (Paris) / France II", factory.getDescriptionText("27582").toString(Locale.US));
- assertEquals("Ellipsoidal height", factory.getDescriptionText( "84").toString(Locale.US));
+ assertEquals("World Geodetic System 1984", factory.getDescriptionText(IdentifiedObject.class, "6326").get().toString(Locale.US));
+ assertEquals("Mean Sea Level", factory.getDescriptionText(IdentifiedObject.class, "5100").get().toString(Locale.US));
+ assertEquals("NTF (Paris) / Nord France", factory.getDescriptionText(IdentifiedObject.class, "27591").get().toString(Locale.US));
+ assertEquals("NTF (Paris) / France II", factory.getDescriptionText(IdentifiedObject.class, "27582").get().toString(Locale.US));
+ assertEquals("Ellipsoidal height", factory.getDescriptionText(IdentifiedObject.class, "84").get().toString(Locale.US));
loggings.assertNoUnexpectedLog();
}
diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/report/CoordinateReferenceSystems.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/report/CoordinateReferenceSystems.java
index 14fbad016d..05bcffd341 100644
--- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/report/CoordinateReferenceSystems.java
+++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/report/CoordinateReferenceSystems.java
@@ -584,7 +584,7 @@ public final class CoordinateReferenceSystems extends AuthorityCodesReport {
}
final Row row = super.createRow(code, exception);
try {
- row.name = factory.getDescriptionText(code).toString(getLocale());
+ row.name = factory.getDescriptionText(CoordinateReferenceSystem.class, code).get().toString(getLocale());
} catch (FactoryException e) {
Logging.unexpectedException(null, CoordinateReferenceSystems.class, "createRow", e);
}
diff --git a/endorsed/src/org.apache.sis.storage.netcdf/main/org/apache/sis/storage/netcdf/base/Axis.java b/endorsed/src/org.apache.sis.storage.netcdf/main/org/apache/sis/storage/netcdf/base/Axis.java
index 0f1799a1e0..c0ccbf3514 100644
--- a/endorsed/src/org.apache.sis.storage.netcdf/main/org/apache/sis/storage/netcdf/base/Axis.java
+++ b/endorsed/src/org.apache.sis.storage.netcdf/main/org/apache/sis/storage/netcdf/base/Axis.java
@@ -870,7 +870,7 @@ public final class Axis extends NamedElement {
* at `LocalizationGridException` construction time.
*/
for (final Linearizer linearizer : linearizers) {
- final CharSequence reason = linearizer.getPotentialCause(coordinates);
+ final CharSequence reason = linearizer.getPotentialCause();
if (reason != null) {
ex.setPotentialCause(reason);
break; // Take the cause of the linearizer that had the highest priority.
diff --git a/endorsed/src/org.apache.sis.storage.netcdf/main/org/apache/sis/storage/netcdf/base/Linearizer.java b/endorsed/src/org.apache.sis.storage.netcdf/main/org/apache/sis/storage/netcdf/base/Linearizer.java
index cccd73b7b9..95f1ca3c54 100644
--- a/endorsed/src/org.apache.sis.storage.netcdf/main/org/apache/sis/storage/netcdf/base/Linearizer.java
+++ b/endorsed/src/org.apache.sis.storage.netcdf/main/org/apache/sis/storage/netcdf/base/Linearizer.java
@@ -178,12 +178,11 @@ public final class Linearizer {
* If this linearizer can give a probable reason why it failed to compute the localization grid, returns that reason.
* Otherwise returns {@code null}.
*
- * @param owner for fetching localized resources.
* @return potential error cause, or {@code null} if unknown.
*/
- final InternationalString getPotentialCause(final Node owner) {
+ final InternationalString getPotentialCause() {
if (longitudeSpan >= 180 - 6) { // 180° of longitude minus a UTM zone width.
- final String name = IdentifiedObjects.getDisplayName(targetCRS, owner.getLocale());
+ final InternationalString name = IdentifiedObjects.getDisplayName(targetCRS);
return Resources.formatInternational(Resources.Keys.GridLongitudeSpanTooWide_2,
longitudeSpan, (name != null) ? name : type);
}
diff --git a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/wkt/Store.java b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/wkt/Store.java
index 7ecb16f8b1..afed1b8705 100644
--- a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/wkt/Store.java
+++ b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/wkt/Store.java
@@ -24,6 +24,7 @@ import java.io.IOException;
import java.text.ParsePosition;
import java.text.ParseException;
import org.opengis.metadata.Metadata;
+import org.opengis.util.InternationalString;
import org.opengis.referencing.ReferenceSystem;
import org.apache.sis.storage.StorageConnector;
import org.apache.sis.storage.DataStoreException;
@@ -152,13 +153,13 @@ final class Store extends URIDataStore {
if (metadata == null) {
parse();
final MetadataBuilder builder = new MetadataBuilder();
- String name = null;
+ InternationalString name = null;
int count = 0;
for (final Object object : objects) {
if (object instanceof ReferenceSystem) {
final ReferenceSystem rs = (ReferenceSystem) object;
builder.addReferenceSystem(rs);
- name = IdentifiedObjects.getDisplayName(rs, getLocale());
+ name = IdentifiedObjects.getDisplayName(rs);
count++;
builder.addIdentifier(IdentifiedObjects.getIdentifier(rs, null), MetadataBuilder.Scope.RESOURCE);
}
diff --git a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/AuthorityCodes.java b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/AuthorityCodes.java
index bdbd05dce4..92e0c60078 100644
--- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/AuthorityCodes.java
+++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/AuthorityCodes.java
@@ -392,7 +392,8 @@ final class AuthorityCodes extends ObservableListBase<Code>
for (final Code code : snapshot) {
String text;
try {
- text = Strings.trimOrNull(Types.toString(factory.getDescriptionText(code.code), locale));
+ var i18n = factory.getDescriptionText(CoordinateReferenceSystem.class, code.code).orElse(null);
+ text = Strings.trimOrNull(Types.toString(i18n, locale));
if (text == null) {
text = Vocabulary.forLocale(locale).getString(Vocabulary.Keys.Unnamed);
}