Author: desruisseaux
Date: Sat Dec 7 01:20:39 2013
New Revision: 1548771
URL: http://svn.apache.org/r1548771
Log:
Fix JAXB annotation on the identifier, and add tests.
Added:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/RS_IdentifierSingleton.java
(with props)
sis/branches/JDK7/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Paris.xml
(with props)
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/RS_Identifier.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DatumTestCase.java
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java
sis/branches/JDK7/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Greenwich.xml
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/RS_Identifier.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/RS_Identifier.java?rev=1548771&r1=1548770&r2=1548771&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/RS_Identifier.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/RS_Identifier.java
[UTF-8] Sat Dec 7 01:20:39 2013
@@ -84,9 +84,6 @@ public final class RS_Identifier extends
Value(final ReferenceIdentifier identifier) {
code = identifier.getCode();
codeSpace = identifier.getCodeSpace();
- if (codeSpace == null) {
- codeSpace = "";
- }
String version = identifier.getVersion();
if (version != null) {
final StringBuilder buffer = new StringBuilder(codeSpace);
@@ -97,6 +94,14 @@ public final class RS_Identifier extends
codeSpace = buffer.toString();
}
}
+
+ /**
+ * Returns the identifier for this value. This method is the converse
of the constructor.
+ */
+ ReferenceIdentifier getIdentifier() {
+ final Citation authority = Citations.fromName(codeSpace); // May
be null.
+ return new ImmutableIdentifier(authority,
Citations.getIdentifier(authority), code);
+ }
}
/**
@@ -108,11 +113,7 @@ public final class RS_Identifier extends
*/
@Override
public ReferenceIdentifier unmarshal(final Value value) {
- if (value != null) {
- final Citation authority = Citations.fromName(value.codeSpace); //
May be null.
- return new ImmutableIdentifier(authority,
Citations.getIdentifier(authority), value.code);
- }
- return null;
+ return (value != null) ? value.getIdentifier() : null;
}
/**
Added:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/RS_IdentifierSingleton.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/RS_IdentifierSingleton.java?rev=1548771&view=auto
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/RS_IdentifierSingleton.java
(added)
+++
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/RS_IdentifierSingleton.java
[UTF-8] Sat Dec 7 01:20:39 2013
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.jaxb.referencing;
+
+import java.util.Set;
+import java.util.Iterator;
+import org.opengis.referencing.ReferenceIdentifier;
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
+import static java.util.Collections.singleton;
+
+
+/**
+ * A JAXB adapter for expressing the {@code Set<ReferenceIdentifier>}
collection as a singleton.
+ * We have to define this adapter because ISO 19111 defines the {@code
identifiers} property as
+ * a collection while GML 3.2 defines it as a singleton.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.4
+ * @version 0.4
+ * @module
+ */
+public final class RS_IdentifierSingleton extends
XmlAdapter<RS_Identifier.Value, Set<ReferenceIdentifier>> {
+ /**
+ * Substitutes the wrapper value read from an XML stream by the object
which will
+ * represents the identifier. JAXB calls automatically this method at
unmarshalling time.
+ *
+ * @param value The wrapper for this metadata value.
+ * @return An identifier which represents the value.
+ */
+ @Override
+ public Set<ReferenceIdentifier> unmarshal(final RS_Identifier.Value value)
{
+ return (value != null) ? singleton(value.getIdentifier()) : null;
+ }
+
+ /**
+ * Substitutes the first identifier by the wrapper to be marshalled into
an XML file or stream.
+ * Only the first identifier is taken, on the assumption that it is the
"main" one.
+ *
+ * @param value The metadata value.
+ * @return The adapter for the given metadata.
+ */
+ @Override
+ public RS_Identifier.Value marshal(final Set<ReferenceIdentifier> value) {
+ if (value != null) {
+ final Iterator<ReferenceIdentifier> it = value.iterator();
+ if (it.hasNext()) {
+ return new RS_Identifier.Value(it.next());
+ }
+ }
+ return null;
+ }
+}
Propchange:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/RS_IdentifierSingleton.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/RS_IdentifierSingleton.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java?rev=1548771&r1=1548770&r2=1548771&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
[UTF-8] Sat Dec 7 01:20:39 2013
@@ -37,7 +37,7 @@ import org.opengis.referencing.ObjectFac
import org.opengis.referencing.AuthorityFactory;
import org.opengis.referencing.IdentifiedObject;
import org.opengis.referencing.ReferenceIdentifier;
-import org.apache.sis.internal.jaxb.referencing.RS_Identifier;
+import org.apache.sis.internal.jaxb.referencing.RS_IdentifierSingleton;
import org.apache.sis.io.wkt.FormattableObject;
import org.apache.sis.xml.Namespaces;
import org.apache.sis.util.Immutable;
@@ -106,8 +106,9 @@ import java.util.Objects;
@Immutable
@ThreadSafe
@XmlType(name="IdentifiedObjectType", propOrder={
- "identifier",
- "name"
+ "identifiers",
+ "name",
+ "remarks"
})
@XmlSeeAlso({
AbstractReferenceSystem.class,
@@ -127,10 +128,8 @@ public class AbstractIdentifiedObject ex
* The name for this object or code. Should never be {@code null}.
*
* @see #getName()
- * @see #getIdentifier()
*/
@XmlElement
- @XmlJavaTypeAdapter(RS_Identifier.class) // Not the same RS_Identifier
than metadata.
private final ReferenceIdentifier name;
/**
@@ -148,13 +147,15 @@ public class AbstractIdentifiedObject ex
* "no identifiers" because we may get both on unmarshalling.</p>
*
* @see #getIdentifiers()
- * @see #getIdentifier()
*/
+ @XmlElement(name = "identifier")
+ @XmlJavaTypeAdapter(RS_IdentifierSingleton.class)
private final Set<ReferenceIdentifier> identifiers;
/**
* Comments on or information about this object, or {@code null} if none.
*/
+ @XmlElement(name = "remarks")
private final InternationalString remarks;
/**
@@ -440,18 +441,6 @@ public class AbstractIdentifiedObject ex
}
/**
- * Returns the first identifier found, or {@code null} if none.
- * This method is invoked by JAXB at marshalling time.
- *
- * @see #name
- */
- @XmlElement(name = "identifier")
- final ReferenceIdentifier getIdentifier() {
- final Iterator<ReferenceIdentifier> it = iterator(identifiers);
- return (it != null && it.hasNext()) ? it.next() : null;
- }
-
- /**
* Returns comments on or information about this object, including data
source information.
*
* @return The remarks, or {@code null} if none.
Modified:
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java?rev=1548771&r1=1548770&r2=1548771&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java
[UTF-8] Sat Dec 7 01:20:39 2013
@@ -57,7 +57,6 @@ public final strictfp class AbstractIden
assertNull ("version",
object.getName().getVersion());
assertTrue ("aliases",
object.getAlias().isEmpty());
assertTrue ("identifiers",
object.getIdentifiers().isEmpty());
- assertNull ("identifier",
object.getIdentifier());
assertEquals("ID", "Thisisaname", object.getID());
assertEquals("remarks", "There is remarks",
object.getRemarks().toString(Locale.ENGLISH));
assertEquals("remarks_fr", "Voici des remarques",
object.getRemarks().toString(Locale.FRENCH));
@@ -90,7 +89,6 @@ public final strictfp class AbstractIden
assertEquals("name", "WGS 84",
object.getName().getCode());
assertEquals("identifiers", "[EPSG:4326, EPSG:IgnoreMe]",
object.getIdentifiers().toString());
- assertEquals("identifier", "EPSG:4326",
object.getIdentifier().toString());
assertEquals("ID", "EPSG4326",
object.getID());
}
Modified:
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DatumTestCase.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DatumTestCase.java?rev=1548771&r1=1548770&r2=1548771&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DatumTestCase.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DatumTestCase.java
[UTF-8] Sat Dec 7 01:20:39 2013
@@ -19,6 +19,8 @@ package org.apache.sis.referencing.datum
import java.net.URL;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.JAXBException;
+import javax.measure.unit.NonSI;
+import org.opengis.referencing.datum.PrimeMeridian;
import org.apache.sis.xml.MarshallerPool;
import org.apache.sis.test.XMLTestCase;
@@ -41,6 +43,24 @@ abstract strictfp class DatumTestCase ex
}
/**
+ * Asserts the the given prime meridian is the Greenwich one.
+ */
+ static void assertIsGreenwichMeridian(final PrimeMeridian meridian) {
+ assertEquals("name", "Greenwich", meridian.getName().getCode());
+ assertEquals("greenwichLongitude", 0,
meridian.getGreenwichLongitude(), 0);
+ assertEquals("angularUnit", NonSI.DEGREE_ANGLE,
meridian.getAngularUnit());
+ }
+
+ /**
+ * Asserts the the given prime meridian is the Paris one.
+ */
+ static void assertIsParisMeridian(final PrimeMeridian meridian) {
+ assertEquals("name", "Paris", meridian.getName().getCode());
+ assertEquals("greenwichLongitude", 2.5969213,
meridian.getGreenwichLongitude(), 0);
+ assertEquals("angularUnit", NonSI.GRADE, meridian.getAngularUnit());
+ }
+
+ /**
* Unmarshalls the given test file.
*
* @param type The expected object type.
Modified:
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java?rev=1548771&r1=1548770&r2=1548771&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java
[UTF-8] Sat Dec 7 01:20:39 2013
@@ -20,13 +20,13 @@ import javax.measure.unit.NonSI;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.JAXBException;
-import org.opengis.referencing.datum.PrimeMeridian;
import org.apache.sis.xml.XML;
import org.apache.sis.xml.Namespaces;
import org.apache.sis.xml.MarshallerPool;
import org.apache.sis.util.CharSequences;
import org.apache.sis.internal.jaxb.LegacyNamespaces;
import org.apache.sis.test.DependsOnMethod;
+import org.apache.sis.test.DependsOn;
import org.junit.Test;
import static org.apache.sis.referencing.Assert.*;
@@ -41,23 +41,15 @@ import static org.apache.sis.test.mock.P
* @version 0.4
* @module
*/
+@DependsOn(org.apache.sis.referencing.AbstractIdentifiedObjectTest.class)
public final strictfp class DefaultPrimeMeridianTest extends DatumTestCase {
/**
- * Asserts the the given prime meridian is the Greenwich one.
- */
- private static void assertIsGreenwich(final PrimeMeridian meridian) {
- assertEquals("name", "Greenwich", meridian.getName().getCode());
- assertEquals("greenwichLongitude", 0,
meridian.getGreenwichLongitude(), 0);
- assertEquals("", NonSI.DEGREE_ANGLE, meridian.getAngularUnit());
- }
-
- /**
* Tests {@link DefaultPrimeMeridian#toWKT()}.
*/
@Test
public void testToWKT() {
final DefaultPrimeMeridian pm = new DefaultPrimeMeridian(GREENWICH);
- assertIsGreenwich(pm);
+ assertIsGreenwichMeridian(pm);
assertWktEquals(pm, "PRIMEM[“Greenwich”, 0.0]");
}
@@ -113,14 +105,14 @@ public final strictfp class DefaultPrime
*/
@Test
public void testUnmarshall() throws JAXBException {
- DefaultPrimeMeridian pm = unmarshall(DefaultPrimeMeridian.class,
"Greenwich.xml");
- assertIsGreenwich(pm);
+ final DefaultPrimeMeridian pm = unmarshall(DefaultPrimeMeridian.class,
"Greenwich.xml");
+ assertIsGreenwichMeridian(pm);
}
/**
* Tests marshalling in the GML 3.1 namespace.
*
- * @throws JAXBException If an error occurred during marshalling.
+ * @throws JAXBException If an error occurred during unmarshalling.
*/
@Test
@DependsOnMethod("testUnmarshall")
@@ -128,8 +120,33 @@ public final strictfp class DefaultPrime
final MarshallerPool pool = getMarshallerPool();
final Unmarshaller unmarshaller = pool.acquireUnmarshaller();
unmarshaller.setProperty(XML.GML_VERSION,
LegacyNamespaces.VERSION_3_0);
- PrimeMeridian pm = (PrimeMeridian) unmarshal(unmarshaller,
getGreenwichXml(LegacyNamespaces.GML));
+ final DefaultPrimeMeridian pm = (DefaultPrimeMeridian)
+ unmarshal(unmarshaller, getGreenwichXml(LegacyNamespaces.GML));
pool.recycle(unmarshaller);
- assertIsGreenwich(pm);
+ assertIsGreenwichMeridian(pm);
+ }
+
+ /**
+ * Tests unmarshalling of Paris prime meridian.
+ *
+ * @throws JAXBException If an error occurred during unmarshalling.
+ */
+ @Test
+ @DependsOnMethod({"testUnmarshall", "testMarshall"})
+ public void testParisMeridian() throws JAXBException {
+ final DefaultPrimeMeridian pm = unmarshall(DefaultPrimeMeridian.class,
"Paris.xml");
+ assertIsParisMeridian(pm);
+ assertEquals("greenwichLongitude", 2.33722917,
pm.getGreenwichLongitude(NonSI.DEGREE_ANGLE), 1E-12);
+ assertEquals("Equivalent to 2°20′14.025″.",
pm.getRemarks().toString());
+ assertNull("name.codeSpace", pm.getName().getCodeSpace());
+ assertWktEquals(pm, "PRIMEM[“Paris”, 2.33722917, AUTHORITY[“OGP”,
“urn:ogc:def:meridian:EPSG::8903”]]");
+ assertXmlEquals(
+ "<gml:PrimeMeridian xmlns:gml=\"" + Namespaces.GML + "\">\n" +
+ " <gml:identifier
codeSpace=\"OGP\">urn:ogc:def:meridian:EPSG::8903</gml:identifier>" +
+ " <gml:name>Paris</gml:name>\n" +
+ " <gml:remarks>Equivalent to 2°20′14.025″.</gml:remarks>\n" +
+ " <gml:greenwichLongitude
uom=\"urn:ogc:def:uom:EPSG::9105\">2.5969213</gml:greenwichLongitude>\n" +
+ "</gml:PrimeMeridian>\n",
+ marshal(pm), "xmlns:*", "xsi:schemaLocation");
}
}
Modified:
sis/branches/JDK7/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Greenwich.xml
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Greenwich.xml?rev=1548771&r1=1548770&r2=1548771&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Greenwich.xml
(original)
+++
sis/branches/JDK7/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Greenwich.xml
Sat Dec 7 01:20:39 2013
@@ -18,7 +18,7 @@
under the License.
-->
-<gml:PrimeMeridian gml:id = "epsg-meridian-8901"
+<gml:PrimeMeridian
xmlns:gml = "http://www.opengis.net/gml/3.2"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://www.opengis.net/gml/3.2
http://schemas.opengis.net/gml/3.2.1/datums.xsd">
Added:
sis/branches/JDK7/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Paris.xml
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Paris.xml?rev=1548771&view=auto
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Paris.xml
(added)
+++
sis/branches/JDK7/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Paris.xml
Sat Dec 7 01:20:39 2013
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+
+<gml:PrimeMeridian
+ xmlns:gml = "http://www.opengis.net/gml/3.2"
+ xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation = "http://www.opengis.net/gml/3.2
http://schemas.opengis.net/gml/3.2.1/datums.xsd">
+
+ <gml:identifier
codeSpace="OGP">urn:ogc:def:meridian:EPSG::8903</gml:identifier>
+ <gml:name>Paris</gml:name>
+ <gml:greenwichLongitude
uom="urn:ogc:def:uom:EPSG::9105">2.5969213</gml:greenwichLongitude>
+ <gml:remarks>Equivalent to 2°20â²14.025â³.</gml:remarks>
+</gml:PrimeMeridian>
Propchange:
sis/branches/JDK7/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Paris.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK7/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Paris.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml