sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1726784 - 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/util/resources/
Date Tue, 26 Jan 2016 12:34:54 GMT
Author: desruisseaux
Date: Tue Jan 26 12:34:54 2016
New Revision: 1726784

URL: http://svn.apache.org/viewvc?rev=1726784&view=rev
Log:
Implement MultiAuthoritiesFactory.createFromCoordinateReferenceSystemCodes(String,String).

Modified:
    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/util/resources/Messages.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.properties
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages_fr.properties

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=1726784&r1=1726783&r2=1726784&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] Tue Jan 26 12:34:54 2016
@@ -30,6 +30,8 @@ import java.util.concurrent.ConcurrentMa
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.ConcurrentModificationException;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
 import javax.measure.unit.Unit;
 import org.opengis.referencing.*;
 import org.opengis.referencing.cs.*;
@@ -41,6 +43,7 @@ import org.opengis.metadata.extent.Exten
 import org.opengis.parameter.ParameterDescriptor;
 import org.opengis.util.FactoryException;
 import org.opengis.util.InternationalString;
+import org.apache.sis.internal.system.Loggers;
 import org.apache.sis.internal.util.AbstractIterator;
 import org.apache.sis.internal.util.Citations;
 import org.apache.sis.internal.util.DefinitionURI;
@@ -51,7 +54,9 @@ import org.apache.sis.internal.util.SetO
 import org.apache.sis.util.ArraysExt;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.ArgumentChecks;
+import org.apache.sis.util.logging.Logging;
 import org.apache.sis.util.resources.Errors;
+import org.apache.sis.util.resources.Messages;
 import org.apache.sis.util.iso.DefaultNameSpace;
 import org.apache.sis.util.collection.BackingStoreException;
 
@@ -1363,6 +1368,57 @@ public class MultiAuthoritiesFactory ext
     }
 
     /**
+     * Creates operations from source and target coordinate reference system codes.
+     * If the authority for the two given CRS is handled by the same factory, then
+     * this method delegates to that factory. Otherwise this method returns an empty set.
+     *
+     * @throws FactoryException if the object creation failed.
+     */
+    @Override
+    public Set<CoordinateOperation> createFromCoordinateReferenceSystemCodes(
+            final String sourceCRS, final String targetCRS) throws FactoryException
+    {
+        final Deferred deferred = new Deferred();
+        final CoordinateOperationAuthorityFactory factory = create(deferred, sourceCRS);
+        final String source = deferred.code;
+        if (create(deferred, targetCRS) == factory) {
+            return factory.createFromCoordinateReferenceSystemCodes(source, deferred.code);
+        }
+        /*
+         * No coordinate operation because of mismatched factories. This is not illegal (the
result is an empty set)
+         * but it is worth to notify the user because this case has some chances to be an
user error.
+         */
+        final LogRecord record = Messages.getResources(null).getLogRecord(Level.WARNING,
+                Messages.Keys.MismatchedOperationFactories_2, sourceCRS, targetCRS);
+        record.setLoggerName(Loggers.CRS_FACTORY);
+        Logging.log(MultiAuthoritiesFactory.class, "createFromCoordinateReferenceSystemCodes",
record);
+        return super.createFromCoordinateReferenceSystemCodes(sourceCRS, targetCRS);
+    }
+
+    /**
+     * A proxy that does not execute immediately the {@code create} method on a factory,
+     * but instead stores information for later execution.
+     */
+    private static final class Deferred extends AuthorityFactoryProxy<CoordinateOperationAuthorityFactory>
{
+        Deferred() {super(CoordinateOperationAuthorityFactory.class, AuthorityFactoryIdentifier.OPERATION);}
+
+        /** The authority code saved by the {@code createFromAPI(…)} method. */
+        String code;
+
+        /**
+         * Saves the given code in the {@link #code} field and returns the given factory
unchanged.
+         * @throws FactoryException if the given factory is not an instance of {@link CoordinateOperationAuthorityFactory}.
+         */
+        @Override
+        CoordinateOperationAuthorityFactory createFromAPI(final AuthorityFactory factory,
final String code)
+                throws FactoryException
+        {
+            this.code = code;
+            return opFactory(factory);
+        }
+    }
+
+    /**
      * Returns a finder which can be used for looking up unidentified objects.
      * The default implementation delegates the lookups to the underlying factories.
      *

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=1726784&r1=1726783&r2=1726784&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] Tue Jan 26 12:34:54 2016
@@ -18,6 +18,7 @@ package org.apache.sis.referencing.facto
 
 import java.util.Set;
 import java.util.LinkedHashSet;
+import javax.measure.unit.Unit;
 import org.opengis.metadata.extent.Extent;
 import org.opengis.metadata.citation.Citation;
 import org.opengis.referencing.IdentifiedObject;
@@ -31,8 +32,8 @@ import org.opengis.referencing.datum.Dat
 import org.opengis.referencing.datum.GeodeticDatum;
 import org.opengis.referencing.datum.PrimeMeridian;
 import org.opengis.referencing.datum.VerticalDatum;
+import org.opengis.referencing.operation.CoordinateOperationAuthorityFactory;
 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;
@@ -52,7 +53,7 @@ import static org.junit.Assert.*;
  * @module
  */
 public final strictfp class AuthorityFactoryMock extends GeodeticAuthorityFactory
-        implements CRSAuthorityFactory, CSAuthorityFactory, DatumAuthorityFactory
+        implements CRSAuthorityFactory, CSAuthorityFactory, DatumAuthorityFactory, CoordinateOperationAuthorityFactory
 {
     /**
      * The authority.

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=1726784&r1=1726783&r2=1726784&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] Tue Jan 26 12:34:54 2016
@@ -79,8 +79,6 @@ public final strictfp class MultiAuthori
 
         /** Verifies the log message. */
         @Override protected void verifyMessage(final String message) {
-            assertTrue(message, message.contains("CRSAuthorityFactory"));
-            assertTrue(message, message.contains("AuthorityFactoryMock"));
             for (final String keyword : expectedKeywords) {
                 assertTrue(message, message.contains(keyword));
             }
@@ -186,12 +184,12 @@ public final strictfp class MultiAuthori
         assertSame("MOCK1", mock1, factory.getAuthorityFactory(CRSAuthorityFactory.class,
"mock1", "2.3"));
 
         listener.maximumLogCount = 1;
-        ((Listener) listener).expectedKeywords = new String[] {"MOCK1", "2.3"};
+        ((Listener) listener).expectedKeywords = new String[] {"CRSAuthorityFactory", "AuthorityFactoryMock",
"MOCK1", "2.3"};
         assertSame("MOCK3", mock3, factory.getAuthorityFactory(CRSAuthorityFactory.class,
"mock3", null));
         assertEquals("Expected a warning about the extraneous MOCK1 factory.", 0, listener.maximumLogCount);
 
         listener.maximumLogCount = 1;
-        ((Listener) listener).expectedKeywords = new String[] {"MOCK3"};
+        ((Listener) listener).expectedKeywords = new String[] {"CRSAuthorityFactory", "AuthorityFactoryMock",
"MOCK3"};
         assertSame("MOCK5", mock5, factory.getAuthorityFactory(CRSAuthorityFactory.class,
"mock5", null));
         assertEquals("Expected a warning about the extraneous MOCK3 factory.", 0, listener.maximumLogCount);
 
@@ -309,6 +307,31 @@ public final strictfp class MultiAuthori
     }
 
     /**
+     * Tests {@link MultiAuthoritiesFactory#createFromCoordinateReferenceSystemCodes(String,
String)}.
+     *
+     * @throws FactoryException if an error occurred while creating the operation.
+     */
+    @Test
+    public void testCreateFromCoordinateReferenceSystemCodes() throws FactoryException {
+        final List<AuthorityFactoryMock> mock = Arrays.asList(
+                new AuthorityFactoryMock("MOCK", null),
+                new AuthorityFactoryMock("MOCK", "2.3"));
+        final MultiAuthoritiesFactory factory = new MultiAuthoritiesFactory(mock, null, null,
mock);
+        /*
+         * Our mock factory does not implement createFromCoordinateReferenceSystemCodes(String,
String),
+         * so we just test that we didn't got an exception and no message were logged.
+         */
+        assertTrue(factory.createFromCoordinateReferenceSystemCodes("MOCK:4326", "MOCK:84").isEmpty());
+        /*
+         * Following should log a warning telling that the authority factories do not match.
+         */
+        listener.maximumLogCount = 1;
+        ((Listener) listener).expectedKeywords = new String[] {"MOCK:4326", "MOCK:2.3:84"};
+        assertTrue(factory.createFromCoordinateReferenceSystemCodes("MOCK:4326", "MOCK:2.3:84").isEmpty());
+        assertEquals("Expected a warning about mismatched factories.", 0, listener.maximumLogCount);
+    }
+
+    /**
      * Tests {@link MultiAuthoritiesFactory#newIdentifiedObjectFinder()}.
      *
      * @throws FactoryException if an error occurred while creating the finder.

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.java?rev=1726784&r1=1726783&r2=1726784&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.java
[UTF-8] Tue Jan 26 12:34:54 2016
@@ -208,6 +208,11 @@ public final class Messages extends Inde
         public static final short MismatchedEllipsoidAxisLength_3 = 9;
 
         /**
+         * No coordinate operation from “{0}” to “{1}” because of mismatched factories.
+         */
+        public static final short MismatchedOperationFactories_2 = 37;
+
+        /**
          * Despite its name, this parameter is effectively “{0}”.
          */
         public static final short MisnamedParameter_1 = 18;

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.properties?rev=1726784&r1=1726783&r2=1726784&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.properties
[ISO-8859-1] Tue Jan 26 12:34:54 2016
@@ -45,6 +45,7 @@ LoadingDatumShiftFile_1          = Loadi
 LocalesDiscarded                 = Text were discarded for some locales.
 OptionalModuleNotFound_1         = Optional module \u201c{0}\u201d requested but not found.
 PropertyHiddenBy_2               = Property \u201c{0}\u201d is hidden by \u201c{1}\u201d.
+MismatchedOperationFactories_2   = No coordinate operation from \u201c{0}\u201d to \u201c{1}\u201d
because of mismatched factories.
 MismatchedEllipsoidAxisLength_3  = The \u201c{1}\u201d parameter could have been omitted.
But it has been given a value of {2} which does not match the definition of the \u201c{0}\u201d
ellipsoid.
 MisnamedParameter_1              = Despite its name, this parameter is effectively \u201c{0}\u201d.
 NonConformFormatting_1           = Formatting of \u201c{0}\u201d is not conform to the format
standard.

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages_fr.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages_fr.properties?rev=1726784&r1=1726783&r2=1726784&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages_fr.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages_fr.properties
[ISO-8859-1] Tue Jan 26 12:34:54 2016
@@ -52,6 +52,7 @@ LoadingDatumShiftFile_1          = Charg
 LocalesDiscarded                 = Des textes ont \u00e9t\u00e9 ignor\u00e9s pour certaines
langues.
 OptionalModuleNotFound_1         = Le module optionnel \u00ab\u202f{0}\u202f\u00bb a \u00e9t\u00e9
demand\u00e9 mais n\u2019a pas \u00e9t\u00e9 trouv\u00e9.
 PropertyHiddenBy_2               = La propri\u00e9t\u00e9 \u00ab\u202f{0}\u202f\u00bb est
masqu\u00e9e par \u00ab\u202f{1}\u202f\u00bb.
+MismatchedOperationFactories_2   = Il n\u2019y a pas d\u2019op\u00e9rations allant de \u00ab\u202f{0}\u202f\u00bb
vers \u00ab\u202f{1}\u202f\u00bb parce que ces derniers sont associ\u00e9s \u00e0 deux fabriques
diff\u00e9rentes.
 MismatchedEllipsoidAxisLength_3  = Le param\u00e8tre \u00ab\u202f{1}\u202f\u00bb aurait pu
\u00eatre omis. Mais il lui a \u00e9t\u00e9 donn\u00e9 la valeur {2} qui ne correspond pas
\u00e0 la d\u00e9finition de l\u2019ellipso\u00efde \u00ab\u202f{0}\u202f\u00bb.
 MisnamedParameter_1              = Malgr\u00e9 son nom, ce param\u00e8tre produit en r\u00e9alit\u00e9
l\u2019effet d\u2019un \u00ab\u202f{0}\u202f\u00bb.
 NonConformFormatting_1           = L\u2019\u00e9criture de \u00ab\u202f{0}\u202f\u00bb n\u2019est
pas conforme au format standard.



Mime
View raw message