sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1822418 - in /sis/branches/ISO-19115-3/core/sis-metadata/src: main/java/org/apache/sis/metadata/iso/content/ main/java/org/apache/sis/metadata/iso/lineage/ main/java/org/apache/sis/metadata/iso/maintenance/ main/java/org/apache/sis/metadat...
Date Sat, 27 Jan 2018 15:29:32 GMT
Author: desruisseaux
Date: Sat Jan 27 15:29:32 2018
New Revision: 1822418

URL: http://svn.apache.org/viewvc?rev=1822418&view=rev
Log:
Fix more namespace URLs with SchemaVerifier help.

Modified:
    sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultRangeElementDescription.java
    sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultAlgorithm.java
    sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultNominalResolution.java
    sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultProcessStepReport.java
    sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultProcessing.java
    sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultScope.java
    sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultScopeDescription.java
    sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultCoverageResult.java
    sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGCP.java
    sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGCPCollection.java
    sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/SchemaVerifier.java

Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultRangeElementDescription.java
URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultRangeElementDescription.java?rev=1822418&r1=1822417&r2=1822418&view=diff
==============================================================================
--- sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultRangeElementDescription.java
[UTF-8] (original)
+++ sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultRangeElementDescription.java
[UTF-8] Sat Jan 27 15:29:32 2018
@@ -25,7 +25,6 @@ import org.opengis.util.InternationalStr
 import org.opengis.metadata.content.RangeElementDescription;
 import org.apache.sis.metadata.iso.ISOMetadata;
 import org.apache.sis.metadata.TitleProperty;
-import org.apache.sis.xml.Namespaces;
 
 
 /**
@@ -54,12 +53,12 @@ import org.apache.sis.xml.Namespaces;
  */
 @SuppressWarnings("CloneableClassWithoutClone")                 // ModifiableMetadata needs
shallow clones.
 @TitleProperty(name = "name")
-@XmlType(name = "MI_RangeElementDescription_Type", namespace = Namespaces.GMI, propOrder
= {
+@XmlType(name = "MI_RangeElementDescription_Type", propOrder = {
     "name",
     "definition",
     "rangeElements"
 })
-@XmlRootElement(name = "MI_RangeElementDescription", namespace = Namespaces.GMI)
+@XmlRootElement(name = "MI_RangeElementDescription")
 public class DefaultRangeElementDescription extends ISOMetadata implements RangeElementDescription
{
     /**
      * Serial number for inter-operability with different versions.

Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultAlgorithm.java
URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultAlgorithm.java?rev=1822418&r1=1822417&r2=1822418&view=diff
==============================================================================
--- sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultAlgorithm.java
[UTF-8] (original)
+++ sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultAlgorithm.java
[UTF-8] Sat Jan 27 15:29:32 2018
@@ -23,7 +23,6 @@ import org.opengis.metadata.citation.Cit
 import org.opengis.metadata.lineage.Algorithm;
 import org.opengis.util.InternationalString;
 import org.apache.sis.metadata.iso.ISOMetadata;
-import org.apache.sis.xml.Namespaces;
 
 
 /**
@@ -53,11 +52,11 @@ import org.apache.sis.xml.Namespaces;
  * @module
  */
 @SuppressWarnings("CloneableClassWithoutClone")                 // ModifiableMetadata needs
shallow clones.
-@XmlType(name = "LE_Algorithm_Type", namespace = Namespaces.GMI, propOrder = {
+@XmlType(name = "LE_Algorithm_Type", propOrder = {
     "citation",
     "description"
 })
-@XmlRootElement(name = "LE_Algorithm", namespace = Namespaces.GMI)
+@XmlRootElement(name = "LE_Algorithm")
 public class DefaultAlgorithm extends ISOMetadata implements Algorithm {
     /**
      * Serial number for inter-operability with different versions.

Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultNominalResolution.java
URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultNominalResolution.java?rev=1822418&r1=1822417&r2=1822418&view=diff
==============================================================================
--- sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultNominalResolution.java
[UTF-8] (original)
+++ sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultNominalResolution.java
[UTF-8] Sat Jan 27 15:29:32 2018
@@ -22,7 +22,6 @@ import javax.xml.bind.annotation.XmlType
 import org.opengis.metadata.lineage.NominalResolution;
 import org.apache.sis.metadata.iso.ISOMetadata;
 import org.apache.sis.measure.ValueRange;
-import org.apache.sis.xml.Namespaces;
 
 import static org.apache.sis.internal.metadata.MetadataUtilities.ensurePositive;
 
@@ -51,11 +50,11 @@ import static org.apache.sis.internal.me
  * @module
  */
 @SuppressWarnings("CloneableClassWithoutClone")                 // ModifiableMetadata needs
shallow clones.
-@XmlType(name = "LE_NominalResolution_Type", namespace = Namespaces.GMI, propOrder = {
+@XmlType(name = "LE_NominalResolution_Type", propOrder = {
     "scanningResolution",
     "groundResolution"
 })
-@XmlRootElement(name = "LE_NominalResolution", namespace = Namespaces.GMI)
+@XmlRootElement(name = "LE_NominalResolution")
 public class DefaultNominalResolution extends ISOMetadata implements NominalResolution {
     /**
      * Serial number for inter-operability with different versions.

Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultProcessStepReport.java
URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultProcessStepReport.java?rev=1822418&r1=1822417&r2=1822418&view=diff
==============================================================================
--- sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultProcessStepReport.java
[UTF-8] (original)
+++ sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultProcessStepReport.java
[UTF-8] Sat Jan 27 15:29:32 2018
@@ -23,7 +23,6 @@ import org.opengis.metadata.lineage.Proc
 import org.opengis.util.InternationalString;
 import org.apache.sis.metadata.iso.ISOMetadata;
 import org.apache.sis.metadata.TitleProperty;
-import org.apache.sis.xml.Namespaces;
 
 
 /**
@@ -51,12 +50,12 @@ import org.apache.sis.xml.Namespaces;
  */
 @SuppressWarnings("CloneableClassWithoutClone")                 // ModifiableMetadata needs
shallow clones.
 @TitleProperty(name = "name")
-@XmlType(name = "LE_ProcessStepReport_Type", namespace = Namespaces.GMI, propOrder = {
+@XmlType(name = "LE_ProcessStepReport_Type", propOrder = {
     "name",
     "description",
     "fileType"
 })
-@XmlRootElement(name = "LE_ProcessStepReport", namespace = Namespaces.GMI)
+@XmlRootElement(name = "LE_ProcessStepReport")
 public class DefaultProcessStepReport extends ISOMetadata implements ProcessStepReport {
     /**
      * Serial number for inter-operability with different versions.

Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultProcessing.java
URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultProcessing.java?rev=1822418&r1=1822417&r2=1822418&view=diff
==============================================================================
--- sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultProcessing.java
[UTF-8] (original)
+++ sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultProcessing.java
[UTF-8] Sat Jan 27 15:29:32 2018
@@ -25,7 +25,6 @@ import org.opengis.metadata.citation.Cit
 import org.opengis.metadata.lineage.Algorithm;
 import org.opengis.metadata.lineage.Processing;
 import org.opengis.util.InternationalString;
-import org.apache.sis.xml.Namespaces;
 import org.apache.sis.metadata.iso.ISOMetadata;
 import org.apache.sis.internal.jaxb.NonMarshalledAuthority;
 
@@ -55,7 +54,7 @@ import org.apache.sis.internal.jaxb.NonM
  * @module
  */
 @SuppressWarnings("CloneableClassWithoutClone")                 // ModifiableMetadata needs
shallow clones.
-@XmlType(name = "LE_Processing_Type", namespace = Namespaces.GMI, propOrder = {
+@XmlType(name = "LE_Processing_Type", propOrder = {
     "identifier",
     "softwareReferences",
     "procedureDescription",
@@ -63,7 +62,7 @@ import org.apache.sis.internal.jaxb.NonM
     "runTimeParameters",
     "algorithms"
 })
-@XmlRootElement(name = "LE_Processing", namespace = Namespaces.GMI)
+@XmlRootElement(name = "LE_Processing")
 public class DefaultProcessing extends ISOMetadata implements Processing {
     /**
      * Serial number for inter-operability with different versions.

Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultScope.java
URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultScope.java?rev=1822418&r1=1822417&r2=1822418&view=diff
==============================================================================
--- sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultScope.java
[UTF-8] (original)
+++ sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultScope.java
[UTF-8] Sat Jan 27 15:29:32 2018
@@ -25,6 +25,7 @@ import org.opengis.metadata.maintenance.
 import org.opengis.metadata.maintenance.ScopeCode;
 import org.opengis.metadata.maintenance.ScopeDescription;
 import org.apache.sis.metadata.iso.ISOMetadata;
+import org.apache.sis.xml.Namespaces;
 
 
 /**
@@ -59,12 +60,12 @@ import org.apache.sis.metadata.iso.ISOMe
  * @module
  */
 @SuppressWarnings("CloneableClassWithoutClone")                 // ModifiableMetadata needs
shallow clones.
-@XmlType(name = "MD_Scope_Type", propOrder = {
+@XmlType(name = "MD_Scope_Type", namespace = Namespaces.MCC, propOrder = {
    "level",
    "extents",
    "levelDescription"
 })
-@XmlRootElement(name = "MD_Scope")
+@XmlRootElement(name = "MD_Scope", namespace = Namespaces.MCC)
 public class DefaultScope extends ISOMetadata implements Scope {
     /**
      * Serial number for inter-operability with different versions.

Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultScopeDescription.java
URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultScopeDescription.java?rev=1822418&r1=1822417&r2=1822418&view=diff
==============================================================================
--- sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultScopeDescription.java
[UTF-8] (original)
+++ sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultScopeDescription.java
[UTF-8] Sat Jan 27 15:29:32 2018
@@ -30,6 +30,7 @@ import org.apache.sis.internal.jaxb.Cont
 import org.apache.sis.internal.system.Semaphores;
 import org.apache.sis.util.collection.CheckedContainer;
 import org.apache.sis.util.resources.Messages;
+import org.apache.sis.xml.Namespaces;
 
 import static org.apache.sis.util.collection.Containers.isNullOrEmpty;
 
@@ -69,8 +70,8 @@ import static org.apache.sis.util.collec
  * @module
  */
 @SuppressWarnings("CloneableClassWithoutClone")                 // ModifiableMetadata needs
shallow clones.
-@XmlType(name = "MD_ScopeDescription_Type") // No need for propOrder since this structure
is a union (see javadoc).
-@XmlRootElement(name = "MD_ScopeDescription")
+@XmlType(name = "MD_ScopeDescription_Type", namespace = Namespaces.MCC) // No need for propOrder
since this structure is a union (see javadoc).
+@XmlRootElement(name = "MD_ScopeDescription", namespace = Namespaces.MCC)
 public class DefaultScopeDescription extends ISOMetadata implements ScopeDescription {
     /**
      * Serial number for inter-operability with different versions.

Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultCoverageResult.java
URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultCoverageResult.java?rev=1822418&r1=1822417&r2=1822418&view=diff
==============================================================================
--- sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultCoverageResult.java
[UTF-8] (original)
+++ sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultCoverageResult.java
[UTF-8] Sat Jan 27 15:29:32 2018
@@ -60,14 +60,14 @@ import org.apache.sis.xml.Namespaces;
  * @module
  */
 @SuppressWarnings("CloneableClassWithoutClone")                 // ModifiableMetadata needs
shallow clones.
-@XmlType(name = "QE_CoverageResult_Type", namespace = Namespaces.GMI, propOrder = {
+@XmlType(name = "QE_CoverageResult_Type", propOrder = {
     "spatialRepresentationType",
     "resultSpatialRepresentation",
     "resultContentDescription",
     "resultFormat",
     "resultFile"
 })
-@XmlRootElement(name = "QE_CoverageResult", namespace = Namespaces.GMI)
+@XmlRootElement(name = "QE_CoverageResult")
 public class DefaultCoverageResult extends AbstractResult implements CoverageResult {
     /**
      * Serial number for inter-operability with different versions.

Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGCP.java
URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGCP.java?rev=1822418&r1=1822417&r2=1822418&view=diff
==============================================================================
--- sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGCP.java
[UTF-8] (original)
+++ sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGCP.java
[UTF-8] Sat Jan 27 15:29:32 2018
@@ -24,7 +24,6 @@ import org.opengis.geometry.DirectPositi
 import org.opengis.metadata.quality.Element;
 import org.opengis.metadata.spatial.GCP;
 import org.apache.sis.metadata.iso.ISOMetadata;
-import org.apache.sis.xml.Namespaces;
 
 
 /**
@@ -55,11 +54,11 @@ import org.apache.sis.xml.Namespaces;
  * @module
  */
 @SuppressWarnings("CloneableClassWithoutClone")                 // ModifiableMetadata needs
shallow clones.
-@XmlType(name = "MI_GCP_Type", namespace = Namespaces.GMI, propOrder = {
+@XmlType(name = "MI_GCP_Type", propOrder = {
     //"geographicCoordinates",
     "accuracyReports"
 })
-@XmlRootElement(name = "MI_GCP", namespace = Namespaces.GMI)
+@XmlRootElement(name = "MI_GCP")
 public class DefaultGCP extends ISOMetadata implements GCP {
     /**
      * Serial number for inter-operability with different versions.

Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGCPCollection.java
URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGCPCollection.java?rev=1822418&r1=1822417&r2=1822418&view=diff
==============================================================================
--- sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGCPCollection.java
[UTF-8] (original)
+++ sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGCPCollection.java
[UTF-8] Sat Jan 27 15:29:32 2018
@@ -25,7 +25,6 @@ import org.opengis.metadata.spatial.GCPC
 import org.opengis.referencing.ReferenceSystem;
 import org.opengis.util.InternationalString;
 import org.apache.sis.metadata.TitleProperty;
-import org.apache.sis.xml.Namespaces;
 
 
 /**
@@ -59,13 +58,13 @@ import org.apache.sis.xml.Namespaces;
  */
 @SuppressWarnings("CloneableClassWithoutClone")                 // ModifiableMetadata needs
shallow clones.
 @TitleProperty(name = "collectionName")
-@XmlType(name = "MI_GCPCollection_Type", namespace = Namespaces.GMI, propOrder = {
+@XmlType(name = "MI_GCPCollection_Type", propOrder = {
     "collectionIdentification",
     "collectionName",
     "coordinateReferenceSystem",
     "GCPs"
 })
-@XmlRootElement(name = "MI_GCPCollection", namespace = Namespaces.GMI)
+@XmlRootElement(name = "MI_GCPCollection")
 public class DefaultGCPCollection extends AbstractGeolocationInformation implements GCPCollection
{
     /**
      * Serial number for inter-operability with different versions.

Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/SchemaVerifier.java
URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/SchemaVerifier.java?rev=1822418&r1=1822417&r2=1822418&view=diff
==============================================================================
--- sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/SchemaVerifier.java
[UTF-8] (original)
+++ sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/SchemaVerifier.java
[UTF-8] Sat Jan 27 15:29:32 2018
@@ -143,17 +143,48 @@ public final strictfp class SchemaVerifi
     private final Deque<String> schemaLocations;
 
     /**
-     * Definition of XML types for each classes. In OGC/ISO schemas, those definitions have
the {@value #TYPE_SUFFIX}
-     * suffix in their name (which is omitted). The value is another map, where keys are
property names and values are
-     * their types, having the {@link #PROPERTY_TYPE_SUFFIX} suffix in their name (which
is omitted).
+     * The type and namespace of a property or class. Used in {@link #typeDefinitions} map.
      */
-    private final Map<String, Map<String,String>> typeDefinitions;
+    private static final class Info {
+        final String type;
+        final String namespace;
+
+        Info(final String type, final String namespace) {
+            this.type = type;
+            this.namespace = namespace;
+        }
+
+        boolean equal(final Info other) {
+            return type.equals(other.type) && namespace.equals(other.namespace);
+        }
+
+        @Override public String toString() {
+            return type;
+        }
+    }
+
+    /**
+     * Definitions of XML type for each class. In OGC/ISO schemas, those definitions have
the {@value #TYPE_SUFFIX}
+     * suffix in their name (which is omitted). The value is another map, where keys are
property names and values
+     * are their types, having the {@link #PROPERTY_TYPE_SUFFIX} suffix in their name (which
is omitted).
+     */
+    private final Map<String, Map<String,Info>> typeDefinitions;
+
+    /**
+     * Notifies that we are about to define the XML type for each property. In OGC/ISO schemas,
those definitions
+     * have the {@value #PROPERTY_TYPE_SUFFIX} suffix in their name (which is omitted). After
this method call,
+     * properties can be defined by calls to {@link #addProperty(String, String)}.
+     */
+    private void preparePropertyDefinitions(final String type) throws SchemaException {
+        currentProperties = typeDefinitions.computeIfAbsent(trim(type, TYPE_SUFFIX).intern(),
(k) -> new HashMap<>());
+    }
 
     /**
      * The properties of the XML type under examination, or {@code null} if none.
      * If non-null, this is one of the values in the {@link #typeDefinitions} map.
+     * By convention, the {@code null} key is associated to information about the class.
      */
-    private transient Map<String,String> currentProperties;
+    private transient Map<String,Info> currentProperties;
 
     /**
      * A single property type under examination, or {@code null} if none.
@@ -162,6 +193,12 @@ public final strictfp class SchemaVerifi
     private transient String currentPropertyType;
 
     /**
+     * Namespace of the type or properties being defined.
+     * This is specified by {@code <xs:schema targetNamespace="(…)">}.
+     */
+    private transient String targetNamespace;
+
+    /**
      * Creates a new verifier for classes under the given directory. The given directory
shall be the
      * root of {@code "*.class"} files. For example if the {@code mypackage.MyClass} class
is compiled
      * in the {@code "MyProject/target/classes/mypackage/MyClass.class"} file, then the root
directory
@@ -239,27 +276,35 @@ public final strictfp class SchemaVerifi
     private void storeClassDefinition(final Node node) throws IOException, ParserConfigurationException,
SAXException {
         if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(node.getNamespaceURI())) {
             switch (node.getNodeName()) {
+                case "schema": {
+                    targetNamespace = getMandatoryAttribute(node, "targetNamespace").intern();
+                    break;
+                }
                 /*
                  * <xs:include schemaLocation="(…).xsd">
                  * Load the schema at the given URL, which is assumed relative.
                  */
                 case "include": {
+                    final String oldTarget = targetNamespace;
                     final String location = schemaLocations.getLast();
                     buffer.setLength(0);
                     buffer.append(location, 0, location.lastIndexOf('/') + 1).append(getMandatoryAttribute(node,
"schemaLocation"));
                     loadSchema(buffer.toString());
+                    targetNamespace = oldTarget;
                     return;                             // Skip children (normally, there
is none).
                 }
                 /*
                  * <xs:element name="(…)" type="(…)_Type">
-                 * There is actually nothing to store here;
-                 * we just verify that the names comply with our assumptions.
+                 * Verify that the names comply with our assumptions.
                  */
                 case "element": {
+                    final String name = getMandatoryAttribute(node, "name");
                     final String type = getMandatoryAttribute(node, "type");
                     if (!TYPE_TO_IGNORE.equals(type)) {
-                        verifyNamingConvention(schemaLocations.getLast(),
-                                getMandatoryAttribute(node, "name"), type, TYPE_SUFFIX);
+                        verifyNamingConvention(schemaLocations.getLast(), name, type, TYPE_SUFFIX);
+                        preparePropertyDefinitions(type);
+                        addProperty(null, type);
+                        currentProperties = null;
                     }
                     return;                             // Ignore children (they are about
documentation).
                 }
@@ -274,7 +319,7 @@ public final strictfp class SchemaVerifi
                         verifyPropertyType(node);
                         currentPropertyType = null;
                     } else {
-                        currentProperties = typeDefinitions.computeIfAbsent(trim(name, TYPE_SUFFIX).intern(),
(k) -> new HashMap<>());
+                        preparePropertyDefinitions(name);
                         storePropertyDefinition(node);
                         currentProperties = null;
                     }
@@ -299,14 +344,8 @@ public final strictfp class SchemaVerifi
     private void storePropertyDefinition(final Node node) throws SAXException {
         if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(node.getNamespaceURI())) {
             if ("element".equals(node.getNodeName())) {
-                final String type = trim(getMandatoryAttribute(node, "type"), PROPERTY_TYPE_SUFFIX).intern();
-                final String name = getMandatoryAttribute(node, "name").intern();
-                final String old = currentProperties.put(name, type);
-                if (old != null && !old.equals(type)) {
-                    throw new SchemaException("Error while parsing " + schemaLocations.getLast()
+ ":\n"
-                            + "Property \"" + name + "\" is associated to type \"" + type
+ "\", but that "
-                            + "property was already associated to \"" + old + "\".");
-                }
+                addProperty(getMandatoryAttribute(node, "name").intern(),
+                       trim(getMandatoryAttribute(node, "type"), PROPERTY_TYPE_SUFFIX).intern());
                 return;
             }
         }
@@ -368,6 +407,20 @@ public final strictfp class SchemaVerifi
     }
 
     /**
+     * Adds a property of the current name and type. This method is invoked during schema
parsing.
+     * The property namespace is assumed to be {@link #targetNamespace}.
+     */
+    private void addProperty(final String name, final String type) throws SchemaException
{
+        final Info info = new Info(type, targetNamespace);
+        final Info old = currentProperties.put(name, info);
+        if (old != null && !old.equal(info)) {
+            throw new SchemaException("Error while parsing " + schemaLocations.getLast()
+ ":\n"
+                    + "Property \"" + name + "\" is associated to type \"" + type + "\",
but that "
+                    + "property was already associated to \"" + old + "\".");
+        }
+    }
+
+    /**
      * Removes leading and trailing spaces if any, then the prefix and the suffix in the
given name.
      * The prefix is anything before the first {@value #PREFIX_SEPARATOR} character.
      * The suffix must be the given string, otherwise an exception is thrown.
@@ -410,52 +463,69 @@ public final strictfp class SchemaVerifi
      * @param  type  the class on which to verify annotations.
      */
     private void verify(final Class<?> type) throws IOException, ParserConfigurationException,
SAXException {
+        /*
+         * Get information from the @XmlSchema annotation in package-info.
+         * Opportunistically verify consistency with naming convention.
+         */
         final Package pkg = type.getPackage();
-        final XmlSchema schema = pkg.getAnnotation(XmlSchema.class);
-        if (schema != null) {
-            String location = schema.location();
-            if (XmlSchema.NO_LOCATION.equals(location)) {
-                throw new SchemaException("Package " + pkg.getName() + " does not specify
XML schema location.");
-            }
-            if (location.startsWith(SCHEMA_ROOT_DIRECTORY)) {
-                if (!location.startsWith(schema.namespace())) {
-                    throw new SchemaException("XML schema location inconsistent with namespace
in " + pkg.getName() + " package.");
-                }
-                if (schemaRootDirectory != null) {
-                    location = schemaRootDirectory.resolve(location.substring(SCHEMA_ROOT_DIRECTORY.length())).toUri().toString();
+        String namespace = "";
+        if (pkg != null) {
+            final XmlSchema schema = pkg.getAnnotation(XmlSchema.class);
+            if (schema != null) {
+                namespace = schema.namespace();
+                String location = schema.location();
+                if (!XmlSchema.NO_LOCATION.equals(location)) {
+                    if (location.startsWith(SCHEMA_ROOT_DIRECTORY)) {
+                        if (!location.startsWith(schema.namespace())) {
+                            throw new SchemaException("XML schema location inconsistent with
namespace in " + pkg.getName() + " package.");
+                        }
+                        if (schemaRootDirectory != null) {
+                            location = schemaRootDirectory.resolve(location.substring(SCHEMA_ROOT_DIRECTORY.length())).toUri().toString();
+                        }
+                    }
+                    loadSchema(location);
                 }
             }
-            loadSchema(location);
         }
         /*
          * Verify @XmlType and @XmlRootElement on the class. First, we verify naming convention
          * (type name should be same as root element name with "_Type" suffix appended).
Then,
          * we verify that the name exists in the schema, and finally we check its namespace.
          */
-        final String className = type.getSimpleName();
-        final XmlType xmlType = type.getDeclaredAnnotation(XmlType.class);
-        if (xmlType != null) {
-            final XmlRootElement root = type.getDeclaredAnnotation(XmlRootElement.class);
-            if (root == null) {
-                throw new SchemaException("Missing @XmlRootElement in " + className + " class.");
-            }
-            verifyNamingConvention(type.getName(), root.name(), xmlType.name(), TYPE_SUFFIX);
-            final String namespace = xmlType.namespace();
-            if (!namespace.equals(root.namespace())) {
+        final String         className   = type.getSimpleName();
+        final XmlType        xmlType     = type.getDeclaredAnnotation(XmlType.class);
+        final XmlRootElement rootElement = type.getDeclaredAnnotation(XmlRootElement.class);
+        if (xmlType == null && rootElement == null) {
+            return;
+        }
+        if (xmlType == null || rootElement == null) {
+            throw new SchemaException("Missing @XmlType or @XmlRootElement in " + className
+ " class.");
+        } else {
+            final String ns = xmlType.namespace();
+            if (!ns.equals(rootElement.namespace())) {
                 throw new SchemaException("Mismatched namespace in @XmlType and @XmlRootElement
of " + className + " class.");
             }
-            final boolean isDeprecated = DEPRECATED_NAMESPACES.contains(namespace);
-            if (!isDeprecated && type.isAnnotationPresent(Deprecated.class)) {
-                throw new SchemaException("Unexpected deprecation status of " + className
+ " class.");
-            }
-            final Map<String,String> properties = typeDefinitions.get(root.name());
-            if (properties == null) {
-                if (!isDeprecated) {
-                    throw new SchemaException("Unknown name declared in @XmlRootElement of
" + className + " class.");
-                }
-            } else {
-                // TODO: scan for properties here.
+            if (!ns.equals("##default")) {
+                namespace = ns;
+            }
+        }
+        verifyNamingConvention(type.getName(), rootElement.name(), xmlType.name(), TYPE_SUFFIX);
+        final boolean isDeprecated = DEPRECATED_NAMESPACES.contains(namespace);
+        if (!isDeprecated && type.isAnnotationPresent(Deprecated.class)) {
+            throw new SchemaException("Unexpected deprecation status of " + className + "
class.");
+        }
+        final Map<String,Info> properties = typeDefinitions.get(rootElement.name());
+        if (properties == null) {
+            if (!isDeprecated) {
+                throw new SchemaException("Unknown name declared in @XmlRootElement of "
+ className + " class.");
+            }
+        } else {
+            // By convention, null key is associated to class information.
+            final String expectedNS = properties.get(null).namespace;
+            if (!namespace.equals(expectedNS)) {
+                throw new SchemaException("Class " + className + " shall be associated to
namespace " + expectedNS);
             }
+            // TODO: scan for properties here.
         }
     }
 }



Mime
View raw message