sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1812174 - in /sis/branches/JDK8/core: sis-metadata/src/main/java/org/apache/sis/internal/metadata/ sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/ sis-metadata/src/test/java/org/apache/sis/internal/metadata/ sis-utility/sr...
Date Sat, 14 Oct 2017 09:31:32 GMT
Author: desruisseaux
Date: Sat Oct 14 09:31:32 2017
New Revision: 1812174

URL: http://svn.apache.org/viewvc?rev=1812174&view=rev
Log:
Simplify a little bit DefinitionURI by moving the 'format(…)' code to the only place where
it was used.

Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/NameMeaning.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/Citations.java
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/NameMeaningTest.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java
    sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/DefinitionURITest.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/NameMeaning.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/NameMeaning.java?rev=1812174&r1=1812173&r2=1812174&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/NameMeaning.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/NameMeaning.java
[UTF-8] Sat Oct 14 09:31:32 2017
@@ -29,6 +29,7 @@ import org.opengis.referencing.operation
 import org.opengis.util.InternationalString;
 import org.opengis.metadata.citation.Citation;
 import org.apache.sis.util.Static;
+import org.apache.sis.internal.util.Utilities;
 import org.apache.sis.internal.util.Constants;
 import org.apache.sis.internal.util.DefinitionURI;
 import org.apache.sis.metadata.iso.citation.Citations;
@@ -39,9 +40,9 @@ import org.apache.sis.metadata.iso.citat
  * The meaning are defined by <cite>OGC Naming Authority</cite> (OGCNA) or other
OGC sources.
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
- * @version 0.7
+ * @version 0.8
  *
- * @see org.apache.sis.internal.util.DefinitionURI
+ * @see DefinitionURI
  * @see <a href="http://www.opengeospatial.org/ogcna">http://www.opengeospatial.org/ogcna</a>
  * @see <a href="http://portal.opengeospatial.org/files/?artifact_id=24045">Definition
identifier URNs in OGC namespace</a>
  *
@@ -71,7 +72,7 @@ public final class NameMeaning extends S
 
     /**
      * The object types for instances of {@link #CLASSES}.
-     * See {@link org.apache.sis.internal.util.DefinitionURI} javadoc for a list of object
types in URN.
+     * See {@link DefinitionURI} javadoc for a list of object types in URN.
      *
      * <p>Types not yet listed (waiting to see if there is a use for them):</p>
      *
@@ -142,8 +143,10 @@ public final class NameMeaning extends S
 
     /**
      * Formats the given identifier using the {@code "ogc:urn:def:"} syntax with possible
heuristic changes to
-     * the given values. This method delegates to {@link DefinitionURI#format(String, String,
String, String)}
-     * after "fixing" the given values using some heuristic knowledge about the meaning of
URN.
+     * the given values. 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}. This method tries to "fix" the given values using
some heuristic
+     * knowledge about the meaning of URN.
      *
      * @param  type       the object type.
      * @param  authority  the authority as one of the values documented in {@link DefinitionURI}
javadoc.
@@ -151,49 +154,67 @@ public final class NameMeaning extends S
      * @param  code       the code.
      * @return an identifier using the URN syntax, or {@code null} if a mandatory information
is missing.
      *
-     * @see DefinitionURI#format(String, String, String, String)
-     *
      * @since 0.7
      */
     public static String toURN(final Class<?> type, final String authority, String
version, String code) {
-        if (type != null && authority != null && code != null) {
-            final String key = authority.toUpperCase(Locale.US);
-            String codeSpace = AUTHORITIES.get(key);
-            if (codeSpace == null) {
-                /*
-                 * If the given authority is not one of the authorities that we expected
for the OGC namespace,
-                 * verify if we can related it to one of the specifications enumerated in
the Citations class.
-                 * For example if the user gave us "OGP" as the authority, we will replace
that by "IOGP" (the
-                 * new name for that organization).
-                 */
-                final Citation c = Citations.fromName(key);
-                codeSpace = Citations.getCodeSpace(c);
-                if (AUTHORITIES.get(codeSpace) == null) {
-                    return null;            // Not an authority that we recognize for the
OGC namespace.
-                }
-                version = getVersion(c);    // Unconditionally overwrite the user-specified
version.
+        if (type == null || authority == null || code == null) {
+            return null;
+        }
+        final String key = authority.toUpperCase(Locale.US);
+        String codeSpace = AUTHORITIES.get(key);
+        if (codeSpace == null) {
+            /*
+             * If the given authority is not one of the authorities that we expected for
the OGC namespace,
+             * verify if we can related it to one of the specifications enumerated in the
Citations class.
+             * For example if the user gave us "OGP" as the authority, we will replace that
by "IOGP" (the
+             * new name for that organization).
+             */
+            final Citation c = Citations.fromName(key);
+            codeSpace = Citations.getCodeSpace(c);
+            if (AUTHORITIES.get(codeSpace) == null) {
+                return null;            // Not an authority that we recognize for the OGC
namespace.
+            }
+            version = getVersion(c);    // Unconditionally overwrite the user-specified version.
+            /*
+             * If the above lines resulted in a change of codespace, we may need to concatenate
the authority
+             * with the code for preserving information. The main use case is WMS codes like
"CRS:84":
+             *
+             *   1) Citations.fromName("CRS") gave us Citations.WMS (version 1.3) as the
authority.
+             *   2) getCodeSpace(Citations.WMS) gave us "OGC", which is indeed the codespace
used in URN.
+             *   3) OGC Naming Authority – Procedures (OGC-09-046r2) said that "CRS:84"
should be formatted
+             *      as "urn:ogc:def:crs:OGC:1.3:CRS84". We already got the "OGC" and "1.3"
parts with above
+             *      steps, the last part is to replace "84" by "CRS84".
+             */
+            if (!authority.equals(codeSpace) && !code.startsWith(authority)) {
+                code = authority + code;    // Intentionally no ':' separator.
+            }
+        }
+        final StringBuilder buffer = new StringBuilder(DefinitionURI.PREFIX);
+loop:   for (int p=0; ; p++) {
+            final String part;
+            switch (p) {
+                case 0:  part = toObjectType(type); break;
+                case 1:  part = codeSpace;          break;
+                case 2:  part = version;            break;
+                case 3:  part = code;               break;
+                default: break loop;
+            }
+            if (!Utilities.appendUnicodeIdentifier(buffer.append(DefinitionURI.SEPARATOR),
'\u0000', part, ".-", false)) {
                 /*
-                 * If the above lines resulted in a chance of codespace, we may need to concatenate
the authority
-                 * with the code for preserving information. The main use case is WMS codes
like "CRS:84":
-                 *
-                 *   1) Citations.fromName("CRS") gave us Citations.WMS (version 1.3) as
the authority.
-                 *   2) getCodeSpace(Citations.WMS) gave us "OGC", which is indeed the codespace
used in URN.
-                 *   3) OGC Naming Authority – Procedures (OGC-09-046r2) said that "CRS:84"
should be formatted
-                 *      as "urn:ogc:def:crs:OGC:1.3:CRS84". We already got the "OGC" and
"1.3" parts with above
-                 *      steps, the last part is to replace "84" by "CRS84".
+                 * 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 (!authority.equals(codeSpace) && !code.startsWith(authority))
{
-                    code = authority + code;    // Intentionally no ':' separator.
+                if (p != 2) {
+                    return null;
                 }
             }
-            return DefinitionURI.format(toObjectType(type), codeSpace, version, code);
         }
-        return null;
+        return buffer.toString();
     }
 
     /**
      * Returns the "object type" part of an OGC URN for the given class, or {@code null}
if unknown.
-     * See {@link org.apache.sis.internal.util.DefinitionURI} javadoc for a list of object
types in URN.
+     * See {@link DefinitionURI} javadoc for a list of object types in URN.
      *
      * @param  type  the class for which to get the URN type.
      * @return the URN type, or {@code null} if unknown.

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/Citations.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/Citations.java?rev=1812174&r1=1812173&r2=1812174&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/Citations.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/Citations.java
[UTF-8] Sat Oct 14 09:31:32 2017
@@ -251,7 +251,7 @@ public final class Citations extends Sta
      * <ul>
      *   <li><a href="http://www.opengeospatial.org/standards/ct">Coordinate
Transformation Service</a></li>
      *   <li><a href="http://www.opengeospatial.org/standards/wms">Web Map Service</a></li>
-     *   <li>Definition identifier URNs in OGC namespace</li>
+     *   <li><a href="http://portal.opengeospatial.org/files/?artifact_id=24045">Definition
identifier URNs in OGC namespace</a></li>
      * </ul>
      *
      * We do not commit to a particular OGC specification in order to keep the flexibility
to change the

Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/NameMeaningTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/NameMeaningTest.java?rev=1812174&r1=1812173&r2=1812174&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/NameMeaningTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/NameMeaningTest.java
[UTF-8] Sat Oct 14 09:31:32 2017
@@ -64,7 +64,9 @@ public final strictfp class NameMeaningT
     @Test
     @DependsOnMethod("testToObjectType")
     public void testToURN() {
+        assertEquals("urn:ogc:def:crs:EPSG::4326",    NameMeaning.toURN(GeodeticCRS.class,
  "EPSG", null, "4326"));
         assertEquals("urn:ogc:def:crs:OGC:1.3:CRS84", NameMeaning.toURN(GeographicCRS.class,
"CRS",  null,   "84"));
         assertEquals("urn:ogc:def:datum:EPSG::6326",  NameMeaning.toURN(GeodeticDatum.class,
"EPSG", null, "6326"));
+        assertNull  ("Authority is not optional.",    NameMeaning.toURN(GeographicCRS.class,
null,   null, "4326"));
     }
 }

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java?rev=1812174&r1=1812173&r2=1812174&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java
[UTF-8] Sat Oct 14 09:31:32 2017
@@ -25,7 +25,6 @@ import org.apache.sis.internal.system.Lo
 
 import static org.apache.sis.util.CharSequences.*;
 import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
-import static org.apache.sis.internal.util.Utilities.appendUnicodeIdentifier;
 
 
 /**
@@ -684,43 +683,6 @@ public final class DefinitionURI {
     }
 
     /**
-     * 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 types documented in class javadoc,
or {@code null}.
-     * @param  authority  the authority as one of the values documented in class javadoc,
or {@code null}.
-     * @param  version    the code version, or {@code null}. This is the only optional information.
-     * @param  code       the code, or {@code null}.
-     * @return an identifier using the URN syntax, or {@code null} if a mandatory information
is missing.
-     *
-     * @see org.apache.sis.internal.metadata.NameMeaning#toURN(Class, String, String, String)
-     */
-    public static String format(final String type, final String authority, final String version,
final String code) {
-        final StringBuilder buffer = new StringBuilder(PREFIX);
-loop:   for (int p=0; ; p++) {
-            final String part;
-            switch (p) {
-                case 0:  part = type;      break;
-                case 1:  part = authority; break;
-                case 2:  part = version;   break;
-                case 3:  part = code;      break;
-                default: break loop;
-            }
-            if (!appendUnicodeIdentifier(buffer.append(SEPARATOR), '\u0000', part, ".-",
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 null;
-                }
-            }
-        }
-        return buffer.toString();
-    }
-
-    /**
      * Returns a string representation of this URI. If the URI were originally a GML's URL,
then this method formats
      * the URI in the {@code "http://www.opengis.net/gml/srs/"} namespace. Otherwise the
URI were originally a URL,
      * then this method formats the URI in the {@code "http://www.opengis.net/"} namespace.

Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/DefinitionURITest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/DefinitionURITest.java?rev=1812174&r1=1812173&r2=1812174&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/DefinitionURITest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/DefinitionURITest.java
[UTF-8] Sat Oct 14 09:31:32 2017
@@ -232,13 +232,4 @@ public final strictfp class DefinitionUR
         assertNull  (        DefinitionURI.codeOf("uom", "EPSG", "http://www.opengis.net/gml/srs/epsg.xml#4326"));
         assertNull  (        DefinitionURI.codeOf("uom", "EPSG", "http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#xpointer(//*[@gml:id='m'])"));
     }
-
-    /**
-     * Tests {@link DefinitionURI#format(String, String, String, String)}.
-     */
-    @Test
-    public void testToURN() {
-        assertEquals("urn:ogc:def:crs:EPSG::4326", DefinitionURI.format("crs", "EPSG", null,
"4326"));
-        assertNull  ("Authority is not optional.", DefinitionURI.format("crs", null,   null,
"4326"));
-    }
 }



Mime
View raw message