Author: desruisseaux Date: Tue Jan 16 15:48:34 2018 New Revision: 1821259 URL: http://svn.apache.org/viewvc?rev=1821259&view=rev Log: Adaptation of commit 39e5464004f8531b707e273570aa841c9074ef2e from Image Matter (complete first pass on tests for ISO 19115-3). The project at this revision can be built but is known to have test failures. Tests will pass only after we completed the port of all ISO 19115-3 work. Added: sis/branches/ISO-19115-3/core/sis-metadata/src/test/resources/org/apache/sis/metadata/iso/quality/PositionalAccuracy (legacy).xml - copied unchanged from r1821258, sis/branches/ISO-19115-3/core/sis-metadata/src/test/resources/org/apache/sis/metadata/iso/quality/PositionalAccuracy.xml Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/package-info.java sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/lineage/DefaultLineageTest.java sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/lineage/DefaultProcessStepTest.java sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/quality/AbstractPositionalAccuracyTest.java sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/xml/CharSequenceSubstitutionTest.java sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/xml/FreeTextMarshallingTest.java sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/xml/NilReasonMarshallingTest.java sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/xml/UUIDMarshallingTest.java sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/xml/XLinkMarshallingTest.java sis/branches/ISO-19115-3/core/sis-metadata/src/test/resources/org/apache/sis/metadata/iso/quality/PositionalAccuracy.xml sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_CharacterString.java sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/ObjectIdentification.html sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamResolver.java sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/Namespaces.java sis/branches/ISO-19115-3/core/sis-utility/src/main/resources/org/apache/sis/xml/NamespaceContent.txt sis/branches/ISO-19115-3/core/sis-utility/src/test/java/org/apache/sis/xml/NamespacesTest.java Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/package-info.java URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/package-info.java?rev=1821259&r1=1821258&r2=1821259&view=diff ============================================================================== --- sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/package-info.java [UTF-8] (original) +++ sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/package-info.java [UTF-8] Tue Jan 16 15:48:34 2018 @@ -114,8 +114,8 @@ * @since 0.3 * @module */ -@XmlSchema(location=Schemas.METADATA_XSD_QUALITY, elementFormDefault=XmlNsForm.QUALIFIED, namespace=Namespaces.DQC, xmlns = { - @XmlNs(prefix = "dqc", namespaceURI = Namespaces.DQC), +@XmlSchema(location=Schemas.METADATA_XSD_QUALITY, elementFormDefault=XmlNsForm.QUALIFIED, namespace=Namespaces.MDQ, xmlns = { + @XmlNs(prefix = "mdq", namespaceURI = Namespaces.MDQ), @XmlNs(prefix = "cit", namespaceURI = Namespaces.CIT), @XmlNs(prefix = "mrc", namespaceURI = Namespaces.MRC), @XmlNs(prefix = "mrd", namespaceURI = Namespaces.MRD), Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/lineage/DefaultLineageTest.java URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/lineage/DefaultLineageTest.java?rev=1821259&r1=1821258&r2=1821259&view=diff ============================================================================== --- sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/lineage/DefaultLineageTest.java [UTF-8] (original) +++ sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/lineage/DefaultLineageTest.java [UTF-8] Tue Jan 16 15:48:34 2018 @@ -18,11 +18,10 @@ package org.apache.sis.metadata.iso.line import java.util.Arrays; import javax.xml.bind.JAXBException; +import org.apache.sis.internal.jaxb.LegacyNamespaces; import org.apache.sis.util.iso.SimpleInternationalString; import org.apache.sis.metadata.iso.DefaultIdentifier; import org.apache.sis.test.XMLTestCase; -import org.apache.sis.xml.Namespaces; -import org.apache.sis.xml.XML; import org.junit.Test; import static org.apache.sis.test.Assert.*; @@ -33,7 +32,7 @@ import static org.apache.sis.test.Assert * {@code "gmi"} namespace that GeoAPI merged with the object of same name in the {@code "gmd"} namespace. * * @author Martin Desruisseaux (Geomatys) - * @version 0.4 + * @version 1.0 * @since 0.3 * @module */ @@ -54,10 +53,10 @@ public final strictfp class DefaultLinea * If this simpler case, only ISO 19115 elements are defined (no ISO 19115-2). * Consequently the XML name shall be "gmd:LI_Source". */ - String actual = XML.marshal(lineage); + String actual = marshal(lineage, LegacyNamespaces.ISO_19139); assertXmlEquals( - "\n" + + "\n" + " \n" + " \n" + " \n" + @@ -70,11 +69,11 @@ public final strictfp class DefaultLinea * Now add a ISO 19115-2 specific property. The XML name shall become "gmi:LE_Source". */ source.setProcessedLevel(new DefaultIdentifier("DummyLevel")); - actual = XML.marshal(lineage); + actual = marshal(lineage, LegacyNamespaces.ISO_19139); assertXmlEquals( - "\n" + + "\n" + " \n" + " \n" + " \n" + Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/lineage/DefaultProcessStepTest.java URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/lineage/DefaultProcessStepTest.java?rev=1821259&r1=1821258&r2=1821259&view=diff ============================================================================== --- sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/lineage/DefaultProcessStepTest.java [UTF-8] (original) +++ sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/lineage/DefaultProcessStepTest.java [UTF-8] Tue Jan 16 15:48:34 2018 @@ -19,6 +19,7 @@ package org.apache.sis.metadata.iso.line import javax.xml.bind.JAXBException; import org.apache.sis.util.iso.SimpleInternationalString; import org.apache.sis.internal.jaxb.gmi.LE_ProcessStep; +import org.apache.sis.internal.jaxb.LegacyNamespaces; import org.apache.sis.test.XMLTestCase; import org.junit.Test; @@ -30,7 +31,7 @@ import static org.opengis.test.Assert.*; * * @author Cédric Briançon (Geomatys) * @author Martin Desruisseaux (Geomatys) - * @version 0.8 + * @version 1.0 * @since 0.3 * @module */ @@ -57,7 +58,7 @@ public final strictfp class DefaultProce /* * XML marshalling, and compare with the content of "ProcessStep.xml" file. */ - assertMarshalEqualsFile(XML_FILE, processStep, "xlmns:*", "xsi:schemaLocation"); + assertMarshalEqualsFile(XML_FILE, processStep, LegacyNamespaces.ISO_19139, "xlmns:*", "xsi:schemaLocation"); /* * XML unmarshalling: ensure that we didn't lost any information. * Note that since the XML uses the namespace, we got an instance of LE_ProcessStep, which Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/quality/AbstractPositionalAccuracyTest.java URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/quality/AbstractPositionalAccuracyTest.java?rev=1821259&r1=1821258&r2=1821259&view=diff ============================================================================== --- sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/quality/AbstractPositionalAccuracyTest.java [UTF-8] (original) +++ sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/quality/AbstractPositionalAccuracyTest.java [UTF-8] Tue Jan 16 15:48:34 2018 @@ -20,6 +20,8 @@ import java.util.Locale; import javax.xml.bind.JAXBException; import org.opengis.util.InternationalString; import org.apache.sis.xml.FreeTextMarshallingTest; +import org.apache.sis.internal.jaxb.LegacyNamespaces; +import org.apache.sis.util.Version; import org.apache.sis.test.XMLTestCase; import org.apache.sis.test.DependsOn; import org.junit.Test; @@ -33,18 +35,14 @@ import static org.apache.sis.test.TestUt * * @author Cédric Briançon (Geomatys) * @author Martin Desruisseaux (Geomatys) - * @version 0.4 + * @author Cullen Rombach (Image Matters) + * @version 1.0 * @since 0.3 * @module */ @DependsOn(FreeTextMarshallingTest.class) public final strictfp class AbstractPositionalAccuracyTest extends XMLTestCase { /** - * An XML file in this package containing a positional accuracy definition. - */ - private static final String XML_FILE = "PositionalAccuracy.xml"; - - /** * Tests the (un)marshalling of a text group with a default {@code } element. * This test is somewhat a duplicate of {@link FreeTextMarshallingTest}, but the context is more * elaborated. @@ -59,7 +57,25 @@ public final strictfp class AbstractPosi */ @Test public void testXML() throws JAXBException { - final AbstractElement metadata = unmarshalFile(AbstractElement.class, XML_FILE); + roundtrip("PositionalAccuracy.xml", LegacyNamespaces.ISO_19115_3); + } + + /** + * Tests the (un)marshalling of a text group from/to legacy ISO 19139:2007 schema. + * + * @throws JAXBException if an error occurred during the during marshalling / unmarshalling processes. + */ + @Test + public void testLegacyXML() throws JAXBException { + roundtrip("PositionalAccuracy (legacy).xml", LegacyNamespaces.ISO_19139); + } + + /** + * Unmarshals the given file and verify the content. + * Then marshals the object and verify that we get equivalent XML. + */ + private void roundtrip(final String filename, final Version version) throws JAXBException { + final AbstractElement metadata = unmarshalFile(AbstractElement.class, filename); final InternationalString nameOfMeasure = getSingleton(metadata.getNamesOfMeasure()); /* * Programmatic verification of the text group. @@ -77,6 +93,6 @@ public final strictfp class AbstractPosi /* * Marshalling: ensure that we didn't lost any information. */ - assertMarshalEqualsFile(XML_FILE, metadata, "xmlns:*", "xsi:schemaLocation", "xsi:type"); + assertMarshalEqualsFile(filename, metadata, version, "xmlns:*", "xsi:schemaLocation", "xsi:type"); } } Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/xml/CharSequenceSubstitutionTest.java URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/xml/CharSequenceSubstitutionTest.java?rev=1821259&r1=1821258&r2=1821259&view=diff ============================================================================== --- sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/xml/CharSequenceSubstitutionTest.java [UTF-8] (original) +++ sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/xml/CharSequenceSubstitutionTest.java [UTF-8] Tue Jan 16 15:48:34 2018 @@ -22,6 +22,7 @@ import org.opengis.metadata.Identifier; import org.opengis.metadata.acquisition.Instrument; import org.opengis.metadata.identification.DataIdentification; import org.opengis.metadata.identification.InitiativeType; +import org.apache.sis.internal.jaxb.LegacyNamespaces; import org.apache.sis.internal.metadata.SensorType; import org.apache.sis.util.iso.Types; import org.apache.sis.test.DependsOnMethod; @@ -42,28 +43,56 @@ import static org.apache.sis.test.Assert */ public final strictfp class CharSequenceSubstitutionTest extends XMLTestCase { /** - * Tests unmarshalling of anchor in an identifier element. The {@code xlink:href} attribute - * is lost because the Java type of the {@code gmd:code} attribute is {@link String}. + * Tests unmarshalling of {@code "RS_Identifier"} element. This element was defined in legacy ISO 19139:2007 + * but has been removed in ISO 19115-3. That element is extensively used for Coordinate Reference Systems in + * GML 3.2. * * @throws JAXBException if the unmarshalling failed. */ @Test - @DependsOnMethod("testAnchor") - public void testAnchorForString() throws JAXBException { + @DependsOnMethod("testAnchorForString") + public void testLegacy() throws JAXBException { final String expected = - "\n" + " \n" + - " EPSG:4326\n" + + " EPSG:4326\n" + " \n" + " \n" + " L101\n" + " \n" + ""; - final Identifier id = (Identifier) XML.unmarshal(expected); + final Identifier id = unmarshal(Identifier.class, expected); + assertEquals("codespace", "L101", id.getCodeSpace()); + assertEquals("code", "EPSG:4326", id.getCode()); + } + + /** + * Tests unmarshalling of anchor in an identifier element. The {@code xlink:href} attribute + * is lost because the Java type of the {@code gmd:code} attribute is {@link String}. + * + * @throws JAXBException if the unmarshalling failed. + */ + @Test + @DependsOnMethod("testAnchor") + public void testAnchorForString() throws JAXBException { + final String expected = + "\n" + + " \n" + + " EPSG:4326\n" + + " \n" + + " \n" + + " L101\n" + + " \n" + + ""; + + final Identifier id = unmarshal(Identifier.class, expected); assertEquals("codespace", "L101", id.getCodeSpace()); assertEquals("code", "EPSG:4326", id.getCode()); } @@ -77,28 +106,28 @@ public final strictfp class CharSequence @Test public void testAnchor() throws JAXBException { final String expected = - "\n" + - " \n" + + " \n" + " Centre IFREMER de Brest BP 70\n" + - " \n" + - " \n" + + " \n" + + " \n" + " Plouzané\n" + - " \n" + - " \n" + + " \n" + + " \n" + " 29280\n" + - " \n" + - " \n" + + " \n" + + " \n" + " France\n" + - " \n" + - " \n" + + " \n" + + " \n" + " (hiden)@ifremer.fr\n" + - " \n" + - ""; + " \n" + + ""; - final Address address = (Address) XML.unmarshal(expected); + final Address address = unmarshal(Address.class, expected); assertEquals("Plouzané", address.getCity().toString()); assertEquals("France", address.getCountry().toString()); assertEquals(1, address.getElectronicMailAddresses().size()); @@ -111,7 +140,7 @@ public final strictfp class CharSequence anchor.setType(XLink.Type.AUTO); assertEquals(XLink.Type.LOCATOR, anchor.getType()); - final String actual = XML.marshal(address); + final String actual = marshal(address); assertXmlEquals(expected, actual, "xmlns:*"); } @@ -125,19 +154,19 @@ public final strictfp class CharSequence @Test public void testCodeList() throws JAXBException { final String expected = - "\n" + - " \n" + - " Investigation\n" + - " \n" + - ""; + "\n" + + " \n" + + " Investigation\n" + + " \n" + + ""; - final DataIdentification id = (DataIdentification) XML.unmarshal(expected); + final DataIdentification id = unmarshal(DataIdentification.class, expected); assertEquals("purpose", "Investigation", String.valueOf(id.getPurpose())); assertSame("purpose", InitiativeType.INVESTIGATION, Types.forCodeTitle(id.getPurpose())); - final String actual = XML.marshal(id); + final String actual = marshal(id); assertXmlEquals(expected, actual, "xmlns:*"); } @@ -161,7 +190,7 @@ public final strictfp class CharSequence " \n" + ""; - final Instrument instrument = (Instrument) XML.unmarshal(expected); + final Instrument instrument = unmarshal(Instrument.class, expected); assertEquals("type", "RADIOMETER", String.valueOf(instrument.getType())); assertInstanceOf("type", SensorType.class, Types.forCodeTitle(instrument.getType())); } Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/xml/FreeTextMarshallingTest.java URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/xml/FreeTextMarshallingTest.java?rev=1821259&r1=1821258&r2=1821259&view=diff ============================================================================== --- sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/xml/FreeTextMarshallingTest.java [UTF-8] (original) +++ sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/xml/FreeTextMarshallingTest.java [UTF-8] Tue Jan 16 15:48:34 2018 @@ -30,7 +30,7 @@ import static org.apache.sis.test.Assert * Tests the XML marshalling of {@code FreeText}. * * @author Martin Desruisseaux (Geomatys) - * @version 0.3 + * @version 1.0 * * @see GEOTK-107 * @see GEOTK-152 @@ -60,26 +60,29 @@ public final strictfp class FreeTextMars @Test public void testStandard() throws JAXBException { final String expected = - "\n" + - " \n" + + "\n" + + " \n" + " OpenSource Project\n" + - " \n" + - " \n" + - " OpenSource Project\n" + - " \n" + - " \n" + - " Progetto OpenSource\n" + - " \n" + - " \n" + - " Projet OpenSource\n" + - " \n" + - " \n" + - " \n" + - "\n"; + " \n" + + " \n" + + " OpenSource Project\n" + + " \n" + + " \n" + + " Progetto OpenSource\n" + + " \n" + + " \n" + + " Projet OpenSource\n" + + " \n" + + " \n" + + " \n" + + "\n"; - final Citation citation = (Citation) XML.unmarshal(expected); + final Citation citation = unmarshal(Citation.class, expected); assertEquals(getExpectedI18N(), citation.getTitle()); - final String actual = XML.marshal(citation); + final String actual = marshal(citation); assertXmlEquals(expected, actual, "xmlns:*"); } @@ -94,20 +97,23 @@ public final strictfp class FreeTextMars @Test public void testLegacy() throws JAXBException { final String legacy = - "\n" + - " \n" + + "\n" + + " \n" + " OpenSource Project\n" + - " \n" + - " \n" + - " OpenSource Project\n" + - " Progetto OpenSource\n" + - " Projet OpenSource\n" + - " \n" + - " \n" + - " \n" + - "\n"; + " \n" + + " \n" + + " OpenSource Project\n" + + " Progetto OpenSource\n" + + " Projet OpenSource\n" + + " \n" + + " \n" + + " \n" + + "\n"; - final Citation citation = (Citation) XML.unmarshal(legacy); + final Citation citation = unmarshal(Citation.class, legacy); assertEquals(getExpectedI18N(), citation.getTitle()); } } Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/xml/NilReasonMarshallingTest.java URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/xml/NilReasonMarshallingTest.java?rev=1821259&r1=1821258&r2=1821259&view=diff ============================================================================== --- sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/xml/NilReasonMarshallingTest.java [UTF-8] (original) +++ sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/xml/NilReasonMarshallingTest.java [UTF-8] Tue Jan 16 15:48:34 2018 @@ -33,7 +33,7 @@ import static org.apache.sis.test.Metada * Tests the XML marshalling of object having {@code nilReason} attribute. * * @author Martin Desruisseaux (Geomatys) - * @version 0.4 + * @version 1.0 * * @see GEOTK-149 * @@ -49,15 +49,15 @@ public final strictfp class NilReasonMar @Test public void testMissing() throws JAXBException { final String expected = - "\n" + - " \n" + + " \n" + " A title\n" + - " \n" + - " \n" + - ""; + " \n" + + " \n" + + ""; - final Citation citation = (Citation) XML.unmarshal(expected); + final Citation citation = unmarshal(Citation.class, expected); assertTitleEquals("citation", "A title", citation); final Series series = citation.getSeries(); @@ -71,9 +71,9 @@ public final strictfp class NilReasonMar assertEquals("Series[missing]", series.toString()); assertNull("All attributes are expected to be null.", series.getName()); - final String actual = XML.marshal(citation); + final String actual = marshal(citation); assertXmlEquals(expected, actual, "xmlns:*"); - assertEquals(citation, XML.unmarshal(actual)); + assertEquals(citation, unmarshal(Citation.class, actual)); } /** @@ -87,15 +87,15 @@ public final strictfp class NilReasonMar @DependsOnMethod("testMissing") public void testMissingBoolean() throws JAXBException { final String expected = - "\n" + - " \n" + + " \n" + " An explanation\n" + - " \n" + - " \n" + - ""; + " \n" + + " \n" + + ""; - final ConformanceResult result = (ConformanceResult) XML.unmarshal(expected); + final ConformanceResult result = unmarshal(ConformanceResult.class, expected); assertEquals("explanation", "An explanation", result.getExplanation().toString()); final Boolean pass = result.pass(); @@ -104,9 +104,9 @@ public final strictfp class NilReasonMar assertNotSame("Expected a sentinel value.", Boolean.FALSE, pass); assertSame("nilReason", NilReason.MISSING, NilReason.forObject(pass)); - final String actual = XML.marshal(result); + final String actual = marshal(result); assertXmlEquals(expected, actual, "xmlns:*"); - assertEquals(result, XML.unmarshal(actual)); + assertEquals(result, unmarshal(ConformanceResult.class, actual)); } /** @@ -121,12 +121,12 @@ public final strictfp class NilReasonMar @SuppressWarnings("UnnecessaryBoxing") public void testMissingInteger() throws JAXBException { final String expected = - "\n" + - " \n" + - ""; + " \n" + + ""; - final Dimension result = (Dimension) XML.unmarshal(expected); + final Dimension result = unmarshal(Dimension.class, expected); final Integer size = result.getDimensionSize(); assertNotNull("Expected a sentinel value.", size); @@ -134,9 +134,9 @@ public final strictfp class NilReasonMar assertNotSame("Expected a sentinel value.", Integer.valueOf(0), size); assertSame("nilReason", NilReason.UNKNOWN, NilReason.forObject(size)); - final String actual = XML.marshal(result); + final String actual = marshal(result); assertXmlEquals(expected, actual, "xmlns:*"); - assertEquals(result, XML.unmarshal(actual)); + assertEquals(result, unmarshal(Dimension.class, actual)); } /** @@ -148,13 +148,13 @@ public final strictfp class NilReasonMar @DependsOnMethod("testMissing") public void testMissingDouble() throws JAXBException { final String expected = - "\n" + - " \n" + - " \n" + - ""; + " \n" + + " \n" + + ""; - final Band result = (Band) XML.unmarshal(expected); + final Band result = unmarshal(Band.class, expected); final Double minValue = result.getMinValue(); assertNotNull("Expected a sentinel value.", minValue); @@ -166,9 +166,9 @@ public final strictfp class NilReasonMar assertTrue("Nil value shall be NaN.", peakResponse.isNaN()); assertSame("nilReason", NilReason.UNKNOWN, NilReason.forObject(peakResponse)); - final String actual = XML.marshal(result); + final String actual = marshal(result); assertXmlEquals(expected, actual, "xmlns:*"); - assertEquals(result, XML.unmarshal(actual)); + assertEquals(result, unmarshal(Band.class, actual)); } /** @@ -180,15 +180,15 @@ public final strictfp class NilReasonMar @DependsOnMethod("testMissing") public void testOther() throws JAXBException { final String expected = - "\n" + - " \n" + + " \n" + " A title\n" + - " \n" + - " \n" + - ""; + " \n" + + " \n" + + ""; - final Citation citation = (Citation) XML.unmarshal(expected); + final Citation citation = unmarshal(Citation.class, expected); assertTitleEquals("citation", "A title", citation); final Series series = citation.getSeries(); @@ -201,9 +201,9 @@ public final strictfp class NilReasonMar assertEquals("Series[other:myReason]", series.toString()); assertNull("All attributes are expected to be null.", series.getName()); - final String actual = XML.marshal(citation); + final String actual = marshal(citation); assertXmlEquals(expected, actual, "xmlns:*"); - assertEquals(citation, XML.unmarshal(actual)); + assertEquals(citation, unmarshal(Citation.class, actual)); } /** @@ -215,15 +215,15 @@ public final strictfp class NilReasonMar @DependsOnMethod("testMissing") public void testURI() throws JAXBException { final String expected = - "\n" + - " \n" + + " \n" + " A title\n" + - " \n" + - " \n" + - ""; + " \n" + + " \n" + + ""; - final Citation citation = (Citation) XML.unmarshal(expected); + final Citation citation = unmarshal(Citation.class, expected); assertTitleEquals("citation", "A title", citation); final Series series = citation.getSeries(); @@ -236,8 +236,8 @@ public final strictfp class NilReasonMar assertEquals("Series[http://www.myreason.org]", series.toString()); assertNull("All attributes are expected to be null.", series.getName()); - final String actual = XML.marshal(citation); + final String actual = marshal(citation); assertXmlEquals(expected, actual, "xmlns:*"); - assertEquals(citation, XML.unmarshal(actual)); + assertEquals(citation, unmarshal(Citation.class, actual)); } } Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/xml/UUIDMarshallingTest.java URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/xml/UUIDMarshallingTest.java?rev=1821259&r1=1821258&r2=1821259&view=diff ============================================================================== --- sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/xml/UUIDMarshallingTest.java [UTF-8] (original) +++ sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/xml/UUIDMarshallingTest.java [UTF-8] Tue Jan 16 15:48:34 2018 @@ -32,7 +32,7 @@ import static org.apache.sis.test.Metada * Tests the XML marshalling of object having {@code uuid} or {@code uuidref} attributes. * * @author Martin Desruisseaux (Geomatys) - * @version 0.4 + * @version 1.0 * * @see GEOTK-165 * @@ -50,50 +50,50 @@ public final strictfp class UUIDMarshall * A XML with a {@code uuid} identifier in the {@code } element. */ private static final String IDENTIFIED_XML = - "\n" + - " \n" + + "\n" + + " \n" + " My data\n" + - " \n" + - " \n" + - " \n" + - " \n" + + " \n" + + " \n" + + " \n" + + " \n" + " My aggregate dataset\n" + - " \n" + - " \n" + - " \n" + - ""; + " \n" + + " \n" + + " \n" + + ""; /** * A XML with a {@code uuidref} identifier in the {@code } element. * This XML declares the method body anyway, which is kind of contradictory with usage of reference. */ private static final String REFERENCED_XML_WITH_BODY = - "\n" + - " \n" + + "\n" + + " \n" + " My data\n" + - " \n" + - " \n" + - " \n" + - " \n" + + " \n" + + " \n" + + " \n" + + " \n" + " My aggregate dataset\n" + - " \n" + - " \n" + - " \n" + - ""; + " \n" + + " \n" + + " \n" + + ""; /** * A XML with a {@code uuidref} identifier in the {@code } element. */ private static final String REFERENCED_XML = - "\n" + - " \n" + + "\n" + + " \n" + " My data\n" + - " \n" + - " \n" + - ""; + " \n" + + " \n" + + ""; /** * Tests (un)marshalling of an object identified by the {@code uuid} attribute. @@ -101,18 +101,18 @@ public final strictfp class UUIDMarshall * in the {@code } element of the following XML fragment: * * {@preformat xml - * - * + * + * * My data - * - * - * - * + * + * + * + * * My aggregate dataset - * - * - * - * + * + * + * + * * } * * On an implementation note, the {@code uuid} and other attributes of the {@code } @@ -152,18 +152,18 @@ public final strictfp class UUIDMarshall * in the {@code } property of the following XML fragment:

* * {@preformat xml - * - * + * + * * My data - * - * - * - * + * + * + * + * * My aggregate dataset - * - * - * - * + * + * + *
+ * * } * * On an implementation note, the {@code uuidref}, {@code xlink:href} and other attributes of the Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/xml/XLinkMarshallingTest.java URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/xml/XLinkMarshallingTest.java?rev=1821259&r1=1821258&r2=1821259&view=diff ============================================================================== --- sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/xml/XLinkMarshallingTest.java [UTF-8] (original) +++ sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/xml/XLinkMarshallingTest.java [UTF-8] Tue Jan 16 15:48:34 2018 @@ -37,7 +37,7 @@ import static org.apache.sis.test.TestUt * Tests the XML marshalling of object having {@code xlink} attribute. * * @author Martin Desruisseaux (Geomatys) - * @version 0.4 + * @version 1.0 * * @see GEOTK-165 * @@ -50,26 +50,27 @@ public final strictfp class XLinkMarshal * A XML with a {@code xlink:href} without element definition. */ private static final String LINK_ONLY_XML = - "\n" + - " \n" + - ""; + " \n" + + ""; /** * A XML with a {@code xlink:href} without element definition. */ private static final String LINK_WITH_ELEMENT_XML = - "\n" + - " \n" + - " \n" + - " \n" + + " \n" + + " \n" + + " \n" + " This is a test.\n" + - " \n" + - " \n" + - " \n" + - ""; + " \n" + + " \n" + + " \n" + + ""; /** * Verifies if the given metadata contains the expected {@code xlink:href} attribute value. @@ -90,9 +91,9 @@ public final strictfp class XLinkMarshal * The XML fragment is: * * {@preformat xml - * - * - * + * + * + * * } * * @throws JAXBException if an error occurred during (un)marshalling. @@ -107,7 +108,7 @@ public final strictfp class XLinkMarshal final DefaultMetadata metadata = new DefaultMetadata(); metadata.setIdentificationInfo(Collections.singleton(identification)); - assertXmlEquals(LINK_ONLY_XML, XML.marshal(metadata), "xmlns:*"); + assertXmlEquals(LINK_ONLY_XML, marshal(metadata), "xmlns:*"); verify(true, unmarshal(DefaultMetadata.class, LINK_ONLY_XML)); } @@ -116,15 +117,15 @@ public final strictfp class XLinkMarshal * The XML fragment is: * * {@preformat xml - * - * - * - * + * + * + * + * * This is a test. - * - * - * - * + * + * + * + * * } * * @throws JAXBException if an error occurred during (un)marshalling. @@ -140,7 +141,7 @@ public final strictfp class XLinkMarshal final DefaultMetadata metadata = new DefaultMetadata(); metadata.setIdentificationInfo(Collections.singleton(identification)); - assertXmlEquals(LINK_WITH_ELEMENT_XML, XML.marshal(metadata), "xmlns:*"); + assertXmlEquals(LINK_WITH_ELEMENT_XML, marshal(metadata), "xmlns:*"); final DefaultMetadata unmarshal = unmarshal(DefaultMetadata.class, LINK_WITH_ELEMENT_XML); verify(false, unmarshal); assertTrue(metadata.equals(unmarshal, ComparisonMode.DEBUG)); Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/test/resources/org/apache/sis/metadata/iso/quality/PositionalAccuracy.xml URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/test/resources/org/apache/sis/metadata/iso/quality/PositionalAccuracy.xml?rev=1821259&r1=1821258&r2=1821259&view=diff ============================================================================== --- sis/branches/ISO-19115-3/core/sis-metadata/src/test/resources/org/apache/sis/metadata/iso/quality/PositionalAccuracy.xml (original) +++ sis/branches/ISO-19115-3/core/sis-metadata/src/test/resources/org/apache/sis/metadata/iso/quality/PositionalAccuracy.xml Tue Jan 16 15:48:34 2018 @@ -18,55 +18,67 @@ under the License. --> - + xsi:schemaLocation = "http://standards.iso.org/iso/19157/-2/mdq/1.0 http://standards.iso.org/iso/19157/-2/mdq/1.0/mdq.xsd + http://standards.iso.org/iso/19115/-3/lan/1.0 http://standards.iso.org/iso/19115/-3/lan/1.0/lan.xsd"> - - Quantitative quality measure focusing on the effective class percent regarded to the total surface size - - - Mesure qualité quantitative de type pourcentage de représentation de la classe par rapport à la surface totale - - - - + + + + + + Quantitative quality measure focusing on the effective class percent regarded to the total surface size + + + Mesure qualité quantitative de type pourcentage de représentation de la classe par rapport à la surface totale + + + + + + + + - - - - + + + + Some documentation for a conformance test. - - - - + + + + 2009-08-12T19:40:17.653+02:00 - - - Creation - - - - - - + + + Creation + + + + + + We should explain here what a test conformance means. - - + + true - - - - + + + + Modified: sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_CharacterString.java URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_CharacterString.java?rev=1821259&r1=1821258&r2=1821259&view=diff ============================================================================== --- sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_CharacterString.java [UTF-8] (original) +++ sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_CharacterString.java [UTF-8] Tue Jan 16 15:48:34 2018 @@ -234,7 +234,7 @@ public class GO_CharacterString { * *
Note: * we have to rely on a somewhat complicated mechanism because the code lists implementations in GeoAPI - * do not hae JAXB annotations. If those annotations are added in a future GeoAPI implementation, then + * do not have JAXB annotations. If those annotations are added in a future GeoAPI implementation, then * we could replace this mechanism by a simple property annotated with {@code XmlElementRef}.
* * @since 0.7 @@ -247,23 +247,15 @@ public class GO_CharacterString { } final ControlledVocabulary code = Types.forCodeTitle(text); final String name = Types.getListName(code); - final String namespace; /* - * The namespace is usually GMD, but we also have some other namespaces link GMI. + * The namespace is often MDB, but we also have some other namespaces link CIT. * The real namespace is declared in the @XmlElement annotation of the getElement * method in the JAXB adapter. We could use reflection, but we do not in order to * avoid potential class loading issue and also because not all CodeList are in the * same package. */ - if (name.startsWith("MD_") || name.startsWith("CI_") || name.startsWith("DS_")) { - namespace = Namespaces.GMD; - } else if (name.startsWith("MI_")) { - namespace = Namespaces.GMI; - } else if (name.startsWith("SV_") || name.equals("DCPList")) { - namespace = Namespaces.SRV; - } else if (name.startsWith("CS_") || name.startsWith("CD_") || name.startsWith("SC_")) { - namespace = Namespaces.GML; - } else { + String namespace = Namespaces.guessForType(name); + if (namespace == null) { namespace = XMLConstants.NULL_NS_URI; } return new JAXBElement<>(new QName(namespace, name), CodeListUID.class, Modified: sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/ObjectIdentification.html URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/ObjectIdentification.html?rev=1821259&r1=1821258&r2=1821259&view=diff ============================================================================== --- sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/ObjectIdentification.html [UTF-8] (original) +++ sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/ObjectIdentification.html [UTF-8] Tue Jan 16 15:48:34 2018 @@ -49,8 +49,8 @@ for internal cross-references. It is not useful by itself as a persistent unique identifier.
  • uuid is an optional attribute available on every object-with-identity, provided in - the GMD schemas that implement ISO 19115 in XML. May be used as a persistent - unique identifier, but only available within GMD context.
  • + the GCO schemas that implement ISO 19115 in XML. May be used as a persistent + unique identifier, but only available within GCO context.

    However according the OGC schema, Modified: sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamResolver.java URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamResolver.java?rev=1821259&r1=1821258&r2=1821259&view=diff ============================================================================== --- sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamResolver.java [UTF-8] (original) +++ sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamResolver.java [UTF-8] Tue Jan 16 15:48:34 2018 @@ -220,6 +220,17 @@ final class FilteredStreamResolver exten } /** + * Returns the namespace of the given ISO type, or {@code null} if unknown. + * + * @param type a class name defined by ISO 19115 or related standards (e.g. {@code "CI_Citation"}. + * @return a namespace for the given type, or {@code null} if unknown. + */ + static String namespace(final String type) { + final Map attributes = NAMESPACES.get(type); + return (attributes != null) ? attributes.get(TYPE_KEY) : null; + } + + /** * Return the namespace used by implementation (the SIS classes with JAXB annotations) * in the context of the current part of the XML document being read. * Modified: sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/Namespaces.java URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/Namespaces.java?rev=1821259&r1=1821258&r2=1821259&view=diff ============================================================================== --- sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/Namespaces.java [UTF-8] (original) +++ sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/Namespaces.java [UTF-8] Tue Jan 16 15:48:34 2018 @@ -609,4 +609,54 @@ public final class Namespaces extends St } return defaultValue; } + + /** + * Guesses the namespace for a type of the given ISO name. The argument given to this method + * must be a class name defined by ISO 19115 or other standards to be added in the future. + * Those ISO class names usually start with a two letter prefix, e.g. {@code "CI"} + * in {@link org.apache.sis.metadata.iso.citation.DefaultCitation CI_Citation}. + * + *

    This method uses heuristic rules, first looking at the prefix, then the rest of the name in case of ambiguity. + * A namespace is returned on a best effort basis only; this method may or may not check the full name, and + * values returned by this method may change in future SIS versions (e.g. when new standards become supported by SIS + * or when existing standards are upgraded). This method should be used in last resort only, when this information + * can not be obtained easily in a more reliable way.

    + * + * @param type a class name defined by ISO 19115 or related standards (e.g. {@code "CI_Citation"}. + * @return a possible namespace for the given type, or {@code null} if unknown. + * + * @since 1.0 + */ + public static String guessForType(final String type) { + /* + * Implementation note: we could invoke FilteredStreamResolver.namespace(type) unconditionally, + * but that method may be removed in a future SIS version if we replace FilteredStreamResolver + * by XSD (https://issues.apache.org/jira/projects/SIS/issues/SIS-381). By using a switch now, + * we reduce the behavioral change is SIS-381 is applied. It can also reduce classes loading. + */ + if (type != null && type.length() >= 3) { + if (type.charAt(2) == '_') { + switch ((type.charAt(0) << Character.SIZE) | type.charAt(1)) { + case ('C' << Character.SIZE) | 'I': return CIT; + case ('E' << Character.SIZE) | 'X': return GEX; + case ('F' << Character.SIZE) | 'C': return GFC; + case ('L' << Character.SIZE) | 'E': + case ('L' << Character.SIZE) | 'I': return MRL; + case ('D' << Character.SIZE) | 'S': // Usually MDA except for DS_InitiativeTypeCode + case ('M' << Character.SIZE) | 'D': + case ('M' << Character.SIZE) | 'I': return FilteredStreamResolver.namespace(type); + case ('M' << Character.SIZE) | 'X': return MDT; + case ('P' << Character.SIZE) | 'T': return LAN; + case ('S' << Character.SIZE) | 'V': return SRV; + case ('C' << Character.SIZE) | 'S': + case ('C' << Character.SIZE) | 'D': + case ('S' << Character.SIZE) | 'C': return GML; + } + } else { + // Needs to handle at least DCPList + return FilteredStreamResolver.namespace(type); + } + } + return null; + } } Modified: sis/branches/ISO-19115-3/core/sis-utility/src/main/resources/org/apache/sis/xml/NamespaceContent.txt URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-utility/src/main/resources/org/apache/sis/xml/NamespaceContent.txt?rev=1821259&r1=1821258&r2=1821259&view=diff ============================================================================== --- sis/branches/ISO-19115-3/core/sis-utility/src/main/resources/org/apache/sis/xml/NamespaceContent.txt [UTF-8] (original) +++ sis/branches/ISO-19115-3/core/sis-utility/src/main/resources/org/apache/sis/xml/NamespaceContent.txt [UTF-8] Tue Jan 16 15:48:34 2018 @@ -4,6 +4,13 @@ # Lines with two-spaces indentation are classes. # Lines with four-spaces indentation are attributes. # +http://www.isotc211.org/2005/gmd + RS_Identifier + + authority + code + codeSpace + version http://standards.iso.org/iso/19115/-3/cit/1.0 CI_Address @@ -440,12 +447,6 @@ http://standards.iso.org/iso/19115/-3/md referenceSystemInfo resourceLineage spatialRepresentationInfo - RS_Identifier - - authority - code - codeSpace - version URL http://standards.iso.org/iso/19115/-3/mex/1.0 @@ -1003,7 +1004,7 @@ http://standards.iso.org/iso/19115/-3/sr serviceStandard serviceType serviceTypeVersion -http://standards.iso.org/iso/19157/-2/dqc/1.0 +http://standards.iso.org/iso/19157/-2/mdq/1.0 DQ_AbsoluteExternalPositionalAccuracy dateTime Modified: sis/branches/ISO-19115-3/core/sis-utility/src/test/java/org/apache/sis/xml/NamespacesTest.java URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-utility/src/test/java/org/apache/sis/xml/NamespacesTest.java?rev=1821259&r1=1821258&r2=1821259&view=diff ============================================================================== --- sis/branches/ISO-19115-3/core/sis-utility/src/test/java/org/apache/sis/xml/NamespacesTest.java [UTF-8] (original) +++ sis/branches/ISO-19115-3/core/sis-utility/src/test/java/org/apache/sis/xml/NamespacesTest.java [UTF-8] Tue Jan 16 15:48:34 2018 @@ -26,7 +26,7 @@ import static org.junit.Assert.*; * Tests the {@link Namespaces} class. * * @author Martin Desruisseaux (Geomatys) - * @version 0.8 + * @version 1.0 * @since 0.8 * @module */ @@ -38,4 +38,18 @@ public final strictfp class NamespacesTe public void testGetPreferredPrefix() { assertEquals("gml", Namespaces.getPreferredPrefix("http://www.opengis.net/gml/3.2", null)); } + + /** + * Tests {@link Namespaces#guessForType(String)}. This method uses {@code assertSame(…)} instead than + * {@code assertEquals(…)} for verifying that {@link FilteredStreamResolver} invoked {@link String#intern()}. + */ + @Test + public void testGuessForType() { + assertSame("CI_Citation", Namespaces.CIT, Namespaces.guessForType("CI_Citation")); + assertSame("EX_Extent", Namespaces.GEX, Namespaces.guessForType("EX_Extent")); + assertSame("MD_Metadata", Namespaces.MDB, Namespaces.guessForType("MD_Metadata")); + assertSame("MD_DataIdentification", Namespaces.MRI, Namespaces.guessForType("MD_DataIdentification")); + assertSame("DS_InitiativeTypeCode", Namespaces.MRI, Namespaces.guessForType("DS_InitiativeTypeCode")); + assertSame("DCPList", Namespaces.SRV, Namespaces.guessForType("DCPList")); + } }