sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1747559 - in /sis/branches/JDK8: application/sis-console/src/main/java/org/apache/sis/console/ application/sis-console/src/test/java/org/apache/sis/console/ application/sis-console/src/test/java/org/apache/sis/test/suite/ application/sis-o...
Date Thu, 09 Jun 2016 15:44:57 GMT
Author: desruisseaux
Date: Thu Jun  9 15:44:57 2016
New Revision: 1747559

URL: http://svn.apache.org/viewvc?rev=1747559&view=rev
Log:
Allow the EPSG fallback to create also datum objects, and add tests.

Added:
    sis/branches/JDK8/application/sis-console/src/test/java/org/apache/sis/console/CRSCommandTest.java   (with props)
    sis/branches/JDK8/application/sis-openoffice/src/test/java/org/
    sis/branches/JDK8/application/sis-openoffice/src/test/java/org/apache/
    sis/branches/JDK8/application/sis-openoffice/src/test/java/org/apache/sis/
    sis/branches/JDK8/application/sis-openoffice/src/test/java/org/apache/sis/openoffice/
    sis/branches/JDK8/application/sis-openoffice/src/test/java/org/apache/sis/openoffice/ReferencingTest.java   (with props)
    sis/branches/JDK8/application/sis-openoffice/src/test/java/org/apache/sis/openoffice/TransformerTest.java   (with props)
    sis/branches/JDK8/application/sis-openoffice/src/test/java/org/apache/sis/test/
    sis/branches/JDK8/application/sis-openoffice/src/test/java/org/apache/sis/test/suite/
    sis/branches/JDK8/application/sis-openoffice/src/test/java/org/apache/sis/test/suite/OpenOfficeTestSuite.java   (with props)
    sis/branches/JDK8/application/sis-openoffice/src/test/java/org/apache/sis/test/suite/package-info.txt
      - copied unchanged from r1747372, sis/branches/JDK8/application/sis-console/src/test/java/org/apache/sis/test/suite/package-info.txt
Modified:
    sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/CRSCommand.java
    sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/IdentifierCommand.java
    sis/branches/JDK8/application/sis-console/src/test/java/org/apache/sis/console/MetadataCommandTest.java
    sis/branches/JDK8/application/sis-console/src/test/java/org/apache/sis/test/suite/ConsoleTestSuite.java
    sis/branches/JDK8/application/sis-openoffice/src/main/java/org/apache/sis/openoffice/Referencing.java
    sis/branches/JDK8/application/sis-openoffice/src/main/java/org/apache/sis/openoffice/Transformer.java
    sis/branches/JDK8/application/sis-openoffice/src/main/java/org/apache/sis/openoffice/XReferencing.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/EPSGFactoryFallback.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CommonCRSTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/EPSGFactoryFallbackTest.java

Modified: sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/CRSCommand.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/CRSCommand.java?rev=1747559&r1=1747558&r2=1747559&view=diff
==============================================================================
--- sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/CRSCommand.java [UTF-8] (original)
+++ sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/CRSCommand.java [UTF-8] Thu Jun  9 15:44:57 2016
@@ -37,7 +37,7 @@ import org.apache.sis.io.wkt.Convention;
  */
 final class CRSCommand extends MetadataCommand {
     /**
-     * Creates the {@code "metadata"}, {@code "crs"} or {@code "identifier"} sub-command.
+     * Creates the {@code "crs"} sub-command.
      */
     CRSCommand(final int commandIndex, final String... args) throws InvalidOptionException {
         super(commandIndex, args);

Modified: sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/IdentifierCommand.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/IdentifierCommand.java?rev=1747559&r1=1747558&r2=1747559&view=diff
==============================================================================
--- sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/IdentifierCommand.java [UTF-8] (original)
+++ sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/IdentifierCommand.java [UTF-8] Thu Jun  9 15:44:57 2016
@@ -91,7 +91,7 @@ final class IdentifierCommand extends Me
     }
 
     /**
-     * Creates the {@code "metadata"}, {@code "crs"} or {@code "identifier"} sub-command.
+     * Creates the {@code "identifier"} sub-command.
      */
     IdentifierCommand(final int commandIndex, final String... args) throws InvalidOptionException {
         super(commandIndex, args);

Added: sis/branches/JDK8/application/sis-console/src/test/java/org/apache/sis/console/CRSCommandTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/application/sis-console/src/test/java/org/apache/sis/console/CRSCommandTest.java?rev=1747559&view=auto
==============================================================================
--- sis/branches/JDK8/application/sis-console/src/test/java/org/apache/sis/console/CRSCommandTest.java (added)
+++ sis/branches/JDK8/application/sis-console/src/test/java/org/apache/sis/console/CRSCommandTest.java [UTF-8] Thu Jun  9 15:44:57 2016
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.console;
+
+import org.apache.sis.test.DependsOnMethod;
+import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.apache.sis.test.Assert.*;
+
+
+/**
+ * Tests the {@link CRSCommand} sub-command.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.8
+ * @version 0.8
+ * @module
+ */
+@DependsOn(CommandRunnerTest.class)
+public final strictfp class CRSCommandTest extends TestCase {
+    /**
+     * The Well Known Text for EPSG:4326.
+     */
+    private static final String WGS84 =
+            "GeodeticCRS[\"WGS 84\",\n" +
+            "  Datum[\"World Geodetic System 1984\",\n" +
+            "    Ellipsoid[\"WGS 84\", 6378137.0, 298.257223563]],\n" +
+            "  CS[ellipsoidal, 2],\n" +
+            "    Axis[\"Latitude (B)\", north],\n" +
+            "    Axis[\"Longitude (L)\", east],\n" +
+            "    Unit[\"degree\", 0.017453292519943295],\n" +
+            "  Scope[\"Horizontal component of 3D system. Used by the GPS satellite navigation system and for NATO military geodetic surveying.\"],\n" +
+            "  Area[\"World.\"],\n" +
+            "  BBox[-90.00, -180.00, 90.00, 180.00],\n" +
+            "  Id[\"EPSG\", 4326, \"8.9\", URI[\"urn:ogc:def:crs:EPSG:8.9:4326\"]]]\n";
+
+    /**
+     * Tests fetching the CRS from a simple code ({@code "EPSG:4326"}).
+     *
+     * @throws Exception if an error occurred while creating the command.
+     */
+    @Test
+    public void testCode() throws Exception {
+        final CRSCommand test = new CRSCommand(0, CommandRunner.TEST, "EPSG:4326");
+        test.run();
+        assertMultilinesEquals(WGS84, test.outputBuffer.toString());
+    }
+
+    /**
+     * Tests fetching the CRS from a URN ({@code "urn:ogc:def:crs:epsg::4326"}).
+     *
+     * @throws Exception if an error occurred while creating the command.
+     */
+    @Test
+    @DependsOnMethod("testCode")
+    public void testURN() throws Exception {
+        final CRSCommand test = new CRSCommand(0, CommandRunner.TEST, "urn:ogc:def:crs:epsg::4326");
+        test.run();
+        assertMultilinesEquals(WGS84, test.outputBuffer.toString());
+    }
+
+    /**
+     * Tests fetching the CRS from a HTTP code ({@code "http://www.opengis.net/gml/srs/epsg.xml#4326"}).
+     *
+     * @throws Exception if an error occurred while creating the command.
+     */
+    @Test
+    @DependsOnMethod("testURN")
+    public void testHTTP() throws Exception {
+        final CRSCommand test = new CRSCommand(0, CommandRunner.TEST, "http://www.opengis.net/gml/srs/epsg.xml#4326");
+        test.run();
+        assertMultilinesEquals(WGS84, test.outputBuffer.toString());
+    }
+}

Propchange: sis/branches/JDK8/application/sis-console/src/test/java/org/apache/sis/console/CRSCommandTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/application/sis-console/src/test/java/org/apache/sis/console/CRSCommandTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK8/application/sis-console/src/test/java/org/apache/sis/console/MetadataCommandTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/application/sis-console/src/test/java/org/apache/sis/console/MetadataCommandTest.java?rev=1747559&r1=1747558&r2=1747559&view=diff
==============================================================================
--- sis/branches/JDK8/application/sis-console/src/test/java/org/apache/sis/console/MetadataCommandTest.java [UTF-8] (original)
+++ sis/branches/JDK8/application/sis-console/src/test/java/org/apache/sis/console/MetadataCommandTest.java [UTF-8] Thu Jun  9 15:44:57 2016
@@ -39,7 +39,7 @@ public final strictfp class MetadataComm
     /**
      * Tests the sub-command on a NetCDF file.
      *
-     * @throws Exception Should never happen.
+     * @throws Exception if an error occurred while creating the command.
      */
     @Test
     public void testNetCDF() throws Exception {
@@ -65,7 +65,7 @@ public final strictfp class MetadataComm
     /**
      * Tests with the same file than {@link #testNetCDF()}, but producing a XML output.
      *
-     * @throws Exception Should never happen.
+     * @throws Exception if an error occurred while creating the command.
      */
     @Test
     @DependsOnMethod("testNetCDF")

Modified: sis/branches/JDK8/application/sis-console/src/test/java/org/apache/sis/test/suite/ConsoleTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/application/sis-console/src/test/java/org/apache/sis/test/suite/ConsoleTestSuite.java?rev=1747559&r1=1747558&r2=1747559&view=diff
==============================================================================
--- sis/branches/JDK8/application/sis-console/src/test/java/org/apache/sis/test/suite/ConsoleTestSuite.java [UTF-8] (original)
+++ sis/branches/JDK8/application/sis-console/src/test/java/org/apache/sis/test/suite/ConsoleTestSuite.java [UTF-8] Thu Jun  9 15:44:57 2016
@@ -26,7 +26,7 @@ import org.junit.BeforeClass;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.4
+ * @version 0.8
  * @module
  */
 @Suite.SuiteClasses({
@@ -34,7 +34,8 @@ import org.junit.BeforeClass;
     org.apache.sis.console.HelpCommandTest.class,
     org.apache.sis.console.AboutCommandTest.class,
     org.apache.sis.console.MimeTypeCommandTest.class,
-    org.apache.sis.console.MetadataCommandTest.class
+    org.apache.sis.console.MetadataCommandTest.class,
+    org.apache.sis.console.CRSCommandTest.class
 })
 public final strictfp class ConsoleTestSuite extends TestSuite {
     /**

Modified: sis/branches/JDK8/application/sis-openoffice/src/main/java/org/apache/sis/openoffice/Referencing.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/application/sis-openoffice/src/main/java/org/apache/sis/openoffice/Referencing.java?rev=1747559&r1=1747558&r2=1747559&view=diff
==============================================================================
--- sis/branches/JDK8/application/sis-openoffice/src/main/java/org/apache/sis/openoffice/Referencing.java [UTF-8] (original)
+++ sis/branches/JDK8/application/sis-openoffice/src/main/java/org/apache/sis/openoffice/Referencing.java [UTF-8] Thu Jun  9 15:44:57 2016
@@ -35,6 +35,8 @@ import com.sun.star.lang.IllegalArgument
 import org.apache.sis.metadata.iso.extent.Extents;
 import org.apache.sis.referencing.CRS;
 import org.apache.sis.referencing.IdentifiedObjects;
+import org.apache.sis.referencing.AbstractIdentifiedObject;
+import org.apache.sis.io.wkt.Transliterator;
 import org.apache.sis.util.Classes;
 import org.apache.sis.util.collection.Cache;
 import org.apache.sis.util.resources.Errors;
@@ -215,8 +217,9 @@ public class Referencing extends CalcAdd
     }
 
     /**
-     * Returns the axis name and units for the specified dimension
-     * in a coordinate reference system or coordinate system.
+     * Returns the axis name and units for the specified dimension in a coordinate reference system or coordinate system.
+     * This method returns a short axis name as used in Well Known Text (WKT) format, for example <cite>"Latitude"</cite>
+     * instead of <cite>"Geodetic latitude"</cite>.
      *
      * @param  xOptions    provided by OpenOffice.
      * @param  codeOrPath  the code allocated by an authority, or the path to a file.
@@ -238,18 +241,24 @@ public class Referencing extends CalcAdd
                     } catch (Exception exception) {
                         return getLocalizedMessage(exception);
                     }
+                    CoordinateSystem cs = null;
                     final CoordinateSystemAxis axis;
                     if (object instanceof CoordinateSystemAxis) {
                         axis = (CoordinateSystemAxis) object;
                     } else {
-                        final CoordinateSystem cs;
                         if (object instanceof CoordinateReferenceSystem) {
                             cs = ((CoordinateReferenceSystem) object).getCoordinateSystem();
                         } else if (object instanceof CoordinateSystem) {
                             cs = (CoordinateSystem) object;
                         } else {
+                            final Class<?> actual;
+                            if (object instanceof AbstractIdentifiedObject) {
+                                actual = ((AbstractIdentifiedObject) object).getInterface();
+                            } else {
+                                actual = Classes.getClass(object);
+                            }
                             return Errors.getResources(getJavaLocale()).getString(Errors.Keys.UnexpectedTypeForReference_3,
-                                    codeOrPath, CoordinateReferenceSystem.class, Classes.getClass(object));
+                                    codeOrPath, CoordinateReferenceSystem.class, actual);
                         }
                         if (dimension >= 1 && dimension <= cs.getDimension()) {
                             axis = cs.getAxis(dimension - 1);
@@ -258,7 +267,7 @@ public class Referencing extends CalcAdd
                         }
                     }
                     final String unit = PatchedUnitFormat.toString(axis.getUnit());
-                    name = axis.getName().getCode();
+                    name = Transliterator.DEFAULT.toShortAxisName(cs, axis.getDirection(), axis.getName().getCode());
                     if (unit != null && !unit.isEmpty()) {
                         name = name + " (" + unit + ')';
                     }
@@ -307,7 +316,8 @@ public class Referencing extends CalcAdd
         }
         return new double[][] {
             new double[] {area.getNorthBoundLatitude(), area.getWestBoundLongitude()},
-            new double[] {area.getSouthBoundLatitude(), area.getEastBoundLongitude()}};
+            new double[] {area.getSouthBoundLatitude(), area.getEastBoundLongitude()}
+        };
     }
 
     /**
@@ -362,7 +372,9 @@ public class Referencing extends CalcAdd
     public double[][] transformCoordinates(final XPropertySet xOptions,
             final String sourceCRS, final String targetCRS, final double[][] points)
     {
-        try {
+        if (points == null || points.length == 0) {
+            return new double[][] {};
+        } else try {
             return new Transformer(this, getCRS(sourceCRS), targetCRS, points).transform(points);
         } catch (Exception exception) {
             reportException("transformCoordinates", exception, THROW_EXCEPTION);

Modified: sis/branches/JDK8/application/sis-openoffice/src/main/java/org/apache/sis/openoffice/Transformer.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/application/sis-openoffice/src/main/java/org/apache/sis/openoffice/Transformer.java?rev=1747559&r1=1747558&r2=1747559&view=diff
==============================================================================
--- sis/branches/JDK8/application/sis-openoffice/src/main/java/org/apache/sis/openoffice/Transformer.java [UTF-8] (original)
+++ sis/branches/JDK8/application/sis-openoffice/src/main/java/org/apache/sis/openoffice/Transformer.java [UTF-8] Thu Jun  9 15:44:57 2016
@@ -17,6 +17,7 @@
 package org.apache.sis.openoffice;
 
 import org.opengis.util.FactoryException;
+import org.opengis.metadata.extent.GeographicBoundingBox;
 import org.opengis.referencing.crs.GeographicCRS;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.opengis.referencing.operation.CoordinateOperation;
@@ -78,22 +79,24 @@ final class Transformer {
                 southBoundLatitude = Double.POSITIVE_INFINITY;
                 eastBoundLongitude = Double.NEGATIVE_INFINITY;
                 northBoundLatitude = Double.NEGATIVE_INFINITY;
-                for (final double[] coord : points) {
-                    if (coord.length == dimension) {
-                        try {
-                            toDomainOfValidity.transform(coord, 0, domainCoord, 0, 1);
-                        } catch (TransformException e) {
-                            if (warning == null) {
-                                warning = e;
+                if (points != null) {
+                    for (final double[] coord : points) {
+                        if (coord != null && coord.length == dimension) {
+                            try {
+                                toDomainOfValidity.transform(coord, 0, domainCoord, 0, 1);
+                            } catch (TransformException e) {
+                                if (warning == null) {
+                                    warning = e;
+                                }
+                                continue;
                             }
-                            continue;
+                            final double x = domainCoord[0];
+                            final double y = domainCoord[1];
+                            if (x < westBoundLongitude) westBoundLongitude = x;
+                            if (x > eastBoundLongitude) eastBoundLongitude = x;
+                            if (y < southBoundLatitude) southBoundLatitude = y;
+                            if (y > northBoundLatitude) northBoundLatitude = y;
                         }
-                        final double x = domainCoord[0];
-                        final double y = domainCoord[1];
-                        if (x < westBoundLongitude) westBoundLongitude = x;
-                        if (x > eastBoundLongitude) eastBoundLongitude = x;
-                        if (y < southBoundLatitude) southBoundLatitude = y;
-                        if (y > northBoundLatitude) northBoundLatitude = y;
                     }
                 }
             }
@@ -112,9 +115,7 @@ final class Transformer {
                 operation = handler.peek();
                 if (operation == null) {
                     operation = CRS.findOperation(sourceCRS, caller.getCRS(targetCRS),
-                            hasAreaOfInterest ? new DefaultGeographicBoundingBox(
-                                    westBoundLongitude, eastBoundLongitude,
-                                    southBoundLatitude, northBoundLatitude) : null);
+                            hasAreaOfInterest ? getAreaOfInterest() : null);
                 }
             } finally {
                 handler.putAndUnlock(operation);
@@ -125,11 +126,20 @@ final class Transformer {
     /**
      * Returns {@code true} if the area of interest is non-empty.
      */
-    private boolean hasAreaOfInterest() {
+    final boolean hasAreaOfInterest() {
         return (westBoundLongitude < eastBoundLongitude) && (southBoundLatitude < northBoundLatitude);
     }
 
     /**
+     * Returns the area of interest. It is caller's responsibility to verify that
+     * {@link #hasAreaOfInterest()} returned {@code true} before to invoke this method.
+     */
+    final GeographicBoundingBox getAreaOfInterest() {
+        return new DefaultGeographicBoundingBox(westBoundLongitude, eastBoundLongitude,
+                                                southBoundLatitude, northBoundLatitude);
+    }
+
+    /**
      * Returns the accuracy in metres.
      */
     final double getAccuracy() {

Modified: sis/branches/JDK8/application/sis-openoffice/src/main/java/org/apache/sis/openoffice/XReferencing.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/application/sis-openoffice/src/main/java/org/apache/sis/openoffice/XReferencing.java?rev=1747559&r1=1747558&r2=1747559&view=diff
==============================================================================
--- sis/branches/JDK8/application/sis-openoffice/src/main/java/org/apache/sis/openoffice/XReferencing.java [UTF-8] (original)
+++ sis/branches/JDK8/application/sis-openoffice/src/main/java/org/apache/sis/openoffice/XReferencing.java [UTF-8] Thu Jun  9 15:44:57 2016
@@ -48,8 +48,9 @@ public interface XReferencing extends XI
     String getName(XPropertySet xOptions, String codeOrPath);
 
     /**
-     * Returns the axis name and units for the specified dimension
-     * in a coordinate reference system or coordinate system.
+     * Returns the axis name and units for the specified dimension in a coordinate reference system or coordinate system.
+     * This method returns a short axis name as used in Well Known Text (WKT) format, for example <cite>"Latitude"</cite>
+     * instead of <cite>"Geodetic latitude"</cite>.
      *
      * @param  xOptions    provided by OpenOffice.
      * @param  codeOrPath  the code allocated by an authority, or the path to a file.

Added: sis/branches/JDK8/application/sis-openoffice/src/test/java/org/apache/sis/openoffice/ReferencingTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/application/sis-openoffice/src/test/java/org/apache/sis/openoffice/ReferencingTest.java?rev=1747559&view=auto
==============================================================================
--- sis/branches/JDK8/application/sis-openoffice/src/test/java/org/apache/sis/openoffice/ReferencingTest.java (added)
+++ sis/branches/JDK8/application/sis-openoffice/src/test/java/org/apache/sis/openoffice/ReferencingTest.java [UTF-8] Thu Jun  9 15:44:57 2016
@@ -0,0 +1,172 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.openoffice;
+
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.lang.IllegalArgumentException;
+import org.apache.sis.internal.referencing.Formulas;
+import org.apache.sis.internal.referencing.PositionalAccuracyConstant;
+import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.TestCase;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+import static org.junit.Assume.assumeFalse;
+
+
+/**
+ * Tests {@link Referencing}.
+ *
+ * @author  Martin Desruisseaux (IRD, Geomatys)
+ * @since   0.8
+ * @version 0.8
+ * @module
+ */
+@DependsOn(TransformerTest.class)
+public final strictfp class ReferencingTest extends TestCase {
+    /**
+     * A dummy {@code XPropertySet} instance for testing purpose.
+     * The current implementation sets the value to {@code null} since {@link Referencing} ignores the properties.
+     * But that value could be changed if the properties are not ignored anymore in a future SIS version.
+     */
+    private static final XPropertySet properties = null;
+
+    /**
+     * The instance to use for testing purpose.
+     */
+    private static Referencing instance;
+
+    /**
+     * Creates a {@link Referencing} instance to use for all tests.
+     */
+    @BeforeClass
+    public static void createReferencingInstance() {
+        instance = new Referencing();
+        instance.setLocale(new com.sun.star.lang.Locale("en", "US", null));
+    }
+
+    /**
+     * Disposes the {@link Referencing} instance after all tests completed.
+     */
+    @AfterClass
+    public static void disposeReferencingInstance() {
+        instance = null;
+    }
+
+    /**
+     * Tests {@link Referencing#getName(XPropertySet, String)}.
+     */
+    @Test
+    public void testGetName() {
+        assertEquals("Using a simple code.", "WGS 84", instance.getName(properties, "EPSG:4326"));
+        assertEquals("Using a URN.",         "WGS 84", instance.getName(properties, "urn:ogc:def:crs:epsg::4326"));
+        assertEquals("Using a HTTP code.",   "WGS 84", instance.getName(properties, "http://www.opengis.net/gml/srs/epsg.xml#4326"));
+        assertEquals("Cached value.",        "WGS 84", instance.getName(properties, "EPSG:4326"));
+        assertEquals("URN for a datum.", "World Geodetic System 1984",
+                instance.getName(properties, "urn:ogc:def:datum:epsg::6326"));
+    }
+
+    /**
+     * Tests {@link Referencing#getAxis(XPropertySet, String, int)}.
+     */
+    @Test
+    public void testGetAxis() {
+        assertEquals("Latitude (°)",              instance.getAxis(properties, "EPSG:4326", 1));
+        assertEquals("Longitude (°)",             instance.getAxis(properties, "EPSG:4326", 2));
+        assertEquals("Index 3 is out of bounds.", instance.getAxis(properties, "EPSG:4326", 3));
+        assertEquals("Expected “urn:ogc:def:datum:epsg::6326” to reference an instance of ‘CoordinateReferenceSystem’, " +
+                "but found an instance of ‘GeodeticDatum’.", instance.getAxis(properties, "urn:ogc:def:datum:epsg::6326", 1));
+    }
+
+    /**
+     * Tests {@link Referencing#getGeographicArea(XPropertySet, String)}.
+     */
+    @Test
+    public void testGetGeographicArea() {
+        final double[][] bbox = instance.getGeographicArea(properties, "EPSG:32620");     // UTM zone 20
+        assertEquals(2, bbox.length);
+        assumeFalse(Double.isNaN(bbox[0][0]));    // NaN if EPSG dataset is not installed.
+        assertArrayEquals("Upper left corner",  new double[] {84, -66}, bbox[0], STRICT);
+        assertArrayEquals("Lower right corner", new double[] { 0, -60}, bbox[1], STRICT);
+    }
+
+    /**
+     * Tests {@link Referencing#getAccuracy(XPropertySet, String, String, double[][])}.
+     * This test asks for a transformation from NAD83 to WGS84.
+     */
+    @Test
+    public void testGetAccuracy() {
+        final double accuracy = instance.getAccuracy(properties, "EPSG:4269", "EPSG:4326", new double[][] {
+            {37.783, -122.417},     // San-Francisco
+            {40.713,  -74.006},     // New-York
+            {34.050, -118.250},     // Los Angeles
+            {29.763,  -95.383},     // Houston
+            {41.837,  -87.685},     // Chicago
+            {25.775,  -80.209},     // Miami
+        });
+        assertTrue("Accuracy = " + accuracy,
+                accuracy > Formulas.LINEAR_TOLERANCE &&
+                accuracy <= PositionalAccuracyConstant.UNKNOWN_ACCURACY);
+    }
+
+    /**
+     * Tests {@link Referencing#transformCoordinates(XPropertySet, String, String, double[][])}.
+     */
+    @Test
+    public void testTransformCoordinates() {
+        final double[][] points = {
+            new double[] {30,  20,  4},
+            new double[] {34,  17, -3},
+            new double[] {27, -12, 12},
+            new double[] {32,  23, -1}
+        };
+        final double[][] result = {
+            new double[] {30,  20},
+            new double[] {34,  17},
+            new double[] {27, -12},
+            new double[] {32,  23}
+        };
+        TransformerTest.assertPointsEqual(result,
+                instance.transformCoordinates(properties, "EPSG:4979", "EPSG:4326", points), STRICT);
+    }
+
+    /**
+     * Tests {@link Referencing#parseAngle(XPropertySet, String, Object)}.
+     *
+     * @throws IllegalArgumentException if the pattern used by the test is not a string or void.
+     */
+    @Test
+    public void testParseAngle() throws IllegalArgumentException {
+        assertEquals(43.50, instance.parseAngle(properties, "43°30'", "D°MM.m'"), STRICT);
+        assertEquals(43.50, instance.parseAngle(properties, "4330",   "DMM"),     STRICT);
+        assertEquals(-3.25, instance.parseAngle(properties, "-3°15'", "D°MM.m'"), STRICT);
+    }
+
+    /**
+     * Tests {@link Referencing#formatAngle(XPropertySet, String, Object)}.
+     *
+     * @throws IllegalArgumentException if the pattern used by the test is not a string or void.
+     */
+    @Test
+    public void testFormatAngle() throws IllegalArgumentException {
+        assertEquals("43°30.0'", instance.formatAngle(properties, 43.50, "D°MM.m'"));
+        assertEquals("4330",     instance.formatAngle(properties, 43.50, "DMM"));
+        assertEquals("-3°15.0'", instance.formatAngle(properties, -3.25, "D°MM.m'"));
+    }
+}

Propchange: sis/branches/JDK8/application/sis-openoffice/src/test/java/org/apache/sis/openoffice/ReferencingTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/application/sis-openoffice/src/test/java/org/apache/sis/openoffice/ReferencingTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: sis/branches/JDK8/application/sis-openoffice/src/test/java/org/apache/sis/openoffice/TransformerTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/application/sis-openoffice/src/test/java/org/apache/sis/openoffice/TransformerTest.java?rev=1747559&view=auto
==============================================================================
--- sis/branches/JDK8/application/sis-openoffice/src/test/java/org/apache/sis/openoffice/TransformerTest.java (added)
+++ sis/branches/JDK8/application/sis-openoffice/src/test/java/org/apache/sis/openoffice/TransformerTest.java [UTF-8] Thu Jun  9 15:44:57 2016
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.openoffice;
+
+import org.opengis.util.FactoryException;
+import org.opengis.metadata.extent.GeographicBoundingBox;
+import org.apache.sis.referencing.CommonCRS;
+import org.apache.sis.storage.DataStoreException;
+import org.apache.sis.test.DependsOnMethod;
+import org.apache.sis.test.TestCase;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+import static org.junit.Assume.assumeTrue;
+
+
+/**
+ * Tests {@link Transformer}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.8
+ * @version 0.8
+ * @module
+ */
+public final strictfp class TransformerTest extends TestCase {
+    /**
+     * The instance to use for testing purpose.
+     */
+    private static Referencing caller;
+
+    /**
+     * Creates a {@link Referencing} instance to use for all tests.
+     */
+    @BeforeClass
+    public static void createReferencingInstance() {
+        caller = new Referencing();
+        caller.setLocale(new com.sun.star.lang.Locale("en", "US", null));
+    }
+
+    /**
+     * Disposes the {@link Referencing} instance after all tests completed.
+     */
+    @AfterClass
+    public static void disposeReferencingInstance() {
+        caller = null;
+    }
+
+    /**
+     * Asserts that the transformation result is equals to the expected result.
+     */
+    static void assertPointsEqual(final double[][] expected, final double[][] actual, final double tolerance) {
+        assertNotSame("transform", expected, actual);
+        assertEquals("transform.length", expected.length, actual.length);
+        for (int i=0; i<expected.length; i++) {
+            assertArrayEquals(expected[i], actual[i], tolerance);
+        }
+    }
+
+    /**
+     * Tests a trivial identity operation. The main purpose of this method is to test the constructor.
+     *
+     * @throws FactoryException if an error occurred while creating the object.
+     * @throws DataStoreException if an error occurred while reading a data file.
+     */
+    @Test
+    public void testIdentity() throws FactoryException, DataStoreException {
+        final double[][] points = {
+            new double[] {30,  20},
+            new double[] {34,  17},
+            new double[] {27, -12},
+            new double[] {32,  23}
+        };
+        final Transformer tr = new Transformer(caller, CommonCRS.WGS84.geographic(), "EPSG:4326", points);
+        assumeTrue(tr.hasAreaOfInterest());     // False if there is no EPSG geodetic dataset installed.
+        final GeographicBoundingBox bbox = tr.getAreaOfInterest();
+        assertEquals("eastBoundLongitude",  23, bbox.getEastBoundLongitude(), STRICT);
+        assertEquals("westBoundLongitude", -12, bbox.getWestBoundLongitude(), STRICT);
+        assertEquals("northBoundLatitude",  34, bbox.getNorthBoundLatitude(), STRICT);
+        assertEquals("southBoundLatitude",  27, bbox.getSouthBoundLatitude(), STRICT);
+        assertPointsEqual(points, tr.transform(points), STRICT);
+    }
+
+    /**
+     * Same test than {@link #testIdentity()} except that the height values are dropped.
+     *
+     * @throws FactoryException if an error occurred while creating the object.
+     * @throws DataStoreException if an error occurred while reading a data file.
+     */
+    @Test
+    @DependsOnMethod("testIdentity")
+    public void test3D_to_2D() throws FactoryException, DataStoreException {
+        final double[][] points = {
+            new double[] {30,  20,  4},
+            new double[] {34,  17, -3},
+            new double[] {27, -12, 12},
+            new double[] {32,  23, -1}
+        };
+        final double[][] result = {
+            new double[] {30,  20},
+            new double[] {34,  17},
+            new double[] {27, -12},
+            new double[] {32,  23}
+        };
+        final Transformer tr = new Transformer(caller, CommonCRS.WGS84.geographic3D(), "EPSG:4326", points);
+        assumeTrue(tr.hasAreaOfInterest());     // False if there is no EPSG geodetic dataset installed.
+        final GeographicBoundingBox bbox = tr.getAreaOfInterest();
+        assertEquals("eastBoundLongitude",  23, bbox.getEastBoundLongitude(), STRICT);
+        assertEquals("westBoundLongitude", -12, bbox.getWestBoundLongitude(), STRICT);
+        assertEquals("northBoundLatitude",  34, bbox.getNorthBoundLatitude(), STRICT);
+        assertEquals("southBoundLatitude",  27, bbox.getSouthBoundLatitude(), STRICT);
+        assertPointsEqual(result, tr.transform(points), STRICT);
+    }
+}

Propchange: sis/branches/JDK8/application/sis-openoffice/src/test/java/org/apache/sis/openoffice/TransformerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/application/sis-openoffice/src/test/java/org/apache/sis/openoffice/TransformerTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: sis/branches/JDK8/application/sis-openoffice/src/test/java/org/apache/sis/test/suite/OpenOfficeTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/application/sis-openoffice/src/test/java/org/apache/sis/test/suite/OpenOfficeTestSuite.java?rev=1747559&view=auto
==============================================================================
--- sis/branches/JDK8/application/sis-openoffice/src/test/java/org/apache/sis/test/suite/OpenOfficeTestSuite.java (added)
+++ sis/branches/JDK8/application/sis-openoffice/src/test/java/org/apache/sis/test/suite/OpenOfficeTestSuite.java [UTF-8] Thu Jun  9 15:44:57 2016
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.test.suite;
+
+import org.apache.sis.test.TestSuite;
+import org.junit.runners.Suite;
+import org.junit.BeforeClass;
+
+
+/**
+ * All tests from the {@code sis-openoffice} add-ins, in approximative dependency order.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.8
+ * @version 0.8
+ * @module
+ */
+@Suite.SuiteClasses({
+    org.apache.sis.openoffice.TransformerTest.class,
+    org.apache.sis.openoffice.ReferencingTest.class
+})
+public final strictfp class OpenOfficeTestSuite extends TestSuite {
+    /**
+     * Verifies the list of tests before to run the suite.
+     * See {@link #verifyTestList(Class, Class[])} for more information.
+     */
+    @BeforeClass
+    public static void verifyTestList() {
+        assertNoMissingTest(OpenOfficeTestSuite.class);
+        verifyTestList(OpenOfficeTestSuite.class);
+    }
+}

Propchange: sis/branches/JDK8/application/sis-openoffice/src/test/java/org/apache/sis/test/suite/OpenOfficeTestSuite.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/application/sis-openoffice/src/test/java/org/apache/sis/test/suite/OpenOfficeTestSuite.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/EPSGFactoryFallback.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/EPSGFactoryFallback.java?rev=1747559&r1=1747558&r2=1747559&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/EPSGFactoryFallback.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/EPSGFactoryFallback.java [UTF-8] Thu Jun  9 15:44:57 2016
@@ -22,6 +22,12 @@ import java.util.LinkedHashSet;
 import java.util.Locale;
 import org.opengis.referencing.IdentifiedObject;
 import org.opengis.referencing.NoSuchAuthorityCodeException;
+import org.opengis.referencing.datum.DatumAuthorityFactory;
+import org.opengis.referencing.datum.PrimeMeridian;
+import org.opengis.referencing.datum.Ellipsoid;
+import org.opengis.referencing.datum.Datum;
+import org.opengis.referencing.datum.GeodeticDatum;
+import org.opengis.referencing.datum.VerticalDatum;
 import org.opengis.referencing.crs.GeocentricCRS;
 import org.opengis.referencing.crs.GeographicCRS;
 import org.opengis.referencing.crs.ProjectedCRS;
@@ -49,11 +55,11 @@ import org.apache.sis.util.Debug;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.7
- * @version 0.7
+ * @version 0.8
  * @module
  */
 @Fallback
-final class EPSGFactoryFallback extends GeodeticAuthorityFactory implements CRSAuthorityFactory {
+final class EPSGFactoryFallback extends GeodeticAuthorityFactory implements CRSAuthorityFactory, DatumAuthorityFactory {
     /**
      * Whether to disallow {@code CommonCRS} to use {@link org.apache.sis.referencing.factory.sql.EPSGFactory}
      * (in which case {@code CommonCRS} will fallback on hard-coded values).
@@ -65,7 +71,12 @@ final class EPSGFactoryFallback extends
     /**
      * The singleton instance.
      */
-    static final CRSAuthorityFactory INSTANCE = new EPSGFactoryFallback();
+    static final EPSGFactoryFallback INSTANCE = new EPSGFactoryFallback();
+
+    /**
+     * Kinds of object created by this factory. Used as bitmask.
+     */
+    private static final int CRS = 1, DATUM = 2, ELLIPSOID = 4, PRIME_MERIDIAN = 8;
 
     /**
      * The authority, created when first needed.
@@ -107,18 +118,22 @@ final class EPSGFactoryFallback extends
      */
     @Override
     public Set<String> getAuthorityCodes(Class<? extends IdentifiedObject> type) {
+        final boolean pm         = type.isAssignableFrom(PrimeMeridian.class);
+        final boolean ellipsoid  = type.isAssignableFrom(Ellipsoid    .class);
+        final boolean datum      = type.isAssignableFrom(GeodeticDatum.class);
         final boolean geographic = type.isAssignableFrom(GeographicCRS.class);
         final boolean geocentric = type.isAssignableFrom(GeocentricCRS.class);
         final boolean projected  = type.isAssignableFrom(ProjectedCRS .class);
         final Set<String> codes = new LinkedHashSet<>();
+        if (pm) codes.add(StandardDefinitions.GREENWICH);
         for (final CommonCRS crs : CommonCRS.values()) {
+            if (ellipsoid)  add(codes, crs.ellipsoid);
+            if (datum)      add(codes, crs.datum);
+            if (geocentric) add(codes, crs.geocentric);
             if (geographic) {
                 add(codes, crs.geographic);
                 add(codes, crs.geo3D);
             }
-            if (geocentric) {
-                add(codes, crs.geocentric);
-            }
             if (projected && (crs.northUTM != 0 || crs.southUTM != 0)) {
                 for (int zone = crs.firstZone; zone <= crs.lastZone; zone++) {
                     if (crs.northUTM != 0) codes.add(Integer.toString(crs.northUTM + zone));
@@ -126,10 +141,13 @@ final class EPSGFactoryFallback extends
                 }
             }
         }
-        if (type.isAssignableFrom(VerticalCRS.class)) {
+        final boolean vertical = type.isAssignableFrom(VerticalCRS  .class);
+        final boolean vdatum   = type.isAssignableFrom(VerticalDatum.class);
+        if (vertical || vdatum) {
             for (final CommonCRS.Vertical candidate : CommonCRS.Vertical.values()) {
                 if (candidate.isEPSG) {
-                    codes.add(Integer.toString(candidate.crs));
+                    if (vertical) codes.add(Integer.toString(candidate.crs));
+                    if (vdatum)   codes.add(Integer.toString(candidate.datum));
                 }
             }
         }
@@ -147,11 +165,55 @@ final class EPSGFactoryFallback extends
     }
 
     /**
+     * Returns a prime meridian for the given EPSG code.
+     */
+    @Override
+    public PrimeMeridian createPrimeMeridian(final String code) throws NoSuchAuthorityCodeException {
+        return (PrimeMeridian) predefined(code, PRIME_MERIDIAN);
+    }
+
+    /**
+     * Returns an ellipsoid for the given EPSG code.
+     */
+    @Override
+    public Ellipsoid createEllipsoid(final String code) throws NoSuchAuthorityCodeException {
+        return (Ellipsoid) predefined(code, ELLIPSOID);
+    }
+
+    /**
+     * Returns a datum for the given EPSG code.
+     */
+    @Override
+    public Datum createDatum(final String code) throws NoSuchAuthorityCodeException {
+        return (Datum) predefined(code, DATUM);
+    }
+
+    /**
      * Returns a coordinate reference system for the given EPSG code. This method is invoked
      * as a fallback when {@link CRS#forCode(String)} can not create a CRS for a given code.
      */
     @Override
+    public CoordinateReferenceSystem createCoordinateReferenceSystem(final String code) throws NoSuchAuthorityCodeException {
+        return (CoordinateReferenceSystem) predefined(code, CRS);
+    }
+
+    /**
+     * Returns a coordinate reference system, datum or ellipsoid for the given EPSG code.
+     */
+    @Override
     public IdentifiedObject createObject(final String code) throws NoSuchAuthorityCodeException {
+        return predefined(code, -1);
+    }
+
+    /**
+     * Implementation of the {@code createFoo(String)} methods.
+     *
+     * @param  code  the EPSG code.
+     * @param  kind  any combination of {@link #CRS}, {@link #DATUM}, {@link #ELLIPSOID} or {@link #PRIME_MERIDIAN} bits.
+     * @return the requested object.
+     * @throws NoSuchAuthorityCodeException if no matching object has been found.
+     */
+    private IdentifiedObject predefined(final String code, final int kind) throws NoSuchAuthorityCodeException {
         NumberFormatException cause = null;
         try {
             /*
@@ -164,32 +226,55 @@ final class EPSGFactoryFallback extends
             final int n = Integer.parseInt(CharSequences.trimWhitespaces(code,
                             code.lastIndexOf(DefaultNameSpace.DEFAULT_SEPARATOR) + 1,
                             code.length()).toString());
+            if ((kind & PRIME_MERIDIAN) != 0  &&  n == 8901) {
+                return CommonCRS.WGS84.primeMeridian();
+            }
             for (final CommonCRS crs : CommonCRS.values()) {
-                if (n == crs.geographic) return crs.geographic();
-                if (n == crs.geocentric) return crs.geocentric();
-                if (n == crs.geo3D)      return crs.geographic3D();
-                final double latitude;
-                int zone;
-                if (crs.northUTM != 0 && (zone = n - crs.northUTM) >= crs.firstZone && zone <= crs.lastZone) {
-                    latitude = +1;
-                } else if (crs.southUTM != 0 && (zone = n - crs.southUTM) >= crs.firstZone && zone <= crs.lastZone) {
-                    latitude = -1;
-                } else {
-                    continue;
+                /*
+                 * In a complete EPSG dataset we could have an ambiguity below because the same code can be used
+                 * for datum, ellipsoid and CRS objects. However in the particular case of this EPSG-subset, we
+                 * ensured that there is no such collision - see CommonCRSTest.ensureNoCodeCollision().
+                 */
+                if ((kind & ELLIPSOID) != 0  &&  n == crs.ellipsoid) return crs.ellipsoid();
+                if ((kind & DATUM)     != 0  &&  n == crs.datum)     return crs.datum();
+                if ((kind & CRS) != 0) {
+                    if (n == crs.geographic) return crs.geographic();
+                    if (n == crs.geocentric) return crs.geocentric();
+                    if (n == crs.geo3D)      return crs.geographic3D();
+                    final double latitude;
+                    int zone;
+                    if (crs.northUTM != 0 && (zone = n - crs.northUTM) >= crs.firstZone && zone <= crs.lastZone) {
+                        latitude = +1;
+                    } else if (crs.southUTM != 0 && (zone = n - crs.southUTM) >= crs.firstZone && zone <= crs.lastZone) {
+                        latitude = -1;
+                    } else {
+                        continue;
+                    }
+                    return crs.UTM(latitude, TransverseMercator.centralMeridian(zone));
                 }
-                return crs.UTM(latitude, TransverseMercator.centralMeridian(zone));
             }
-            for (final CommonCRS.Vertical candidate : CommonCRS.Vertical.values()) {
-                if (candidate.isEPSG && candidate.crs == n) {
-                    return candidate.crs();
+            if ((kind & (DATUM | CRS)) != 0) {
+                for (final CommonCRS.Vertical candidate : CommonCRS.Vertical.values()) {
+                    if (candidate.isEPSG) {
+                        if ((kind & DATUM) != 0  &&  candidate.datum == n) return candidate.datum();
+                        if ((kind & CRS)   != 0  &&  candidate.crs   == n) return candidate.crs();
+                    }
                 }
             }
         } catch (NumberFormatException e) {
             cause = e;
         }
-        final String authority = Constants.EPSG + " subset";
+        final Class<?> type;
+        switch (kind) {
+            case CRS:            type = CoordinateReferenceSystem.class; break;
+            case DATUM:          type = Datum.class; break;
+            case ELLIPSOID:      type = Ellipsoid.class; break;
+            case PRIME_MERIDIAN: type = PrimeMeridian.class; break;
+            default:             type = IdentifiedObject.class; break;
+        }
+        final String authority = Constants.EPSG + "-subset";
         final NoSuchAuthorityCodeException e = new NoSuchAuthorityCodeException(Errors.format(
-                Errors.Keys.NoSuchAuthorityCode_3, authority, CoordinateReferenceSystem.class, code), authority, code);
+                Errors.Keys.NoSuchAuthorityCode_3, authority, type, code), authority, code);
         e.initCause(cause);
         throw e;
     }

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CommonCRSTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CommonCRSTest.java?rev=1747559&r1=1747558&r2=1747559&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CommonCRSTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CommonCRSTest.java [UTF-8] Thu Jun  9 15:44:57 2016
@@ -17,6 +17,8 @@
 package org.apache.sis.referencing;
 
 import java.util.Date;
+import java.util.Map;
+import java.util.HashMap;
 import org.opengis.parameter.ParameterValueGroup;
 import org.opengis.referencing.crs.TemporalCRS;
 import org.opengis.referencing.crs.VerticalCRS;
@@ -49,7 +51,7 @@ import static org.apache.sis.test.TestUt
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.4
- * @version 0.7
+ * @version 0.8
  * @module
  */
 @DependsOn({
@@ -64,6 +66,58 @@ public final strictfp class CommonCRSTes
     private static final double DAY_LENGTH = 24 * 60 * 60 * 1000;
 
     /**
+     * Verifies that the same EPSG code is not used for two objects. Collisions are not allowed between
+     * {@code geographic}, {@code geocentric}, {@code geo3D} and all UTM projections. Strictly speaking
+     * all the above-cited codes may collide with {@code datum} and {@code ellipsoid}, but we nevertheless
+     * avoid those collisions in order to simplify {@link EPSGFactoryFallback#createObject(String)} implementation.
+     */
+    @Test
+    public void ensureNoCodeCollision() {
+        final Map<Integer,Enum<?>> codes = new HashMap<>();
+        final CommonCRS[] values = CommonCRS.values();
+        for (final CommonCRS crs : values) {
+            assertNoCodeCollision(codes, crs, crs.geographic);
+            assertNoCodeCollision(codes, crs, crs.geocentric);
+            assertNoCodeCollision(codes, crs, crs.geo3D);
+            for (int zone = crs.firstZone; zone <= crs.lastZone; zone++) {
+                if (crs.northUTM != 0) assertNoCodeCollision(codes, crs, crs.northUTM + zone);
+                if (crs.southUTM != 0) assertNoCodeCollision(codes, crs, crs.southUTM + zone);
+            }
+        }
+        final CommonCRS.Vertical[] vertical = CommonCRS.Vertical.values();
+        for (final CommonCRS.Vertical crs : vertical) {
+            if (crs.isEPSG) {
+                assertNoCodeCollision(codes, crs, crs.crs);
+            }
+        }
+        /*
+         * Following restrictions are not strictly required, but their enforcement
+         * simplifies the EPSGFactoryFallback.createObject(String) implementation.
+         */
+        assertNull(codes.put(Integer.valueOf(StandardDefinitions.GREENWICH), CommonCRS.WGS84));
+        for (final CommonCRS crs : values) assertNull   (crs.name(),      codes.get(Integer.valueOf(crs.ellipsoid)));
+        for (final CommonCRS crs : values) assertNotSame(crs.name(), crs, codes.put(Integer.valueOf(crs.ellipsoid), crs));
+        for (final CommonCRS crs : values) assertNull   (crs.name(),      codes.get(Integer.valueOf(crs.datum)));
+        for (final CommonCRS.Vertical crs : vertical) {
+            if (crs.isEPSG) {
+                assertNull(crs.name(), codes.get(Integer.valueOf(crs.datum)));
+            }
+        }
+    }
+
+    /**
+     * Helper method for {@link #ensureNoCodeCollision()} only.
+     */
+    private static void assertNoCodeCollision(final Map<Integer,Enum<?>> codes, final Enum<?> crs, final int n) {
+        if (n != 0) {
+            final Enum<?> existing = codes.put(n, crs);
+            if (existing != null) {
+                fail(existing + " and " + crs + " both use the same EPSG:" + n + " code.");
+            }
+        }
+    }
+
+    /**
      * Tests the {@link CommonCRS#geographic()} method.
      */
     @Test

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/EPSGFactoryFallbackTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/EPSGFactoryFallbackTest.java?rev=1747559&r1=1747558&r2=1747559&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/EPSGFactoryFallbackTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/EPSGFactoryFallbackTest.java [UTF-8] Thu Jun  9 15:44:57 2016
@@ -26,6 +26,9 @@ import org.opengis.referencing.crs.Geogr
 import org.opengis.referencing.crs.GeocentricCRS;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.opengis.referencing.crs.CRSAuthorityFactory;
+import org.opengis.referencing.datum.Datum;
+import org.opengis.referencing.datum.Ellipsoid;
+import org.opengis.referencing.datum.PrimeMeridian;
 import org.apache.sis.util.ComparisonMode;
 import org.apache.sis.util.Utilities;
 
@@ -44,7 +47,7 @@ import static org.apache.sis.test.Assert
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.7
- * @version 0.7
+ * @version 0.8
  * @module
  */
 @DependsOn({
@@ -59,6 +62,12 @@ public final strictfp class EPSGFactoryF
      */
     @Test
     public void testGetAuthorityCodes() throws FactoryException {
+        assertSetEquals(Arrays.asList(StandardDefinitions.GREENWICH),
+                EPSGFactoryFallback.INSTANCE.getAuthorityCodes(PrimeMeridian.class));
+        assertSetEquals(Arrays.asList("7030", "7043", "7019", "7008", "7022", "7048"),
+                EPSGFactoryFallback.INSTANCE.getAuthorityCodes(Ellipsoid.class));
+        assertSetEquals(Arrays.asList("6326", "6322", "6269", "6267", "6258", "6230", "6047", "5100", "5103"),
+                EPSGFactoryFallback.INSTANCE.getAuthorityCodes(Datum.class));
         assertSetEquals(Arrays.asList("4978", "4984", "4936"),
                 EPSGFactoryFallback.INSTANCE.getAuthorityCodes(GeocentricCRS.class));
         assertSetEquals(Arrays.asList("4326", "4322", "4047", "4269", "4267", "4258", "4230", "4979", "4985", "4937"),
@@ -68,6 +77,46 @@ public final strictfp class EPSGFactoryF
     }
 
     /**
+     * Tests {@link EPSGFactoryFallback#createPrimeMeridian(String)}.
+     *
+     * @throws FactoryException if a prime meridian can not be constructed.
+     */
+    @Test
+    public void testCreatePrimeMeridian() throws FactoryException {
+        verifyCreatePrimeMeridian(CommonCRS.WGS84.primeMeridian(), StandardDefinitions.GREENWICH);
+    }
+
+    /**
+     * Tests {@link EPSGFactoryFallback#createEllipsoid(String)}.
+     *
+     * @throws FactoryException if an ellipsoid can not be constructed.
+     */
+    @Test
+    public void testCreateEllipsoid() throws FactoryException {
+        verifyCreateEllipsoid(CommonCRS.WGS84 .ellipsoid(), "7030");
+        verifyCreateEllipsoid(CommonCRS.WGS72 .ellipsoid(), "7043");
+        verifyCreateEllipsoid(CommonCRS.NAD83 .ellipsoid(), "7019");
+        verifyCreateEllipsoid(CommonCRS.NAD27 .ellipsoid(), "7008");
+        verifyCreateEllipsoid(CommonCRS.ED50  .ellipsoid(), "7022");
+        verifyCreateEllipsoid(CommonCRS.SPHERE.ellipsoid(), "7048");
+    }
+
+    /**
+     * Tests {@link EPSGFactoryFallback#createEllipsoid(String)}.
+     *
+     * @throws FactoryException if an ellipsoid can not be constructed.
+     */
+    @Test
+    public void testCreateDatum() throws FactoryException {
+        verifyCreateDatum(CommonCRS.WGS84 .datum(), "6326");
+        verifyCreateDatum(CommonCRS.WGS72 .datum(), "6322");
+        verifyCreateDatum(CommonCRS.NAD83 .datum(), "6269");
+        verifyCreateDatum(CommonCRS.NAD27 .datum(), "6267");
+        verifyCreateDatum(CommonCRS.ED50  .datum(), "6230");
+        verifyCreateDatum(CommonCRS.SPHERE.datum(), "6047");
+    }
+
+    /**
      * Tests {@link EPSGFactoryFallback#createCoordinateReferenceSystem(String)}.
      *
      * @throws FactoryException if a CRS can not be constructed.
@@ -77,30 +126,55 @@ public final strictfp class EPSGFactoryF
      */
     @Test
     public void testCreateCRS() throws FactoryException {
-        verifyCreate(CommonCRS.WGS84 .geographic(),            "4326");
-        verifyCreate(CommonCRS.WGS72 .geographic(),            "4322");
-        verifyCreate(CommonCRS.SPHERE.geographic(),            "4047");
-        verifyCreate(CommonCRS.NAD83 .geographic(),            "4269");
-        verifyCreate(CommonCRS.NAD27 .geographic(),            "4267");
-        verifyCreate(CommonCRS.ETRS89.geographic(),            "4258");
-        verifyCreate(CommonCRS.ED50  .geographic(),            "4230");
-        verifyCreate(CommonCRS.WGS84 .geocentric(),            "4978");
-        verifyCreate(CommonCRS.WGS72 .geocentric(),            "4984");
-        verifyCreate(CommonCRS.ETRS89.geocentric(),            "4936");
-        verifyCreate(CommonCRS.WGS84 .geographic(),       "EPSG:4326");
-        verifyCreate(CommonCRS.WGS72 .geographic(),      "EPSG::4322");
-        verifyCreate(CommonCRS.WGS84 .geographic3D(),          "4979");
-        verifyCreate(CommonCRS.WGS72 .geographic3D(),          "4985");
-        verifyCreate(CommonCRS.ETRS89.geographic3D(),          "4937");
-        verifyCreate(CommonCRS.Vertical.MEAN_SEA_LEVEL.crs(),  "5714");
-        verifyCreate(CommonCRS.Vertical.DEPTH.crs(),           "5715");
+        verifyCreateCRS(CommonCRS.WGS84 .geographic(),            "4326");
+        verifyCreateCRS(CommonCRS.WGS72 .geographic(),            "4322");
+        verifyCreateCRS(CommonCRS.SPHERE.geographic(),            "4047");
+        verifyCreateCRS(CommonCRS.NAD83 .geographic(),            "4269");
+        verifyCreateCRS(CommonCRS.NAD27 .geographic(),            "4267");
+        verifyCreateCRS(CommonCRS.ETRS89.geographic(),            "4258");
+        verifyCreateCRS(CommonCRS.ED50  .geographic(),            "4230");
+        verifyCreateCRS(CommonCRS.WGS84 .geocentric(),            "4978");
+        verifyCreateCRS(CommonCRS.WGS72 .geocentric(),            "4984");
+        verifyCreateCRS(CommonCRS.ETRS89.geocentric(),            "4936");
+        verifyCreateCRS(CommonCRS.WGS84 .geographic(),       "EPSG:4326");
+        verifyCreateCRS(CommonCRS.WGS72 .geographic(),      "EPSG::4322");
+        verifyCreateCRS(CommonCRS.WGS84 .geographic3D(),          "4979");
+        verifyCreateCRS(CommonCRS.WGS72 .geographic3D(),          "4985");
+        verifyCreateCRS(CommonCRS.ETRS89.geographic3D(),          "4937");
+        verifyCreateCRS(CommonCRS.Vertical.MEAN_SEA_LEVEL.crs(),  "5714");
+        verifyCreateCRS(CommonCRS.Vertical.DEPTH.crs(),           "5715");
+    }
+
+    /**
+     * Asserts that the result of {@link EPSGFactoryFallback#createObject(String)} is the given prime meridian.
+     */
+    private static void verifyCreatePrimeMeridian(final PrimeMeridian expected, final String code) throws FactoryException {
+        assertSame(code, expected, EPSGFactoryFallback.INSTANCE.createPrimeMeridian(code));
+        assertSame(code, expected, EPSGFactoryFallback.INSTANCE.createObject(code));
+    }
+
+    /**
+     * Asserts that the result of {@link EPSGFactoryFallback#createObject(String)} is the given ellipsoid.
+     */
+    private static void verifyCreateEllipsoid(final Ellipsoid expected, final String code) throws FactoryException {
+        assertSame(code, expected, EPSGFactoryFallback.INSTANCE.createEllipsoid(code));
+        assertSame(code, expected, EPSGFactoryFallback.INSTANCE.createObject(code));
+    }
+
+    /**
+     * Asserts that the result of {@link EPSGFactoryFallback#createObject(String)} is the given datum.
+     */
+    private static void verifyCreateDatum(final Datum expected, final String code) throws FactoryException {
+        assertSame(code, expected, EPSGFactoryFallback.INSTANCE.createDatum(code));
+        assertSame(code, expected, EPSGFactoryFallback.INSTANCE.createObject(code));
     }
 
     /**
-     * Asserts that the result of {@link CommonCRS#forCode(String, String, FactoryException)} is the given CRS.
+     * Asserts that the result of {@link EPSGFactoryFallback#createObject(String)} is the given CRS.
      */
-    private static void verifyCreate(final SingleCRS expected, final String code) throws FactoryException {
+    private static void verifyCreateCRS(final SingleCRS expected, final String code) throws FactoryException {
         assertSame(code, expected, EPSGFactoryFallback.INSTANCE.createCoordinateReferenceSystem(code));
+        assertSame(code, expected, EPSGFactoryFallback.INSTANCE.createObject(code));
     }
 
     /**



Mime
View raw message