sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1701063 - in /sis/branches/JDK8/core/sis-referencing/src: main/java/org/apache/sis/internal/jaxb/referencing/ main/java/org/apache/sis/referencing/datum/ main/java/org/apache/sis/referencing/operation/ test/java/org/apache/sis/referencing/...
Date Thu, 03 Sep 2015 16:31:24 GMT
Author: desruisseaux
Date: Thu Sep  3 16:31:23 2015
New Revision: 1701063

URL: http://svn.apache.org/r1701063
Log:
Reconstruct the MathTransform after <gml:Transformation> unmarshalling.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_OperationMethod.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/OperationMarshallingTest.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_OperationMethod.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_OperationMethod.java?rev=1701063&r1=1701062&r2=1701063&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_OperationMethod.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_OperationMethod.java
[UTF-8] Thu Sep  3 16:31:23 2015
@@ -177,6 +177,7 @@ public final class CC_OperationMethod ex
         if (factory != null) try {
             method = factory.getOperationMethod(name.getCode());
         } catch (FactoryException e) {
+            // Use DefaultOperationMethod as the source class because it is the first public
class in callers.
             Context.warningOccured(Context.current(), DefaultOperationMethod.class, "setDescriptors",
e, true);
         }
         final Map<String,?> properties = Collections.singletonMap(ParameterDescriptorGroup.NAME_KEY,
name);

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java?rev=1701063&r1=1701062&r2=1701063&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
[UTF-8] Thu Sep  3 16:31:23 2015
@@ -353,6 +353,11 @@ public class DefaultEllipsoid extends Ab
      * been defined, it is now possible to calculate the value of the missing parameter
      * using the values of those that are set.
      *
+     * <div class="note"><b>Note:</b>
+     * we use a method invoked from setter methods rather than defining an {@code afterUnmarshal(Unmarshaller,
Object)}
+     * method (automatically invoked by JAXB) in order to avoid a dependency to the {@link
javax.xml.bind.Unmarshaller}
+     * interface when the user does not want to read GML documents.</div>
+     *
      * @see #setSemiMajorAxisMeasure(Measure)
      * @see #setSecondDefiningParameter(SecondDefiningParameter)
      */

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java?rev=1701063&r1=1701062&r2=1701063&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java
[UTF-8] Thu Sep  3 16:31:23 2015
@@ -165,8 +165,11 @@ public class AbstractCoordinateOperation
     /**
      * Transform from positions in the {@linkplain #getSourceCRS source coordinate reference
system}
      * to positions in the {@linkplain #getTargetCRS target coordinate reference system}.
+     *
+     * <p><b>Consider this field as final!</b>
+     * This field is modified only at unmarshalling time by {@link #afterUnmarshal()}</p>
      */
-    private final MathTransform transform;
+    private MathTransform transform;
 
     /**
      * Creates a new object in which every attributes are set to a null value.
@@ -180,7 +183,6 @@ public class AbstractCoordinateOperation
         coordinateOperationAccuracy = null;
         domainOfValidity            = null;
         scope                       = null;
-        transform                   = null;
     }
 
     /**
@@ -324,6 +326,7 @@ public class AbstractCoordinateOperation
      * are consistent with {@link #transform} input and output dimensions.
      */
     private void checkDimensions(final Map<String,?> properties) {
+        final MathTransform transform = this.transform;   // Protect from changes.
         if (transform != null) {
             final int interpDim = ReferencingUtilities.getDimension(interpolationCRS);
 check:      for (int isTarget=0; ; isTarget++) {        // 0 == source check; 1 == target
check.
@@ -843,6 +846,7 @@ check:      for (int isTarget=0; ; isTar
                 "setSource", "sourceCRS", sourceCRS != null))
         {
             sourceCRS = crs;
+            afterUnmarshal();
         }
     }
 
@@ -862,6 +866,30 @@ check:      for (int isTarget=0; ; isTar
                 "setTarget", "targetCRS", targetCRS != null))
         {
             targetCRS = crs;
+            afterUnmarshal();
+        }
+    }
+
+    /**
+     * Invoked by setter methods for computing the math transform as soon as we can.
+     * It is okay to invoke this method more than once.
+     *
+     * <div class="note"><b>Note:</b>
+     * we use a method invoked from setter methods rather than defining an {@code afterUnmarshal(Unmarshaller,
Object)}
+     * method (automatically invoked by JAXB) in order to avoid a dependency to the {@link
javax.xml.bind.Unmarshaller}
+     * interface when the user does not want to read GML documents.</div>
+     */
+    final void afterUnmarshal() {
+        if (transform == null && sourceCRS != null && targetCRS != null)
{
+            transform = createMathTransform();
         }
     }
+
+    /**
+     * Implemented by subclasses at unmarshalling time for creating the math transform from
available information.
+     * Can return {@code null} if there is not enough information.
+     */
+    MathTransform createMathTransform() {
+        return null;
+    }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java?rev=1701063&r1=1701062&r2=1701063&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java
[UTF-8] Thu Sep  3 16:31:23 2015
@@ -23,6 +23,7 @@ import javax.xml.bind.annotation.XmlType
 import javax.xml.bind.annotation.XmlSeeAlso;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
+import org.opengis.util.FactoryException;
 import org.opengis.parameter.ParameterValueGroup;
 import org.opengis.parameter.ParameterDescriptorGroup;
 import org.opengis.parameter.GeneralParameterDescriptor;
@@ -31,6 +32,7 @@ import org.opengis.referencing.operation
 import org.opengis.referencing.operation.SingleOperation;
 import org.opengis.referencing.operation.OperationMethod;
 import org.opengis.referencing.operation.MathTransform;
+import org.opengis.referencing.operation.MathTransformFactory;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.apache.sis.parameter.Parameters;
 import org.apache.sis.parameter.Parameterized;
@@ -40,8 +42,10 @@ import org.apache.sis.referencing.operat
 import org.apache.sis.referencing.operation.transform.PassThroughTransform;
 import org.apache.sis.internal.jaxb.referencing.CC_OperationParameterGroup;
 import org.apache.sis.internal.jaxb.referencing.CC_OperationMethod;
+import org.apache.sis.internal.jaxb.Context;
 import org.apache.sis.internal.referencing.ReferencingUtilities;
 import org.apache.sis.internal.metadata.ReferencingServices;
+import org.apache.sis.internal.system.DefaultFactories;
 import org.apache.sis.internal.util.Constants;
 import org.apache.sis.util.collection.Containers;
 import org.apache.sis.util.resources.Errors;
@@ -486,6 +490,22 @@ class AbstractSingleOperation extends Ab
              */
             parameters = new DefaultParameterValueGroup(method.getParameters());
             CC_OperationMethod.store(values, parameters.values(), replacements);
+            afterUnmarshal();   // For creating the math transform.
         }
     }
+
+    /**
+     * Invoked at unmarshalling time for creating the math transform from available information.
+     * Can return {@code null} if there is not enough information.
+     */
+    @Override
+    final MathTransform createMathTransform() {
+        if (parameters != null) try {
+            return DefaultFactories.forBuildin(MathTransformFactory.class).createBaseToDerived(
+                    super.getSourceCRS(), parameters, super.getTargetCRS().getCoordinateSystem());
+        } catch (FactoryException e) {
+            Context.warningOccured(Context.current(), AbstractCoordinateOperation.class,
"createMathTransform", e, true);
+        }
+        return super.createMathTransform();
+    }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/OperationMarshallingTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/OperationMarshallingTest.java?rev=1701063&r1=1701062&r2=1701063&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/OperationMarshallingTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/OperationMarshallingTest.java
[UTF-8] Thu Sep  3 16:31:23 2015
@@ -30,11 +30,14 @@ import org.opengis.parameter.ParameterVa
 import org.opengis.parameter.GeneralParameterValue;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.opengis.referencing.crs.GeodeticCRS;
+import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.OperationMethod;
 import org.opengis.test.Validators;
 import org.apache.sis.parameter.ParameterBuilder;
 import org.apache.sis.internal.referencing.provider.Mercator1SP;
 import org.apache.sis.internal.jaxb.referencing.CC_OperationParameterGroupTest;
+import org.apache.sis.referencing.operation.transform.LinearTransform;
+import org.apache.sis.referencing.operation.matrix.Matrix3;
 import org.apache.sis.xml.Namespaces;
 import org.apache.sis.xml.XML;
 import org.apache.sis.test.DependsOn;
@@ -233,5 +236,14 @@ public final strictfp class OperationMar
         assertEquals    ("targetCRS.name",       "NTF",              targetCRS.getName().getCode());
         assertEquals    ("targetCRS.scope",      "Geodetic survey.", targetCRS.getScope().toString());
         assertEquals    ("targetCRS.identifier", "4275",             getSingleton(targetCRS.getIdentifiers()).getCode());
+
+        final MathTransform tr = c.getMathTransform();
+        assertInstanceOf("mathTransform", LinearTransform.class, tr);
+        assertMatrixEquals("mathTransform.matrix",
+                new Matrix3(1, 0, 0,
+                            0, 1, 2.33722917,
+                            0, 0, 1), ((LinearTransform) tr).getMatrix(), STRICT);
+
+        Validators.validate(c);
     }
 }



Mime
View raw message