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/11/10 19:30:38 UTC

[sis] 02/02: Update for a change in GeoAPI: - New method: `ParameterDescriptor.getValueType()`.

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 5967341a84747e75423892fe746fb6399e54ac58
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Thu Nov 10 20:21:27 2022 +0100

    Update for a change in GeoAPI:
    - New method: `ParameterDescriptor.getValueType()`.
    
    https://github.com/opengeospatial/geoapi/issues/76
---
 .../main/java/org/apache/sis/feature/Features.java |  6 ++--
 .../jaxb/metadata/replace/ServiceParameter.java    |  3 +-
 .../apache/sis/util/iso/DefaultNameFactory.java    |  1 +
 .../org/apache/sis/util/iso/DefaultTypeName.java   | 37 +++++++++++-----------
 .../main/java/org/apache/sis/util/iso/Names.java   | 22 +++++++++++--
 .../sis/parameter/DefaultParameterDescriptor.java  | 18 +++++++++--
 .../org/apache/sis/parameter/ParametersTest.java   |  4 ++-
 7 files changed, 63 insertions(+), 28 deletions(-)

diff --git a/core/sis-feature/src/main/java/org/apache/sis/feature/Features.java b/core/sis-feature/src/main/java/org/apache/sis/feature/Features.java
index 0ecfd7ccff..86e00cb23d 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/feature/Features.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/feature/Features.java
@@ -20,7 +20,6 @@ import java.util.Map;
 import java.util.Optional;
 import java.util.IdentityHashMap;
 import org.opengis.util.GenericName;
-import org.opengis.util.NameFactory;
 import org.opengis.util.InternationalString;
 import org.opengis.metadata.maintenance.ScopeCode;
 import org.opengis.metadata.quality.ConformanceResult;
@@ -28,8 +27,8 @@ import org.opengis.metadata.quality.DataQuality;
 import org.opengis.metadata.quality.Element;
 import org.opengis.metadata.quality.Result;
 import org.apache.sis.util.Static;
+import org.apache.sis.util.iso.Names;
 import org.apache.sis.util.iso.DefaultNameFactory;
-import org.apache.sis.internal.system.DefaultFactories;
 import org.apache.sis.internal.feature.Resources;
 
 // Branch-dependent imports
@@ -244,8 +243,7 @@ public final class Features extends Static {
             // Tested first because this is the main interest for this method.
             return DefaultAssociationRole.getValueTypeName((FeatureAssociationRole) property);
         } else if (property instanceof AttributeType<?>) {
-            final DefaultNameFactory factory = DefaultFactories.forBuildin(NameFactory.class, DefaultNameFactory.class);
-            return factory.toTypeName(((AttributeType<?>) property).getValueClass());
+            return Names.createTypeName(((AttributeType<?>) property).getValueClass());
         } else if (property instanceof Operation) {
             final IdentifiedType result = ((Operation) property).getResult();
             if (result != null) {
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/replace/ServiceParameter.java b/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/replace/ServiceParameter.java
index f3187366cc..7613231284 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/replace/ServiceParameter.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/replace/ServiceParameter.java
@@ -293,9 +293,10 @@ public final class ServiceParameter extends SimpleIdentifiedObject implements Pa
      * Note that there is not setter method, since we expect the same information
      * to be provided in the {@link #name} attribute type.
      */
+    @Override
     @XmlElement(name = "valueType", namespace = LegacyNamespaces.SRV)
     @XmlJavaTypeAdapter(GO_GenericName.class)    // Not in package-info because shall not be applied to getLegacyName().
-    final TypeName getValueType() {
+    public final TypeName getValueType() {
         if (memberName != null && FilterByVersion.LEGACY_METADATA.accept()) {
             return memberName.getAttributeType();
         }
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/util/iso/DefaultNameFactory.java b/core/sis-metadata/src/main/java/org/apache/sis/util/iso/DefaultNameFactory.java
index 92fcc67b5d..a7557d787a 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/util/iso/DefaultNameFactory.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/util/iso/DefaultNameFactory.java
@@ -419,6 +419,7 @@ public class DefaultNameFactory extends AbstractFactory implements NameFactory {
      *
      * @see DefaultTypeName#toClass()
      * @see Names#toClass(TypeName)
+     * @see Names#createTypeName(Class)
      *
      * @since 0.5
      */
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/util/iso/DefaultTypeName.java b/core/sis-metadata/src/main/java/org/apache/sis/util/iso/DefaultTypeName.java
index c065bd66b3..deaca620e4 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/util/iso/DefaultTypeName.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/util/iso/DefaultTypeName.java
@@ -34,10 +34,11 @@ import org.apache.sis.util.UnknownNameException;
  *
  * <h2>Mapping Java classes to type names</h2>
  * It is sometime useful to establish a mapping between {@link Class} and {@code TypeName}.
- * When an UML identifier from an OGC standard exists for a given {@code Class}, Apache SIS
- * uses that identifier prefixed by the {@code "OGC"} namespace.
+ * When an UML identifier from an OGC standard exists for a given {@code Class},
+ * Apache SIS uses that identifier prefixed by the {@code "OGC"} namespace.
  * Note that this is <strong>not</strong> a standard practice.
- * A more standard practice would be to use the <cite>definition identifiers in OGC namespace</cite>
+ * A more standard practice would be to use the
+ * <a href="https://schemas.opengis.net/definitions/1.1.0/dataType.xml">data type URN standard values</a>
  * (third column in the table below), but the set of data type identifiers defined by OGC is currently
  * small and is sometime not an exact match.
  *
@@ -45,68 +46,68 @@ import org.apache.sis.util.UnknownNameException;
  *   <caption>Mapping from Java classes to type names (non-exhaustive list)</caption>
  *   <tr>
  *     <th>Java class</th>
- *     <th>Type name (unofficial)</th>
- *     <th>Definition identifier in OGC namespace</th>
- *     <th>Recommended URL in Web Processing Services</th>
+ *     <th>Scoped type name</th>
+ *     <th class="sep">Data type URN standard values</th>
+ *     <th>URL in Web Services</th>
  *   </tr><tr>
  *     <td>{@link org.opengis.util.InternationalString}</td>
  *     <td>{@code OGC:FreeText}</td>
- *     <td></td>
+ *     <td class="sep"></td>
  *     <td></td>
  *   </tr><tr>
  *     <td>{@link java.lang.String}</td>
  *     <td>{@code OGC:CharacterString}</td>
- *     <td>{@code urn:ogc:def:dataType:OGC::string}</td>
+ *     <td class="sep">{@code urn:ogc:def:dataType:OGC::string}</td>
  *     <td>{@code http://www.w3.org/2001/XMLSchema#string}</td>
  *   </tr><tr>
  *     <td>{@link java.net.URI}</td>
  *     <td>{@code OGC:URI}</td>
- *     <td>{@code urn:ogc:def:dataType:OGC::anyURI}</td>
+ *     <td class="sep">{@code urn:ogc:def:dataType:OGC::anyURI}</td>
  *     <td></td>
  *   </tr><tr>
  *     <td>{@link java.lang.Boolean}</td>
  *     <td>{@code OGC:Boolean}</td>
- *     <td>{@code urn:ogc:def:dataType:OGC::boolean}</td>
+ *     <td class="sep">{@code urn:ogc:def:dataType:OGC::boolean}</td>
  *     <td>{@code http://www.w3.org/2001/XMLSchema#boolean}</td>
  *   </tr><tr>
  *     <td>{@link java.lang.Integer}</td>
  *     <td>{@code OGC:Integer}</td>
- *     <td>{@code urn:ogc:def:dataType:OGC::nonNegativeInteger}</td>
+ *     <td class="sep">{@code urn:ogc:def:dataType:OGC::nonNegativeInteger}</td>
  *     <td>{@code http://www.w3.org/2001/XMLSchema#integer}</td>
  *   </tr><tr>
  *     <td>{@link java.math.BigDecimal}</td>
  *     <td>{@code OGC:Decimal}</td>
- *     <td></td>
+ *     <td class="sep"></td>
  *     <td>{@code http://www.w3.org/2001/XMLSchema#decimal}</td>
  *   </tr><tr>
  *     <td>{@link java.lang.Double}</td>
  *     <td>{@code OGC:Real}</td>
- *     <td></td>
+ *     <td class="sep"></td>
  *     <td>{@code http://www.w3.org/2001/XMLSchema#double}</td>
  *   </tr><tr>
  *     <td>{@link java.lang.Float}</td>
  *     <td>{@code OGC:Real}</td>
- *     <td></td>
+ *     <td class="sep"></td>
  *     <td>{@code http://www.w3.org/2001/XMLSchema#float}</td>
  *   </tr><tr>
  *     <td>{@link java.util.Date}</td>
  *     <td>{@code OGC:DateTime}</td>
- *     <td></td>
+ *     <td class="sep"></td>
  *     <td></td>
  *   </tr><tr>
  *     <td>{@link java.util.Locale}</td>
  *     <td>{@code OGC:PT_Locale}</td>
- *     <td></td>
+ *     <td class="sep"></td>
  *     <td></td>
  *   </tr><tr>
  *     <td>{@link org.opengis.metadata.Metadata}</td>
  *     <td>{@code OGC:MD_Metadata}</td>
- *     <td></td>
+ *     <td class="sep"></td>
  *     <td></td>
  *   </tr><tr>
  *     <td>Unknown Java class</td>
  *     <td>{@code class:}&lt;the class name&gt;</td>
- *     <td></td>
+ *     <td class="sep"></td>
  *     <td></td>
  *   </tr>
  * </table>
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/util/iso/Names.java b/core/sis-metadata/src/main/java/org/apache/sis/util/iso/Names.java
index 8fc8d6b6bc..cdce2bb011 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/util/iso/Names.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/util/iso/Names.java
@@ -72,7 +72,7 @@ import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
  * </table></blockquote>
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.0
+ * @version 1.3
  *
  * @see DefaultNameFactory
  * @see DefaultNameSpace
@@ -250,6 +250,24 @@ public final class Names extends Static {
         return factory.createTypeName(createNameSpace(factory, namespace, separator), localPart);
     }
 
+    /**
+     * Suggests a type name for the given class. Apache SIS provides a mapping between {@code Class}
+     * and {@code TypeName} objects as documented in the {@link DefaultTypeName} javadoc.
+     * This is the converse of {@link #toClass(TypeName)} method.
+     *
+     * @param  valueClass the type of values, used for inferring a {@link TypeName} instance.
+     * @return a type name for values of the given type.
+     *
+     * @see DefaultNameFactory#toTypeName(Class)
+     *
+     * @since 1.3
+     */
+    public static TypeName createTypeName(final Class<?> valueClass) {
+        ensureNonNull("valueClass", valueClass);
+        final DefaultNameFactory factory = DefaultFactories.forBuildin(NameFactory.class, DefaultNameFactory.class);
+        return factory.toTypeName(valueClass);    // SIS-specific method.
+    }
+
     /**
      * Creates a member name for values of the given class. A {@link TypeName} will be inferred
      * from the given {@code valueClass} as documented in the {@link DefaultTypeName} javadoc.
@@ -353,8 +371,8 @@ public final class Names extends Static {
      * @throws UnknownNameException if a mapping from the given name to a Java class was expected to exist
      *         (typically because of the {@linkplain DefaultTypeName#scope() scope}) but the operation failed.
      *
+     * @see #createTypeName(Class)
      * @see DefaultTypeName#toClass()
-     * @see DefaultNameFactory#toTypeName(Class)
      *
      * @since 0.5
      */
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptor.java b/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptor.java
index da4b0e09fa..e73d118369 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptor.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptor.java
@@ -24,6 +24,7 @@ import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.measure.Unit;
 import org.opengis.util.CodeList;
+import org.opengis.util.TypeName;
 import org.opengis.parameter.ParameterValue;
 import org.opengis.parameter.ParameterDescriptor;
 import org.apache.sis.util.Classes;
@@ -31,6 +32,7 @@ import org.apache.sis.util.Numbers;
 import org.apache.sis.util.Utilities;
 import org.apache.sis.util.ComparisonMode;
 import org.apache.sis.util.resources.Errors;
+import org.apache.sis.util.iso.Names;
 import org.apache.sis.measure.Range;
 import org.apache.sis.measure.MeasurementRange;
 import org.apache.sis.internal.util.Numerics;
@@ -65,7 +67,7 @@ import static org.apache.sis.util.ArgumentChecks.ensureCanCast;
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @author  Johann Sorel (Geomatys)
- * @version 0.8
+ * @version 1.3
  *
  * @param <T>  the type of elements to be returned by {@link DefaultParameterValue#getValue()}.
  *
@@ -313,7 +315,19 @@ public class DefaultParameterDescriptor<T> extends AbstractParameterDescriptor i
     }
 
     /**
-     * Returns the class that describe the type of the parameter.
+     * Returns the name that describes the type of parameter values.
+     *
+     * @return value type of the parameter.
+     *
+     * @since 1.3
+     */
+    @Override
+    public final TypeName getValueType() {
+        return Names.createTypeName(valueClass);
+    }
+
+    /**
+     * Returns the class that describes the type of parameter values.
      *
      * @return the parameter value class.
      */
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParametersTest.java b/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParametersTest.java
index ed1c8e9a49..fdb16740a8 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParametersTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParametersTest.java
@@ -25,6 +25,7 @@ import org.opengis.parameter.ParameterDirection;
 import org.opengis.parameter.ParameterValue;
 import org.opengis.parameter.ParameterValueGroup;
 import org.opengis.metadata.Identifier;
+import org.opengis.util.TypeName;
 import org.opengis.util.GenericName;
 import org.opengis.util.InternationalString;
 import org.apache.sis.measure.Range;
@@ -43,7 +44,7 @@ import static org.junit.Assert.*;
  * Tests the static methods in the {@link Parameters} class.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.3
  * @since   0.4
  * @module
  */
@@ -123,6 +124,7 @@ public final strictfp class ParametersTest extends TestCase {
             @Override public ParameterDirection       getDirection()     {return descriptor.getDirection();}
             @Override public int                      getMinimumOccurs() {return descriptor.getMinimumOccurs();}
             @Override public int                      getMaximumOccurs() {return descriptor.getMaximumOccurs();}
+            @Override public TypeName                 getValueType()     {return descriptor.getValueType();}
             @Override public Class<T>                 getValueClass()    {return descriptor.getValueClass();}
             @Override public Set<T>                   getValidValues()   {return descriptor.getValidValues();}
             @Override public Comparable<T>            getMinimumValue()  {return descriptor.getMinimumValue();}