sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1552492 - in /sis/branches/JDK7/core/sis-referencing/src: main/java/org/apache/sis/internal/referencing/ main/java/org/apache/sis/referencing/ test/java/org/apache/sis/internal/referencing/ test/java/org/apache/sis/referencing/ test/java/o...
Date Fri, 20 Dec 2013 04:48:50 GMT
Author: desruisseaux
Date: Fri Dec 20 04:48:50 2013
New Revision: 1552492

URL: http://svn.apache.org/r1552492
Log:
Format gml:id in a way closer to the epsg-registry practice.

Added:
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/ReferencingUtilitiesTest.java
  (with props)
Modified:
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.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/test/suite/ReferencingTestSuite.java

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java?rev=1552492&r1=1552491&r2=1552492&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java
[UTF-8] Fri Dec 20 04:48:50 2013
@@ -16,7 +16,12 @@
  */
 package org.apache.sis.internal.referencing;
 
-import org.opengis.referencing.operation.Matrix;
+import org.opengis.parameter.*;
+import org.opengis.referencing.*;
+import org.opengis.referencing.cs.*;
+import org.opengis.referencing.crs.*;
+import org.opengis.referencing.datum.*;
+import org.opengis.referencing.operation.*;
 import org.apache.sis.referencing.operation.matrix.MatrixSIS;
 import org.apache.sis.util.Static;
 
@@ -35,6 +40,42 @@ import org.apache.sis.util.Static;
  */
 public final class ReferencingUtilities extends Static {
     /**
+     * Subtypes of {@link IdentifiedObject} for which a URN type is defined.
+     * For each interface at index <var>i</var>, the URN type is {@code URN_TYPES[i]}.
+     *
+     * <p>For performance reasons, most frequently used types should be first.</p>
+     */
+    private static final Class<?>[] TYPES = {
+        CoordinateReferenceSystem.class,
+        Datum.class,
+        Ellipsoid.class,
+        PrimeMeridian.class,
+        CoordinateSystem.class,
+        CoordinateSystemAxis.class,
+        CoordinateOperation.class,
+        OperationMethod.class,
+        ParameterDescriptor.class,
+        ReferenceSystem.class
+    };
+
+    /**
+     * The URN types for instances of {@link #TYPES}.
+     * See {@link URIParser} javadoc for a list of URN types.
+     */
+    private static final String[] URN_TYPES = {
+        "crs",
+        "datum",
+        "ellipsoid",
+        "meridian",
+        "cs",
+        "axis",
+        "coordinateOperation",
+        "method",
+        "parameter",
+        "referenceSystem"
+    };
+
+    /**
      * Do not allow instantiation of this class.
      */
     private ReferencingUtilities() {
@@ -56,4 +97,22 @@ public final class ReferencingUtilities 
             return matrix.getElement(row, column);
         }
     }
+
+    /**
+     * Returns the URN type for the given class, or {@code null} if unknown.
+     * See {@link URIParser} javadoc for a list of URN types.
+     *
+     * @param  type The class for which to get the URN type.
+     * @return The URN type, or {@code null} if unknown.
+     *
+     * @see org.apache.sis.internal.util.URIParser
+     */
+    public static String toURNType(final Class<?> type) {
+        for (int i=0; i<TYPES.length; i++) {
+            if (TYPES[i].isAssignableFrom(type)) {
+                return URN_TYPES[i];
+            }
+        }
+        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=1552492&r1=1552491&r2=1552492&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] Fri Dec 20 04:48:50 2013
@@ -38,6 +38,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.referencing.ReferencingUtilities;
 import org.apache.sis.internal.jaxb.referencing.RS_IdentifierSingleton;
 import org.apache.sis.io.wkt.FormattableObject;
 import org.apache.sis.xml.Namespaces;
@@ -349,8 +350,15 @@ public class AbstractIdentifiedObject ex
      * regardless its authority. If no identifier is found, then the name is used.
      * If no name is found (which should not occur for valid objects), then this method returns
{@code null}.
      *
-     * <p>When an identifier has been found, this method returns the concatenation
of its code space with its code,
-     * <em>without separator</em>. For example this method may return {@code
"EPSG4326"}, not {@code "EPSG:4326"}.</p>
+     * <p>If an identifier has been found, this method returns the concatenation of
the following elements
+     * separated by hyphens:</p>
+     * <ul>
+     *   <li>The code space in lower case, retaining only characters that are valid
for Unicode identifiers.</li>
+     *   <li>The object type as defined in OGC's URN (see {@link org.apache.sis.internal.util.URIParser})</li>
+     *   <li>The object code, retaining only characters that are valid for Unicode
identifiers.</li>
+     * </ul>
+     *
+     * Example: {@code "epsg-crs-4326"}.
      *
      * <p>The returned ID needs to be unique only in the XML document being marshalled.
      * Consecutive invocations of this method do not need to return the same value,
@@ -367,9 +375,10 @@ public class AbstractIdentifiedObject ex
          */
         if (identifiers != null) {
             for (final ReferenceIdentifier identifier : identifiers) {
-                appendID(id, identifier.getCodeSpace());
-                appendID(id, identifier.getCode());
-                if (id.length() != 0) {
+                if (appendID(id, identifier.getCodeSpace(), true) | // Really |, not ||
+                    appendID(id, ReferencingUtilities.toURNType(getClass()), false) |
+                    appendID(id, identifier.getCode(), true))
+                {
                     /*
                      * TODO: If we want to check for ID uniqueness or any other condition
before to accept the ID,
                      * we would do that here. If the ID is rejected, then we just need to
clear the buffer and let
@@ -380,28 +389,35 @@ public class AbstractIdentifiedObject ex
             }
         }
         // In last ressort, append code without codespace since the name are often verbose.
-        appendID(id, name.getCode());
-        if (id.length() == 0) {
-            return null;
-        }
-        return id.toString();
+        return appendID(id, name.getCode(), false) ? id.toString() : null;
     }
 
     /**
      * Appends only the characters that are valid for a Unicode identifier.
+     * If the buffer is non-empty and this method added at least one character,
+     * then a hyphen is inserted before the characters added by this method.
+     *
+     * @return {@code true} if at least one character has been added to the buffer.
      */
-    private static void appendID(final StringBuilder buffer, final String text) {
+    private static boolean appendID(final StringBuilder buffer, final String text, final
boolean toLowerCase) {
+        boolean added = false;
         if (text != null) {
             for (int i=0; i<text.length();) {
                 final int c = text.codePointAt(i);
-                if (buffer.length() == 0 ? Character.isUnicodeIdentifierStart(c)
-                                         : Character.isUnicodeIdentifierPart(c))
+                final boolean isFirst = buffer.length() == 0;
+                if (isFirst ? Character.isUnicodeIdentifierStart(c)
+                            : Character.isUnicodeIdentifierPart(c))
                 {
-                    buffer.appendCodePoint(c);
+                    if (!isFirst && !added) {
+                        buffer.append('-');
+                    }
+                    buffer.appendCodePoint(toLowerCase ? Character.toLowerCase(c) : c);
+                    added = true;
                 }
                 i += Character.charCount(c);
             }
         }
+        return added;
     }
 
     /**

Added: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/ReferencingUtilitiesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/ReferencingUtilitiesTest.java?rev=1552492&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/ReferencingUtilitiesTest.java
(added)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/ReferencingUtilitiesTest.java
[UTF-8] Fri Dec 20 04:48:50 2013
@@ -0,0 +1,58 @@
+/*
+ * 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.referencing;
+
+import org.opengis.referencing.cs.*;
+import org.opengis.referencing.crs.*;
+import org.opengis.referencing.datum.*;
+import org.opengis.referencing.ReferenceSystem;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+import static org.apache.sis.internal.referencing.ReferencingUtilities.*;
+
+
+/**
+ * Tests {@link ReferencingUtilities}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.4
+ * @version 0.4
+ * @module
+ */
+public final strictfp class ReferencingUtilitiesTest extends TestCase {
+    /**
+     * Tests {@link ReferencingUtilities#toURNType()}.
+     */
+    @Test
+    public void testToURNType() {
+        assertEquals("crs",             toURNType(GeographicCRS       .class));
+        assertEquals("crs",             toURNType(ProjectedCRS        .class));
+        assertEquals("crs",             toURNType(VerticalCRS         .class));
+        assertEquals("crs",             toURNType(TemporalCRS         .class));
+        assertEquals("datum",           toURNType(GeodeticDatum       .class));
+        assertEquals("datum",           toURNType(VerticalDatum       .class));
+        assertEquals("datum",           toURNType(TemporalDatum       .class));
+        assertEquals("ellipsoid",       toURNType(Ellipsoid           .class));
+        assertEquals("meridian",        toURNType(PrimeMeridian       .class));
+        assertEquals("cs",              toURNType(EllipsoidalCS       .class));
+        assertEquals("cs",              toURNType(CartesianCS         .class));
+        assertEquals("axis",            toURNType(CoordinateSystemAxis.class));
+        assertEquals("referenceSystem", toURNType(ReferenceSystem     .class));
+    }
+}

Propchange: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/ReferencingUtilitiesTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

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=1552492&r1=1552491&r2=1552492&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] Fri Dec 20 04:48:50 2013
@@ -56,16 +56,16 @@ public final strictfp class AbstractIden
         assertNull(properties.put("name",       "GRS 1980"));
         assertNull(properties.put("codespace",  "EPSG"));
         assertNull(properties.put("version",    "8.3"));
-        assertNull(properties.put("alias",      "International 1979"));//7019
+        assertNull(properties.put("alias",      "International 1979"));
         assertNull(properties.put("remarks",    "Adopted by IUGG 1979 Canberra"));
         assertNull(properties.put("remarks_fr", "Adopté par IUGG 1979 Canberra"));
         validate(new AbstractIdentifiedObject(properties), Collections.<ReferenceIdentifier>emptySet(),
"GRS1980");
         /*
          * Adds an identifier. This should change the choice made by AbstractIdentifiedObject.getID().
          */
-        final ReferenceIdentifier identifier = new ImmutableIdentifier(null, "EPSG", "4326");
+        final ReferenceIdentifier identifier = new ImmutableIdentifier(null, "EPSG", "7019");
         assertNull(properties.put("identifiers", identifier));
-        validate(new AbstractIdentifiedObject(properties), Collections.singleton(identifier),
"EPSG4326");
+        validate(new AbstractIdentifiedObject(properties), Collections.singleton(identifier),
"epsg-7019");
     }
 
     /**
@@ -113,7 +113,7 @@ public final strictfp class AbstractIden
 
         assertEquals("name",        "WGS 84",                     object.getName().getCode());
         assertEquals("identifiers", "[EPSG:4326, EPSG:IgnoreMe]", object.getIdentifiers().toString());
-        assertEquals("ID",          "EPSG4326",                   object.getID());
+        assertEquals("ID",          "epsg-4326",                  object.getID());
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java?rev=1552492&r1=1552491&r2=1552492&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] Fri Dec 20 04:48:50 2013
@@ -44,6 +44,7 @@ import org.junit.BeforeClass;
     org.apache.sis.internal.referencing.FormulasTest.class,
     org.apache.sis.internal.referencing.VerticalDatumTypesTest.class,
     org.apache.sis.internal.referencing.AxisDirectionsTest.class,
+    org.apache.sis.internal.referencing.ReferencingUtilitiesTest.class,
     org.apache.sis.io.wkt.ConventionTest.class,
     org.apache.sis.io.wkt.SymbolsTest.class,
     org.apache.sis.io.wkt.FormatterTest.class,



Mime
View raw message