sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1552966 - in /sis/branches/JDK7/core: sis-metadata/src/main/java/org/apache/sis/metadata/ sis-metadata/src/main/java/org/apache/sis/metadata/iso/ sis-metadata/src/test/java/org/apache/sis/metadata/iso/ sis-metadata/src/test/java/org/apache...
Date Sun, 22 Dec 2013 06:01:26 GMT
Author: desruisseaux
Date: Sun Dec 22 06:01:25 2013
New Revision: 1552966

URL: http://svn.apache.org/r1552966
Log:
AbstractIdentifiedObject.getIdentifier() now build a URN in OGC namespace.

Added:
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultIdentifierTest.java
  (with props)
Modified:
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyInformation.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultIdentifier.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/ImmutableIdentifierTest.java
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.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/DefaultEllipsoidTest.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/simple/SimpleReferenceIdentifier.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/DefinitionURITest.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/XMLComparator.java

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyInformation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyInformation.java?rev=1552966&r1=1552965&r2=1552966&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyInformation.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyInformation.java
[UTF-8] Sun Dec 22 06:01:25 2013
@@ -175,6 +175,24 @@ final class PropertyInformation<E> exten
     }
 
     /**
+     * Version identifier for the namespace, as specified by the code authority.
+     * When appropriate, the edition is identified by the effective date, coded
+     * using ISO 8601 date format.
+     *
+     * @return A version inferred from the authority given at construction time, or {@code
null} if none.
+     */
+    @Override
+    public String getVersion() {
+        if (authority != null) {
+            final InternationalString version = authority.getEdition();
+            if (version != null) {
+                return version.toString();
+            }
+        }
+        return super.getVersion();
+    }
+
+    /**
      * Unconditionally returns {@code null}.
      *
      * @deprecated This property was defined in the 2003 edition of ISO 19115,

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultIdentifier.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultIdentifier.java?rev=1552966&r1=1552965&r2=1552966&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultIdentifier.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultIdentifier.java
[UTF-8] Sun Dec 22 06:01:25 2013
@@ -25,6 +25,43 @@ import org.opengis.metadata.citation.Cit
 
 /**
  * Value uniquely identifying an object within a namespace.
+ * One or more {@code Identifier} instances can be associated to some metadata objects like
+ * {@linkplain org.apache.sis.metadata.iso.acquisition.DefaultOperation operation},
+ * {@linkplain org.apache.sis.metadata.iso.acquisition.DefaultPlatform platform},
+ * {@linkplain org.apache.sis.metadata.iso.acquisition.DefaultInstrument instrument},
+ * {@linkplain org.apache.sis.metadata.iso.acquisition.DefaultEvent event},
+ * {@linkplain org.apache.sis.metadata.iso.lineage.DefaultProcessing processing},
+ * {@linkplain org.apache.sis.metadata.iso.lineage.DefaultSource source},
+ * {@linkplain org.apache.sis.metadata.iso.content.DefaultImageDescription image description},
+ * {@linkplain org.apache.sis.metadata.iso.extent.DefaultGeographicDescription geographic
description}
+ * and more.
+ *
+ * <p>Referencing objects like
+ * {@linkplain org.apache.sis.referencing.cs.DefaultCoordinateSystemAxis coordinate system
axis},
+ * {@linkplain org.apache.sis.referencing.datum.DefaultGeodeticDatum geodetic datum},
+ * {@linkplain org.apache.sis.referencing.crs.DefaultGeographicCRS geographic CRS} and more
+ * rather use an {@code Identifier} sub-interface, namely {@link org.opengis.referencing.ReferenceIdentifier}.
+ * The later is implemented in SIS by {@link ImmutableIdentifier}, which is a class unrelated
to the usual
+ * {@code org.apache.metadata} hierarchy because of the immutable nature of referencing objects.</p>
+ *
+ * {@section Text, URN and XML representations}
+ * The XML representation of {@link DefaultIdentifier} is similar to the {@link ImmutableIdentifier}
+ * one except for the {@code "MD_"} prefix. Example:
+ *
+ * {@preformat xml
+ *   <gmd:MD_Identifier>
+ *     <gmd:code>
+ *       <gco:CharacterString>4326</gco:CharacterString>
+ *     </gmd:code>
+ *     <gmd:authority>
+ *       <gmd:CI_Citation>
+ *         <gmd:title>
+ *           <gco:CharacterString>EPSG</gco:CharacterString>
+ *         </gmd:title>
+ *       </gmd:CI_Citation>
+ *     </gmd:authority>
+ *   </gmd:MD_Identifier>
+ * }
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @author  Touraïvane (IRD)

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java?rev=1552966&r1=1552965&r2=1552966&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java
[UTF-8] Sun Dec 22 06:01:25 2013
@@ -26,6 +26,7 @@ import org.opengis.metadata.citation.Cit
 import org.opengis.parameter.InvalidParameterValueException;
 import org.opengis.referencing.ReferenceIdentifier;
 import org.opengis.util.InternationalString;
+import org.apache.sis.util.Debug;
 import org.apache.sis.util.Immutable;
 import org.apache.sis.util.Deprecable;
 import org.apache.sis.util.resources.Errors;
@@ -52,7 +53,67 @@ import java.util.Objects;
  *        to be immutable. For better safety, factory codes are encouraged to pass only immutable
  *        citations and immutable international strings to the constructors.}
  *
- * @author Martin Desruisseaux (Geomatys)
+ *
+ * {@section Text, URN and XML representations}
+ * Identifiers are represented in various ways depending on the context. In particular identifiers
are
+ * marshalled differently depending on whether they appear in a metadata object or a referencing
object.
+ * The following examples show an identifier for a Geographic Coordinate Reference System
(CRS)
+ * identified by code 4326 in the "EPSG" code space:
+ *
+ * <p><b><cite>Well Known Text</cite> (WKT) version 1</b></p>
+ * The WKT 1 format contains only the {@linkplain #getCodeSpace() code space} and the {@linkplain
#getCode() code}.
+ * If there is no code space, then the {@linkplain #getAuthority() authority} abbreviation
is used as a fallback.
+ * Example:
+ *
+ * {@preformat wkt
+ *   AUTHORITY["EPSG", "4326"]
+ * }
+ *
+ * <p><b><cite>Well Known Text</cite> (WKT) version 2</b></p>
+ * The WKT 2 format contains the {@linkplain #getCodeSpace() code space}, the {@linkplain
#getCode() code} and
+ * the {@linkplain #getVersion() version} if available. The WKT can optionally provides a
{@code URI} element,
+ * which expresses the same information in a different way (the URN syntax is described in
the next item below).
+ * Example:
+ *
+ * {@preformat wkt
+ *   ID["EPSG", 4326, URI["urn:ogc:def:crs:EPSG::4326"]]
+ * }
+ *
+ * <p><b>XML in referencing objects</b></p>
+ * The <cite>Definition identifier URNs in OGC namespace</cite> paper defines
a syntax for identifiers commonly
+ * found in Geographic Markup Language (GML) documents. Example:
+ *
+ * {@preformat xml
+ *   <gml:identifier codeSpace="OGP">urn:ogc:def:crs:EPSG::4326</gml:identifier>
+ * }
+ *
+ * In Apache SIS, the GML {@code codeSpace} attribute - despite its name - is mapped to the
identifier
+ * {@linkplain #getAuthority() authority}. The components of the URN value are mapped as
below:
+ *
+ * <blockquote><code>
+ * urn:ogc:def:&lt;type&gt;:&lt;{@linkplain #getCodeSpace() codespace}&gt;:&lt;{@linkplain
#getVersion() version}&gt;:&lt;{@linkplain #getCode() code}&gt;
+ * </code></blockquote>
+ *
+ * <p><b>XML in metadata objects</b></p>
+ * The XML representation of {@link ImmutableIdentifier} in a metadata is similar to the
{@link DefaultIdentifier}
+ * one except for the {@code "RS_"} prefix:
+ *
+ * {@preformat xml
+ *   <gmd:RS_Identifier>
+ *     <gmd:code>
+ *       <gco:CharacterString>4326</gco:CharacterString>
+ *     </gmd:code>
+ *     <gmd:authority>
+ *       <gmd:CI_Citation>
+ *         <gmd:title>
+ *           <gco:CharacterString>EPSG</gco:CharacterString>
+ *         </gmd:title>
+ *       </gmd:CI_Citation>
+ *     </gmd:authority>
+ *   </gmd:RS_Identifier>
+ * }
+ *
+ * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-3.03)
  * @version 0.4
  * @module
@@ -461,6 +522,7 @@ public class ImmutableIdentifier impleme
 
     /**
      * Returns a string representation of this identifier.
+     * The string representation is mostly for debugging purpose and may change in any future
SIS version.
      * The default implementation returns a pseudo-WKT format.
      *
      * {@note The <code>NamedIdentifier</code> subclass overrides this method
with a different behavior,
@@ -469,6 +531,7 @@ public class ImmutableIdentifier impleme
      * @see org.apache.sis.referencing.IdentifiedObjects#toString(Identifier)
      * @see org.apache.sis.referencing.NamedIdentifier#toString()
      */
+    @Debug
     @Override
     public String toString() {
         return SimpleIdentifiedObject.toString("IDENTIFIER", authority, codeSpace, code,
isDeprecated());

Added: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultIdentifierTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultIdentifierTest.java?rev=1552966&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultIdentifierTest.java
(added)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultIdentifierTest.java
[UTF-8] Sun Dec 22 06:01:25 2013
@@ -0,0 +1,91 @@
+/*
+ * 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.metadata.iso;
+
+import javax.xml.bind.JAXBException;
+import org.opengis.metadata.Identifier;
+import org.apache.sis.metadata.iso.citation.DefaultCitation;
+import org.apache.sis.util.CharSequences;
+import org.apache.sis.xml.Namespaces;
+import org.apache.sis.test.XMLTestCase;
+import org.apache.sis.test.DependsOn;
+import org.junit.*;
+
+import static org.apache.sis.test.Assert.*;
+
+
+/**
+ * Tests {@link DefaultIdentifier}.
+ *
+ * @author  Martin Desruisseaux
+ * @since   0.4
+ * @version 0.4
+ * @module
+ */
+@DependsOn(org.apache.sis.metadata.iso.citation.DefaultCitationTest.class)
+public final strictfp class DefaultIdentifierTest extends XMLTestCase {
+    /**
+     * The expected XML representation for this test.
+     */
+    private static final String XML =
+            "<gmd:MD_Identifier xmlns:gmd=\"" + Namespaces.GMD + "\" " +
+                               "xmlns:gco=\"" + Namespaces.GCO + "\">\n" +
+            "  <gmd:code>\n" +
+            "    <gco:CharacterString>4326</gco:CharacterString>\n" +
+            "  </gmd:code>\n" +
+            "  <gmd:authority>\n" +
+            "    <gmd:CI_Citation>\n" +
+            "      <gmd:title>\n" +
+            "        <gco:CharacterString>EPSG</gco:CharacterString>\n" +
+            "      </gmd:title>\n" +
+            "    </gmd:CI_Citation>\n" +
+            "  </gmd:authority>\n" +
+            "</gmd:MD_Identifier>";
+
+    /**
+     * Asserts that XML marshalling of the given object produce the {@link #XML} string.
+     */
+    void testMarshal(final String type, final Identifier identifier) throws JAXBException
{
+        assertXmlEquals(CharSequences.replace(XML, "MD_Identifier", type).toString(), marshal(identifier),
"xmlns:*");
+    }
+
+    /**
+     * Test XML marshalling.
+     *
+     * @throws JAXBException Should never happen.
+     */
+    @Test
+    public void testMarshal() throws JAXBException {
+        final DefaultIdentifier identifier = new DefaultIdentifier();
+        identifier.setAuthority(new DefaultCitation("EPSG"));
+        identifier.setCode("4326");
+        testMarshal("MD_Identifier", identifier);
+    }
+
+    /**
+     * Test XML unmarshalling.
+     *
+     * @throws JAXBException Should never happen.
+     */
+    @Test
+    public void testUnmarshall() throws JAXBException {
+        final DefaultIdentifier identifier = unmarshal(DefaultIdentifier.class, XML);
+        assertNull  (        identifier.getVersion());
+        assertEquals("4326", identifier.getCode());
+        assertEquals("EPSG", identifier.getAuthority().getTitle().toString());
+    }
+}

Propchange: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultIdentifierTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultIdentifierTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/ImmutableIdentifierTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/ImmutableIdentifierTest.java?rev=1552966&r1=1552965&r2=1552966&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/ImmutableIdentifierTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/ImmutableIdentifierTest.java
[UTF-8] Sun Dec 22 06:01:25 2013
@@ -19,12 +19,14 @@ package org.apache.sis.metadata.iso;
 import java.util.Map;
 import java.util.HashMap;
 import java.util.Locale;
+import javax.xml.bind.JAXBException;
 import org.apache.sis.metadata.iso.citation.Citations;
 import org.apache.sis.metadata.iso.citation.DefaultCitation;
 import org.apache.sis.util.iso.SimpleInternationalString;
 import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.TestCase;
 import org.opengis.test.Validators;
+import org.apache.sis.test.DependsOn;
 import org.junit.Test;
 
 import static org.junit.Assert.*;
@@ -36,9 +38,10 @@ import static org.opengis.referencing.Re
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-2.2)
- * @version 0.3
+ * @version 0.4
  * @module
  */
+@DependsOn(DefaultIdentifierTest.class)
 public final strictfp class ImmutableIdentifierTest extends TestCase {
     /**
      * Returns the properties map to be used in argument to test methods.
@@ -153,4 +156,15 @@ public final strictfp class ImmutableIde
             assertTrue(message, message.contains(AUTHORITY_KEY));
         }
     }
+
+    /**
+     * Test XML marshalling.
+     *
+     * @throws JAXBException Should never happen.
+     */
+    @Test
+    public void testMarshal() throws JAXBException {
+        final ImmutableIdentifier identifier = new ImmutableIdentifier(new DefaultCitation("EPSG"),
null, "4326");
+        new DefaultIdentifierTest().testMarshal("RS_Identifier", identifier);
+    }
 }

Modified: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java?rev=1552966&r1=1552965&r2=1552966&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
[UTF-8] Sun Dec 22 06:01:25 2013
@@ -76,6 +76,7 @@ import org.junit.BeforeClass;
     org.apache.sis.metadata.iso.quality.AbstractPositionalAccuracyTest.class,
     org.apache.sis.metadata.iso.lineage.DefaultLineageTest.class,
     org.apache.sis.metadata.iso.lineage.DefaultProcessStepTest.class,
+    org.apache.sis.metadata.iso.DefaultIdentifierTest.class,
     org.apache.sis.metadata.iso.ImmutableIdentifierTest.class,
     org.apache.sis.metadata.iso.DefaultMetadataTest.class,
     org.apache.sis.metadata.iso.CustomMetadataTest.class,

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=1552966&r1=1552965&r2=1552966&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] Sun Dec 22 06:01:25 2013
@@ -39,6 +39,7 @@ import org.opengis.referencing.Authority
 import org.opengis.referencing.IdentifiedObject;
 import org.opengis.referencing.ReferenceIdentifier;
 import org.apache.sis.internal.referencing.ReferencingUtilities;
+import org.apache.sis.internal.util.DefinitionURI;
 import org.apache.sis.io.wkt.FormattableObject;
 import org.apache.sis.xml.Namespaces;
 import org.apache.sis.util.Immutable;
@@ -405,35 +406,32 @@ public class AbstractIdentifiedObject ex
      */
     @XmlElement(name = "identifier")
     final ReferenceIdentifier getIdentifier() {
+        ReferenceIdentifier fallback = null;
         if (identifiers != null) {
-            ReferenceIdentifier first = null, fallback = null;
+            boolean isHTTP = false;
             for (final ReferenceIdentifier identifier : identifiers) {
                 final String code = identifier.getCode();
                 if (code == null) continue; // Paranoiac check.
                 if (code.regionMatches(true, 0, "urn:", 0, 4)) {
                     return identifier;
                 }
-                if (fallback == null && code.regionMatches(true, 0, "http:", 0, 5))
{
-                    fallback = identifier;
-                }
-                if (first == null) {
-                    first = identifier;
+                if (!isHTTP) {
+                    isHTTP = code.regionMatches(true, 0, "http:", 0, 5);
+                    if (isHTTP || fallback == null) {
+                        fallback = identifier;
+                    }
                 }
             }
-            if (fallback != null) {
-                return fallback;
-            }
             /*
              * If no "urn:" or "http:" form has been found, try to create a "urn:" form from
the first identifier.
              * For example "EPSG:4326" may be converted to "urn:ogc:def:crs:EPSG:8.2:4326".
If the first identifier
              * can not be converted to a "urn:" form, then it will be returned as-is.
              */
-            if (first != null) {
-                // TODO: apply conversion here.
-                return first;
+            if (!isHTTP && fallback != null) {
+                fallback = DefinitionURI.toURN(ReferencingUtilities.toURNType(getClass()),
fallback);
             }
         }
-        return null;
+        return fallback;
     }
 
     /**

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=1552966&r1=1552965&r2=1552966&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] Sun Dec 22 06:01:25 2013
@@ -25,6 +25,8 @@ import java.util.Collections;
 import org.opengis.test.Validators;
 import org.opengis.referencing.ReferenceIdentifier;
 import org.apache.sis.metadata.iso.ImmutableIdentifier;
+import org.apache.sis.internal.simple.SimpleReferenceIdentifier;
+import org.apache.sis.referencing.datum.AbstractDatum;
 import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
@@ -94,7 +96,7 @@ public final strictfp class AbstractIden
      * This method compares the property values against the expected values.
      */
     @Test
-    public void testCreateFromMap() {
+    public void testWithoutIdentifier() {
         final Map<String,Object> properties = properties();
         validate(new AbstractIdentifiedObject(properties),
                  Collections.<ReferenceIdentifier>emptySet(), null, "GRS1980");
@@ -111,8 +113,8 @@ public final strictfp class AbstractIden
      * </ul>
      */
     @Test
-    @DependsOnMethod("testCreateFromMap")
-    public void testCreateWithSingleIdentifier() {
+    @DependsOnMethod("testWithoutIdentifier")
+    public void testWithSingleIdentifier() {
         final Map<String,Object> properties = properties();
         final ReferenceIdentifier identifier = new ImmutableIdentifier(null, "EPSG", "7019");
         assertNull(properties.put("identifiers", identifier));
@@ -126,8 +128,8 @@ public final strictfp class AbstractIden
      * than the {@link #testCreateWithSingleIdentifier()} one.
      */
     @Test
-    @DependsOnMethod("testCreateWithSingleIdentifier")
-    public void testCreateWithManyIdentifiers() {
+    @DependsOnMethod("testWithSingleIdentifier")
+    public void testWithManyIdentifiers() {
         final Map<String,Object> properties = properties();
         final Set<ReferenceIdentifier> identifiers = new LinkedHashSet<>(4);
         final ReferenceIdentifier identifier = new NamedIdentifier(EPSG, "7019");
@@ -138,10 +140,27 @@ public final strictfp class AbstractIden
     }
 
     /**
+     * Tests {@link AbstractIdentifiedObject#getIdentifier()} with a sub-type of {@code AbstractIdentifiedObject}.
+     * The use of a subtype will allow {@code getIdentifier()} to build a URN and {@code
getId()} to know what to
+     * insert between {@code "epsg-"} and the code.
+     */
+    @Test
+    @DependsOnMethod("testWithManyIdentifiers")
+    public void testAsSubtype() {
+        final Map<String,Object> properties = properties();
+        final Set<ReferenceIdentifier> identifiers = new LinkedHashSet<>(4);
+        final ReferenceIdentifier identifier = new NamedIdentifier(EPSG, "6258");
+        assertTrue(identifiers.add(identifier));
+        assertNull(properties.put("identifiers", identifier));
+        validate(new AbstractDatum(properties), identifiers,
+                new SimpleReferenceIdentifier(EPSG, "urn:ogc:def:datum:EPSG::6258"), "epsg-datum-6258");
+    }
+
+    /**
      * Tests serialization.
      */
     @Test
-    @DependsOnMethod("testCreateFromMap")
+    @DependsOnMethod("testWithoutIdentifier")
     public void testSerialization() {
         final Map<String,Object> properties = properties();
         final AbstractIdentifiedObject object = new AbstractIdentifiedObject(properties);

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultEllipsoidTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultEllipsoidTest.java?rev=1552966&r1=1552965&r2=1552966&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultEllipsoidTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultEllipsoidTest.java
[UTF-8] Sun Dec 22 06:01:25 2013
@@ -175,5 +175,9 @@ public final strictfp class DefaultEllip
         assertEquals("semiMinorAxis",     20854895,           ellipsoid.getSemiMinorAxis(),
0);
         assertEquals("inverseFlattening", 293.46630765562986, ellipsoid.getInverseFlattening(),
1E-12);
         assertEquals("axisUnit",          NonSI.FOOT,         ellipsoid.getAxisUnit());
+        /*
+         * Marshall and compare to the original file.
+         */
+        assertMarshalEqualsFile("Clarke 1880.xml", ellipsoid);
     }
 }

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=1552966&r1=1552965&r2=1552966&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] Sun Dec 22 06:01:25 2013
@@ -142,7 +142,7 @@ public final strictfp class DefaultPrime
         assertWktEquals(pm, "PRIMEM[“Paris”, 2.33722917, AUTHORITY[“EPSG”, “8903”]]");
         assertXmlEquals(
                 "<gml:PrimeMeridian xmlns:gml=\"" + Namespaces.GML + "\">\n" +
-                "  <gml:identifier codeSpace=\"EPSG\">8903</gml:identifier>"
+
+                "  <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"
+

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/simple/SimpleReferenceIdentifier.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/simple/SimpleReferenceIdentifier.java?rev=1552966&r1=1552965&r2=1552966&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/simple/SimpleReferenceIdentifier.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/simple/SimpleReferenceIdentifier.java
[UTF-8] Sun Dec 22 06:01:25 2013
@@ -18,7 +18,6 @@ package org.apache.sis.internal.simple;
 
 import java.io.Serializable;
 import org.opengis.referencing.ReferenceIdentifier;
-import org.opengis.util.InternationalString;
 import org.opengis.metadata.citation.Citation;
 import org.apache.sis.internal.util.Citations;
 import org.apache.sis.util.CharSequences;
@@ -34,12 +33,12 @@ import java.util.Objects;
 /**
  * An implementation of {@link ReferenceIdentifier} as a wrapper around a {@link Citation}.
  * {@code ReferenceIdentifier} is defined by the ISO 19111 standard and is implemented publicly
- * in the {@link org.apache.sis.referencing} package. This class is provided for non-referencing
- * code that need a lightweight version.
+ * in the {@link org.apache.sis.referencing} package. This class is provided for codes that
do
+ * not depend on the {@code sis-referencing} module but still need a lightweight implementation.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.3
+ * @version 0.4
  * @module
  */
 public class SimpleReferenceIdentifier implements ReferenceIdentifier, Serializable {
@@ -121,19 +120,15 @@ public class SimpleReferenceIdentifier i
 
     /**
      * Version identifier for the namespace, as specified by the code authority.
-     * When appropriate, the edition is identified by the effective date, coded
-     * using ISO 8601 date format.
+     * The default implementation returns {@code null}.
      *
-     * @return A version inferred from the authority given at construction time, or {@code
null} if none.
+     * {@note <code>DefinitionURI.toURN(…)</code> requires this method to return
<code>null</code>, because
+     *        the version number is expanded in the code using the <code>"urn:ogc:dec:…</code>
syntax.}
+     *
+     * @return Version identifier for the namespace, or {@code null} if none.
      */
     @Override
     public String getVersion() {
-        if (authority != null) {
-            final InternationalString version = authority.getEdition();
-            if (version != null) {
-                return version.toString();
-            }
-        }
         return null;
     }
 

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java?rev=1552966&r1=1552965&r2=1552966&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java
[UTF-8] Sun Dec 22 06:01:25 2013
@@ -19,6 +19,7 @@ package org.apache.sis.internal.util;
 import java.util.Map;
 import java.util.Collections;
 import org.opengis.referencing.ReferenceIdentifier;
+import org.apache.sis.internal.simple.SimpleReferenceIdentifier;
 
 import static org.apache.sis.util.CharSequences.*;
 import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
@@ -433,14 +434,16 @@ public final class DefinitionURI {
     }
 
     /**
-     * Format a {@code "ogc:urn:def:"} identifier. The identifier code space, version and
code are
-     * formatted in lower case, ignoring all characters that are not valid for a Unicode
identifier.
+     * Returns an identifier for the same code and code space than the given identifier,
but using
+     * the {@code "ogc:urn:def:"} syntax. The identifier code space, version and code are
appended
+     * omitting any characters that are not valid for a Unicode identifier. If some information
are
+     * missing in the given identifier, then this method returns that identifier as-is.
      *
      * @param  type The object type, as one of the type documented in class javadoc.
      * @param  identifier The identifier to format.
-     * @return The URN.
+     * @return An identifier using the URN syntax, or the given identifier returned as-is.
      */
-    public static String format(final String type, final ReferenceIdentifier identifier)
{
+    public static ReferenceIdentifier toURN(final String type, final ReferenceIdentifier
identifier) {
         final StringBuilder buffer = new StringBuilder("urn:ogc:def");
         for (int p=0; p<4; p++) {
             final String component;
@@ -451,9 +454,15 @@ public final class DefinitionURI {
                 case 3:  component = identifier.getCode();      break;
                 default: throw new AssertionError(p);
             }
-            appendUnicodeIdentifier(buffer.append(SEPARATOR), '\u0000', component, p != 0);
+            if (!appendUnicodeIdentifier(buffer.append(SEPARATOR), '\u0000', component, false))
{
+                // Only the version (p = 2) is optional. All other fields are mandatory.
+                // If no character has been added for a mandatory field, we can not build
a URN.
+                if (p != 2) {
+                    return identifier;
+                }
+            }
         }
-        return buffer.toString();
+        return new SimpleReferenceIdentifier(identifier.getAuthority(), buffer.toString());
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java?rev=1552966&r1=1552965&r2=1552966&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java
[UTF-8] Sun Dec 22 06:01:25 2013
@@ -1964,7 +1964,8 @@ cmp:    while (ia < lga) {
 
     /**
      * Replaces all occurrences of a given string in the given character sequence. If no
occurrence of
-     * {@code toSearch} is found in the given text, then this method returns the {@code text}
unchanged.
+     * {@code toSearch} is found in the given text or if {@code toSearch} is equal to {@code
replaceBy},
+     * then this method returns the {@code text} unchanged.
      * Otherwise this method returns a new character sequence with all occurrences replaced
by {@code replaceBy}.
      *
      * <p>This method is similar to {@link String#replace(CharSequence, CharSequence)}
except for the following:</p>

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/DefinitionURITest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/DefinitionURITest.java?rev=1552966&r1=1552965&r2=1552966&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/DefinitionURITest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/DefinitionURITest.java
[UTF-8] Sun Dec 22 06:01:25 2013
@@ -147,12 +147,20 @@ public final strictfp class DefinitionUR
     }
 
     /**
-     * Tests {@link DefinitionURI#format(String, ReferenceIdentifier)}.
+     * Tests {@link DefinitionURI#toURN(String, ReferenceIdentifier)}.
      */
     @Test
-    public void testFormatIdentifier() {
-        final SimpleCitation epsg = new SimpleCitation("EPSG");
-        assertEquals("urn:ogc:def:crs:epsg::4326",
-                DefinitionURI.format("crs", new SimpleReferenceIdentifier(epsg, "4326")));
+    public void testToURN() {
+        final SimpleCitation ogp = new SimpleCitation("OGP");
+        @SuppressWarnings("serial")
+        final ReferenceIdentifier simple = new SimpleReferenceIdentifier(ogp, "4326") {
+            @Override public String getCodeSpace() {return "EPSG";}
+        };
+        final ReferenceIdentifier asURN = DefinitionURI.toURN("crs", simple);
+        assertNotSame(simple, asURN);
+        assertSame   (ogp,    asURN.getAuthority());
+        assertEquals ("OGP",  asURN.getCodeSpace());
+        assertNull   (        asURN.getVersion());
+        assertEquals ("urn:ogc:def:crs:EPSG::4326", asURN.getCode());
     }
 }

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/XMLComparator.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/XMLComparator.java?rev=1552966&r1=1552965&r2=1552966&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/XMLComparator.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/XMLComparator.java
[UTF-8] Sun Dec 22 06:01:25 2013
@@ -625,7 +625,7 @@ public strictfp class XMLComparator {
         actual   = trim(actual);
         if ((expected != actual) && (expected == null || !expected.equals(actual)))
{
             // Before to declare a test failure, compares again as numerical values if possible.
-            if (tolerance > 0 && abs(doubleValue(expected) - doubleValue(actual))
<= tolerance) {
+            if (abs(doubleValue(expected) - doubleValue(actual)) <= tolerance) {
                 return;
             }
             final String lineSeparator = System.lineSeparator();



Mime
View raw message