Return-Path: X-Original-To: apmail-sis-commits-archive@www.apache.org Delivered-To: apmail-sis-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1FED611864 for ; Fri, 11 Jul 2014 22:49:40 +0000 (UTC) Received: (qmail 63044 invoked by uid 500); 11 Jul 2014 22:49:40 -0000 Delivered-To: apmail-sis-commits-archive@sis.apache.org Received: (qmail 63015 invoked by uid 500); 11 Jul 2014 22:49:40 -0000 Mailing-List: contact commits-help@sis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: sis-dev@sis.apache.org Delivered-To: mailing list commits@sis.apache.org Received: (qmail 63006 invoked by uid 99); 11 Jul 2014 22:49:39 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 Jul 2014 22:49:39 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 Jul 2014 22:49:38 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 7631D23889EC; Fri, 11 Jul 2014 22:49:17 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@sis.apache.org From: desruisseaux@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140711224917.7631D23889EC@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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. + * + *

The spelling of "license" was changed to "licence" in latest standard, but XML + * marshalling shall use the previous spelling until XML schema are updated.

+ * + * @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 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 { @@ -119,4 +119,34 @@ public final strictfp class DefaultLegal assertEquals("warning", "NullCollectionElement_1", resourceKey); assertArrayEquals("warning", new String[] {"CodeListSet"}, 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 = + "\n" + + " \n" + + " Licence\n" + // Note the "c" - this one come from resource file. + " \n" + + "\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); + } }