sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] branch geoapi-4.0 updated: Verify conformate of JAXB annotations with ISO 19115-3 schemas.
Date Wed, 12 Jun 2019 15:25:04 GMT
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


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new b1f8b1b  Verify conformate of JAXB annotations with ISO 19115-3 schemas.
b1f8b1b is described below

commit b1f8b1b95805b7a41d251bc1c81458b32a250493
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Wed Jun 12 17:24:38 2019 +0200

    Verify conformate of JAXB annotations with ISO 19115-3 schemas.
---
 .../org/apache/sis/metadata/iso/package-info.java  |  2 +-
 .../sis/metadata/iso/quality/AbstractElement.java  |  2 +-
 .../sis/metadata/iso/quality/package-info.java     |  2 +-
 .../sis/metadata/iso/spatial/package-info.java     |  2 +-
 .../internal/jaxb/cat/CodeListMarshallingTest.java |  6 +-
 .../sis/metadata/xml/SchemaComplianceTest.java     | 79 ++++++++++++++++++++++
 .../apache/sis/test/suite/MetadataTestSuite.java   |  3 +-
 .../sis/test/xml/AnnotationConsistencyCheck.java   |  2 +-
 .../org/apache/sis/test/xml/PackageVerifier.java   | 45 +++++++-----
 .../org/apache/sis/test/xml/SchemaCompliance.java  |  2 +-
 .../apache/sis/internal/system/DataDirectory.java  |  9 +++
 11 files changed, 127 insertions(+), 27 deletions(-)

diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/package-info.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/package-info.java
index b630224..b940230 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/package-info.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/package-info.java
@@ -95,7 +95,7 @@
                 @XmlNs(prefix = "mex", namespaceURI = Namespaces.MEX),      // Metadata with
Schema Extensions
                 @XmlNs(prefix = "lan", namespaceURI = Namespaces.LAN),      // Language localization
                 @XmlNs(prefix = "mcc", namespaceURI = Namespaces.MCC),      // Metadata Common
Classes
-                @XmlNs(prefix = "dqc", namespaceURI = Namespaces.DQC),      // Data Quality
Common Classes
+           //   @XmlNs(prefix = "dqc", namespaceURI = Namespaces.DQC),      // Data Quality
Common Classes
                 @XmlNs(prefix = "gmd", namespaceURI = LegacyNamespaces.GMD)
 })
 @XmlAccessorType(XmlAccessType.NONE)
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 1a672f8..19bb488 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
@@ -537,7 +537,7 @@ public class AbstractElement extends ISOMetadata implements Element {
      * @return date or range of dates on which a data quality measure was applied.
      */
     @Override
-    @XmlElement(name = "dateTime", namespace = Namespaces.DQC)
+    @XmlElement(name = "dateTime", namespace = Namespaces.GMD)
     @SuppressWarnings("ReturnOfCollectionOrArrayField")
     public Collection<Date> getDates() {
         if (Semaphores.query(Semaphores.NULL_COLLECTION)) {
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/package-info.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/package-info.java
index 20012e0..d27c272 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/package-info.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/package-info.java
@@ -122,7 +122,7 @@
            xmlns = {
                 @XmlNs(prefix = "mdq", namespaceURI = Namespaces.MDQ),      // Metadata for
Data Quality
                 @XmlNs(prefix = "mrd", namespaceURI = Namespaces.MRD),      // Metadata for
Resource Distribution
-                @XmlNs(prefix = "dqc", namespaceURI = Namespaces.DQC),      // Data Quality
Common Classes
+           //   @XmlNs(prefix = "dqc", namespaceURI = Namespaces.DQC),      // Data Quality
Common Classes
                 @XmlNs(prefix = "mcc", namespaceURI = Namespaces.MCC),      // Metadata Common
Classes
                 @XmlNs(prefix = "gmd", namespaceURI = LegacyNamespaces.GMD),
                 @XmlNs(prefix = "gmi", namespaceURI = LegacyNamespaces.GMI)
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/package-info.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/package-info.java
index 42cd55d..e4c7f1c 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/package-info.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/package-info.java
@@ -93,7 +93,7 @@
            xmlns = {
                 @XmlNs(prefix = "msr", namespaceURI = Namespaces.MSR),      // Metadata for
Spatial Representation
                 @XmlNs(prefix = "mcc", namespaceURI = Namespaces.MCC),      // Metadata Common
Classes
-                @XmlNs(prefix = "dqc", namespaceURI = Namespaces.DQC)       // Data Quality
Common Classes
+           //   @XmlNs(prefix = "dqc", namespaceURI = Namespaces.DQC)       // Data Quality
Common Classes
 })
 @XmlAccessorType(XmlAccessType.NONE)
 @XmlJavaTypeAdapters({
diff --git a/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/cat/CodeListMarshallingTest.java
b/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/cat/CodeListMarshallingTest.java
index 7aaf79c..28b529f 100644
--- a/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/cat/CodeListMarshallingTest.java
+++ b/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/cat/CodeListMarshallingTest.java
@@ -113,12 +113,14 @@ public final strictfp class CodeListMarshallingTest extends TestCase
{
     }
 
     /**
-     * Tests marshalling using the ISO URL.
+     * Tests marshalling using legacy ISO URLs.
      *
      * @throws JAXBException if an error occurred while marshalling the XML.
+     *
+     * @see <a href="https://standards.iso.org/iso/19115/-3/">ISO schemas</a>
      */
     @Test
-    public void testISO_URL() throws JAXBException {
+    public void testLegacyISO_URL() throws JAXBException {
         final String expected = getResponsiblePartyXML("http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/");
         final Responsibility rp = unmarshal(Responsibility.class, expected);
         assertEquals(Role.PRINCIPAL_INVESTIGATOR, rp.getRole());
diff --git a/core/sis-metadata/src/test/java/org/apache/sis/metadata/xml/SchemaComplianceTest.java
b/core/sis-metadata/src/test/java/org/apache/sis/metadata/xml/SchemaComplianceTest.java
new file mode 100644
index 0000000..be775fc
--- /dev/null
+++ b/core/sis-metadata/src/test/java/org/apache/sis/metadata/xml/SchemaComplianceTest.java
@@ -0,0 +1,79 @@
+/*
+ * 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.metadata.xml;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.Files;
+import org.apache.sis.metadata.iso.ISOMetadata;
+import org.apache.sis.internal.system.DataDirectory;
+import org.apache.sis.test.xml.SchemaCompliance;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assume.*;
+import static org.junit.Assert.*;
+
+
+/**
+ * Tests conformance of JAXB annotations with XML schemas if those schemas are available.
+ * This tests requires the {@code $SIS_DATA/Schemas/iso/19115/-3} directory to exists.
+ * Those files must be installed manually; they are not distributed with Apache SIS for licensing
reasons.
+ * Content can be downloaded as ZIP files from <a href="https://standards.iso.org/iso/19115/">ISO
portal</a>.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 1.0
+ * @since   1.0
+ * @module
+ */
+public final strictfp class SchemaComplianceTest extends TestCase {
+    /**
+     * Verifies compliance with metadata schemas.
+     *
+     * @throws Exception if an error occurred while checking the schema.
+     *
+     * @see <a href="https://standards.iso.org/iso/19115/-3/">ISO schemas for metadata</a>
+     */
+    @Test
+    public void verifyMetadata() throws Exception {
+        Path directory = DataDirectory.SCHEMAS.getDirectory();
+        assumeNotNull(directory);
+        directory = directory.resolve("iso");
+        assumeTrue(Files.isDirectory(directory.resolve("19115")));
+        /*
+         * Locate the root of metadata class directory. In a Maven build:
+         * "core/sis-metadata/target/classes/org/apache/sis/metadata/iso"
+         */
+        final Path mdp = Paths.get(ISOMetadata.class.getResource("ISOMetadata.class").toURI()).getParent();
+        final Path cp = getParent(mdp, "org", "apache", "sis", "metadata", "iso");
+        final SchemaCompliance checker = new SchemaCompliance(cp, directory);
+        checker.loadDefaultSchemas();
+        checker.verify(mdp);
+    }
+
+    /**
+     * Returns the parent directory. The expected names of skipped directories are given
in argument;
+     * they will be verified.
+     */
+    private static Path getParent(Path cp, final String... parents) {
+        for (int i=parents.length; --i >= 0;) {
+            assertTrue(cp.endsWith(parents[i]));
+            cp = cp.getParent();
+        }
+        return cp;
+    }
+}
diff --git a/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
b/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
index cc15b61..bcd9d9e 100644
--- a/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
+++ b/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
@@ -144,7 +144,8 @@ import org.junit.BeforeClass;
     org.apache.sis.metadata.sql.IdentifierGeneratorTest.class,
     org.apache.sis.metadata.sql.MetadataSourceTest.class,
     org.apache.sis.metadata.sql.MetadataWriterTest.class,
-    org.apache.sis.metadata.iso.citation.CitationsTest.class
+    org.apache.sis.metadata.iso.citation.CitationsTest.class,
+    org.apache.sis.metadata.xml.SchemaComplianceTest.class
 })
 public final strictfp class MetadataTestSuite extends TestSuite {
     /**
diff --git a/core/sis-metadata/src/test/java/org/apache/sis/test/xml/AnnotationConsistencyCheck.java
b/core/sis-metadata/src/test/java/org/apache/sis/test/xml/AnnotationConsistencyCheck.java
index 33919ec..8fb142c 100644
--- a/core/sis-metadata/src/test/java/org/apache/sis/test/xml/AnnotationConsistencyCheck.java
+++ b/core/sis-metadata/src/test/java/org/apache/sis/test/xml/AnnotationConsistencyCheck.java
@@ -293,7 +293,7 @@ public abstract strictfp class AnnotationConsistencyCheck extends TestCase
{
             }
             case "dateTime": {
                 if (org.opengis.metadata.quality.Element.class.isAssignableFrom(impl)) {
-                    return Namespaces.DQC;
+                    return Namespaces.GMD;
                 }
                 break;
             }
diff --git a/core/sis-metadata/src/test/java/org/apache/sis/test/xml/PackageVerifier.java
b/core/sis-metadata/src/test/java/org/apache/sis/test/xml/PackageVerifier.java
index 3a5547e..7e7ba0f 100644
--- a/core/sis-metadata/src/test/java/org/apache/sis/test/xml/PackageVerifier.java
+++ b/core/sis-metadata/src/test/java/org/apache/sis/test/xml/PackageVerifier.java
@@ -36,8 +36,10 @@ import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters;
 import javax.xml.parsers.ParserConfigurationException;
 import org.xml.sax.SAXException;
+import org.opengis.util.CodeList;
 import org.opengis.annotation.UML;
 import org.opengis.geoapi.SchemaException;
+import org.opengis.geoapi.SchemaInformation;
 import org.apache.sis.util.Classes;
 import org.apache.sis.internal.system.Modules;
 import org.apache.sis.internal.xml.LegacyNamespaces;
@@ -384,21 +386,25 @@ final strictfp class PackageVerifier {
          * because JAXB has default adapters for String, Double, Boolean, Date, etc. which
do not match the way
          * OGC/ISO marshal those elements.
          */
-        if (!property.isAnnotationPresent(XmlJavaTypeAdapter.class) && (valueType
!= null)
-                && !valueType.getName().startsWith(Modules.CLASSNAME_PREFIX))
-        {
-            Class<?> c = valueType;
-            while (adapterIsUsed.replace(c, Boolean.TRUE) == null) {
-                final Class<?> parent = c.getSuperclass();
-                if (parent != null) {
-                    c = parent;
-                } else {
-                    final Class<?>[] p = c.getInterfaces();
-                    if (p.length == 0) {
-                        throw new SchemaException(errorInClassMember(javaName)
-                                .append("Missing @XmlJavaTypeAdapter for ").append(valueType).toString());
+        if (!property.isAnnotationPresent(XmlJavaTypeAdapter.class) && valueType
!= null) {
+            /*
+             * Internal classes in Apache SIS "jaxb" subpackages can be marshalled directly.
+             * Apache SIS classes defined in other packages may be code lists, which still
need adapters.
+             */
+            if (!valueType.getName().startsWith(Modules.CLASSNAME_PREFIX) || CodeList.class.isAssignableFrom(valueType))
{
+                Class<?> c = valueType;
+                while (adapterIsUsed.replace(c, Boolean.TRUE) == null) {
+                    final Class<?> parent = c.getSuperclass();
+                    if (parent != null) {
+                        c = parent;
+                    } else {
+                        final Class<?>[] p = c.getInterfaces();
+                        if (p.length == 0) {
+                            throw new SchemaException(errorInClassMember(javaName)
+                                    .append("Missing @XmlJavaTypeAdapter for ").append(valueType).toString());
+                        }
+                        c = p[0];       // Take only the first interface, which should be
the "main" parent.
                     }
-                    c = p[0];   // Take only the first interface, which should be the "main"
parent.
                 }
             }
         }
@@ -469,10 +475,13 @@ final strictfp class PackageVerifier {
              */
             final Map<String, SchemaCompliance.Element> valueInfo = schemas.getTypeDefinition(info.typeName);
             if (valueInfo != null) {
-                final String valueNS = valueInfo.get(null).namespace;
-                if (namespaceIsUsed.put(valueNS, Boolean.TRUE) == null) {
-                    throw new SchemaException(errorInClassMember(javaName)
-                            .append("Missing @XmlNs for property value namespace: ").append(valueNS).toString());
+                final SchemaInformation.Element typeAndNS = valueInfo.get(null);
+                if (typeAndNS != null) {
+                    final String valueNS = typeAndNS.namespace;
+                    if (namespaceIsUsed.put(valueNS, Boolean.TRUE) == null) {
+                        throw new SchemaException(errorInClassMember(javaName)
+                                .append("Missing @XmlNs for property value namespace: ").append(valueNS).toString());
+                    }
                 }
             }
         }
diff --git a/core/sis-metadata/src/test/java/org/apache/sis/test/xml/SchemaCompliance.java
b/core/sis-metadata/src/test/java/org/apache/sis/test/xml/SchemaCompliance.java
index ad6edcb..8b01faa 100644
--- a/core/sis-metadata/src/test/java/org/apache/sis/test/xml/SchemaCompliance.java
+++ b/core/sis-metadata/src/test/java/org/apache/sis/test/xml/SchemaCompliance.java
@@ -36,7 +36,7 @@ import org.apache.sis.util.StringBuilders;
 
 /**
  * Compares JAXB annotations against the ISO 19115 schemas. This test requires a connection
to
- * <a href="http://standards.iso.org/iso/19115/-3/">http://standards.iso.org/iso/19115/-3/</a>.
+ * <a href="https://standards.iso.org/iso/19115/-3/">https://standards.iso.org/iso/19115/-3/</a>.
  * All classes in a given directory are scanned.
  *
  * <div class="section">Limitations</div>
diff --git a/core/sis-utility/src/main/java/org/apache/sis/internal/system/DataDirectory.java
b/core/sis-utility/src/main/java/org/apache/sis/internal/system/DataDirectory.java
index b1af2c4..ef8c7f0 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/internal/system/DataDirectory.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/internal/system/DataDirectory.java
@@ -57,6 +57,15 @@ public enum DataDirectory {
     DOMAINS_OF_VALIDITY,
 
     /**
+     * The {@code "Schemas"} directory.
+     * This directory contains XML schemas published by ISO. If this directory is present,
+     * it should contains a {@code "iso/19115/-3"} sub-directory among others.
+     *
+     * @see <a href="https://standards.iso.org/iso/19115/-3/">ISO schemas for metadata</a>
+     */
+    SCHEMAS,
+
+    /**
      * The {@code "Tests" directory}.
      * This directory is used for optional test files that are too large for inclusion in
source code repository.
      * This is used at build time of Apache SIS project, but not used during normal execution.


Mime
View raw message