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 6c716e38966ae983996bb8823e9a83bbfe576c5e Author: Martin Desruisseaux <[email protected]> AuthorDate: Mon Nov 20 15:29:13 2023 +0100 Apply the same technic than `DefaultConformanceResult` to other mandatory properties of type `Integer`. This is related to https://issues.apache.org/jira/browse/SIS-590 --- .../org.apache.sis.metadata/main/module-info.java | 1 + .../iso/quality/DefaultConformanceResult.java | 26 +++++++------ .../sis/metadata/iso/spatial/DefaultDimension.java | 44 ++++++++++++++++++++-- .../metadata/iso/spatial/DefaultGCPCollection.java | 44 ++++++++++++++++++++-- .../spatial/DefaultGridSpatialRepresentation.java | 44 ++++++++++++++++++++-- .../sis/metadata/iso/spatial/package-info.java | 2 +- .../org/apache/sis/xml/bind/gco/GO_Boolean.java | 11 +++--- .../org/apache/sis/xml/bind/gco/GO_Integer.java | 13 +++++++ .../org/apache/sis/xml/bind/gco/PropertyType.java | 14 ++++--- .../iso/quality/DefaultConformanceResultTest.java | 3 +- 10 files changed, 170 insertions(+), 32 deletions(-) diff --git a/endorsed/src/org.apache.sis.metadata/main/module-info.java b/endorsed/src/org.apache.sis.metadata/main/module-info.java index 76bb50ec4c..40f5fd8033 100644 --- a/endorsed/src/org.apache.sis.metadata/main/module-info.java +++ b/endorsed/src/org.apache.sis.metadata/main/module-info.java @@ -180,6 +180,7 @@ module org.apache.sis.metadata { opens org.apache.sis.metadata.iso.citation to jakarta.xml.bind, org.glassfish.jaxb.runtime; opens org.apache.sis.metadata.iso.constraint to jakarta.xml.bind, org.glassfish.jaxb.runtime; opens org.apache.sis.metadata.iso.identification to jakarta.xml.bind, org.glassfish.jaxb.runtime; + opens org.apache.sis.metadata.iso.spatial to jakarta.xml.bind, org.glassfish.jaxb.runtime; opens org.apache.sis.metadata.iso.quality to jakarta.xml.bind, org.glassfish.jaxb.runtime; opens org.apache.sis.metadata.iso.lineage to jakarta.xml.bind, org.glassfish.jaxb.runtime; opens org.apache.sis.metadata.iso.content to jakarta.xml.bind, org.glassfish.jaxb.runtime; diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/quality/DefaultConformanceResult.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/quality/DefaultConformanceResult.java index 6bf335d0f1..b42b547a1a 100644 --- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/quality/DefaultConformanceResult.java +++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/quality/DefaultConformanceResult.java @@ -212,29 +212,33 @@ public class DefaultConformanceResult extends AbstractResult implements Conforma - ////////////////////////////////////////////////////////////////////////////////////////////////// - //////// //////// - //////// XML support with JAXB //////// - //////// //////// - //////// The following methods are invoked by JAXB using reflection (even if //////// - //////// they are private) or are helpers for other methods invoked by JAXB. //////// - //////// Those methods can be safely removed if Geographic Markup Language //////// - //////// (GML) support is not needed. //////// - //////// //////// - ////////////////////////////////////////////////////////////////////////////////////////////////// + /* + ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ + ┃ ┃ + ┃ XML support with JAXB ┃ + ┃ ┃ + ┃ The following methods are invoked by JAXB using reflection (even if ┃ + ┃ they are private) or are helpers for other methods invoked by JAXB. ┃ + ┃ Those methods can be safely removed if Geographic Markup Language ┃ + ┃ (GML) support is not needed. ┃ + ┃ ┃ + ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + */ /** * Invoked by JAXB for fetching the value to marshal. + * This property is handled in a special way for allowing nil reason. * * @return the value to marshal. */ @XmlElement(name = "pass", required = true) private GO_Boolean getResult() { - return new GO_Boolean(this, "pass", pass()); + return new GO_Boolean(this, "pass", pass(), true); } /** * Invoked by JAXB for setting the value. + * This property is handled in a special way for allowing nil reason. * * @param result the value. */ diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/spatial/DefaultDimension.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/spatial/DefaultDimension.java index d81dad5cfe..40074b2042 100644 --- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/spatial/DefaultDimension.java +++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/spatial/DefaultDimension.java @@ -23,6 +23,7 @@ import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import org.opengis.util.InternationalString; import org.opengis.metadata.spatial.Dimension; import org.opengis.metadata.spatial.DimensionNameType; +import org.apache.sis.xml.bind.gco.GO_Integer; import org.apache.sis.xml.bind.gco.GO_Measure; import org.apache.sis.xml.bind.gco.InternationalStringAdapter; import org.apache.sis.metadata.TitleProperty; @@ -55,13 +56,13 @@ import static org.apache.sis.metadata.internal.ImplementationHelper.ensurePositi * @author Cédric Briançon (Geomatys) * @author Rémi Maréchal (Geomatys) * @author Cullen Rombach (Image Matters) - * @version 1.4 + * @version 1.5 * @since 0.3 */ @TitleProperty(name = "dimensionName") @XmlType(name = "MD_Dimension_Type", propOrder = { "dimensionName", - "dimensionSize", + "size", "resolution", "dimensionTitle", "dimensionDescription" @@ -200,7 +201,6 @@ public class DefaultDimension extends ISOMetadata implements Dimension { */ @Override @ValueRange(minimum = 0) - @XmlElement(name = "dimensionSize", required = true) public Integer getDimensionSize() { return dimensionSize; } @@ -298,4 +298,42 @@ public class DefaultDimension extends ISOMetadata implements Dimension { checkWritePermission(dimensionDescription); dimensionDescription = newValue; } + + + + + /* + ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ + ┃ ┃ + ┃ XML support with JAXB ┃ + ┃ ┃ + ┃ The following methods are invoked by JAXB using reflection (even if ┃ + ┃ they are private) or are helpers for other methods invoked by JAXB. ┃ + ┃ Those methods can be safely removed if Geographic Markup Language ┃ + ┃ (GML) support is not needed. ┃ + ┃ ┃ + ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + */ + + /** + * Invoked by JAXB for fetching the value to marshal. + * This property is handled in a special way for allowing nil reason. + * + * @return the value to marshal. + */ + @XmlElement(name = "dimensionSize", required = true) + private GO_Integer getSize() { + return new GO_Integer(this, "dimensionSize", getDimensionSize(), true); + } + + /** + * Invoked by JAXB for setting the value. + * This property is handled in a special way for allowing nil reason. + * + * @param result the value. + */ + private void setSize(final GO_Integer result) { + setDimensionSize(result.getElement()); + result.getNilReason(this, "dimensionSize"); + } } diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/spatial/DefaultGCPCollection.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/spatial/DefaultGCPCollection.java index 4063c53f60..301f3bcb19 100644 --- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/spatial/DefaultGCPCollection.java +++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/spatial/DefaultGCPCollection.java @@ -25,6 +25,7 @@ import org.opengis.metadata.spatial.GCPCollection; import org.opengis.referencing.ReferenceSystem; import org.opengis.util.InternationalString; import org.apache.sis.metadata.TitleProperty; +import org.apache.sis.xml.bind.gco.GO_Integer; /** @@ -49,7 +50,7 @@ import org.apache.sis.metadata.TitleProperty; * * @author Cédric Briançon (Geomatys) * @author Martin Desruisseaux (Geomatys) - * @version 1.4 + * @version 1.5 * * @see DefaultGCP * @@ -57,7 +58,7 @@ import org.apache.sis.metadata.TitleProperty; */ @TitleProperty(name = "collectionName") @XmlType(name = "MI_GCPCollection_Type", propOrder = { - "collectionIdentification", + "identification", "collectionName", "coordinateReferenceSystem", "GCPs" @@ -148,7 +149,6 @@ public class DefaultGCPCollection extends AbstractGeolocationInformation impleme * @return the identifier, or {@code null}. */ @Override - @XmlElement(name = "collectionIdentification", required = true) public Integer getCollectionIdentification() { return collectionIdentification; } @@ -224,4 +224,42 @@ public class DefaultGCPCollection extends AbstractGeolocationInformation impleme public void setGCPs(final Collection<? extends GCP> newValues) { GCPs = writeCollection(newValues, GCPs, GCP.class); } + + + + + /* + ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ + ┃ ┃ + ┃ XML support with JAXB ┃ + ┃ ┃ + ┃ The following methods are invoked by JAXB using reflection (even if ┃ + ┃ they are private) or are helpers for other methods invoked by JAXB. ┃ + ┃ Those methods can be safely removed if Geographic Markup Language ┃ + ┃ (GML) support is not needed. ┃ + ┃ ┃ + ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + */ + + /** + * Invoked by JAXB for fetching the value to marshal. + * This property is handled in a special way for allowing nil reason. + * + * @return the value to marshal. + */ + @XmlElement(name = "collectionIdentification", required = true) + private GO_Integer getIdentification() { + return new GO_Integer(this, "collectionIdentification", getCollectionIdentification(), true); + } + + /** + * Invoked by JAXB for setting the value. + * This property is handled in a special way for allowing nil reason. + * + * @param result the value. + */ + private void setIdentification(final GO_Integer result) { + setCollectionIdentification(result.getElement()); + result.getNilReason(this, "collectionIdentification"); + } } diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/spatial/DefaultGridSpatialRepresentation.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/spatial/DefaultGridSpatialRepresentation.java index 6dc20ee055..8f282291e7 100644 --- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/spatial/DefaultGridSpatialRepresentation.java +++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/spatial/DefaultGridSpatialRepresentation.java @@ -26,6 +26,7 @@ import org.opengis.metadata.spatial.CellGeometry; import org.opengis.metadata.spatial.Georectified; import org.opengis.metadata.spatial.Georeferenceable; import org.opengis.metadata.spatial.GridSpatialRepresentation; +import org.apache.sis.xml.bind.gco.GO_Integer; import org.apache.sis.measure.ValueRange; import static org.apache.sis.metadata.internal.ImplementationHelper.ensurePositive; @@ -55,11 +56,11 @@ import static org.apache.sis.metadata.internal.ImplementationHelper.ensurePositi * @author Martin Desruisseaux (IRD, Geomatys) * @author Touraïvane (IRD) * @author Cédric Briançon (Geomatys) - * @version 1.4 + * @version 1.5 * @since 0.3 */ @XmlType(name = "MD_GridSpatialRepresentation_Type", propOrder = { - "numberOfDimensions", + "dimensions", "axisDimensionProperties", "cellGeometry", "transformationParameterAvailable" @@ -190,7 +191,6 @@ public class DefaultGridSpatialRepresentation extends AbstractSpatialRepresentat */ @Override @ValueRange(minimum = 0) - @XmlElement(name = "numberOfDimensions", required = true) public Integer getNumberOfDimensions() { return numberOfDimensions; } @@ -280,4 +280,42 @@ public class DefaultGridSpatialRepresentation extends AbstractSpatialRepresentat booleans &= ~TRANSFORMATION_MASK; } } + + + + + /* + ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ + ┃ ┃ + ┃ XML support with JAXB ┃ + ┃ ┃ + ┃ The following methods are invoked by JAXB using reflection (even if ┃ + ┃ they are private) or are helpers for other methods invoked by JAXB. ┃ + ┃ Those methods can be safely removed if Geographic Markup Language ┃ + ┃ (GML) support is not needed. ┃ + ┃ ┃ + ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + */ + + /** + * Invoked by JAXB for fetching the value to marshal. + * This property is handled in a special way for allowing nil reason. + * + * @return the value to marshal. + */ + @XmlElement(name = "numberOfDimensions", required = true) + private GO_Integer getDimensions() { + return new GO_Integer(this, "numberOfDimensions", getNumberOfDimensions(), true); + } + + /** + * Invoked by JAXB for setting the value. + * This property is handled in a special way for allowing nil reason. + * + * @param result the value. + */ + private void setDimensions(final GO_Integer result) { + setNumberOfDimensions(result.getElement()); + result.getNilReason(this, "numberOfDimensions"); + } } diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/spatial/package-info.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/spatial/package-info.java index 51f30c6d58..162402d098 100644 --- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/spatial/package-info.java +++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/spatial/package-info.java @@ -84,7 +84,7 @@ * @author Touraïvane (IRD) * @author Cédric Briançon (Geomatys) * @author Cullen Rombach (Image Matters) - * @version 1.4 + * @version 1.5 * @since 0.3 */ @XmlSchema(location="https://schemas.isotc211.org/19115/-3/msr/1.0/msr.xsd", diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gco/GO_Boolean.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gco/GO_Boolean.java index cfabbda482..20d9c61e73 100644 --- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gco/GO_Boolean.java +++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gco/GO_Boolean.java @@ -42,12 +42,13 @@ public final class GO_Boolean extends PropertyType<GO_Boolean, Boolean> { /** * Builds a wrapper for the specified value, which may be nil. * - * @param owner the metadata providing the value object. - * @param property UML identifier of the property for which a value is provided. - * @param value the property value, or {@code null} if none. + * @param owner the metadata providing the value object. + * @param property UML identifier of the property for which a value is provided. + * @param value the property value, or {@code null} if none. + * @param mandatory whether a value is mandatory. */ - public GO_Boolean(final AbstractMetadata owner, final String property, final Boolean value) { - super(owner, property, value); + public GO_Boolean(AbstractMetadata owner, String property, Boolean value, boolean mandatory) { + super(owner, property, value, mandatory); } /** diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gco/GO_Integer.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gco/GO_Integer.java index c0d0d60dec..3dfafbc3b3 100644 --- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gco/GO_Integer.java +++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gco/GO_Integer.java @@ -19,6 +19,7 @@ package org.apache.sis.xml.bind.gco; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlSchemaType; import jakarta.xml.bind.annotation.XmlType; +import org.apache.sis.metadata.AbstractMetadata; /** @@ -41,6 +42,18 @@ public class GO_Integer extends PropertyType<GO_Integer, Integer> { public GO_Integer() { } + /** + * Builds a wrapper for the specified value, which may be nil. + * + * @param owner the metadata providing the value object. + * @param property UML identifier of the property for which a value is provided. + * @param value the property value, or {@code null} if none. + * @param mandatory whether a value is mandatory. + */ + public GO_Integer(AbstractMetadata owner, String property, Integer value, boolean mandatory) { + super(owner, property, value, mandatory); + } + /** * Constructs a wrapper for the given value. * diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gco/PropertyType.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gco/PropertyType.java index 11bb222560..84348fe66a 100644 --- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gco/PropertyType.java +++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gco/PropertyType.java @@ -147,18 +147,22 @@ public abstract class PropertyType<ValueType extends PropertyType<ValueType,Boun * Those property types are handled in a different way because final classes * cannot implement the {@link NilObject} interface. * - * @param owner the metadata providing the value object. - * @param property UML identifier of the property for which a value is provided. - * @param value the property value, or {@code null} if none. + * @param owner the metadata providing the value object. + * @param property UML identifier of the property for which a value is provided. + * @param value the property value, or {@code null} if none. + * @param mandatory whether a value is mandatory. */ - protected PropertyType(final AbstractMetadata owner, final String property, final BoundType value) { - final NilReason nilReason; + protected PropertyType(final AbstractMetadata owner, final String property, final BoundType value, final boolean mandatory) { + NilReason nilReason; if (value != null) { nilReason = NilReason.forObject(value); } else { // May cause a `HashMap` to be created, so invoke only if necessary. nilReason = owner.nilReasons().get(property); } + if (mandatory && value == null && nilReason == null) { + nilReason = NilReason.UNKNOWN; + } if (nilReason != null) { reference = nilReason.toString(); } else { diff --git a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/iso/quality/DefaultConformanceResultTest.java b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/iso/quality/DefaultConformanceResultTest.java index 1384da9a84..7f870a2510 100644 --- a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/iso/quality/DefaultConformanceResultTest.java +++ b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/iso/quality/DefaultConformanceResultTest.java @@ -77,13 +77,14 @@ public final class DefaultConformanceResultTest extends TestCase { /** * Tests (un)marshalling of an XML document with a result missing for an unknown reason. + * At marshaling time, the nil reason of mandatory properties should default to {@link NilReason#UNKNOWN}. * * @throws JAXBException if an error occurred during the during marshalling / unmarshalling processes. */ @Test public void testUnknownReason() throws JAXBException { final var result = new DefaultConformanceResult(); - assertNull(result.nilReasons().put("pass", NilReason.UNKNOWN)); + assertNull(result.nilReasons().get("pass")); testXML(result, "<mdq:DQ_ConformanceResult xmlns:mdq=\"" + Namespaces.MDQ + '"' + " xmlns:gco=\"" + Namespaces.GCO + "\">\n" +
