sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1706791 - in /sis/branches/JDK8/core/sis-referencing/src: main/java/org/apache/sis/referencing/crs/ main/java/org/apache/sis/referencing/operation/ test/java/org/apache/sis/referencing/operation/
Date Mon, 05 Oct 2015 10:40:53 GMT
Author: desruisseaux
Date: Mon Oct  5 10:40:53 2015
New Revision: 1706791

URL: http://svn.apache.org/viewvc?rev=1706791&view=rev
Log:
More conservative way to search for an OperationMethod alias:
search in the ParameterDescriptorGroup associated to the enclosing object.
At least that descriptor has some association (even if indirectly) with the
OperationMethod being formatted, as opposed to the previous approach which
was searching unconditionally in the hard-coded system-wide aliases.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultProjectedCRS.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultOperationMethod.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultOperationMethodTest.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultProjectedCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultProjectedCRS.java?rev=1706791&r1=1706790&r2=1706791&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultProjectedCRS.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultProjectedCRS.java
[UTF-8] Mon Oct  5 10:40:53 2015
@@ -227,7 +227,8 @@ public class DefaultProjectedCRS extends
     @Override
     @XmlElement(name = "baseGeodeticCRS", required = true)  // Note: older GML version used
"baseGeographicCRS".
     public GeographicCRS getBaseCRS() {
-        return super.getConversionFromBase().getSourceCRS();
+        final Projection projection = super.getConversionFromBase();
+        return (projection != null) ? projection.getSourceCRS() : null;
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultOperationMethod.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultOperationMethod.java?rev=1706791&r1=1706790&r2=1706791&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultOperationMethod.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultOperationMethod.java
[UTF-8] Mon Oct  5 10:40:53 2015
@@ -24,23 +24,22 @@ import javax.xml.bind.annotation.XmlType
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlSchemaType;
-import org.opengis.util.FactoryException;
 import org.opengis.util.InternationalString;
 import org.opengis.metadata.citation.Citation;
 import org.opengis.referencing.IdentifiedObject;
 import org.opengis.referencing.operation.Formula;
+import org.opengis.referencing.operation.Conversion;
 import org.opengis.referencing.operation.Projection;
 import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.OperationMethod;
 import org.opengis.referencing.operation.SingleOperation;
-import org.opengis.referencing.operation.CoordinateOperationFactory;
+import org.opengis.referencing.crs.GeneralDerivedCRS;
 import org.opengis.parameter.GeneralParameterDescriptor;
 import org.opengis.parameter.ParameterDescriptorGroup;
 import org.opengis.parameter.ParameterDescriptor;
 import org.apache.sis.util.Utilities;
 import org.apache.sis.util.Workaround;
 import org.apache.sis.util.ComparisonMode;
-import org.apache.sis.util.logging.Logging;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.resources.Vocabulary;
 import org.apache.sis.util.iso.SimpleInternationalString;
@@ -50,16 +49,14 @@ import org.apache.sis.internal.jaxb.gco.
 import org.apache.sis.internal.jaxb.referencing.CC_OperationMethod;
 import org.apache.sis.internal.referencing.NilReferencingObject;
 import org.apache.sis.internal.referencing.ReferencingUtilities;
-import org.apache.sis.internal.system.DefaultFactories;
-import org.apache.sis.internal.system.Loggers;
 import org.apache.sis.parameter.DefaultParameterDescriptorGroup;
 import org.apache.sis.parameter.Parameterized;
 import org.apache.sis.referencing.NamedIdentifier;
 import org.apache.sis.referencing.IdentifiedObjects;
 import org.apache.sis.referencing.AbstractIdentifiedObject;
-import org.apache.sis.referencing.operation.transform.MathTransformProvider;
 import org.apache.sis.io.wkt.Formatter;
 import org.apache.sis.io.wkt.ElementKind;
+import org.apache.sis.io.wkt.FormattableObject;
 
 import static org.apache.sis.util.ArgumentChecks.*;
 
@@ -687,6 +684,7 @@ public class DefaultOperationMethod exte
      */
     @Override
     protected String formatTo(final Formatter formatter) {
+        final boolean isWKT1 = formatter.getConvention().majorVersion() == 1;
         /*
          * The next few lines below are basically a copy of the work done by super.formatTo(formatter),
          * which search for the name to write inside METHOD["name"]. The difference is in
the fallback
@@ -696,48 +694,42 @@ public class DefaultOperationMethod exte
         String name = IdentifiedObjects.getName(this, authority);
         ElementKind kind = ElementKind.METHOD;
         if (name == null) {
-            name = IdentifiedObjects.getName(this, null);
-            if (name == null) {
-                name = Vocabulary.getResources(formatter.getLocale()).getString(Vocabulary.Keys.Unnamed);
-                kind = ElementKind.NAME;  // Because the "Unnamed" string is not a real OperationMethod
name.
-            } else if (!(this instanceof MathTransformProvider)) {
-                /*
-                 * No name found for the given authority. We may use the primary name as
a fallback.
-                 * But before doing that, maybe we can find the name that we are looking
for in the
-                 * hard-coded values in the 'org.apache.sis.internal.referencing.provider'
package.
-                 * The typical use case is when this DefaultOperationMethod has been instantiated
-                 * by the EPSG factory using only the information found in the EPSG database.
-                 *
-                 * We skip this operation if this DefaultOperationMethod is also a MathTransformProvider
-                 * on the assumption that those providers already choose carefuly their aliases,
and are
-                 * already registered in CoordinateOperationFactory (so the call to 'getOperationMethod'
-                 * is likely to return 'this'). This is the case at least for SIS build-in
methods. The
-                 * intend is to avoid class loading (the factory, potentially followed by
all providers)
-                 * when it is likely to not give us a better name.
-                 */
-                final CoordinateOperationFactory factory = DefaultFactories.forClass(CoordinateOperationFactory.class);
-                if (factory != null) try {
-                    final OperationMethod method = factory.getOperationMethod(name);
-                    if (method != null) {  // Paranoiac check, but should never be null.
-                        final String candidate = IdentifiedObjects.getName(method, authority);
-                        if (candidate != null) {
-                            name = candidate;
-                        }
+            /*
+             * No name found for the given authority. We may use the primary name as a fallback.
+             * But before doing that, maybe we can find the name that we are looking for
in the
+             * hard-coded values in the 'org.apache.sis.internal.referencing.provider' package.
+             * The typical use case is when this DefaultOperationMethod has been instantiated
+             * by the EPSG factory using only the information found in the EPSG database.
+             *
+             * We can find the hard-coded names by looking at the ParameterDescriptorGroup
of the
+             * enclosing ProjectedCRS or DerivedCRS. This is because that parameter descriptor
was
+             * typically provided by the 'org.apache.sis.internal.referencing.provider' package
in
+             * order to create the MathTransform associated with the enclosing CRS.  The
enclosing
+             * CRS is either the immediate parent in WKT 1, or the parent of the parent in
WKT 2.
+             */
+            final FormattableObject parent = formatter.getEnclosingElement(isWKT1 ? 1 : 2);
+            if (parent instanceof GeneralDerivedCRS) {
+                final Conversion conversion = ((GeneralDerivedCRS) parent).getConversionFromBase();
+                if (conversion != null) {   // Should never be null, but let be safe.
+                    final ParameterDescriptorGroup descriptor;
+                    if (conversion instanceof Parameterized) {  // Usual case in SIS implementation.
+                        descriptor = ((Parameterized) conversion).getParameterDescriptors();
+                    } else {
+                        descriptor = conversion.getParameterValues().getDescriptor();
                     }
-                } catch (FactoryException e) {
-                    /*
-                     * If this OperationMethod is not know to the CoordinateOperationFactory,
do not declare the WKT
-                     * as invalid because this is not a WKT syntax problem. We will fallback
on the primary name.
-                     * Even if that name is not from the specified authority, maybe the user
know that the target
-                     * software will understand that name.
-                     */
-                    Logging.recoverableException(Logging.getLogger(Loggers.WKT),
-                            DefaultOperationMethod.class, "formatTo", e);
+                    name = IdentifiedObjects.getName(descriptor, authority);
+                }
+            }
+            if (name == null) {
+                name = IdentifiedObjects.getName(this, null);
+                if (name == null) {
+                    name = Vocabulary.getResources(formatter.getLocale()).getString(Vocabulary.Keys.Unnamed);
+                    kind = ElementKind.NAME;  // Because the "Unnamed" string is not a real
OperationMethod name.
                 }
             }
         }
         formatter.append(name, kind);
-        if (formatter.getConvention().majorVersion() == 1) {
+        if (isWKT1) {
             /*
              * The WKT 1 keyword is "PROJECTION", which imply that the operation method should
be of type
              * org.opengis.referencing.operation.Projection. So strictly speaking only the
first check in

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultOperationMethodTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultOperationMethodTest.java?rev=1706791&r1=1706790&r2=1706791&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultOperationMethodTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultOperationMethodTest.java
[UTF-8] Mon Oct  5 10:40:53 2015
@@ -161,12 +161,6 @@ public final strictfp class DefaultOpera
     public void testWKT() {
         final OperationMethod method = create("Mercator (variant A)", "9804", "EPSG guidance
note #7-2", 2);
         assertWktEquals("METHOD[“Mercator (variant A)”, ID[“EPSG”, 9804, URI[“urn:ogc:def:method:EPSG::9804”]]]",
method);
-        /*
-         * By default, WKT 1 conventions implies usage of OGC names instead then ESRI ones.
-         * Even if the OperationMethod created in this test did not declared explicitely
the OGC name,
-         * DefaultOperationMethod.formatTo(Formatter) is expected to check the aliases declared
in the
-         * 'org.apache.sis.internal.referencing.provider' package.
-         */
-        assertWktEquals(Convention.WKT1, "PROJECTION[“Mercator_1SP”, AUTHORITY[“EPSG”,
“9804”]]", method);
+        assertWktEquals(Convention.WKT1, "PROJECTION[“Mercator (variant A)”, AUTHORITY[“EPSG”,
“9804”]]", method);
     }
 }



Mime
View raw message