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 41e6a8261c505155364bc8c57bcfe7994c42d369
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Wed Nov 9 11:14:41 2022 +0100

    Use adapters for deciding whether to marshall an element (depending on 
metadata standard).
---
 .../apache/sis/internal/jaxb/gco/GO_DateTime.java  | 26 ++++++++++++--
 .../apache/sis/internal/jaxb/gco/package-info.java |  2 +-
 .../jaxb/metadata/DQ_EvaluationMethod.java         |  8 +++--
 .../jaxb/metadata/DQ_MeasureReference.java         |  8 +++--
 .../DQ_StandaloneQualityReportInformation.java     |  8 +++--
 .../sis/metadata/iso/quality/AbstractElement.java  | 42 ++++++++++++++++------
 .../sis/metadata/iso/quality/AbstractResult.java   |  7 +++-
 .../metadata/iso/quality/DefaultDataQuality.java   |  2 +-
 8 files changed, 81 insertions(+), 22 deletions(-)

diff --git 
a/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gco/GO_DateTime.java
 
b/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gco/GO_DateTime.java
index e39d0a435e..0e7b9e1dc1 100644
--- 
a/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gco/GO_DateTime.java
+++ 
b/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gco/GO_DateTime.java
@@ -25,6 +25,7 @@ import javax.xml.datatype.DatatypeConfigurationException;
 import javax.xml.datatype.XMLGregorianCalendar;
 import javax.xml.datatype.DatatypeConstants;
 import org.apache.sis.internal.jaxb.Context;
+import org.apache.sis.internal.jaxb.FilterByVersion;
 import org.apache.sis.internal.xml.XmlUtilities;
 
 
@@ -48,7 +49,7 @@ import org.apache.sis.internal.xml.XmlUtilities;
  *
  * @author  Cédric Briançon (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.0
+ * @version 1.3
  *
  * @see org.apache.sis.internal.jaxb.gml.DateAdapter
  * @see org.apache.sis.internal.jaxb.gml.UniversalTimeAdapter
@@ -57,7 +58,7 @@ import org.apache.sis.internal.xml.XmlUtilities;
  * @module
  */
 @XmlType(name = "Date_PropertyType")
-public final class GO_DateTime extends XmlAdapter<GO_DateTime, Date> {
+public class GO_DateTime extends XmlAdapter<GO_DateTime, Date> {
     /**
      * The date and time value using the {@code code "DateTime"} name.
      * Only one of {@code date} and {@link #dateTime} shall be non-null.
@@ -122,7 +123,7 @@ public final class GO_DateTime extends 
XmlAdapter<GO_DateTime, Date> {
      * @return a {@linkplain Date date} which represents the metadata value.
      */
     @Override
-    public Date unmarshal(final GO_DateTime value) {
+    public final Date unmarshal(final GO_DateTime value) {
         return (value != null) ? value.getDate() : null;
     }
 
@@ -138,4 +139,23 @@ public final class GO_DateTime extends 
XmlAdapter<GO_DateTime, Date> {
     public GO_DateTime marshal(final Date value) {
         return (value != null) ? new GO_DateTime(value) : null;
     }
+
+    /**
+     * Wraps the value only if marshalling ISO 19115-3 element.
+     * Otherwise (i.e. if marshalling a legacy ISO 19139:2007 document), omit 
the element.
+     */
+    public static final class Since2014 extends GO_DateTime {
+        /** Empty constructor used only by JAXB. */
+        public Since2014() {
+        }
+
+        /**
+         * Wraps the given value in an ISO 19115-3 element, unless we are 
marshalling an older document.
+         *
+         * @return a non-null value only if marshalling ISO 19115-3 or newer.
+         */
+        @Override public GO_DateTime marshal(final Date value) {
+            return FilterByVersion.CURRENT_METADATA.accept() ? 
super.marshal(value) : null;
+        }
+    }
 }
diff --git 
a/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gco/package-info.java
 
b/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gco/package-info.java
index b9f2fea697..dcb5e4f479 100644
--- 
a/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gco/package-info.java
+++ 
b/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gco/package-info.java
@@ -78,7 +78,7 @@
  * @author  Cédric Briançon (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
  * @author  Cullen Rombach (Image Matters)
- * @version 1.0
+ * @version 1.3
  *
  * @see javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter
  *
diff --git 
a/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/DQ_EvaluationMethod.java
 
b/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/DQ_EvaluationMethod.java
index 245c4ce976..60426907b1 100644
--- 
a/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/DQ_EvaluationMethod.java
+++ 
b/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/DQ_EvaluationMethod.java
@@ -26,6 +26,9 @@ import org.apache.sis.internal.jaxb.gco.PropertyType;
  * JAXB adapter mapping implementing class to the GeoAPI interface. See
  * package documentation for more information about JAXB and interface.
  *
+ * <p>This adapter excludes the value when marshalling the older version of 
ISO 19115 standard.
+ * That exclusion is systematic because the type did not existed in the old 
standard version.</p>
+ *
  * @author  Alexis Gaillard (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
  * @version 1.3
@@ -63,11 +66,12 @@ public final class DQ_EvaluationMethod extends 
PropertyType<DQ_EvaluationMethod,
      * in a {@code <mdq:DQ_EvaluationMethod>} XML element.
      *
      * @param  metadata  the metadata element to marshal.
-     * @return a {@code PropertyType} wrapping the given the metadata element.
+     * @return a {@code PropertyType} wrapping the given the metadata element,
+     *         or {@code null} if marshalling a too old version of the 
standard.
      */
     @Override
     protected DQ_EvaluationMethod wrap(final EvaluationMethod metadata) {
-        return new DQ_EvaluationMethod(metadata);
+        return accept2014() ? new DQ_EvaluationMethod(metadata) : null;
     }
 
     /**
diff --git 
a/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/DQ_MeasureReference.java
 
b/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/DQ_MeasureReference.java
index 14d60127dc..f79e9f4fee 100644
--- 
a/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/DQ_MeasureReference.java
+++ 
b/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/DQ_MeasureReference.java
@@ -26,6 +26,9 @@ import org.apache.sis.internal.jaxb.gco.PropertyType;
  * JAXB adapter mapping implementing class to the GeoAPI interface. See
  * package documentation for more information about JAXB and interface.
  *
+ * <p>This adapter excludes the value when marshalling the older version of 
ISO 19115 standard.
+ * That exclusion is systematic because the type did not existed in the old 
standard version.</p>
+ *
  * @author  Alexis Gaillard (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
  * @version 1.3
@@ -63,11 +66,12 @@ public final class DQ_MeasureReference extends 
PropertyType<DQ_MeasureReference,
      * in a {@code <mdq:DQ_MeasureReference>} XML element.
      *
      * @param  metadata  the metadata element to marshal.
-     * @return a {@code PropertyType} wrapping the given the metadata element.
+     * @return a {@code PropertyType} wrapping the given the metadata element,
+     *         or {@code null} if marshalling a too old version of the 
standard.
      */
     @Override
     protected DQ_MeasureReference wrap(final MeasureReference metadata) {
-        return new DQ_MeasureReference(metadata);
+        return accept2014() ? new DQ_MeasureReference(metadata) : null;
     }
 
     /**
diff --git 
a/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/DQ_StandaloneQualityReportInformation.java
 
b/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/DQ_StandaloneQualityReportInformation.java
index 181195e264..a4449f863e 100644
--- 
a/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/DQ_StandaloneQualityReportInformation.java
+++ 
b/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/DQ_StandaloneQualityReportInformation.java
@@ -26,6 +26,9 @@ import org.apache.sis.internal.jaxb.gco.PropertyType;
  * JAXB adapter mapping implementing class to the GeoAPI interface. See
  * package documentation for more information about JAXB and interface.
  *
+ * <p>This adapter excludes the value when marshalling the older version of 
ISO 19115 standard.
+ * That exclusion is systematic because the type did not existed in the old 
standard version.</p>
+ *
  * @author  Alexis Gaillard (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
  * @version 1.3
@@ -65,11 +68,12 @@ public final class DQ_StandaloneQualityReportInformation 
extends
      * in a {@code <mdq:DQ_StandaloneQualityReportInformation>} XML element.
      *
      * @param  metadata  the metadata element to marshal.
-     * @return a {@code PropertyType} wrapping the given the metadata element.
+     * @return a {@code PropertyType} wrapping the given the metadata element,
+     *         or {@code null} if marshalling a too old version of the 
standard.
      */
     @Override
     protected DQ_StandaloneQualityReportInformation wrap(final 
StandaloneQualityReportInformation metadata) {
-        return new DQ_StandaloneQualityReportInformation(metadata);
+        return accept2014() ? new 
DQ_StandaloneQualityReportInformation(metadata) : null;
     }
 
     /**
diff --git 
a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/AbstractElement.java
 
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/AbstractElement.java
index 1a426d8151..b4b639256b 100644
--- 
a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/AbstractElement.java
+++ 
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/AbstractElement.java
@@ -25,6 +25,7 @@ import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlSeeAlso;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 import org.opengis.metadata.Identifier;
 import org.opengis.metadata.citation.Citation;
 import org.opengis.metadata.quality.Result;
@@ -41,6 +42,7 @@ import org.opengis.metadata.quality.MeasureReference;
 import org.opengis.metadata.quality.Metaquality;
 import org.opengis.util.InternationalString;
 import org.apache.sis.internal.jaxb.FilterByVersion;
+import org.apache.sis.internal.jaxb.gco.InternationalStringAdapter;
 import org.apache.sis.internal.metadata.Dependencies;
 import org.apache.sis.internal.xml.LegacyNamespaces;
 
@@ -84,7 +86,7 @@ import static 
org.apache.sis.util.collection.Containers.isNullOrEmpty;
     "evaluationProcedure",
     "dates",
     "results",
-    "derivedElements"
+    "derivedElement"
 })
 @XmlRootElement(name = "AbstractDQ_Element")
 @XmlSeeAlso({
@@ -235,8 +237,9 @@ public class AbstractElement extends ISOMetadata implements 
Element {
      */
     @Override
     @XmlElement(name = "standaloneQualityReportDetails")
+    @XmlJavaTypeAdapter(InternationalStringAdapter.Since2014.class)
     public InternationalString getStandaloneQualityReportDetails() {
-        return FilterByVersion.CURRENT_METADATA.accept() ? 
standaloneQualityReportDetails : null;
+        return standaloneQualityReportDetails;
     }
 
     /**
@@ -261,11 +264,7 @@ public class AbstractElement extends ISOMetadata 
implements Element {
     @Override
     @XmlElement(name = "measure", required = false)
     public MeasureReference getMeasureReference() {
-        if (FilterByVersion.CURRENT_METADATA.accept()) {
-            return (measureReference != null) ? measureReference : 
Element.super.getMeasureReference();
-        } else {
-            return null;
-        }
+        return (measureReference != null) ? measureReference : 
Element.super.getMeasureReference();
     }
 
     /**
@@ -405,7 +404,7 @@ public class AbstractElement extends ISOMetadata implements 
Element {
     @Override
     @XmlElement(name = "evaluationMethod", required = false)
     public EvaluationMethod getEvaluationMethod() {
-        return FilterByVersion.CURRENT_METADATA.accept() ? evaluationMethod : 
null;
+        return evaluationMethod;
     }
 
     /**
@@ -595,9 +594,8 @@ public class AbstractElement extends ISOMetadata implements 
Element {
      * @since 1.3
      */
     @Override
-    @XmlElement(name = "derivedElement")
+    // @XmlElement at the end of this class.
     public Collection<Element> getDerivedElements() {
-        if (!FilterByVersion.CURRENT_METADATA.accept()) return null;
         return derivedElements = nonNullCollection(derivedElements, 
Element.class);
     }
 
@@ -611,4 +609,28 @@ public class AbstractElement extends ISOMetadata 
implements Element {
     public void setDerivedElements(final Collection<? extends Element> 
newValues) {
         derivedElements = writeCollection(newValues, derivedElements, 
Element.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 at both marshalling and unmarshalling time.
+     * This attribute has been added by ISO 19157:2013 standard.
+     * If (and only if) marshalling an older standard version, we omit this 
attribute.
+     */
+    @XmlElement(name = "derivedElement")
+    private Collection<Element> getDerivedElement() {
+        return FilterByVersion.CURRENT_METADATA.accept() ? 
getDerivedElements() : null;
+    }
 }
diff --git 
a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/AbstractResult.java
 
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/AbstractResult.java
index f1ca9dcf32..2813fc5e2b 100644
--- 
a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/AbstractResult.java
+++ 
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/AbstractResult.java
@@ -21,13 +21,16 @@ import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.XmlSeeAlso;
 import javax.xml.bind.annotation.XmlRootElement;
-import org.apache.sis.internal.metadata.ImplementationHelper;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 import org.opengis.metadata.quality.Result;
 import org.opengis.metadata.quality.CoverageResult;
 import org.opengis.metadata.quality.ConformanceResult;
 import org.opengis.metadata.quality.QuantitativeResult;
 import org.opengis.metadata.quality.DescriptiveResult;
 import org.opengis.metadata.maintenance.Scope;
+import org.apache.sis.internal.jaxb.metadata.MD_Scope;
+import org.apache.sis.internal.jaxb.gco.GO_DateTime;
+import org.apache.sis.internal.metadata.ImplementationHelper;
 
 
 /**
@@ -155,6 +158,7 @@ public class AbstractResult extends ISOMetadata implements 
Result {
      */
     @Override
     @XmlElement(name = "resultScope")
+    @XmlJavaTypeAdapter(MD_Scope.Since2014.class)
     public Scope getResultScope() {
         return resultScope;
     }
@@ -179,6 +183,7 @@ public class AbstractResult extends ISOMetadata implements 
Result {
      */
     @Override
     @XmlElement(name = "dateTime")
+    @XmlJavaTypeAdapter(GO_DateTime.Since2014.class)
     public Date getDateTime() {
         return ImplementationHelper.toDate(dateTime);
     }
diff --git 
a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultDataQuality.java
 
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultDataQuality.java
index 6389f6eb7a..b60c360ec5 100644
--- 
a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultDataQuality.java
+++ 
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultDataQuality.java
@@ -222,7 +222,7 @@ public class DefaultDataQuality extends ISOMetadata 
implements DataQuality {
     @Override
     @XmlElement(name = "standaloneQualityReport")
     public StandaloneQualityReportInformation getStandaloneQualityReport() {
-        return FilterByVersion.CURRENT_METADATA.accept() ? 
standaloneQualityReport : null;
+        return standaloneQualityReport;
     }
 
     /**

Reply via email to