Author: desruisseaux Date: Thu Feb 15 17:28:51 2018 New Revision: 1824334 URL: http://svn.apache.org/viewvc?rev=1824334&view=rev Log: Fix unmarshalling of ServiceIdentification. Marshalling still needs to be fixed.
Removed: sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_MemberName.java sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_ScopedName.java Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/replace/ServiceParameter.java sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/replace/package-info.java sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultCoupledResource.java sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/package-info.java sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultServiceIdentificationTest.java sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_GenericName.java sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/NameAdapter.java sis/branches/ISO-19115-3/core/sis-utility/src/main/resources/org/apache/sis/xml/NamespaceContent.txt Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/replace/ServiceParameter.java URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/replace/ServiceParameter.java?rev=1824334&r1=1824333&r2=1824334&view=diff ============================================================================== --- sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/replace/ServiceParameter.java [UTF-8] (original) +++ sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/replace/ServiceParameter.java [UTF-8] Thu Feb 15 17:28:51 2018 @@ -21,6 +21,7 @@ import java.util.Objects; import javax.xml.bind.annotation.XmlType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import javax.measure.Unit; import org.opengis.util.TypeName; import org.opengis.util.MemberName; @@ -33,11 +34,14 @@ import org.opengis.parameter.ParameterDe import org.apache.sis.internal.simple.SimpleIdentifiedObject; import org.apache.sis.internal.jaxb.FilterByVersion; import org.apache.sis.internal.jaxb.LegacyNamespaces; +import org.apache.sis.internal.jaxb.gco.GO_GenericName; import org.apache.sis.internal.metadata.ReferencingServices; import org.apache.sis.internal.metadata.NameToIdentifier; -import org.apache.sis.util.ComparisonMode; +import org.apache.sis.util.iso.DefaultMemberName; import org.apache.sis.util.iso.Names; import org.apache.sis.xml.Namespaces; +import org.apache.sis.util.ComparisonMode; +import org.apache.sis.util.resources.Errors; import static org.apache.sis.util.Utilities.deepEquals; import static org.apache.sis.internal.util.CollectionsExt.nonNull; @@ -68,7 +72,8 @@ import static org.apache.sis.internal.ut */ @SuppressWarnings("rawtypes") // For the omission of <T> in ParameterDescriptor<T> - see javadoc. @XmlType(name = "SV_Parameter_Type", namespace = Namespaces.SRV, propOrder = { - "memberName", + "memberName", // The ISO 19115-3:2016 way to marshal name. + "legacyName", // Legacy ISO 19139:2007 way to marshal name. "direction", "description", "optionality", @@ -87,11 +92,23 @@ public final class ServiceParameter exte * The name, as used by the service for this parameter. Note that in ISO 19115-3:2016, this element is * inside a {@code <gco:MemberName>} element (i.e. ISO inserts the same kind of {@code Property_Type} * element as it does for all other attributes) while in ISO 19139:2007 it was not (i.e. name attributes - * like {@code <gco:aName>} were marshalled directly, without wrapper). + * like {@code <gco:aName>} were marshalled directly, without wrapper). Example: + * + * {@preformat xml + * <srv:name> + * <gco:MemberName> + * <gco:aName> + * <gco:CharacterString>A parameter name</gco:CharacterString> + * </gco:aName> + * </gco:MemberName> + * </srv:name> + * } * + * @see #getLegacyName() * @see #getValueType() */ @XmlElement(required=true, name="name") + @XmlJavaTypeAdapter(GO_GenericName.Since2014.class) MemberName memberName; /** @@ -199,6 +216,48 @@ public final class ServiceParameter exte } /** + * Returns the name to be marshalled in the ISO 19139:2007 way. Example: + * + * {@preformat xml + * <srv:name> + * <gco:aName> + * <gco:CharacterString>A parameter name</gco:CharacterString> + * </gco:aName> + * </srv:name> + * } + * + * @return the name if marshalling legacy ISO 19139:2007 format, or {@code null} otherwise. + */ + @XmlElement(name = "name", namespace = LegacyNamespaces.SRV) + private DefaultMemberName getLegacyName() { + return FilterByVersion.LEGACY_METADATA.accept() ? DefaultMemberName.castOrCopy(memberName) : null; + } + + /** + * Sets the value from the {@code <gco:aName>} (legacy ISO 19139:2007 format). + * This method is called at unmarshalling-time by JAXB. + * + * @param value the new name. + * @throws IllegalStateException if a name is already defined. + */ + @SuppressWarnings("unused") + private void setLegacyName(final DefaultMemberName value) { + ensureUndefined(); + memberName = value; + } + + /** + * Ensures that the {@linkplain #memberName} is not already defined. + * + * @throws IllegalStateException if a name is already defined. + */ + private void ensureUndefined() throws IllegalStateException { + if (memberName != null) { + throw new IllegalStateException(Errors.format(Errors.Keys.ValueAlreadyDefined_1, "name")); + } + } + + /** * Returns the name as an {@code Identifier}, which is the type requested by ISO 19111. * Note that this is different than the type requested by ISO 19115, which is {@link MemberName}. * @@ -232,11 +291,12 @@ public final class ServiceParameter exte } /** - * For JAXB marshalling of ISO 19139 document only. + * For JAXB marshalling of ISO 19139:2007 document only. * Note that there is not setter method, since we expect the same information * to be provided in the {@link #name} attribute type. */ @XmlElement(name = "valueType", namespace = LegacyNamespaces.SRV) + @XmlJavaTypeAdapter(GO_GenericName.class) // Not in package-info because shall not be applied to getLegacyName(). final TypeName getValueType() { if (memberName != null && FilterByVersion.LEGACY_METADATA.accept()) { return memberName.getAttributeType(); Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/replace/package-info.java URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/replace/package-info.java?rev=1824334&r1=1824333&r2=1824334&view=diff ============================================================================== --- sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/replace/package-info.java [UTF-8] (original) +++ sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/replace/package-info.java [UTF-8] Thu Feb 15 17:28:51 2018 @@ -44,8 +44,6 @@ @XmlAccessorType(XmlAccessType.NONE) @XmlJavaTypeAdapters({ @XmlJavaTypeAdapter(GO_Boolean.class), - @XmlJavaTypeAdapter(GO_GenericName.class), - @XmlJavaTypeAdapter(GO_MemberName.class), @XmlJavaTypeAdapter(SV_ParameterDirection.class), // Java types, primitive types and basic OGC types handling Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultCoupledResource.java URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultCoupledResource.java?rev=1824334&r1=1824333&r2=1824334&view=diff ============================================================================== --- sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultCoupledResource.java [UTF-8] (original) +++ sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultCoupledResource.java [UTF-8] Thu Feb 15 17:28:51 2018 @@ -21,6 +21,7 @@ import javax.xml.bind.annotation.XmlType import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; import org.opengis.util.ScopedName; import org.opengis.metadata.citation.Citation; import org.opengis.metadata.identification.DataIdentification; @@ -30,6 +31,9 @@ import org.apache.sis.metadata.iso.ISOMe import org.apache.sis.internal.jaxb.metadata.SV_OperationMetadata; import org.apache.sis.internal.jaxb.FilterByVersion; import org.apache.sis.internal.jaxb.LegacyNamespaces; +import org.apache.sis.internal.jaxb.gco.GO_GenericName; +import org.apache.sis.util.iso.DefaultNameSpace; +import org.apache.sis.util.iso.Names; import org.apache.sis.xml.Namespaces; @@ -54,12 +58,13 @@ import org.apache.sis.xml.Namespaces; */ @SuppressWarnings("CloneableClassWithoutClone") // ModifiableMetadata needs shallow clones. @XmlType(name = "SV_CoupledResource_Type", namespace = Namespaces.SRV, propOrder = { - "scopedName", + "scopedName", // ISO 19115-3:2016 way to write scoped name "resourceReference", // New in ISO 19115:2014 "resource", // Ibid. "operation", // Ibid. "operationName", // Legacy ISO 19139:2007 - "identifier" // Ibid. + "identifier", // Ibid. + "legacyName" // Legacy ISO 19139:2007 way to write scoped name }) @XmlRootElement(name = "SV_CoupledResource", namespace = Namespaces.SRV) public class DefaultCoupledResource extends ISOMetadata implements CoupledResource { @@ -164,6 +169,7 @@ public class DefaultCoupledResource exte */ @Override @XmlElement(name = "scopedName") + @XmlJavaTypeAdapter(GO_GenericName.Since2014.class) public ScopedName getScopedName() { return scopedName; } @@ -297,6 +303,42 @@ public class DefaultCoupledResource exte } /** + * Returns the {@code <gco:ScopedName>} element to marshal in legacy ISO 19139:2007 element. + * The {@code <srv:scopedName>} element wrapper (note the lower-case "s") was missing in that + * legacy specification. This departure from ISO patterns has been fixed in ISO 19115-3:2016. + * + * <p>Note that the namespace is {@value Namespaces#GCO} rather than {@value LegacyNamespaces#GCO} + * because this is the namespace of the {@link ScopedName} type, not the namespace of a property + * in {@code SV_CoupledResource}.</p> + */ + @XmlElement(name = "ScopedName", namespace = Namespaces.GCO) + @XmlJavaTypeAdapter(CollapsedStringAdapter.class) + private String getLegacyName() { + if (FilterByVersion.LEGACY_METADATA.accept()) { + final ScopedName name = getScopedName(); + if (name != null) return name.toString(); + } + return null; + } + + /** + * Invoked by JAXB when unmarshalling a legacy ISO 19139:2007 documents. + */ + @SuppressWarnings("unused") + private void setLegacyName(String value) { + if (value != null && !value.isEmpty()) { + /* + * If the given name does not have a namespace, add an arbitrary namespace + * in order to get an instanceof ScopedName instead of LocalName after parsing. + */ + if (value.indexOf(DefaultNameSpace.DEFAULT_SEPARATOR) < 0) { + value = "global" + DefaultNameSpace.DEFAULT_SEPARATOR + value; + } + setScopedName((ScopedName) Names.parseGenericName(null, null, value)); + } + } + + /** * Invoked by JAXB at both marshalling and unmarshalling time. * This attribute has been added by ISO 19115:2014 standard. * If (and only if) marshalling an older standard version, we omit this attribute. Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/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/identification/package-info.java?rev=1824334&r1=1824333&r2=1824334&view=diff ============================================================================== --- sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/package-info.java [UTF-8] (original) +++ sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/package-info.java [UTF-8] Thu Feb 15 17:28:51 2018 @@ -119,7 +119,6 @@ @XmlJavaTypeAdapter(EX_Extent.class), @XmlJavaTypeAdapter(GO_DateTime.class), @XmlJavaTypeAdapter(GO_GenericName.class), - @XmlJavaTypeAdapter(GO_ScopedName.class), @XmlJavaTypeAdapter(MD_AggregateInformation.class), @XmlJavaTypeAdapter(MD_AssociatedResource.class), @XmlJavaTypeAdapter(MD_BrowseGraphic.class), Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultServiceIdentificationTest.java URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultServiceIdentificationTest.java?rev=1824334&r1=1824333&r2=1824334&view=diff ============================================================================== --- sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultServiceIdentificationTest.java [UTF-8] (original) +++ sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/identification/DefaultServiceIdentificationTest.java [UTF-8] Thu Feb 15 17:28:51 2018 @@ -109,26 +109,6 @@ public final strictfp class DefaultServi } /** - * Tests the marshalling of a service metadata. - * - * @throws JAXBException if an error occurred during the during marshalling process. - */ - @Test - public void testMarshal() throws JAXBException { - assertMarshalEqualsFile(XML_FILE, create(), "xlmns:*", "xsi:schemaLocation"); - } - - /** - * Tests the marshalling of a service metadata to legacy ISO 19139:2007 schema. - * - * @throws JAXBException if an error occurred during the during marshalling process. - */ - @Test - public void testMarshalLegacy() throws JAXBException { - assertMarshalEqualsFile(XML_FILE_LEGACY, create(), VERSION_2007, "xlmns:*", "xsi:schemaLocation"); - } - - /** * Tests the unmarshalling of a service metadata. * * <p><b>XML test file:</b> @@ -156,4 +136,24 @@ public final strictfp class DefaultServi final CoupledResource resource = getSingleton(id.getCoupledResources()); assertEquals("scopedName", "mySpace:ABC-123", String.valueOf(resource.getScopedName())); } + + /** + * Tests the marshalling of a service metadata. + * + * @throws JAXBException if an error occurred during the during marshalling process. + */ + @Test + public void testMarshal() throws JAXBException { + assertMarshalEqualsFile(XML_FILE, create(), "xlmns:*", "xsi:schemaLocation"); + } + + /** + * Tests the marshalling of a service metadata to legacy ISO 19139:2007 schema. + * + * @throws JAXBException if an error occurred during the during marshalling process. + */ + @Test + public void testMarshalLegacy() throws JAXBException { + assertMarshalEqualsFile(XML_FILE_LEGACY, create(), VERSION_2007, "xmlns:*", "xsi:schemaLocation"); + } } Modified: sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_GenericName.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_GenericName.java?rev=1824334&r1=1824333&r2=1824334&view=diff ============================================================================== --- sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_GenericName.java [UTF-8] (original) +++ sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_GenericName.java [UTF-8] Thu Feb 15 17:28:51 2018 @@ -17,6 +17,7 @@ package org.apache.sis.internal.jaxb.gco; import org.opengis.util.GenericName; +import org.apache.sis.internal.jaxb.FilterByVersion; /** @@ -34,11 +35,11 @@ import org.opengis.util.GenericName; * @author Cédric Briançon (Geomatys) * @author Martin Desruisseaux (Geomatys) * @author Guilhem Legal (Geomatys) - * @version 0.3 + * @version 1.0 * @since 0.3 * @module */ -public final class GO_GenericName extends NameAdapter<GO_GenericName, GenericName> { +public class GO_GenericName extends NameAdapter<GO_GenericName, GenericName> { /** * Empty constructor for JAXB only. */ @@ -72,7 +73,26 @@ public final class GO_GenericName extend * @return the implementing class. */ @Override - public GenericName unmarshal(final GO_GenericName value) { + public final GenericName unmarshal(final GO_GenericName value) { return (value != null) ? value.name : null; } + + /** + * Wraps the value only if marshalling ISO 19115-3 element. + * Otherwise (i.e. if marshalling a legacy ISO 19139:2007 document), omit the element. + */ + public static final class Since2014 extends GO_GenericName { + /** Empty constructor used only by JAXB. */ + public Since2014() { + } + + /** + * Wraps the given value in an ISO 19115-3 element, unless we are marshalling an older document. + * + * @return a non-null value only if marshalling ISO 19115-3 or newer. + */ + @Override public GO_GenericName marshal(final GenericName value) { + return FilterByVersion.CURRENT_METADATA.accept() ? super.marshal(value) : null; + } + } } Modified: sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/NameAdapter.java URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/NameAdapter.java?rev=1824334&r1=1824333&r2=1824334&view=diff ============================================================================== --- sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/NameAdapter.java [UTF-8] (original) +++ sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/NameAdapter.java [UTF-8] Thu Feb 15 17:28:51 2018 @@ -64,17 +64,6 @@ abstract class NameAdapter<ValueType ext } /** - * Ensures that the {@linkplain #name} is not already defined. - * - * @throws IllegalStateException if a name is already defined. - */ - private void ensureUndefined() throws IllegalStateException { - if (name != null) { - throw new IllegalStateException(Errors.format(Errors.Keys.ValueAlreadyDefined_1, "name")); - } - } - - /** * Returns the {@code LocalName} or {@code ScopedName} to marshal. Returns {@code null} if the name * is a {@link TypeName} or a {@link MemberName}, in order to use {@link #getName()} instead. * Example: @@ -163,4 +152,15 @@ abstract class NameAdapter<ValueType ext ensureUndefined(); name = value; } + + /** + * Ensures that the {@linkplain #name} is not already defined. + * + * @throws IllegalStateException if a name is already defined. + */ + private void ensureUndefined() throws IllegalStateException { + if (name != null) { + throw new IllegalStateException(Errors.format(Errors.Keys.ValueAlreadyDefined_1, "name")); + } + } } 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=1824334&r1=1824333&r2=1824334&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] Thu Feb 15 17:28:51 2018 @@ -975,7 +975,6 @@ http://standards.iso.org/iso/19115/-3/sr <type> description direction - name repeatability valueType SV_ParameterDirection