sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1609862 - in /sis/branches/JDK8/core/sis-metadata/src: main/java/org/apache/sis/internal/jaxb/code/MD_RestrictionCode.java test/java/org/apache/sis/metadata/iso/constraint/DefaultLegalConstraintsTest.java
Date Fri, 11 Jul 2014 22:49:17 GMT
Author: desruisseaux
Date: Fri Jul 11 22:49:17 2014
New Revision: 1609862

URL: http://svn.apache.org/r1609862
Log:
Make MD_RestrictionCode tolerant to both "license" and "licence" spelling.
The former was used in ISO 19115:2003 while the later is used in ISO 19115:2014.
XML document shall continue to use the "license" spelling for now, until ISO/OGC
publish the new XML schemas.

Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/code/MD_RestrictionCode.java
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/constraint/DefaultLegalConstraintsTest.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/code/MD_RestrictionCode.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/code/MD_RestrictionCode.java?rev=1609862&r1=1609861&r2=1609862&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/code/MD_RestrictionCode.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/code/MD_RestrictionCode.java
[UTF-8] Fri Jul 11 22:49:17 2014
@@ -47,15 +47,27 @@ public final class MD_RestrictionCode ex
     }
 
     /**
-     * {@inheritDoc}
+     * Fix the spelling of words that changed between ISO 19115:2003 and ISO 19115:2014,
+     * then wraps the proxy value into an adapter.
+     *
+     * <p>The spelling of "license" was changed to "licence" in latest standard, but
XML
+     * marshalling shall use the previous spelling until XML schema are updated.</p>
+     *
+     * @param proxy The proxy version of {@link CodeList}, to be marshalled.
+     * @return The adapter that wraps the proxy value.
      */
     @Override
     protected MD_RestrictionCode wrap(CodeListProxy proxy) {
+        if ("licence".equals(proxy.codeListValue)) {
+            proxy.codeListValue = "license";
+        }
         return new MD_RestrictionCode(proxy);
     }
 
     /**
-     * {@inheritDoc}
+     * Returns the class of code list wrapped by this adapter.
+     *
+     * @return The code list class.
      */
     @Override
     protected Class<Restriction> getCodeListClass() {
@@ -75,10 +87,16 @@ public final class MD_RestrictionCode ex
 
     /**
      * Invoked by JAXB on unmarshalling.
+     * This method performs the reverse of the {@link #wrap(CodeListProxy)} spelling change:
+     * it converts "license" (ISO 19115:2003) to "licence" (ISO 19115:2014) in order to have
+     * only one {@code CodeList} instance for both.
      *
      * @param proxy The unmarshalled value.
      */
     public void setElement(final CodeListProxy proxy) {
+        if ("license".equals(proxy.codeListValue)) {
+            proxy.codeListValue = "licence";
+        }
         this.proxy = proxy;
     }
 }

Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/constraint/DefaultLegalConstraintsTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/constraint/DefaultLegalConstraintsTest.java?rev=1609862&r1=1609861&r2=1609862&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/constraint/DefaultLegalConstraintsTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/constraint/DefaultLegalConstraintsTest.java
[UTF-8] Fri Jul 11 22:49:17 2014
@@ -27,7 +27,7 @@ import org.apache.sis.util.logging.Warni
 import org.apache.sis.test.XMLTestCase;
 import org.junit.Test;
 
-import static org.junit.Assert.*;
+import static org.apache.sis.test.Assert.*;
 import static org.apache.sis.test.TestUtilities.getSingleton;
 
 
@@ -36,7 +36,7 @@ import static org.apache.sis.test.TestUt
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.4
- * @version 0.4
+ * @version 0.5
  * @module
  */
 public final strictfp class DefaultLegalConstraintsTest extends XMLTestCase implements WarningListener<Object>
{
@@ -119,4 +119,34 @@ public final strictfp class DefaultLegal
         assertEquals("warning", "NullCollectionElement_1", resourceKey);
         assertArrayEquals("warning", new String[] {"CodeListSet<Restriction>"}, parameters);
     }
+
+    /**
+     * Tests (un)marshalling of a XML fragment containing the {@link Restriction#LICENCE}
code.
+     * The spelling changed between ISO 19115:2003 and 19115:2014, from "license" to "licence".
+     * We need to ensure that XML marshalling use the old spelling, until the XML schema
is updated.
+     *
+     * @throws JAXBException If an error occurred during the during unmarshalling processes.
+     */
+    @Test
+    public void testLicenceCode() throws JAXBException {
+        final String xml =
+                "<gmd:MD_LegalConstraints xmlns:gmd=\"" + Namespaces.GMD + "\">\n"
+
+                "  <gmd:useConstraints>\n" +
+                "    <gmd:MD_RestrictionCode"
+                        + " codeList=\"http://schemas.opengis.net/iso/19139/20070417/resources/Codelist/gmxCodelists.xml#MD_RestrictionCode\""
+                        + " codeListValue=\"license\""                              // Note
the "s" - from old ISO 19115:2013 spelling.
+                        + " codeSpace=\"eng\">Licence</gmd:MD_RestrictionCode>\n"
+ // Note the "c" - this one come from resource file.
+                "  </gmd:useConstraints>\n" +
+                "</gmd:MD_LegalConstraints>\n";
+
+        final DefaultLegalConstraints c = new DefaultLegalConstraints();
+        c.getUseConstraints().add(Restriction.LICENCE);
+        assertXmlEquals(xml, marshal(c), "xmlns:*");
+        /*
+         * Unmarshall and ensure that we got back the original LICENCE code, not a new "LICENSE"
code.
+         */
+        final DefaultLegalConstraints actual = unmarshal(xml);
+        assertSame(Restriction.LICENCE, getSingleton(actual.getUseConstraints()));
+        assertEquals(c, actual);
+    }
 }



Mime
View raw message