sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1553047 - in /sis/branches/JDK7/core: sis-metadata/src/main/java/org/apache/sis/metadata/ sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/ sis-referencing/src/main/java/org/apache/sis/referencing/ sis-referencing/src...
Date Sun, 22 Dec 2013 23:24:48 GMT
Author: desruisseaux
Date: Sun Dec 22 23:24:48 2013
New Revision: 1553047

URL: http://svn.apache.org/r1553047
Log:
Minor refactoring of <gml:identifier> support. This provides slightly
better division of tasks and avoid creation of an intermediate object.

Modified:
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyInformation.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/Code.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/internal/jaxb/referencing/CodeTest.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.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/internal/util/Utilities.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/DefinitionURITest.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=1553047&r1=1553046&r2=1553047&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 23:24:48 2013
@@ -175,24 +175,6 @@ 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-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/Code.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/Code.java?rev=1553047&r1=1553046&r2=1553047&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/Code.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/Code.java
[UTF-8] Sun Dec 22 23:24:48 2013
@@ -25,6 +25,8 @@ import org.apache.sis.internal.util.Defi
 import org.apache.sis.metadata.iso.ImmutableIdentifier;
 import org.apache.sis.metadata.iso.citation.Citations;
 
+import static org.apache.sis.internal.referencing.ReferencingUtilities.toURNType;
+
 
 /**
  * The {@code gml:CodeType}, which is made of a code space and a code value.
@@ -57,9 +59,9 @@ public final class Code {
     String codeSpace;
 
     /**
-     * Empty constructor for JAXB only.
+     * Empty constructor for JAXB.
      */
-    public Code() {
+    Code() {
     }
 
     /**
@@ -88,8 +90,10 @@ public final class Code {
      * If the {@link #codeSpace} contains a semicolon, then the part after the last semicolon
      * will be taken as the authority version number. This is for consistency with what the
      * constructor does.
+     *
+     * @return The identifier, or {@code null} if none.
      */
-    ReferenceIdentifier getIdentifier() {
+    public ReferenceIdentifier getIdentifier() {
         String c = code;
         if (c == null) {
             return null;
@@ -112,4 +116,55 @@ public final class Code {
         }
         return new ImmutableIdentifier(authority, cs, c, version, null);
     }
+
+    /**
+     * Returns a {@code <gml:identifier>} for the given identified object, or {@code
null} if none.
+     * This method searches for the following identifiers, in preference order:
+     * <ul>
+     *   <li>The first identifier having a code that begin with {@code "urn:"}.</li>
+     *   <li>The first identifier having a code that begin with {@code "http:"}.</li>
+     *   <li>The first identifier, converted to the {@code "urn:} syntax if possible.</li>
+     * </ul>
+     *
+     * @param  type The type of the identified object.
+     * @param  identifiers The object identifiers, or {@code null} if none.
+     * @return The {@code <gml:identifier>} as a {@code Code} instance, or {@code null}
if none.
+     */
+    public static Code forIdentifiedObject(final Class<?> type, final Iterable<?
extends ReferenceIdentifier> identifiers) {
+        if (identifiers != null) {
+            boolean isHTTP = false;
+            ReferenceIdentifier fallback = null;
+            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 new Code(identifier);
+                }
+                if (!isHTTP) {
+                    isHTTP = code.regionMatches(true, 0, "http:", 0, 5);
+                    if (isHTTP || fallback == null) {
+                        fallback = identifier;
+                    }
+                }
+            }
+            /*
+             * 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 (fallback != null) {
+                if (!isHTTP) {
+                    final String urn = DefinitionURI.format(toURNType(type), fallback);
+                    if (urn != null) {
+                        final Code code = new Code();
+                        code.codeSpace = Citations.getIdentifier(fallback.getAuthority());
+                        code.code = urn;
+                        return code;
+                    }
+                }
+                return new Code(fallback);
+            }
+        }
+        return null;
+    }
 }

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=1553047&r1=1553046&r2=1553047&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 23:24:48 2013
@@ -39,7 +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.internal.jaxb.referencing.Code;
 import org.apache.sis.io.wkt.FormattableObject;
 import org.apache.sis.xml.Namespaces;
 import org.apache.sis.util.Immutable;
@@ -375,9 +375,9 @@ public class AbstractIdentifiedObject ex
          */
         if (identifiers != null) {
             for (final ReferenceIdentifier identifier : identifiers) {
-                if (appendUnicodeIdentifier(id, '-', identifier.getCodeSpace(), true) | //
Really |, not ||
-                    appendUnicodeIdentifier(id, '-', ReferencingUtilities.toURNType(getClass()),
false) |
-                    appendUnicodeIdentifier(id, '-', identifier.getCode(), true))
+                if (appendUnicodeIdentifier(id, '-', identifier.getCodeSpace(), ":", true)
| // Really |, not ||
+                    appendUnicodeIdentifier(id, '-', ReferencingUtilities.toURNType(getClass()),
":", false) |
+                    appendUnicodeIdentifier(id, '-', identifier.getCode(), ":", true))
                 {
                     /*
                      * TODO: If we want to check for ID uniqueness or any other condition
before to accept the ID,
@@ -386,10 +386,11 @@ public class AbstractIdentifiedObject ex
                      */
                     return id.toString();
                 }
+                id.setLength(0); // Clear the buffer for an other try.
             }
         }
         // In last ressort, append code without codespace since the name are often verbose.
-        return appendUnicodeIdentifier(id, '-', name.getCode(), false) ? id.toString() :
null;
+        return appendUnicodeIdentifier(id, '-', name.getCode(), ":", false) ? id.toString()
: null;
     }
 
     /**
@@ -405,41 +406,19 @@ public class AbstractIdentifiedObject ex
      * </ul>
      */
     @XmlElement(name = "identifier")
-    final ReferenceIdentifier getIdentifier() {
-        ReferenceIdentifier fallback = null;
-        if (identifiers != 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 (!isHTTP) {
-                    isHTTP = code.regionMatches(true, 0, "http:", 0, 5);
-                    if (isHTTP || fallback == null) {
-                        fallback = identifier;
-                    }
-                }
-            }
-            /*
-             * 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 (!isHTTP && fallback != null) {
-                fallback = DefinitionURI.toURN(ReferencingUtilities.toURNType(getClass()),
fallback);
-            }
-        }
-        return fallback;
+    final Code getIdentifier() {
+        return Code.forIdentifiedObject(getClass(), identifiers);
     }
 
     /**
      * Invoked by JAXB at unmarshalling time for setting the identifier.
      */
-    private void setIdentifier(final ReferenceIdentifier identifier) {
+    private void setIdentifier(final Code identifier) {
         if (identifier != null) {
-            identifiers = Collections.singleton(identifier);
+            final ReferenceIdentifier id = identifier.getIdentifier();
+            if (id != null) {
+                identifiers = Collections.singleton(id);
+            }
         }
     }
 

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CodeTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CodeTest.java?rev=1553047&r1=1553046&r2=1553047&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CodeTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CodeTest.java
[UTF-8] Sun Dec 22 23:24:48 2013
@@ -16,6 +16,8 @@
  */
 package org.apache.sis.internal.jaxb.referencing;
 
+import java.util.Collections;
+import org.opengis.referencing.crs.GeographicCRS;
 import org.opengis.referencing.ReferenceIdentifier;
 import org.apache.sis.metadata.iso.ImmutableIdentifier;
 import org.apache.sis.metadata.iso.citation.Citations;
@@ -37,7 +39,7 @@ import static org.junit.Assert.*;
  */
 public final strictfp class CodeTest extends TestCase {
     /**
-     * Tests with {@code "EPSG:4326"}.
+     * Tests the {@link Code#Code(ReferenceIdentifier)} constructor with {@code "EPSG:4326"}
identifier.
      */
     @Test
     public void testSimple() {
@@ -57,7 +59,7 @@ public final strictfp class CodeTest ext
     }
 
     /**
-     * Tests with {@code "EPSG:8.3:4326"}.
+     * Tests the {@link Code#Code(ReferenceIdentifier)} constructor with {@code "EPSG:8.3:4326"}
identifier.
      */
     @Test
     @DependsOnMethod("testSimple")
@@ -78,13 +80,26 @@ public final strictfp class CodeTest ext
     }
 
     /**
-     * Tests with {@code "urn:ogc:def:crs:EPSG:8.2:4326"}.
+     * Tests {@link Code#forIdentifiedObject(Class, Iterable)}.
+     */
+    @Test
+    @DependsOnMethod("testWithVersion")
+    public void testForIdentifiedObject() {
+        final ReferenceIdentifier id = new ImmutableIdentifier(HardCodedCitations.OGP, "EPSG",
"4326", "8.2", null);
+        final Code value = Code.forIdentifiedObject(GeographicCRS.class, Collections.singleton(id));
+        assertNotNull(value);
+        assertEquals("codeSpace", "OGP", value.codeSpace);
+        assertEquals("code", "urn:ogc:def:crs:EPSG:8.2:4326", value.code);
+    }
+
+    /**
+     * Tests {@link Code#getIdentifier()} with {@code "urn:ogc:def:crs:EPSG:8.2:4326"}.
      * This test simulate the {@code Code} object state that we get after
      * XML unmarshalling of an object from the EPSG registry.
      */
     @Test
-    @DependsOnMethod("testWithVersion")
-    public void testURN() {
+    @DependsOnMethod("testForIdentifiedObject")
+    public void testGetIdentifier() {
         final Code value = new Code();
         value.codeSpace = "OGP";
         value.code = "urn:ogc:def:crs:EPSG:8.2:4326";

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=1553047&r1=1553046&r2=1553047&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 23:24:48 2013
@@ -25,8 +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.internal.jaxb.referencing.Code;
 import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
@@ -53,11 +53,13 @@ public final strictfp class AbstractIden
     /**
      * Creates a map of properties to be given to the {@link AbstractIdentifiedObject} constructor.
      * The values in the map are consistent with the values expected by the {@link #validate}
method.
-     * The map does not contain any {@code "identifiers"} entry.
+     *
+     * @param identifier The value for the {@code "identifiers"} property.
      */
-    private static Map<String,Object> properties() {
+    private static Map<String,Object> properties(final Set<ReferenceIdentifier>
identifiers) {
         final Map<String,Object> properties = new HashMap<>(8);
         assertNull(properties.put("name",       "GRS 1980"));
+        assertNull(properties.put("identifiers", identifiers.toArray(new ReferenceIdentifier[identifiers.size()])));
         assertNull(properties.put("codespace",  "EPSG"));
         assertNull(properties.put("version",    "8.3"));
         assertNull(properties.put("alias",      "International 1979"));
@@ -69,13 +71,13 @@ public final strictfp class AbstractIden
     /**
      * Validates the given object created by {@link #testCreateFromMap()}.
      *
-     * @param object      The object to validate.
-     * @param identifiers The expected value of {@link AbstractIdentifiedObject#getIdentifiers()}.
-     * @param identifier  The expected value of {@link AbstractIdentifiedObject#getIdentifier()}.
-     * @param gmlID       The expected value of {@link AbstractIdentifiedObject#getID()}.
+     * @param  object      The object to validate.
+     * @param  identifiers The expected value of {@link AbstractIdentifiedObject#getIdentifiers()}.
+     * @param  gmlID       The expected value of {@link AbstractIdentifiedObject#getID()}.
+     * @return The value of {@link AbstractIdentifiedObject#getIdentifier()}.
      */
-    private static void validate(final AbstractIdentifiedObject object, final Set<ReferenceIdentifier>
identifiers,
-            final ReferenceIdentifier identifier, final String gmlID)
+    private static ReferenceIdentifier validate(final AbstractIdentifiedObject object,
+            final Set<ReferenceIdentifier> identifiers, final String gmlID)
     {
         Validators.validate(object);
         final ReferenceIdentifier name = object.getName();
@@ -85,10 +87,11 @@ public final strictfp class AbstractIden
         assertEquals("aliases",     "International 1979",            getSingleton(object.getAlias()).toString());
         assertEquals("names",       Collections.singletonList(name), object.getNames());
         assertEquals("identifiers", identifiers,                     object.getIdentifiers());
-        assertEquals("identifier",  identifier,                      object.getIdentifier());
         assertEquals("ID",          gmlID,                           object.getID());
         assertEquals("remarks",     "Adopted by IUGG 1979 Canberra", object.getRemarks().toString(Locale.ENGLISH));
         assertEquals("remarks_fr",  "Adopté par IUGG 1979 Canberra", object.getRemarks().toString(Locale.FRENCH));
+        final Code code = object.getIdentifier();
+        return (code != null) ? code.getIdentifier() : null;
     }
 
     /**
@@ -97,9 +100,10 @@ public final strictfp class AbstractIden
      */
     @Test
     public void testWithoutIdentifier() {
-        final Map<String,Object> properties = properties();
-        validate(new AbstractIdentifiedObject(properties),
-                 Collections.<ReferenceIdentifier>emptySet(), null, "GRS1980");
+        final Set<ReferenceIdentifier> identifiers = Collections.<ReferenceIdentifier>emptySet();
+        final AbstractIdentifiedObject object      = new AbstractIdentifiedObject(properties(identifiers));
+        final ReferenceIdentifier      gmlId       = validate(object, identifiers, "GRS1980");
+        assertNull("gmlId", gmlId);
     }
 
     /**
@@ -115,11 +119,13 @@ public final strictfp class AbstractIden
     @Test
     @DependsOnMethod("testWithoutIdentifier")
     public void testWithSingleIdentifier() {
-        final Map<String,Object> properties = properties();
-        final ReferenceIdentifier identifier = new ImmutableIdentifier(null, "EPSG", "7019");
-        assertNull(properties.put("identifiers", identifier));
-        validate(new AbstractIdentifiedObject(properties),
-                 Collections.singleton(identifier), identifier, "epsg-7019");
+        final ReferenceIdentifier      identifier  = new ImmutableIdentifier(null, "EPSG",
"7019");
+        final Set<ReferenceIdentifier> identifiers = Collections.singleton(identifier);
+        final AbstractIdentifiedObject object      = new AbstractIdentifiedObject(properties(identifiers));
+        final ReferenceIdentifier      gmlId       = validate(object, identifiers, "epsg-7019");
+        assertNotNull("gmlId",                   gmlId);
+        assertEquals ("gmlId.codespace", "EPSG", gmlId.getCodeSpace());
+        assertEquals ("gmlId.code",      "7019", gmlId.getCode());
     }
 
     /**
@@ -130,13 +136,14 @@ public final strictfp class AbstractIden
     @Test
     @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");
-        assertTrue(identifiers.add(identifier));
+        assertTrue(identifiers.add(new NamedIdentifier(EPSG, "7019")));
         assertTrue(identifiers.add(new NamedIdentifier(EPSG, "IgnoreMe")));
-        assertNull(properties.put("identifiers", identifiers.toArray(new ReferenceIdentifier[2])));
-        validate(new AbstractIdentifiedObject(properties), identifiers, identifier, "epsg-7019");
+        final AbstractIdentifiedObject object = new AbstractIdentifiedObject(properties(identifiers));
+        final ReferenceIdentifier      gmlId  = validate(object, identifiers, "epsg-7019");
+        assertNotNull("gmlId",                   gmlId);
+        assertEquals ("gmlId.codespace", "EPSG", gmlId.getCodeSpace());
+        assertEquals ("gmlId.code",      "7019", gmlId.getCode());
     }
 
     /**
@@ -147,13 +154,13 @@ public final strictfp class AbstractIden
     @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");
+        final ReferenceIdentifier      identifier  = new NamedIdentifier(EPSG, "7019");
+        final Set<ReferenceIdentifier> identifiers = Collections.singleton(identifier);
+        final AbstractIdentifiedObject object      = new AbstractDatum(properties(identifiers));
+        final ReferenceIdentifier      gmlId       = validate(object, identifiers, "epsg-datum-7019");
+        assertNotNull("gmlId",                   gmlId);
+        assertEquals ("gmlId.codespace", "EPSG", gmlId.getCodeSpace());
+        assertEquals ("gmlId.code",      "7019", gmlId.getCode());
     }
 
     /**
@@ -162,10 +169,10 @@ public final strictfp class AbstractIden
     @Test
     @DependsOnMethod("testWithoutIdentifier")
     public void testSerialization() {
-        final Map<String,Object> properties = properties();
-        final AbstractIdentifiedObject object = new AbstractIdentifiedObject(properties);
-        final AbstractIdentifiedObject actual = assertSerializedEquals(object);
+        final Set<ReferenceIdentifier> identifiers = Collections.emptySet();
+        final AbstractIdentifiedObject object      = new AbstractIdentifiedObject(properties(identifiers));
+        final AbstractIdentifiedObject actual      = assertSerializedEquals(object);
         assertNotSame(object, actual);
-        validate(actual, Collections.<ReferenceIdentifier>emptySet(), null, "GRS1980");
+        assertNull("gmlId", validate(actual, identifiers, "GRS1980"));
     }
 }

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=1553047&r1=1553046&r2=1553047&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 23:24:48 2013
@@ -17,6 +17,7 @@
 package org.apache.sis.internal.simple;
 
 import java.io.Serializable;
+import org.opengis.util.InternationalString;
 import org.opengis.referencing.ReferenceIdentifier;
 import org.opengis.metadata.citation.Citation;
 import org.apache.sis.internal.util.Citations;
@@ -120,15 +121,19 @@ public class SimpleReferenceIdentifier i
 
     /**
      * Version identifier for the namespace, as specified by the code authority.
-     * The default implementation returns {@code null}.
+     * When appropriate, the edition is identified by the effective date, coded
+     * using ISO 8601 date format.
      *
-     * {@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.
+     * @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 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=1553047&r1=1553046&r2=1553047&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 23:24:48 2013
@@ -19,7 +19,6 @@ 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;
@@ -434,16 +433,15 @@ public final class DefinitionURI {
     }
 
     /**
-     * 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.
+     * Formats the given identifier 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
{@code null}.
      *
-     * @param  type The object type, as one of the type documented in class javadoc.
+     * @param  type The object type, as one of the type documented in class javadoc, or {@code
null}.
      * @param  identifier The identifier to format.
-     * @return An identifier using the URN syntax, or the given identifier returned as-is.
+     * @return An identifier using the URN syntax, or {@code null} if an information is missing.
      */
-    public static ReferenceIdentifier toURN(final String type, final ReferenceIdentifier
identifier) {
+    public static String format(final String type, final ReferenceIdentifier identifier)
{
         final StringBuilder buffer = new StringBuilder("urn:ogc:def");
         for (int p=0; p<4; p++) {
             final String component;
@@ -454,15 +452,15 @@ public final class DefinitionURI {
                 case 3:  component = identifier.getCode();      break;
                 default: throw new AssertionError(p);
             }
-            if (!appendUnicodeIdentifier(buffer.append(SEPARATOR), '\u0000', component, false))
{
+            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 null;
                 }
             }
         }
-        return new SimpleReferenceIdentifier(identifier.getAuthority(), buffer.toString());
+        return buffer.toString();
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java?rev=1553047&r1=1553046&r2=1553047&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java
[UTF-8] Sun Dec 22 23:24:48 2013
@@ -59,19 +59,20 @@ public final class Utilities extends Sta
      * @param  appendTo    The buffer where to append the valid characters.
      * @param  separator   The separator to append before the valid characters, or 0 if none.
      * @param  text        The text from which to get the valid character to append in the
given buffer.
+     * @param  accepted    Additional characters to accept (e.g. {@code "-."}), or an empty
string if none.
      * @param  toLowerCase {@code true} for converting the characters to lower case.
      * @return {@code true} if at least one character has been added to the buffer.
      */
-    public static boolean appendUnicodeIdentifier(final StringBuilder appendTo,
-            final char separator, final String text, final boolean toLowerCase)
+    public static boolean appendUnicodeIdentifier(final StringBuilder appendTo, final char
separator,
+            final String text, final String accepted, final boolean toLowerCase)
     {
         boolean added = false;
         if (text != null) {
             for (int i=0; i<text.length();) {
                 final int c = text.codePointAt(i);
                 final boolean isFirst = appendTo.length() == 0;
-                if (isFirst ? Character.isUnicodeIdentifierStart(c)
-                            : Character.isUnicodeIdentifierPart(c))
+                if ((isFirst ? Character.isUnicodeIdentifierStart(c)
+                             : Character.isUnicodeIdentifierPart(c)) || accepted.indexOf(c)
>= 0)
                 {
                     if (!isFirst && !added && separator != 0) {
                         appendTo.append(separator);

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=1553047&r1=1553046&r2=1553047&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 23:24:48 2013
@@ -151,16 +151,7 @@ public final strictfp class DefinitionUR
      */
     @Test
     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());
+        final ReferenceIdentifier identifier = new SimpleReferenceIdentifier(new SimpleCitation("EPSG"),
"4326");
+        assertEquals("urn:ogc:def:crs:EPSG::4326", DefinitionURI.format("crs", identifier));
     }
 }



Mime
View raw message