sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1726170 - in /sis/branches/JDK8/core: sis-referencing/src/main/java/org/apache/sis/referencing/factory/ sis-referencing/src/test/java/org/apache/sis/referencing/factory/ sis-utility/src/main/java/org/apache/sis/internal/util/
Date Fri, 22 Jan 2016 10:49:06 GMT
Author: desruisseaux
Date: Fri Jan 22 10:48:54 2016
New Revision: 1726170

URL: http://svn.apache.org/viewvc?rev=1726170&view=rev
Log:
Add test for codes in the "http://www.opengis.net/gml/srs/" namespace.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/CommonAuthorityFactory.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticAuthorityFactory.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/AuthorityFactoryMock.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

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/CommonAuthorityFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/CommonAuthorityFactory.java?rev=1726170&r1=1726169&r2=1726170&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/CommonAuthorityFactory.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/CommonAuthorityFactory.java
[UTF-8] Fri Jan 22 10:48:54 2016
@@ -313,7 +313,7 @@ public class CommonAuthorityFactory exte
                 }
                 if (!isRecognized) {
                     throw new NoSuchAuthorityCodeException(Errors.format(Errors.Keys.UnknownAuthority_1,
-                            CharSequences.trimWhitespaces(code.substring(0, s))), Constants.OGC,
code);
+                            CharSequences.trimWhitespaces(code, 0, s)), Constants.OGC, code);
                 }
             }
         }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticAuthorityFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticAuthorityFactory.java?rev=1726170&r1=1726169&r2=1726170&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticAuthorityFactory.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticAuthorityFactory.java
[UTF-8] Fri Jan 22 10:48:54 2016
@@ -1195,8 +1195,7 @@ public abstract class GeodeticAuthorityF
                         s = n;
                     }
                     final int length = code.length();
-                    s = CharSequences.skipLeadingWhitespaces(code, s+1, length);
-                    return code.substring(s, CharSequences.skipTrailingWhitespaces(code,
s, length));
+                    return CharSequences.trimWhitespaces(code, s+1, length).toString();
                 }
             }
         }

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=1726170&r1=1726169&r2=1726170&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 10:48:54 2016
@@ -427,15 +427,16 @@ public class MultiAuthoritiesFactory ext
      */
     private <T> T create(AuthorityFactoryProxy<? extends T> proxy, String code)
throws FactoryException {
         ArgumentChecks.ensureNonNull("code", code);
-        final String authority;
-        String version;
+        final String authority, version;
+        final String[] parameters;
         final DefinitionURI uri = DefinitionURI.parse(code);
         if (uri != null) {
             final Class<? extends T> type = proxy.type;
-            authority = uri.authority;
-            version   = uri.version;
-            code      = uri.code;
-            proxy     = proxy.cast(uri.type);
+            authority  = uri.authority;
+            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());
@@ -453,7 +454,6 @@ public class MultiAuthoritiesFactory ext
                 throw new NoSuchAuthorityFactoryException(Errors.format(Errors.Keys.MissingAuthority_1,
code), null);
             }
             authority = code.substring(start, end);
-            version = null;
             /*
              * Separate the version from the rest of the code. The version is optional. The
code may have no room
              * for version (e.g. "EPSG:4326"), or specify an empty version (e.g. "EPSG::4326").
If the version is
@@ -463,18 +463,12 @@ public class MultiAuthoritiesFactory ext
             int afterVersion = code.indexOf(DefaultNameSpace.DEFAULT_SEPARATOR, ++afterAuthority);
             start = CharSequences.skipLeadingWhitespaces(code, afterAuthority, afterVersion);
             end = CharSequences.skipTrailingWhitespaces(code, start, afterVersion);
-            if (start < end) {
-                if (end - start != 1 || code.charAt(start) != '0') {
-                    version = code.substring(start, end);
-                }
-            }
+            version = (start < end) ? code.substring(start, end) : null;
             /*
              * Separate the code from the authority and the version.
              */
-            afterVersion = Math.max(afterAuthority, afterVersion + 1);
-            end   = CharSequences.skipTrailingWhitespaces(code, afterVersion, code.length());
-            start = CharSequences.skipLeadingWhitespaces(code, afterVersion, end);
-            code  = code.substring(start, end);
+            code = CharSequences.trimWhitespaces(code, Math.max(afterAuthority, afterVersion
+ 1), code.length()).toString();
+            parameters = null;
         }
         /*
          * At this point we have the code without the authority and version parts.
@@ -483,11 +477,18 @@ public class MultiAuthoritiesFactory ext
          * depends on whether the authority is "AUTO" or "AUTO2". This works for now, but
we may need a more
          * rigorous approach in a future SIS version.
          */
-        if (code.indexOf(CommonAuthorityFactory.SEPARATOR) >= 0) {
-            code = authority + DefaultNameSpace.DEFAULT_SEPARATOR + code;
+        if (parameters != null || code.indexOf(CommonAuthorityFactory.SEPARATOR) >= 0)
{
+            final StringBuilder buffer = new StringBuilder(authority.length() + code.length()
+ 1)
+                    .append(authority).append(DefaultNameSpace.DEFAULT_SEPARATOR).append(code);
+            if (parameters != null) {
+                for (final String p : parameters) {
+                    buffer.append(CommonAuthorityFactory.SEPARATOR).append(p);
+                }
+            }
+            code = buffer.toString();
         }
-        return proxy.createFromAPI(
-                getAuthorityFactory(AuthorityFactoryIdentifier.create(proxy.factoryType,
authority, version)), code);
+        return proxy.createFromAPI(getAuthorityFactory(AuthorityFactoryIdentifier.create(
+                proxy.factoryType, authority, "0".equals(version) ? null : version)), code);
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/AuthorityFactoryMock.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/AuthorityFactoryMock.java?rev=1726170&r1=1726169&r2=1726170&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/AuthorityFactoryMock.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/AuthorityFactoryMock.java
[UTF-8] Fri Jan 22 10:48:54 2016
@@ -18,7 +18,7 @@ package org.apache.sis.referencing.facto
 
 import java.util.Set;
 import java.util.LinkedHashSet;
-import org.opengis.util.FactoryException;
+import org.opengis.metadata.extent.Extent;
 import org.opengis.metadata.citation.Citation;
 import org.opengis.referencing.IdentifiedObject;
 import org.opengis.referencing.NoSuchAuthorityCodeException;
@@ -26,13 +26,17 @@ import org.opengis.referencing.crs.CRSAu
 import org.opengis.referencing.crs.GeocentricCRS;
 import org.opengis.referencing.crs.GeographicCRS;
 import org.opengis.referencing.crs.VerticalCRS;
+import org.opengis.referencing.cs.CSAuthorityFactory;
 import org.opengis.referencing.datum.DatumAuthorityFactory;
 import org.opengis.referencing.datum.GeodeticDatum;
 import org.opengis.referencing.datum.PrimeMeridian;
 import org.opengis.referencing.datum.VerticalDatum;
 import org.opengis.util.InternationalString;
+import javax.measure.unit.Unit;
 import org.apache.sis.util.iso.SimpleInternationalString;
 import org.apache.sis.internal.simple.SimpleCitation;
+import org.apache.sis.measure.Units;
+import org.apache.sis.metadata.iso.extent.Extents;
 import org.apache.sis.referencing.datum.HardCodedDatum;
 import org.apache.sis.referencing.crs.HardCodedCRS;
 
@@ -48,7 +52,7 @@ import static org.junit.Assert.*;
  * @module
  */
 public final strictfp class AuthorityFactoryMock extends GeodeticAuthorityFactory
-        implements CRSAuthorityFactory, DatumAuthorityFactory
+        implements CRSAuthorityFactory, CSAuthorityFactory, DatumAuthorityFactory
 {
     /**
      * The authority.
@@ -107,9 +111,11 @@ public final strictfp class AuthorityFac
 
     /**
      * Returns the geodetic object for the given code.
+     *
+     * @throws NoSuchAuthorityCodeException if the given code is unknown.
      */
     @Override
-    public IdentifiedObject createObject(final String code) throws FactoryException {
+    public IdentifiedObject createObject(final String code) throws NoSuchAuthorityCodeException
{
         switch (Integer.parseInt(trimNamespace(code))) {
             case   84: return HardCodedCRS.WGS84;
             case 4326: return HardCodedCRS.WGS84_φλ;
@@ -129,4 +135,33 @@ public final strictfp class AuthorityFac
             default: throw new NoSuchAuthorityCodeException(code, authority.getTitle().toString(),
code);
         }
     }
+
+    /**
+     * Returns the unit of measurement for the given code.
+     *
+     * @return The unit of measurement.
+     * @throws NoSuchAuthorityCodeException if the given code is unknown.
+     */
+    @Override
+    public Unit<?> createUnit(final String code) throws NoSuchAuthorityCodeException
{
+        final Unit<?> unit = Units.valueOfEPSG(Integer.parseInt(trimNamespace(code)));
+        if (unit == null) {
+            throw new NoSuchAuthorityCodeException(code, authority.getTitle().toString(),
code);
+        }
+        return unit;
+    }
+
+    /**
+     * Returns the spatial extent for the given code.
+     *
+     * @return The spatial extent.
+     * @throws NoSuchAuthorityCodeException if the given code is unknown.
+     */
+    @Override
+    public Extent createExtent(final String code) throws NoSuchAuthorityCodeException {
+        switch (Integer.parseInt(trimNamespace(code))) {
+            case 1262: return Extents.WORLD;
+            default: throw new NoSuchAuthorityCodeException(code, authority.getTitle().toString(),
code);
+        }
+    }
 }

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=1726170&r1=1726169&r2=1726170&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 10:48:54 2016
@@ -19,6 +19,7 @@ package org.apache.sis.referencing.facto
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Set;
+import javax.measure.unit.SI;
 import org.opengis.referencing.IdentifiedObject;
 import org.opengis.referencing.NoSuchAuthorityCodeException;
 import org.opengis.referencing.crs.CRSAuthorityFactory;
@@ -34,6 +35,7 @@ import org.opengis.referencing.datum.Pri
 import org.opengis.referencing.datum.VerticalDatum;
 import org.opengis.util.FactoryException;
 import org.apache.sis.internal.system.Loggers;
+import org.apache.sis.metadata.iso.extent.Extents;
 import org.apache.sis.referencing.crs.HardCodedCRS;
 import org.apache.sis.referencing.datum.HardCodedDatum;
 import org.apache.sis.util.logging.Logging;
@@ -207,7 +209,7 @@ public final strictfp class MultiAuthori
     @DependsOnMethod("testGetAuthorityFactory")
     public void testCreateFromSimpleCodes() throws FactoryException {
         final Set<AuthorityFactoryMock> mock = Collections.singleton(new AuthorityFactoryMock("MOCK",
"2.3"));
-        final MultiAuthoritiesFactory factory = new MultiAuthoritiesFactory(mock, null, mock,
null);
+        final MultiAuthoritiesFactory factory = new MultiAuthoritiesFactory(mock, mock, mock,
null);
 
         assertSame("Straight",      HardCodedCRS  .WGS84_φλ,  factory.createGeographicCRS("MOCK:4326"));
         assertSame("With spaces",   HardCodedCRS  .WGS84,     factory.createGeographicCRS("
 mock :  84 "));
@@ -215,6 +217,8 @@ public final strictfp class MultiAuthori
         assertSame("Empty version", HardCodedDatum.GREENWICH, factory.createPrimeMeridian("
MoCk :: 8901"));
         assertSame("With spaces",   HardCodedCRS  .DEPTH,     factory.createVerticalCRS 
(" MoCk : : 9905"));
         assertSame("Version 0",     HardCodedDatum.SPHERE,    factory.createGeodeticDatum("MOCK:
0:6047"));
+        assertSame("With spaces",   Extents       .WORLD,     factory.createExtent      
("MOCK: 2.3 : 1262"));
+        assertSame("With spaces",   SI            .METRE,     factory.createUnit        
(" MoCK : : 9001 "));
         assertEquals("Greenwich",   factory.getDescriptionText("MOCK:8901").toString());
         try {
             factory.createGeodeticDatum("MOCK2:4326");
@@ -235,14 +239,15 @@ public final strictfp class MultiAuthori
     @DependsOnMethod("testCreateFromSimpleCodes")
     public void testCreateFromURNs() throws FactoryException {
         final Set<AuthorityFactoryMock> mock = Collections.singleton(new AuthorityFactoryMock("MOCK",
"2.3"));
-        final MultiAuthoritiesFactory factory = new MultiAuthoritiesFactory(mock, null, mock,
null);
+        final MultiAuthoritiesFactory factory = new MultiAuthoritiesFactory(mock, mock, mock,
null);
 
-        assertSame("Straight",      HardCodedCRS  .WGS84_φλ,  factory.createGeographicCRS("urn:ogc:def:crs:MOCK::4326"));
-//      assertSame("With spaces",   HardCodedCRS  .WGS84,     factory.createGeographicCRS("
urn : ogc  : def:crs :  mock :  84 "));
+        assertSame("Empty version", HardCodedCRS  .WGS84_φλ,  factory.createGeographicCRS("urn:ogc:def:crs:MOCK::4326"));
+        assertSame("With spaces",   HardCodedCRS  .WGS84,     factory.createGeographicCRS("
urn : ogc  : def:crs :  mock : :  84 "));
+        assertSame("Mixed case",    HardCodedCRS  .DEPTH,     factory.createVerticalCRS 
(" Urn : OGC : dEf : CRS : MoCk : : 9905"));
         assertSame("With version",  HardCodedDatum.WGS84,     factory.createDatum       
("urn:ogc:def:datum:mock:2.3:6326"));
         assertSame("Empty version", HardCodedDatum.GREENWICH, factory.createObject      
("urn:ogc:def:meridian: MoCk :: 8901"));
-        assertSame("With spaces",   HardCodedCRS  .DEPTH,     factory.createVerticalCRS 
(" urn : ogc : def : crs : MoCk : : 9905"));
-//      assertSame("Version 0",     HardCodedDatum.SPHERE,    factory.createGeodeticDatum("urn:ogc:def:datum:MOCK:
0 :6047"));
+        assertSame("Version 0",     HardCodedDatum.SPHERE,    factory.createGeodeticDatum("urn:ogc:def:datum:MOCK:
0 :6047"));
+        assertSame("Upper case",    SI            .METRE,     factory.createUnit        
("URN:OGC:DEF:UOM:MOCK::9001"));
         try {
             factory.createGeographicCRS("urn:ogc:def:datum:MOCK::4326");
             fail("Should create an object of the wrong type.");
@@ -252,4 +257,29 @@ public final strictfp class MultiAuthori
             assertTrue(message, message.contains("GeographicCRS"));
         }
     }
+
+    /**
+     * Tests {@code MultiAuthoritiesFactory.createFoo(String)} from codes in the
+     * {@code "http://www.opengis.net/gml/srs/authority.xml#code"} form.
+     *
+     * @throws FactoryException if an authority or a code is not recognized.
+     */
+    @Test
+    @DependsOnMethod("testCreateFromURNs")
+    public void testCreateFromHTTPs() throws FactoryException {
+        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("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 {
+            factory.createDatum("http://www.opengis.net/gml/srs/mock.xml#6326");
+            fail("Should create an object of the wrong type.");
+        } catch (NoSuchAuthorityCodeException e) {
+            final String message = e.getMessage();
+            assertTrue(message, message.contains("crs"));
+            assertTrue(message, message.contains("Datum"));
+        }
+    }
 }

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=1726170&r1=1726169&r2=1726170&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 10:48:54 2016
@@ -19,6 +19,7 @@ package org.apache.sis.internal.util;
 import java.util.Map;
 import java.util.Collections;
 
+import org.apache.sis.util.CharSequences;
 import static org.apache.sis.util.CharSequences.*;
 import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
 import static org.apache.sis.internal.util.Utilities.appendUnicodeIdentifier;
@@ -411,12 +412,12 @@ public final class DefinitionURI {
             }
             // TODO: For now do nothing since PATHS is a singleton. However if a future SIS
version
             //       defines more PATHS entries, then we should replace here the 'paths'
reference by
-            //       a new Collection.singletonMap containing only the entry of interest.
+            //       a new Collections.singletonMap containing only the entry of interest.
         }
         for (final Map.Entry<String,String> entry : paths.entrySet()) {
             final String path = entry.getValue();
             if (url.regionMatches(true, lower, path, 0, path.length())) {
-                lower += path.length();
+                lower = CharSequences.skipLeadingWhitespaces(url, lower + path.length(),
url.length());
                 if (authority == null) {
                     authority = url.substring(lower, skipIdentifierPart(url, lower));
                 } else if (!url.regionMatches(true, lower, authority, 0, authority.length()))
{



Mime
View raw message