sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1683377 - in /sis/branches/JDK8/core: sis-metadata/src/main/java/org/apache/sis/internal/metadata/ sis-metadata/src/main/java/org/apache/sis/io/wkt/ sis-referencing/src/main/java/org/apache/sis/internal/referencing/ sis-referencing/src/mai...
Date Wed, 03 Jun 2015 15:48:15 GMT
Author: desruisseaux
Date: Wed Jun  3 15:48:14 2015
New Revision: 1683377

URL: http://svn.apache.org/r1683377
Log:
Referencing: avoid direct reference to DefaultCoordinateOperationFactory from GeodeticObjectParser.
This is needed for allowing us to move GeodeticObjectParser to sis-metadata module, for OSGi
compatibility.

Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/MathTransformParser.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java?rev=1683377&r1=1683376&r2=1683377&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
[UTF-8] Wed Jun  3 15:48:14 2015
@@ -16,11 +16,14 @@
  */
 package org.apache.sis.internal.metadata;
 
+import java.util.Map;
 import org.opengis.geometry.Envelope;
 import org.opengis.metadata.Identifier;
 import org.opengis.parameter.ParameterDescriptor;
 import org.opengis.referencing.IdentifiedObject;
 import org.opengis.referencing.operation.MathTransform;
+import org.opengis.referencing.operation.MathTransformFactory;
+import org.opengis.referencing.operation.CoordinateOperationFactory;
 import org.opengis.referencing.operation.OperationMethod;
 import org.opengis.referencing.operation.TransformException;
 import org.apache.sis.metadata.iso.extent.DefaultExtent;
@@ -28,6 +31,7 @@ import org.apache.sis.metadata.iso.exten
 import org.apache.sis.metadata.iso.extent.DefaultTemporalExtent;
 import org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox;
 import org.apache.sis.metadata.iso.extent.DefaultSpatialTemporalExtent;
+import org.apache.sis.internal.system.DefaultFactories;
 import org.apache.sis.internal.system.SystemListener;
 import org.apache.sis.internal.system.Modules;
 import org.apache.sis.io.wkt.FormattableObject;
@@ -290,6 +294,29 @@ public class ReferencingServices extends
     }
 
     /**
+     * Returns the coordinate operation factory to use for the given properties and math
transform factory.
+     * If the given properties are empty and the {@code mtFactory} is the system default,
then this method
+     * returns the system default {@code CoordinateOperationFactory} instead of creating
a new one.
+     *
+     * @param  properties The default properties.
+     * @param  mtFactory  The math transform factory to use.
+     * @return The coordinate operation factory to use.
+     */
+    public CoordinateOperationFactory getCoordinateOperationFactory(Map<String,?> properties,
MathTransformFactory mtFactory) {
+        /*
+         * The check for 'properties' and 'mtFactory' is performed by the ServicesForMetadata
subclass. If this code is
+         * executed, this means that the "sis-referencing" module is not on the classpath,
in which case we do not know
+         * how to pass the 'properties' and 'mtFactory' arguments to the foreigner CoordinateOperationFactory
anyway.
+         */
+        final CoordinateOperationFactory factory = DefaultFactories.forClass(CoordinateOperationFactory.class);
+        if (factory != null) {
+            return factory;
+        } else {
+            throw referencingModuleNotFound();
+        }
+    }
+
+    /**
      * Returns {@code true} if the {@linkplain org.apache.sis.referencing.AbstractIdentifiedObject#getName()
      * primary name} or an aliases of the given object matches the given name. The comparison
ignores case,
      * some Latin diacritical signs and any characters that are not letters or digits.
@@ -303,6 +330,31 @@ public class ReferencingServices extends
     }
 
     /**
+     * Returns {@code true} if the name or an identifier of the given method matches the
given {@code identifier}.
+     *
+     * @param  method     The method to test for a match.
+     * @param  identifier The name or identifier of the operation method to search.
+     * @return {@code true} if the given method is a match for the given identifier.
+     */
+    private boolean matches(final OperationMethod method, final String identifier) {
+        if (isHeuristicMatchForName(method, identifier)) {
+            return true;
+        }
+        for (int s = identifier.indexOf(IDENTIFIER_SEPARATOR); s >= 0;
+                 s = identifier.indexOf(IDENTIFIER_SEPARATOR, s))
+        {
+            final String codespace = identifier.substring(0, s).trim();
+            final String code = identifier.substring(++s).trim();
+            for (final Identifier id : method.getIdentifiers()) {
+                if (codespace.equalsIgnoreCase(id.getCodeSpace()) && code.equalsIgnoreCase(id.getCode()))
{
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    /**
      * Returns the operation method for the specified name or identifier. The given argument
shall be either a
      * method name (e.g. <cite>"Transverse Mercator"</cite>) or one of its identifiers
(e.g. {@code "EPSG:9807"}).
      *
@@ -313,7 +365,7 @@ public class ReferencingServices extends
      * @see org.apache.sis.referencing.operation.DefaultCoordinateOperationFactory#getOperationMethod(String)
      * @see org.apache.sis.referencing.operation.transform.DefaultMathTransformFactory#getOperationMethod(String)
      */
-    public static OperationMethod getOperationMethod(final Iterable<? extends OperationMethod>
methods, final String identifier) {
+    public final OperationMethod getOperationMethod(final Iterable<? extends OperationMethod>
methods, final String identifier) {
         OperationMethod fallback = null;
         for (final OperationMethod method : methods) {
             if (matches(method, identifier)) {
@@ -331,29 +383,4 @@ public class ReferencingServices extends
         }
         return fallback;
     }
-
-    /**
-     * Returns {@code true} if the name or an identifier of the given method matches the
given {@code identifier}.
-     *
-     * @param  method     The method to test for a match.
-     * @param  identifier The name or identifier of the operation method to search.
-     * @return {@code true} if the given method is a match for the given identifier.
-     */
-    private static boolean matches(final OperationMethod method, final String identifier)
{
-        if (getInstance().isHeuristicMatchForName(method, identifier)) {
-            return true;
-        }
-        for (int s = identifier.indexOf(IDENTIFIER_SEPARATOR); s >= 0;
-                 s = identifier.indexOf(IDENTIFIER_SEPARATOR, s))
-        {
-            final String codespace = identifier.substring(0, s).trim();
-            final String code = identifier.substring(++s).trim();
-            for (final Identifier id : method.getIdentifiers()) {
-                if (codespace.equalsIgnoreCase(id.getCodeSpace()) && code.equalsIgnoreCase(id.getCode()))
{
-                    return true;
-                }
-            }
-        }
-        return false;
-    }
 }

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/MathTransformParser.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/MathTransformParser.java?rev=1683377&r1=1683376&r2=1683377&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/MathTransformParser.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/MathTransformParser.java
[UTF-8] Wed Jun  3 15:48:14 2015
@@ -316,7 +316,7 @@ class MathTransformParser extends Parser
              * getLastMethod(). Performs a slower and less robust check as a fallback.
              */
             if (classification != null) {
-                lastMethod = ReferencingServices.getOperationMethod(
+                lastMethod = ReferencingServices.getInstance().getOperationMethod(
                         mtFactory.getAvailableMethods(SingleOperation.class), classification);
             }
         }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java?rev=1683377&r1=1683376&r2=1683377&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java
[UTF-8] Wed Jun  3 15:48:14 2015
@@ -16,6 +16,7 @@
  */
 package org.apache.sis.internal.referencing;
 
+import java.util.Map;
 import java.util.Iterator;
 import java.util.Collection;
 
@@ -31,6 +32,7 @@ import org.opengis.referencing.crs.Coord
 import org.opengis.referencing.cs.CoordinateSystem;
 import org.opengis.referencing.operation.Matrix;
 import org.opengis.referencing.operation.MathTransform;
+import org.opengis.referencing.operation.MathTransformFactory;
 import org.opengis.referencing.operation.TransformException;
 import org.opengis.referencing.operation.CoordinateOperation;
 import org.opengis.referencing.operation.CoordinateOperationFactory;
@@ -46,6 +48,7 @@ import org.apache.sis.referencing.Identi
 import org.apache.sis.referencing.AbstractIdentifiedObject;
 import org.apache.sis.referencing.crs.DefaultTemporalCRS;
 import org.apache.sis.referencing.operation.transform.MathTransforms;
+import org.apache.sis.referencing.operation.DefaultCoordinateOperationFactory;
 import org.apache.sis.parameter.DefaultParameterDescriptor;
 import org.apache.sis.parameter.Parameterized;
 import org.apache.sis.io.wkt.Formatter;
@@ -59,6 +62,7 @@ import org.apache.sis.metadata.iso.exten
 import org.apache.sis.internal.metadata.ReferencingServices;
 import org.apache.sis.internal.referencing.provider.Affine;
 import org.apache.sis.internal.system.DefaultFactories;
+import org.apache.sis.util.collection.Containers;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.Utilities;
 
@@ -136,21 +140,6 @@ public final class ServicesForMetadata e
     }
 
     /**
-     * Returns the coordinate operation factory to be used for transforming the envelope.
-     * We will fetch a lenient factory because {@link GeographicBoundingBox} are usually
for approximative
-     * bounds (e.g. the area of validity of some CRS). If a user wants accurate bounds, he
should probably
-     * use an {@link Envelope} with the appropriate CRS.
-     */
-    private static CoordinateOperationFactory getFactory() throws TransformException {
-        // TODO: specify a lenient factory when the API will allow that.
-        final CoordinateOperationFactory factory = DefaultFactories.forClass(CoordinateOperationFactory.class);
-        if (factory != null) {
-            return factory;
-        }
-        throw new TransformException(Errors.format(Errors.Keys.MissingRequiredModule_1, "geotk-referencing"));
// This is temporary.
-    }
-
-    /**
      * Creates an exception message for a spatial, vertical or temporal dimension not found.
      */
     private static String dimensionNotFound(final short errorKey, final CoordinateReferenceSystem
crs) {
@@ -183,8 +172,9 @@ public final class ServicesForMetadata e
                 !Utilities.equalsIgnoreMetadata(cs2.getAxis(1), cs1.getAxis(1)))
             {
                 final CoordinateOperation operation;
+                final CoordinateOperationFactory factory = DefaultFactories.forBuildin(CoordinateOperationFactory.class);
                 try {
-                    operation = getFactory().createOperation(crs, normalizedCRS);
+                    operation = factory.createOperation(crs, normalizedCRS);
                 } catch (FactoryException e) {
                     throw new TransformException(Errors.format(Errors.Keys.CanNotTransformEnvelopeToGeodetic),
e);
                 }
@@ -428,4 +418,22 @@ public final class ServicesForMetadata e
     public boolean isHeuristicMatchForName(final IdentifiedObject object, final String name)
{
         return IdentifiedObjects.isHeuristicMatchForName(object, name);
     }
+
+    /**
+     * Returns the coordinate operation factory to use for the given properties and math
transform factory.
+     * If the given properties are empty and the {@code mtFactory} is the system default,
then this method
+     * returns the system default {@code CoordinateOperationFactory} instead of creating
a new one.
+     *
+     * @param  properties The default properties.
+     * @param  mtFactory  The math transform factory to use.
+     * @return The coordinate operation factory to use.
+     */
+    @Override
+    public CoordinateOperationFactory getCoordinateOperationFactory(Map<String,?> properties,
MathTransformFactory mtFactory) {
+        if (Containers.isNullOrEmpty(properties) && DefaultFactories.isDefaultInstance(MathTransformFactory.class,
mtFactory)) {
+            return DefaultFactories.forBuildin(CoordinateOperationFactory.class);
+        } else {
+            return new DefaultCoordinateOperationFactory(properties, mtFactory);
+        }
+    }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java?rev=1683377&r1=1683376&r2=1683377&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java
[UTF-8] Wed Jun  3 15:48:14 2015
@@ -56,9 +56,9 @@ import org.apache.sis.referencing.cs.Axi
 import org.apache.sis.referencing.cs.CoordinateSystems;
 import org.apache.sis.referencing.datum.BursaWolfParameters;
 import org.apache.sis.referencing.operation.DefaultConversion;
-import org.apache.sis.referencing.operation.DefaultCoordinateOperationFactory;
 import org.apache.sis.metadata.iso.citation.Citations;
 import org.apache.sis.internal.metadata.WKTKeywords;
+import org.apache.sis.internal.metadata.ReferencingServices;
 import org.apache.sis.internal.referencing.Legacy;
 import org.apache.sis.internal.referencing.VerticalDatumTypes;
 import org.apache.sis.internal.system.DefaultFactories;
@@ -172,7 +172,7 @@ final class GeodeticObjectParser extends
         crsFactory    = (CRSFactory)   factories;
         csFactory     = (CSFactory)    factories;
         datumFactory  = (DatumFactory) factories;
-        opFactory     = new DefaultCoordinateOperationFactory(defaultProperties, mtFactory);
 // TODO
+        opFactory     = ReferencingServices.getInstance().getCoordinateOperationFactory(defaultProperties,
mtFactory);
         convention    = Convention.DEFAULT;
         isAxisIgnored = false;
     }
@@ -200,7 +200,7 @@ final class GeodeticObjectParser extends
         crsFactory   = getFactory(CRSFactory.class,   factories);
         csFactory    = getFactory(CSFactory.class,    factories);
         datumFactory = getFactory(DatumFactory.class, factories);
-        opFactory    = new DefaultCoordinateOperationFactory(null, mtFactory);  // TODO
+        opFactory    = ReferencingServices.getInstance().getCoordinateOperationFactory(null,
mtFactory);
         this.convention = convention;
         this.isAxisIgnored = isAxisIgnored;
     }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java?rev=1683377&r1=1683376&r2=1683377&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java
[UTF-8] Wed Jun  3 15:48:14 2015
@@ -176,7 +176,7 @@ public class DefaultCoordinateOperationF
         }
         name = CharSequences.trimWhitespaces(name);
         ArgumentChecks.ensureNonEmpty("name", name);
-        final OperationMethod method = ReferencingServices.getOperationMethod(
+        final OperationMethod method = ReferencingServices.getInstance().getOperationMethod(
                 mtFactory.getAvailableMethods(SingleOperation.class), name);
         if (method != null) {
             return method;
@@ -371,7 +371,7 @@ public class DefaultCoordinateOperationF
                                                final OperationMethod method)
             throws FactoryException
     {
-        throw new UnsupportedOperationException("Not supported yet.");
+        return delegate().createOperation(sourceCRS, targetCRS, method);
     }
 
     /**
@@ -388,6 +388,26 @@ public class DefaultCoordinateOperationF
                                                final CoordinateReferenceSystem targetCRS)
             throws OperationNotFoundException, FactoryException
     {
-        throw new UnsupportedOperationException("Not supported yet.");
+        return delegate().createOperation(sourceCRS, targetCRS);
     }
+
+    /**
+     * Temporarily returns a third-party factory for operation not yet implemented by this
class.
+     * This method will be removed when the missing implementation will have been ported
to SIS.
+     */
+    private synchronized CoordinateOperationFactory delegate() throws FactoryException {
+        if (delegate != null) {
+            return delegate;
+        }
+        for (final CoordinateOperationFactory factory : java.util.ServiceLoader.load(CoordinateOperationFactory.class))
{
+            if (!factory.getClass().getName().startsWith("org.apache.sis.")) {
+                delegate = factory;
+                return factory;
+            }
+        }
+        throw new FactoryException(Errors.format(Errors.Keys.MissingRequiredModule_1, "geotk-referencing"));
// This is temporary.
+    }
+
+    /** Temporary, to be deleted in a future SIS version. */
+    private transient CoordinateOperationFactory delegate;
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java?rev=1683377&r1=1683376&r2=1683377&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
[UTF-8] Wed Jun  3 15:48:14 2015
@@ -371,7 +371,7 @@ public class DefaultMathTransformFactory
         ArgumentChecks.ensureNonEmpty("identifier", identifier);
         OperationMethod method = methodsByName.get(identifier);
         if (method == null) {
-            method = ReferencingServices.getOperationMethod(methods, identifier);
+            method = ReferencingServices.getInstance().getOperationMethod(methods, identifier);
             if (method == null) {
                 throw new NoSuchIdentifierException(Errors.format(Errors.Keys.NoSuchOperationMethod_1,
identifier), identifier);
             }

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java?rev=1683377&r1=1683376&r2=1683377&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
[UTF-8] Wed Jun  3 15:48:14 2015
@@ -61,7 +61,19 @@ public final class DefaultFactories exte
     }
 
     /**
-     * Return the default factory implementing the given interface.
+     * Returns {@code true} if the default factory of the given type is the given instance.
+     *
+     * @param  <T>  The interface type.
+     * @param  type The interface type.
+     * @param  factory The factory implementation to test.
+     * @return {@code true} if the given factory implementation is the default instance.
+     */
+    public static synchronized <T> boolean isDefaultInstance(final Class<T> type,
final T factory) {
+        return FACTORIES.get(type) == factory;
+    }
+
+    /**
+     * Returns the default factory implementing the given interface.
      * This method gives preference to Apache SIS implementation of factories if present.
      * This is a temporary mechanism while we are waiting for a real dependency injection
mechanism.
      *



Mime
View raw message