sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1726225 - in /sis/branches/JDK8/core: sis-metadata/src/main/java/org/apache/sis/metadata/iso/ sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/ sis-referencing/src/main/java/org/apache/sis/referencing/ sis-referencing...
Date Fri, 22 Jan 2016 15:00:35 GMT
Author: desruisseaux
Date: Fri Jan 22 15:00:35 2016
New Revision: 1726225

URL: http://svn.apache.org/viewvc?rev=1726225&view=rev
Log:
Add support for codes like "http://www.opengis.net/def/crs/epsg/0/4326".

Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultIdentifier.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/Code.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/AuthorityFactoryProxy.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/AuthorityFactoryProxyTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactoryTest.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/metadata/iso/DefaultIdentifier.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultIdentifier.java?rev=1726225&r1=1726224&r2=1726225&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultIdentifier.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultIdentifier.java [UTF-8] Fri Jan 22 15:00:35 2016
@@ -50,7 +50,10 @@ import org.apache.sis.internal.util.Cita
  * one except for the {@code "MD_"} prefix. Example:
  *
  * {@preformat xml
- *   <gmd:MD_Identifier>
+ *   <gmd:MD_Identifier
+ *     <gmd:code>
+ *       <gco:CharacterString>4326</gco:CharacterString>
+ *     </gmd:code>
  *     <gmd:authority>
  *       <gmd:CI_Citation>
  *         <gmd:title>
@@ -58,9 +61,6 @@ import org.apache.sis.internal.util.Cita
  *         </gmd:title>
  *       </gmd:CI_Citation>
  *     </gmd:authority>
- *     <gmd:code>
- *       <gco:CharacterString>4326</gco:CharacterString>
- *     </gmd:code>
  *   </gmd:MD_Identifier>
  * }
  *

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java?rev=1726225&r1=1726224&r2=1726225&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java [UTF-8] Fri Jan 22 15:00:35 2016
@@ -107,9 +107,6 @@ import java.util.Objects;
  *
  * {@preformat xml
  *   <gmd:RS_Identifier>
- *     <gmd:code>
- *       <gco:CharacterString>4326</gco:CharacterString>
- *     </gmd:code>
  *     <gmd:authority>
  *       <gmd:CI_Citation>
  *         <gmd:title>
@@ -117,6 +114,9 @@ import java.util.Objects;
  *         </gmd:title>
  *       </gmd:CI_Citation>
  *     </gmd:authority>
+ *     <gmd:code>
+ *       <gco:CharacterString>4326</gco:CharacterString>
+ *     </gmd:code>
  *   </gmd:RS_Identifier>
  * }
  * </li></ul>

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/Code.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/Code.java?rev=1726225&r1=1726224&r2=1726225&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/Code.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/Code.java [UTF-8] Fri Jan 22 15:00:35 2016
@@ -103,7 +103,7 @@ public final class Code {
         Citation authority = null;
         String version = null, cs = codeSpace;
         final DefinitionURI parsed = DefinitionURI.parse(c);
-        if (parsed != null) {
+        if (parsed != null && parsed.code != null) {
             /*
              * Case where the URN has been successfully parsed. The OGC's URN contains an "authority" component,
              * which we take as the Identifier.codeSpace value (not Identifier.authority despite what the names

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java?rev=1726225&r1=1726224&r2=1726225&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java [UTF-8] Fri Jan 22 15:00:35 2016
@@ -149,7 +149,7 @@ public final class CRS extends Static {
         final String authority;
         final String value;
         final DefinitionURI uri = DefinitionURI.parse(code);
-        if (uri != null) {
+        if (uri != null && uri.code != null) {
             final String type = uri.type;
             if (type != null && !type.equalsIgnoreCase("crs")) {
                 throw new NoSuchIdentifierException(Errors.format(Errors.Keys.UnknownType_1, type), type);

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/AuthorityFactoryProxy.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/AuthorityFactoryProxy.java?rev=1726225&r1=1726224&r2=1726225&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/AuthorityFactoryProxy.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/AuthorityFactoryProxy.java [UTF-8] Fri Jan 22 15:00:35 2016
@@ -615,7 +615,7 @@ abstract class AuthorityFactoryProxy<T>
      * @return The proxy for the given type, or {@code null} if the given type is illegal.
      */
     @SuppressWarnings("unchecked")
-    final AuthorityFactoryProxy<? extends T> cast(final String typeName) {
+    final AuthorityFactoryProxy<? extends T> specialize(final String typeName) {
         final AuthorityFactoryProxy<?> c = BY_URN_TYPE.get(typeName.toLowerCase(Locale.US));
         if (c != null) {
             if (c.type.isAssignableFrom(type)) {

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java?rev=1726225&r1=1726224&r2=1726225&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java [UTF-8] Fri Jan 22 15:00:35 2016
@@ -51,7 +51,7 @@ import org.apache.sis.util.iso.DefaultNa
  * The list of factories to use as delegates can be specified at construction time.
  *
  * <p>This factory requires that every codes given to a {@code createFoo(String)} method are prefixed by a namespace,
- * for example {@code "EPSG::4326"}.
+ * for example {@code "EPSG:4326"} or {@code "EPSG::4326"}.
  * When a {@code createFoo(String)} method is invoked, this class uses the <var>authority</var> part in the
  * “<var>authority</var>:<var>code</var>” argument for locating a factory capable to create a geodetic object
  * for the <var>code</var> part.  If a factory is found in the list of factories given at construction time,
@@ -62,6 +62,7 @@ import org.apache.sis.util.iso.DefaultNa
  *
  * <ul>
  *   <li>{@code "urn:ogc:def:}<var>type</var>{@code :}<var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var>{@code "}</li>
+ *   <li>{@code "http://www.opengis.net/def/}<var>type</var>{@code /}<var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var>{@code "}</li>
  *   <li>{@code "http://www.opengis.net/gml/srs/}<var>authority</var>{@code .xml#}<var>code</var>{@code "}</li>
  * </ul>
  *
@@ -436,10 +437,16 @@ public class MultiAuthoritiesFactory ext
             version    = uri.version;
             code       = uri.code;
             parameters = uri.parameters;
-            proxy      = proxy.cast(uri.type);
-            if (proxy == null) {
-                throw new NoSuchAuthorityCodeException(Errors.format(Errors.Keys.CanNotCreateObjectOfType_2,
-                        type, uri.type), uri.authority, uri.code, uri.toString());
+            proxy      = proxy.specialize(uri.type);
+            if (code == null || proxy == null) {
+                final String s = uri.toString();
+                final String message;
+                if (code == null) {
+                    message = Errors.format(Errors.Keys.MissingComponentInElement_2, s, "code");
+                } else {
+                    message = Errors.format(Errors.Keys.CanNotCreateObjectOfType_2, type, uri.type);
+                }
+                throw new NoSuchAuthorityCodeException(message, authority, code, s);
             }
         } else {
             /*
@@ -463,7 +470,8 @@ public class MultiAuthoritiesFactory ext
             int afterVersion = code.indexOf(DefaultNameSpace.DEFAULT_SEPARATOR, ++afterAuthority);
             start = CharSequences.skipLeadingWhitespaces(code, afterAuthority, afterVersion);
             end = CharSequences.skipTrailingWhitespaces(code, start, afterVersion);
-            version = (start < end) ? code.substring(start, end) : null;
+            version = (start < end && !code.regionMatches(start, DefinitionURI.NO_VERSION, 0,
+                    DefinitionURI.NO_VERSION.length())) ? code.substring(start, end) : null;
             /*
              * Separate the code from the authority and the version.
              */
@@ -487,8 +495,7 @@ public class MultiAuthoritiesFactory ext
             }
             code = buffer.toString();
         }
-        return proxy.createFromAPI(getAuthorityFactory(AuthorityFactoryIdentifier.create(
-                proxy.factoryType, authority, "0".equals(version) ? null : version)), code);
+        return proxy.createFromAPI(getAuthorityFactory(AuthorityFactoryIdentifier.create(proxy.factoryType, authority, version)), code);
     }
 
     /**
@@ -498,6 +505,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var></li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
      *   <li>{@code urn:ogc:def:}<var>type</var>{@code :}<var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li>{@code http://www.opengis.net/def/}<var>type</var>{@code /}<var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      *   <li>{@code http://www.opengis.net/gml/srs/}<var>authority</var>{@code .xml#}<var>code</var></li>
      * </ul>
      *
@@ -517,6 +525,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var> — note that this form is ambiguous</li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var> — note that this form is ambiguous</li>
      *   <li>{@code urn:ogc:def:}<var>type</var>{@code :}<var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li>{@code http://www.opengis.net/def/}<var>type</var>{@code /}<var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      *   <li>{@code http://www.opengis.net/gml/srs/}<var>authority</var>{@code .xml#}<var>code</var></li>
      * </ul>
      *
@@ -538,6 +547,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var></li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
      *   <li><code>urn:ogc:def:<b>crs</b>:</code><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li><code>http://www.opengis.net/def/<b>crs</b>/</code><var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      *   <li>{@code http://www.opengis.net/gml/srs/}<var>authority</var>{@code .xml#}<var>code</var></li>
      * </ul>
      *
@@ -556,6 +566,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var></li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
      *   <li><code>urn:ogc:def:<b>crs</b>:</code><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li><code>http://www.opengis.net/def/<b>crs</b>/</code><var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      *   <li>{@code http://www.opengis.net/gml/srs/}<var>authority</var>{@code .xml#}<var>code</var></li>
      * </ul>
      *
@@ -574,6 +585,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var></li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
      *   <li><code>urn:ogc:def:<b>crs</b>:</code><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li><code>http://www.opengis.net/def/<b>crs</b>/</code><var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      *   <li>{@code http://www.opengis.net/gml/srs/}<var>authority</var>{@code .xml#}<var>code</var></li>
      * </ul>
      *
@@ -592,6 +604,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var></li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
      *   <li><code>urn:ogc:def:<b>crs</b>:</code><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li><code>http://www.opengis.net/def/<b>crs</b>/</code><var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      *   <li>{@code http://www.opengis.net/gml/srs/}<var>authority</var>{@code .xml#}<var>code</var></li>
      * </ul>
      *
@@ -610,6 +623,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var></li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
      *   <li><code>urn:ogc:def:<b>crs</b>:</code><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li><code>http://www.opengis.net/def/<b>crs</b>/</code><var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      *   <li>{@code http://www.opengis.net/gml/srs/}<var>authority</var>{@code .xml#}<var>code</var></li>
      * </ul>
      *
@@ -628,6 +642,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var></li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
      *   <li><code>urn:ogc:def:<b>crs</b>:</code><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li><code>http://www.opengis.net/def/<b>crs</b>/</code><var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      *   <li>{@code http://www.opengis.net/gml/srs/}<var>authority</var>{@code .xml#}<var>code</var></li>
      * </ul>
      *
@@ -646,6 +661,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var></li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
      *   <li><code>urn:ogc:def:<b>crs</b>:</code><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li><code>http://www.opengis.net/def/<b>crs</b>/</code><var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      *   <li>{@code http://www.opengis.net/gml/srs/}<var>authority</var>{@code .xml#}<var>code</var></li>
      * </ul>
      *
@@ -664,6 +680,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var></li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
      *   <li><code>urn:ogc:def:<b>crs</b>:</code><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li><code>http://www.opengis.net/def/<b>crs</b>/</code><var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      *   <li>{@code http://www.opengis.net/gml/srs/}<var>authority</var>{@code .xml#}<var>code</var></li>
      * </ul>
      *
@@ -682,6 +699,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var></li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
      *   <li><code>urn:ogc:def:<b>crs</b>:</code><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li><code>http://www.opengis.net/def/<b>crs</b>/</code><var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      *   <li>{@code http://www.opengis.net/gml/srs/}<var>authority</var>{@code .xml#}<var>code</var></li>
      * </ul>
      *
@@ -700,6 +718,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var></li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
      *   <li><code>urn:ogc:def:<b>crs</b>:</code><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li><code>http://www.opengis.net/def/<b>crs</b>/</code><var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      *   <li>{@code http://www.opengis.net/gml/srs/}<var>authority</var>{@code .xml#}<var>code</var></li>
      * </ul>
      *
@@ -718,6 +737,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var></li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
      *   <li><code>urn:ogc:def:<b>datum</b>:</code><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li><code>http://www.opengis.net/def/<b>datum</b>/</code><var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      * </ul>
      *
      * @return The datum for the given code.
@@ -735,6 +755,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var></li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
      *   <li><code>urn:ogc:def:<b>datum</b>:</code><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li><code>http://www.opengis.net/def/<b>datum</b>/</code><var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      * </ul>
      *
      * @return The datum for the given code.
@@ -752,6 +773,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var></li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
      *   <li><code>urn:ogc:def:<b>datum</b>:</code><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li><code>http://www.opengis.net/def/<b>datum</b>/</code><var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      * </ul>
      *
      * @return The datum for the given code.
@@ -769,6 +791,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var></li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
      *   <li><code>urn:ogc:def:<b>datum</b>:</code><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li><code>http://www.opengis.net/def/<b>datum</b>/</code><var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      * </ul>
      *
      * @return The datum for the given code.
@@ -786,6 +809,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var></li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
      *   <li><code>urn:ogc:def:<b>datum</b>:</code><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li><code>http://www.opengis.net/def/<b>datum</b>/</code><var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      * </ul>
      *
      * @return The datum for the given code.
@@ -803,6 +827,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var></li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
      *   <li><code>urn:ogc:def:<b>datum</b>:</code><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li><code>http://www.opengis.net/def/<b>datum</b>/</code><var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      * </ul>
      *
      * @return The datum for the given code.
@@ -820,6 +845,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var></li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
      *   <li><code>urn:ogc:def:<b>ellipsoid</b>:</code><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li><code>http://www.opengis.net/def/<b>ellipsoid</b>/</code><var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      * </ul>
      *
      * @return The ellipsoid for the given code.
@@ -837,6 +863,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var></li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
      *   <li><code>urn:ogc:def:<b>meridian</b>:</code><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li><code>http://www.opengis.net/def/<b>meridian</b>/</code><var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      * </ul>
      *
      * @return The prime meridian for the given code.
@@ -870,6 +897,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var></li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
      *   <li><code>urn:ogc:def:<b>cs</b>:</code><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li><code>http://www.opengis.net/def/<b>cs</b>/</code><var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      * </ul>
      *
      * @return The coordinate system for the given code.
@@ -887,6 +915,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var></li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
      *   <li><code>urn:ogc:def:<b>cs</b>:</code><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li><code>http://www.opengis.net/def/<b>cs</b>/</code><var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      * </ul>
      *
      * @return The coordinate system for the given code.
@@ -904,6 +933,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var></li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
      *   <li><code>urn:ogc:def:<b>cs</b>:</code><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li><code>http://www.opengis.net/def/<b>cs</b>/</code><var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      * </ul>
      *
      * @return The coordinate system for the given code.
@@ -921,6 +951,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var></li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
      *   <li><code>urn:ogc:def:<b>cs</b>:</code><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li><code>http://www.opengis.net/def/<b>cs</b>/</code><var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      * </ul>
      *
      * @return The coordinate system for the given code.
@@ -938,6 +969,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var></li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
      *   <li><code>urn:ogc:def:<b>cs</b>:</code><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li><code>http://www.opengis.net/def/<b>cs</b>/</code><var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      * </ul>
      *
      * @return The coordinate system for the given code.
@@ -955,6 +987,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var></li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
      *   <li><code>urn:ogc:def:<b>cs</b>:</code><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li><code>http://www.opengis.net/def/<b>cs</b>/</code><var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      * </ul>
      *
      * @return The coordinate system for the given code.
@@ -973,6 +1006,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var></li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
      *   <li><code>urn:ogc:def:<b>cs</b>:</code><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li><code>http://www.opengis.net/def/<b>cs</b>/</code><var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      * </ul>
      *
      * @return The coordinate system for the given code.
@@ -991,6 +1025,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var></li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
      *   <li><code>urn:ogc:def:<b>cs</b>:</code><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li><code>http://www.opengis.net/def/<b>cs</b>/</code><var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      * </ul>
      *
      * @return The coordinate system for the given code.
@@ -1008,6 +1043,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var></li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
      *   <li><code>urn:ogc:def:<b>axis</b>:</code><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li><code>http://www.opengis.net/def/<b>axis</b>/</code><var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      * </ul>
      *
      * @return The axis for the given code.
@@ -1025,6 +1061,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var></li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
      *   <li><code>urn:ogc:def:<b>uom</b>:</code><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li><code>http://www.opengis.net/def/<b>uom</b>/</code><var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      * </ul>
      *
      * @return The unit of measurement for the given code.
@@ -1042,6 +1079,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var></li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
      *   <li><code>urn:ogc:def:<b>parameter</b>:</code><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li><code>http://www.opengis.net/def/<b>parameter</b>/</code><var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      * </ul>
      *
      * @return The parameter descriptor for the given code.
@@ -1059,6 +1097,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var></li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
      *   <li><code>urn:ogc:def:<b>method</b>:</code><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li><code>http://www.opengis.net/def/<b>method</b>/</code><var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      * </ul>
      *
      * @return The operation method for the given code.
@@ -1076,6 +1115,7 @@ public class MultiAuthoritiesFactory ext
      *   <li><var>authority</var>{@code :}<var>code</var></li>
      *   <li><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
      *   <li><code>urn:ogc:def:<b>coordinateOperation</b>:</code><var>authority</var>{@code :}<var>version</var>{@code :}<var>code</var></li>
+     *   <li><code>http://www.opengis.net/def/<b>coordinateOperation</b>/</code><var>authority</var>{@code /}<var>version</var>{@code /}<var>code</var></li>
      * </ul>
      *
      * @return The operation for the given code.

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/AuthorityFactoryProxyTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/AuthorityFactoryProxyTest.java?rev=1726225&r1=1726224&r2=1726225&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/AuthorityFactoryProxyTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/AuthorityFactoryProxyTest.java [UTF-8] Fri Jan 22 15:00:35 2016
@@ -83,20 +83,20 @@ public final strictfp class AuthorityFac
     }
 
     /**
-     * Tests {@link AuthorityFactoryProxy#cast(String)}.
+     * Tests {@link AuthorityFactoryProxy#specialize(String)}.
      */
     @Test
-    public void testCast() {
+    public void testSpecialize() {
         final AuthorityFactoryProxy<IdentifiedObject> base = AuthorityFactoryProxy.OBJECT;
-        assertEquals(CoordinateReferenceSystem.class, base.cast("CRS")      .type);
-        assertEquals(CoordinateSystem.class,          base.cast("CS")       .type);
-        assertEquals(CoordinateSystemAxis.class,      base.cast("aXis")     .type);
-        assertEquals(PrimeMeridian.class,             base.cast("Meridian") .type);
-        assertEquals(Ellipsoid.class,                 base.cast("ellipsoid").type);
-        assertEquals(Datum.class,                     base.cast("datum")    .type);
+        assertEquals(CoordinateReferenceSystem.class, base.specialize("CRS")      .type);
+        assertEquals(CoordinateSystem.class,          base.specialize("CS")       .type);
+        assertEquals(CoordinateSystemAxis.class,      base.specialize("aXis")     .type);
+        assertEquals(PrimeMeridian.class,             base.specialize("Meridian") .type);
+        assertEquals(Ellipsoid.class,                 base.specialize("ellipsoid").type);
+        assertEquals(Datum.class,                     base.specialize("datum")    .type);
 
-        assertEquals(GeodeticDatum.class, AuthorityFactoryProxy.GEODETIC_DATUM.cast("datum").type);
-        assertNull(AuthorityFactoryProxy.COORDINATE_SYSTEM.cast("datum"));
+        assertEquals(GeodeticDatum.class, AuthorityFactoryProxy.GEODETIC_DATUM.specialize("datum").type);
+        assertNull(AuthorityFactoryProxy.COORDINATE_SYSTEM.specialize("datum"));
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactoryTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactoryTest.java?rev=1726225&r1=1726224&r2=1726225&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactoryTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactoryTest.java [UTF-8] Fri Jan 22 15:00:35 2016
@@ -270,7 +270,8 @@ public final strictfp class MultiAuthori
         final Set<AuthorityFactoryMock> mock = Collections.singleton(new AuthorityFactoryMock("MOCK", "2.3"));
         final MultiAuthoritiesFactory factory = new MultiAuthoritiesFactory(mock, mock, mock, null);
 
-        assertSame("Straight",      HardCodedCRS  .WGS84_φλ,  factory.createGeographicCRS("http://www.opengis.net/gml/srs/mock.xml#4326"));
+        assertSame("HTTP",          HardCodedCRS  .WGS84_φλ,  factory.createGeographicCRS("http://www.opengis.net/def/crs/mock/0/4326"));
+        assertSame("GML",           HardCodedCRS  .WGS84_φλ,  factory.createObject       ("http://www.opengis.net/gml/srs/mock.xml#4326"));
         assertSame("With spaces",   HardCodedCRS  .WGS84,     factory.createGeographicCRS("http://www.opengis.net/gml/srs/ mock.xml # 84 "));
         assertSame("Mixed case",    HardCodedCRS  .DEPTH,     factory.createVerticalCRS  ("HTTP://www.OpenGIS.net/GML/SRS/MoCk.xml#9905"));
         try {

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=1726225&r1=1726224&r2=1726225&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] Fri Jan 22 15:00:35 2016
@@ -36,9 +36,16 @@ import static org.apache.sis.internal.ut
  *   <li>{@code "urn:ogc:def:crs:EPSG::4326"} (version number is omitted)</li>
  *   <li>{@code "urn:ogc:def:crs:EPSG:8.2:4326"} (explicit version number, here 8.2)</li>
  *   <li>{@code "urn:x-ogc:def:crs:EPSG::4326"} (prior registration of {@code "ogc"} to IANA)</li>
+ *   <li>{@code "http://www.opengis.net/def/crs/EPSG/0/4326"}</li>
  *   <li>{@code "http://www.opengis.net/gml/srs/epsg.xml#4326"}</li>
  * </ul>
  *
+ * This class does not attempt to decode URL characters. For example a URL for "m/s" may be encoded as below,
+ * in which case the value in the {@code #code} field will be {@code "m%2Fs"} instead of {@code "m/s"}.
+ * <ul>
+ *   <li>{@code http://www.opengis.net/def/uom/SI/0/m%2Fs}</li>
+ * </ul>
+ *
  * <div class="section">Components or URN</div>
  * URN begins with {@code "urn:ogc:def:"} (formerly {@code "urn:x-ogc:def:"}) followed by:
  * <ul>
@@ -106,7 +113,7 @@ import static org.apache.sis.internal.ut
  */
 public final class DefinitionURI {
     /**
-     * The {@value} prefix used in all URI supported by this class.
+     * The {@value} prefix used in all URN supported by this class.
      */
     public static final String PREFIX = "urn:ogc:def";
 
@@ -116,22 +123,39 @@ public final class DefinitionURI {
     public static final char SEPARATOR = ':';
 
     /**
+     * The domain of URLs in the OGC namespace.
+     */
+    private static final String DOMAIN = "www.opengis.net";
+
+    /**
      * Server and path portions of HTTP URL for various types (currently {@code "crs"}).
      * For each URL, value starts after the protocol part and finishes before the authority filename.
      *
      * <p>As of Apache SIS 0.4, this map has a single entry. However more entries may be added in future SIS versions.
-     * If new entries are added, then see the TODO comment in the {@link #codeForHTTP(String, String, String, int,
+     * If new entries are added, then see the TODO comment in the {@link #codeForGML(String, String, String, int,
      * DefinitionURI)} method.</p>
      */
-    private static final Map<String,String> PATHS = Collections.singletonMap("crs", "//www.opengis.net/gml/srs/");
+    private static final Map<String,String> PATHS = Collections.singletonMap("crs", "//" + DOMAIN + "/gml/srs/");
 
     /**
-     * {@code true} if the URI is a {@code "http://www.opengis.net/gml/…"} URL, or
+     * A version number to be considered as if no version were provided.
+     * This value is part of OGC specification (not a SIS-specific hack).
+     */
+    public static final String NO_VERSION = "0";
+
+    /**
+     * {@code true} if the URI is a {@code "http://www.opengis.net/…"} URL, or
      * {@code false} if the URI is a {@code "urn:ogc:def:…"} URN.
      */
     public boolean isHTTP;
 
     /**
+     * {@code true} if the URI is a {@code "http://www.opengis.net/gml/…"} URL.
+     * A value of {@code true} should imply that {@link #isHTTP} is also {@code true}.
+     */
+    public boolean isGML;
+
+    /**
      * The type part of a URI, or {@code null} if none (empty).
      * Note that the set of valid types in OGC namespace is restricted.
      * See class javadoc for more information.
@@ -157,6 +181,7 @@ public final class DefinitionURI {
 
     /**
      * The version part of a URI, or {@code null} if none (empty).
+     * This field is null if the version in the parsed string was {@value #NO_VERSION}.
      *
      * <div class="note"><b>Example:</b>
      * In the {@code "urn:ogc:def:crs:EPSG:8.2:4326"} URN, this is {@code "8.2"}.</div>
@@ -186,68 +211,99 @@ public final class DefinitionURI {
     }
 
     /**
-     * Parses the given URI.
+     * Attempts to parse the given URI, which may either a URN or URL.
+     * If this method does not recognize the given URI, then it returns {@code null}.
+     * If the given URI is incomplete, then the {@link #code} value will be {@code null}.
      *
      * @param  uri The URI to parse.
      * @return The parse result, or {@code null} if the given URI is not recognized.
      */
-    @SuppressWarnings("null")
     public static DefinitionURI parse(final String uri) {
         ensureNonNull("uri", uri);
         DefinitionURI result = null;
+        char separator = SEPARATOR;
         int upper = -1;
+        /*
+         * Loop on all parts that we expect in the URI. Those parts are:
+         *
+         *   0:  "urn" or "http://www.opengis.net"
+         *   1:  "ogc" or "x-ogc"
+         *   2:  "def"
+         *   3:  "crs", "datum" or other types. The value is not controlled by this method.
+         *   4:  "ogc", "epsg", or other authorities. The value is not controlled by this method.
+         *   5:  version, or null if none.
+         *   6:  code
+         *   7:  parameters, or null if none.
+         */
         for (int p=0; p<=6; p++) {
             final int lower = upper + 1;
-            upper = uri.indexOf(SEPARATOR, lower);
+            upper = uri.indexOf(separator, lower);
             if (upper < 0) {
-                if (p != 6) {
-                    return null; // No more components.
-                }
                 upper = uri.length();
             }
-            final String require;
             switch (p) {
                 /*
-                 * Verifies that the 3 first components are ""urn:ogc:def:" without storing them.
-                 * In the particular case of second component, we also accept "x-ogc" in addition
-                 * to "ogc". The actual verification is performed after the 'switch' case.
+                 * Verifies that the 3 first components are "urn:ogc:def:" or "http://www.opengis.net/def/"
+                 * without storing them. In the particular case of second component, we also accept "x-ogc"
+                 * in addition to "ogc" in URN.
                  */
-                case 0: if (regionMatches("http", uri, lower, upper)) {
-                            result = new DefinitionURI();
-                            return codeForHTTP(null, null, uri, upper+1, result) != null ? result : null;
+                case 0: {
+                    if (regionMatches("http", uri, lower, upper)) {
+                        result = new DefinitionURI();
+                        result.isHTTP = true;
+                        if (codeForGML(null, null, uri, ++upper, result) != null) {
+                            return result;
                         }
-                        require = "urn";   break;
-                case 1: if (regionMatches("ogc", uri, lower, upper)) continue;
-                        require = "x-ogc"; break;
-                case 2: require = "def";   break;
-                default: {
-                    /*
-                     * For all components after the first 3 ones, trim whitespaces and store non-empty values.
-                     */
-                    String value = trimWhitespaces(uri, lower, upper).toString();
-                    if (value.isEmpty()) {
-                        value = null;
+                        if (!uri.regionMatches(upper, "//", 0, 2)) {
+                            return null;
+                        }
+                        upper++;
+                        separator = '/';    // Separator for the HTTP namespace.
+                    } else if (!regionMatches("urn", uri, lower, upper)) {
+                        return null;
                     }
-                    switch (p) {
-                        case 3:  result = new DefinitionURI();
-                                 result.type      = value; break;
-                        case 4:  result.authority = value; break;
-                        case 5:  result.version   = value; break;
-                        case 6:  result.code      = value; break;
-                        default: throw new AssertionError(p);
+                    break;
+                }
+                case 1: {
+                    final boolean isHTTP = (separator != SEPARATOR);
+                    if (!regionMatches(isHTTP ? DOMAIN : "ogc", uri, lower, upper)) {
+                        if (isHTTP  ||  !regionMatches("x-ogc", uri, lower, upper)) {
+                            return null;
+                        }
+                    }
+                    break;
+                }
+                case 2: {
+                    if (!regionMatches("def", uri, lower, upper)) {
+                        return null;
+                    }
+                    break;
+                }
+                /*
+                 * For all components after the first 3 ones, trim whitespaces and store non-empty values.
+                 */
+                default: {
+                    final String value = trimWhitespaces(uri, lower, upper).toString();
+                    if (!value.isEmpty() && (p != 5 || !NO_VERSION.equals(value))) {
+                        if (result == null) {
+                            result = new DefinitionURI();
+                        }
+                        switch (p) {
+                            case 3:  result.type      = value; break;
+                            case 4:  result.authority = value; break;
+                            case 5:  result.version   = value; break;
+                            case 6:  result.code      = value; break;
+                            default: throw new AssertionError(p);
+                        }
                     }
-                    continue;
                 }
-            }
-            if (!regionMatches(require, uri, lower, upper)) {
-                return null;
             }
         }
         /*
          * Take every remaining components as parameters.
          */
-        if (++upper < uri.length()) {
-            result.parameters = (String[]) split(uri.substring(upper), SEPARATOR);
+        if (result != null && ++upper < uri.length()) {
+            result.parameters = (String[]) split(uri.substring(upper), separator);
         }
         return result;
     }
@@ -294,7 +350,7 @@ public final class DefinitionURI {
             // Ignore the version number (actually everything up to the first ':').
             fromIndex = skipLeadingWhitespaces(urn, s+1, length);
             if (fromIndex >= length || urn.indexOf(SEPARATOR, fromIndex) >= 0) {
-                return null; // Empty code, or the code is followed by parameters.
+                return null;    // Empty code, or the code is followed by parameters.
             }
         }
         return urn.substring(fromIndex, skipTrailingWhitespaces(urn, fromIndex, length));
@@ -358,7 +414,7 @@ public final class DefinitionURI {
             return null;
         }
         if (length == 4) {
-            return codeForHTTP(type, authority, uri, upper+1, null);
+            return codeForGML(type, authority, uri, upper+1, null);
         }
         /*
          * At this point we have determined that the protocol is URN. The next components after "urn"
@@ -388,7 +444,7 @@ public final class DefinitionURI {
     }
 
     /**
-     * Implementation of URI parser for the HTTP forms.
+     * Implementation of URI parser for the HTTP forms in GML namespace.
      * The current implementation recognizes the following types:
      *
      * <ul>
@@ -401,7 +457,7 @@ public final class DefinitionURI {
      * @param url       The URL to parse.
      * @param result    If non-null, store the type, authority and code in that object.
      */
-    private static String codeForHTTP(final String type, String authority, final String url, int lower,
+    private static String codeForGML(final String type, String authority, final String url, int lower,
             final DefinitionURI result)
     {
         Map<String, String> paths = PATHS;
@@ -430,7 +486,7 @@ public final class DefinitionURI {
                     if ((lower = url.indexOf('#', lower+1)) >= 0) {
                         final String code = trimWhitespaces(url, lower+1, upper).toString();
                         if (result != null) {
-                            result.isHTTP    = true;
+                            result.isGML     = true;
                             result.type      = entry.getKey();
                             result.authority = authority;
                             result.code      = code;
@@ -478,8 +534,10 @@ public final class DefinitionURI {
                 default: throw new AssertionError(p);
             }
             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.
+                /*
+                 * 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;
                 }
@@ -489,12 +547,28 @@ public final class DefinitionURI {
     }
 
     /**
-     * Returns a URN representation of this URI.
+     * 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 an URL,
+     * then this method formats the URI in the {@code "http://www.opengis.net/"} namespace.
+     * Otherwise this method formats the URI as a URN.
      *
-     * @return A URN representation of this URI.
+     * @return The string representation of this URI.
      */
-    public String toURN() {
+    @Override
+    public String toString() {
+        if (isGML) {
+            final String path = PATHS.get(type);
+            if (path != null) {
+                return "http:" + path + authority + ".xml#" + code;
+            }
+        }
         final StringBuilder buffer = new StringBuilder(PREFIX);
+        char separator = SEPARATOR;
+        if (isHTTP) {
+            buffer.setLength(0);
+            buffer.append("http://").append(DOMAIN).append("/def");
+            separator = '/';
+        }
         int n = 4;
         if (parameters != null) {
             n += parameters.length;
@@ -508,28 +582,13 @@ public final class DefinitionURI {
                 case 3:  component = code;            break;
                 default: component = parameters[p-4]; break;
             }
-            buffer.append(SEPARATOR);
-            if (component != null) {
-                buffer.append(component);
+            buffer.append(separator);
+            if (component == null) {
+                if (!isHTTP) continue;
+                component = NO_VERSION;
             }
+            buffer.append(component);
         }
         return buffer.toString();
     }
-
-    /**
-     * Returns a string representation of this URI. If the URI were originally a HTTP URL,
-     * then this method format the URI as such. Otherwise this method returns {@link #toURN()}.
-     *
-     * @return The string representation of this URI.
-     */
-    @Override
-    public String toString() {
-        if (isHTTP) {
-            final String path = PATHS.get(type);
-            if (path != null) {
-                return "http:" + path + authority + ".xml#" + code;
-            }
-        }
-        return toURN();
-    }
 }

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=1726225&r1=1726224&r2=1726225&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] Fri Jan 22 15:00:35 2016
@@ -29,7 +29,7 @@ import static org.junit.Assert.*;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.4
- * @version 0.4
+ * @version 0.7
  * @module
  */
 public final strictfp class DefinitionURITest extends TestCase {
@@ -44,6 +44,7 @@ public final strictfp class DefinitionUR
         DefinitionURI parsed = DefinitionURI.parse(" urn:ogc:def: crs : EPSG: 8.2 :4326 ");
         assertNotNull("DefinitionURI", parsed);
         assertEquals ("isHTTP",    false,   parsed.isHTTP);
+        assertEquals ("isGML",     false,   parsed.isGML);
         assertEquals ("type",      "crs",   parsed.type);
         assertEquals ("authority", "EPSG",  parsed.authority);
         assertEquals ("version",   "8.2",   parsed.version);
@@ -54,6 +55,7 @@ public final strictfp class DefinitionUR
         parsed = DefinitionURI.parse("URN :X-OGC: Def:crs:EPSG::4326");
         assertNotNull("DefinitionURI", parsed);
         assertEquals ("isHTTP",    false,   parsed.isHTTP);
+        assertEquals ("isGML",     false,   parsed.isGML);
         assertEquals ("type",      "crs",   parsed.type);
         assertEquals ("authority", "EPSG",  parsed.authority);
         assertNull   ("version",            parsed.version);
@@ -72,6 +74,7 @@ public final strictfp class DefinitionUR
         final DefinitionURI parsed = DefinitionURI.parse("urn:ogc:def:crs:OGC:1.3:AUTO42003:1:-100:45");
         assertNotNull("DefinitionURI", parsed);
         assertEquals ("isHTTP",    false,       parsed.isHTTP);
+        assertEquals ("isGML",     false,       parsed.isGML);
         assertEquals ("type",      "crs",       parsed.type);
         assertEquals ("authority", "OGC",       parsed.authority);
         assertEquals ("version",   "1.3",       parsed.version);
@@ -82,14 +85,33 @@ public final strictfp class DefinitionUR
     }
 
     /**
-     * Tests {@link DefinitionURI#parse(String)} on {@code "http://www.opengis.net/gml/srs/epsg.xml#4326"}.
+     * Tests {@link DefinitionURI#parse(String)} on {@code "http://www.opengis.net/def/crs/epsg/0/4326"}.
      */
     @Test
     @DependsOnMethod("testParse")
     public void testParseHTTP() {
+        final DefinitionURI parsed = DefinitionURI.parse("http://www.opengis.net/def/crs/epsg/0/4326");
+        assertNotNull("DefinitionURI", parsed);
+        assertEquals ("isHTTP",    true,   parsed.isHTTP);
+        assertEquals ("isGML",     false,  parsed.isGML);
+        assertEquals ("type",      "crs",  parsed.type);
+        assertEquals ("authority", "epsg", parsed.authority);
+        assertNull   ("version",           parsed.version);
+        assertEquals ("code",      "4326", parsed.code);
+        assertNull   ("parameters",        parsed.parameters);
+        assertEquals ("toString()", "http://www.opengis.net/def/crs/epsg/0/4326", parsed.toString());
+    }
+
+    /**
+     * Tests {@link DefinitionURI#parse(String)} on {@code "http://www.opengis.net/gml/srs/epsg.xml#4326"}.
+     */
+    @Test
+    @DependsOnMethod("testParse")
+    public void testParseGML() {
         final DefinitionURI parsed = DefinitionURI.parse("http://www.opengis.net/gml/srs/epsg.xml#4326");
         assertNotNull("DefinitionURI", parsed);
         assertEquals ("isHTTP",    true,   parsed.isHTTP);
+        assertEquals ("isGML",     true,   parsed.isGML);
         assertEquals ("type",      "crs",  parsed.type);
         assertEquals ("authority", "epsg", parsed.authority);
         assertNull   ("version",           parsed.version);
@@ -137,7 +159,7 @@ public final strictfp class DefinitionUR
      * {@code "http://www.opengis.net/gml/srs/epsg.xml#4326"}.
      */
     @Test
-    public void testCodeOfHTTP() {
+    public void testCodeOfGML() {
         assertEquals("4326", DefinitionURI.codeOf("crs", "EPSG", "http://www.opengis.net/gml/srs/epsg.xml#4326"));
         assertNull  (        DefinitionURI.codeOf("crs", "OGC",  "http://www.opengis.net/gml/srs/epsg.xml#4326"));
         assertNull  (        DefinitionURI.codeOf("uom", "EPSG", "http://www.opengis.net/gml/srs/epsg.xml#4326"));



Mime
View raw message