sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1701049 - in /sis/branches/JDK8/core/sis-referencing/src: main/java/org/apache/sis/internal/jaxb/referencing/ main/java/org/apache/sis/referencing/operation/ test/java/org/apache/sis/parameter/ test/java/org/apache/sis/referencing/operation/
Date Thu, 03 Sep 2015 15:22:45 GMT
Author: desruisseaux
Date: Thu Sep  3 15:22:44 2015
New Revision: 1701049

URL: http://svn.apache.org/r1701049
Log:
Add GML (un)marshalling of CoordinateOperation.sourceCRS and targetCRS.

Added:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SC_CRS.java
  (with props)
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SC_GeographicCRS.txt
  (with props)
Modified:
    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/main/java/org/apache/sis/referencing/operation/package-info.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterMarshallingTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/OperationMarshallingTest.java

Added: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SC_CRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SC_CRS.java?rev=1701049&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SC_CRS.java
(added)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SC_CRS.java
[UTF-8] Thu Sep  3 15:22:44 2015
@@ -0,0 +1,92 @@
+/*
+ * 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.internal.jaxb.referencing;
+
+import javax.xml.bind.annotation.XmlElementRef;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.apache.sis.referencing.crs.AbstractCRS;
+import org.apache.sis.internal.jaxb.gco.PropertyType;
+
+
+/**
+ * JAXB adapter mapping implementing class to the GeoAPI interface. See
+ * package documentation for more information about JAXB and interface.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.6
+ * @version 0.6
+ * @module
+ */
+public final class SC_CRS extends PropertyType<SC_CRS, CoordinateReferenceSystem> {
+    /**
+     * Empty constructor for JAXB only.
+     */
+    public SC_CRS() {
+    }
+
+    /**
+     * Returns the GeoAPI interface which is bound by this adapter.
+     * This method is indirectly invoked by the private constructor
+     * below, so it shall not depend on the state of this object.
+     *
+     * @return {@code CoordinateReferenceSystem.class}
+     */
+    @Override
+    protected Class<CoordinateReferenceSystem> getBoundType() {
+        return CoordinateReferenceSystem.class;
+    }
+
+    /**
+     * Constructor for the {@link #wrap} method only.
+     */
+    private SC_CRS(final CoordinateReferenceSystem cs) {
+        super(cs);
+    }
+
+    /**
+     * Invoked by {@link PropertyType} at marshalling time for wrapping the given value
+     * in a {@code <gml:AbstractCRS>} XML element.
+     *
+     * @param  cs The element to marshall.
+     * @return A {@code PropertyType} wrapping the given the element.
+     */
+    @Override
+    protected SC_CRS wrap(final CoordinateReferenceSystem cs) {
+        return new SC_CRS(cs);
+    }
+
+    /**
+     * Invoked by JAXB at marshalling time for getting the actual element to write
+     * inside the {@code <gml:AbstractCRS>} XML element.
+     * This is the value or a copy of the value given in argument to the {@code wrap} method.
+     *
+     * @return The element to be marshalled.
+     */
+    @XmlElementRef
+    public AbstractCRS getElement() {
+        return AbstractCRS.castOrCopy(metadata);
+    }
+
+    /**
+     * Invoked by JAXB at unmarshalling time for storing the result temporarily.
+     *
+     * @param cs The unmarshalled element.
+     */
+    public void setElement(final AbstractCRS cs) {
+        metadata = cs;
+    }
+}

Propchange: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SC_CRS.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SC_CRS.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SC_GeographicCRS.txt
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SC_GeographicCRS.txt?rev=1701049&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SC_GeographicCRS.txt
(added)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SC_GeographicCRS.txt
[UTF-8] Thu Sep  3 15:22:44 2015
@@ -0,0 +1,4 @@
+The SC_GeographicCRS adapter is defined in the org.apache.sis.referencing.crs
+package because it needs access to DefaultGeodeticCRS package-private methods.
+Note also that GeographicCRS does not exist in GML, so this is a special case
+anyway.

Propchange: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SC_GeographicCRS.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SC_GeographicCRS.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

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=1701049&r1=1701048&r2=1701049&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 15:22:44 2015
@@ -35,6 +35,7 @@ import org.apache.sis.parameter.Paramete
 import org.opengis.parameter.GeneralParameterValue;
 import org.opengis.parameter.ParameterDescriptorGroup;
 import org.opengis.parameter.ParameterValueGroup;
+import org.opengis.referencing.crs.GeneralDerivedCRS;
 import org.apache.sis.io.wkt.Formatter;
 import org.apache.sis.io.wkt.FormattableObject;
 import org.apache.sis.util.iso.Types;
@@ -95,8 +96,8 @@ import java.util.Objects;
     "scope",
     "operationVersion",
     "coordinateOperationAccuracy",
-//  "sourceCRS",    // TODO
-//  "targetCRS"
+    "source",
+    "target"
 })
 @XmlRootElement(name = "AbstractCoordinateOperation")
 @XmlSeeAlso({
@@ -111,18 +112,22 @@ public class AbstractCoordinateOperation
     /**
      * The source CRS, or {@code null} if not available.
      *
+     * <p><b>Consider this field as final!</b>
+     * This field is modified only at unmarshalling time by {@link #setSource(CoordinateReferenceSystem)}</p>
+     *
      * @see #getSourceCRS()
      */
-//  @XmlElement
-    private final CoordinateReferenceSystem sourceCRS;
+    private CoordinateReferenceSystem sourceCRS;
 
     /**
      * The target CRS, or {@code null} if not available.
      *
+     * <p><b>Consider this field as final!</b>
+     * This field is modified only at unmarshalling time by {@link #setTarget(CoordinateReferenceSystem)}</p>
+     *
      * @see #getTargetCRS()
      */
-//  @XmlElement
-    private final CoordinateReferenceSystem targetCRS;
+    private CoordinateReferenceSystem targetCRS;
 
     /**
      * The CRS which is neither the {@linkplain #getSourceCRS() source CRS} or
@@ -170,8 +175,6 @@ public class AbstractCoordinateOperation
      */
     AbstractCoordinateOperation() {
         super(org.apache.sis.internal.referencing.NilReferencingObject.INSTANCE);
-        sourceCRS                   = null;
-        targetCRS                   = null;
         interpolationCRS            = null;
         operationVersion            = null;
         coordinateOperationAccuracy = null;
@@ -419,6 +422,36 @@ check:      for (int isTarget=0; ; isTar
     }
 
     /**
+     * Returns {@code true} if this coordinate operation is for the definition of a
+     * {@linkplain org.apache.sis.referencing.crs.DefaultDerivedCRS derived} or
+     * {@linkplain org.apache.sis.referencing.crs.DefaultProjectedCRS projected CRS}.
+     * The standard (ISO 19111) approach constructs <cite>defining conversion</cite>
+     * as an operation of type {@link org.opengis.referencing.operation.Conversion}
+     * with null {@linkplain #getSourceCRS() source} and {@linkplain #getTargetCRS() target
CRS}.
+     * But SIS supports also defining conversions with non-null CRS provided that:
+     *
+     * <ul>
+     *   <li>{@link GeneralDerivedCRS#getBaseCRS()} is the {@linkplain #getSourceCRS()
source CRS} of this operation, and</li>
+     *   <li>{@link GeneralDerivedCRS#getConversionFromBase()} is this operation instance.</li>
+     * </ul>
+     *
+     * When this method returns {@code true}, the source and target CRS are not marshalled
in XML documents.
+     *
+     * @return {@code true} if this coordinate operation is for the definition of a derived
or projected CRS.
+     */
+    public boolean isDefiningConversion() {
+        /*
+         * Trick: we do not need to verify if (this instanceof Conversion) because:
+         *   - Only DefaultConversion constructor accepts null source and target CRS.
+         *   - GeneralDerivedCRS.getConversionFromBase() return type is Conversion.
+         */
+        return (sourceCRS == null && targetCRS == null)
+               || ((targetCRS instanceof GeneralDerivedCRS)
+                    && ((GeneralDerivedCRS) targetCRS).getBaseCRS() == sourceCRS
+                    && ((GeneralDerivedCRS) targetCRS).getConversionFromBase() ==
this);
+    }
+
+    /**
      * Returns the source CRS, or {@code null} if unspecified.
      * The source CRS is mandatory for {@linkplain DefaultTransformation transformations}
only.
      * This information is optional for {@linkplain DefaultConversion conversions} according
@@ -791,4 +824,44 @@ check:      for (int isTarget=0; ; isTar
             });
         }
     }
+
+    // ---- XML SUPPORT ----------------------------------------------------
+
+    /**
+     * Invoked by JAXB for getting the source CRS to marshal.
+     */
+    @XmlElement(name = "sourceCRS")
+    private CoordinateReferenceSystem getSource() {
+        return isDefiningConversion() ? null : getSourceCRS();
+    }
+
+    /**
+     * Invoked by JAXB at marshalling time for setting the source CRS.
+     */
+    private void setSource(final CoordinateReferenceSystem crs) {
+        if (ReferencingUtilities.canSetProperty(AbstractCoordinateOperation.class,
+                "setSource", "sourceCRS", sourceCRS != null))
+        {
+            sourceCRS = crs;
+        }
+    }
+
+    /**
+     * Invoked by JAXB for getting the target CRS to marshal.
+     */
+    @XmlElement(name = "targetCRS")
+    private CoordinateReferenceSystem getTarget() {
+        return isDefiningConversion() ? null : getTargetCRS();
+    }
+
+    /**
+     * Invoked by JAXB at marshalling time for setting the target CRS.
+     */
+    private void setTarget(final CoordinateReferenceSystem crs) {
+        if (ReferencingUtilities.canSetProperty(AbstractCoordinateOperation.class,
+                "setTarget", "targetCRS", targetCRS != null))
+        {
+            targetCRS = crs;
+        }
+    }
 }

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=1701049&r1=1701048&r2=1701049&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 15:22:44 2015
@@ -451,7 +451,7 @@ class AbstractSingleOperation extends Ab
      * @see DefaultOperationMethod#setDescriptors
      */
     private void setParameters(final GeneralParameterValue[] values) {
-        if (ReferencingUtilities.canSetProperty(DefaultOperationMethod.class,
+        if (ReferencingUtilities.canSetProperty(AbstractSingleOperation.class,
                 "setParameters", "parameterValue", parameters != null))
         {
             /*

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/package-info.java?rev=1701049&r1=1701048&r2=1701049&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/package-info.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/package-info.java
[UTF-8] Thu Sep  3 15:22:44 2015
@@ -70,6 +70,7 @@
     @XmlJavaTypeAdapter(CC_OperationMethod.class),
     @XmlJavaTypeAdapter(CC_GeneralParameterValue.class),
     @XmlJavaTypeAdapter(CC_GeneralOperationParameter.class),
+    @XmlJavaTypeAdapter(SC_CRS.class),
     @XmlJavaTypeAdapter(InternationalStringConverter.class)
 })
 package org.apache.sis.referencing.operation;

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterMarshallingTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterMarshallingTest.java?rev=1701049&r1=1701048&r2=1701049&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterMarshallingTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterMarshallingTest.java
[UTF-8] Thu Sep  3 15:22:44 2015
@@ -185,7 +185,7 @@ public final strictfp class ParameterMar
         final DefaultParameterValue<Boolean> parameter = create(Boolean.class, null);
         parameter.setValue(Boolean.TRUE);
         testMarshallAndUnmarshall(parameter,
-                "<gml:ParameterValue xmlns:gml=\"" + Namespaces.GML + "\">\n" 
+                "<gml:ParameterValue xmlns:gml=\"" + Namespaces.GML + "\">\n"
               + "  <gml:booleanValue>true</gml:booleanValue>\n"
               + "    <gml:operationParameter>"
               + "      <gml:OperationParameter>"
@@ -206,7 +206,7 @@ public final strictfp class ParameterMar
         final DefaultParameterValue<Integer> parameter = create(Integer.class, null);
         parameter.setValue(2000);
         testMarshallAndUnmarshall(parameter,
-                "<gml:ParameterValue xmlns:gml=\"" + Namespaces.GML + "\">\n" 
+                "<gml:ParameterValue xmlns:gml=\"" + Namespaces.GML + "\">\n"
               + "  <gml:integerValue>2000</gml:integerValue>\n"
               + "    <gml:operationParameter>"
               + "      <gml:OperationParameter>"
@@ -249,7 +249,7 @@ public final strictfp class ParameterMar
                 new MeasurementRange<Double>(Double.class, null, false, null, false,
SI.METRE));
         parameter.setValue(3000, SI.METRE);
         testMarshallAndUnmarshall(parameter,
-                "<gml:ParameterValue xmlns:gml=\"" + Namespaces.GML + "\">\n" 
+                "<gml:ParameterValue xmlns:gml=\"" + Namespaces.GML + "\">\n"
               + "  <gml:value uom=\"urn:ogc:def:uom:EPSG::9001\">3000.0</gml:value>\n"
               + "    <gml:operationParameter>"
               + "      <gml:OperationParameter>"

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=1701049&r1=1701048&r2=1701049&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 15:22:44 2015
@@ -28,7 +28,10 @@ import org.opengis.parameter.GeneralPara
 import org.opengis.parameter.ParameterValue;
 import org.opengis.parameter.ParameterValueGroup;
 import org.opengis.parameter.GeneralParameterValue;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.opengis.referencing.crs.GeodeticCRS;
 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;
@@ -104,7 +107,9 @@ public final strictfp class OperationMar
                         "  </gml:parameter>\n" +
                         "</gml:OperationMethod>", xml, "xmlns:*");
 
-        verifyMethod((DefaultOperationMethod) XML.unmarshal(xml));
+        final OperationMethod method = (OperationMethod) XML.unmarshal(xml);
+        verifyMethod(method);
+        Validators.validate(method);
     }
 
     /**
@@ -160,6 +165,8 @@ public final strictfp class OperationMar
         verifyParameter(method, parameters,  -0.0, (ParameterValue<?>) it.next());
         verifyParameter(method, parameters, -90.0, (ParameterValue<?>) it.next());
         assertFalse("Unexpected parameter.", it.hasNext());
+
+        Validators.validate(c);
     }
 
     /**
@@ -190,9 +197,41 @@ public final strictfp class OperationMar
     @DependsOnMethod("testConversionUnmarshalling")
     public void testTransformationUnmarshalling() throws JAXBException {
         final DefaultTransformation c = unmarshalFile(DefaultTransformation.class, "Transformation.xml");
-        assertEquals("name", "NTF (Paris) to NTF (1)", c.getName().getCode());
-        assertEquals("identifier", "1763", getSingleton(c.getIdentifiers()).getCode());
-        assertEquals("scope", "Change of prime meridian.", String.valueOf(c.getScope()));
-        assertEquals("operationVersion", "IGN-Fra", c.getOperationVersion());
+        assertEquals("name",             "NTF (Paris) to NTF (1)",    c.getName().getCode());
+        assertEquals("identifier",       "1763",                      getSingleton(c.getIdentifiers()).getCode());
+        assertEquals("scope",            "Change of prime meridian.", String.valueOf(c.getScope()));
+        assertEquals("operationVersion", "IGN-Fra",                   c.getOperationVersion());
+
+        final OperationMethod method = c.getMethod();
+        assertNotNull("method", method);
+        assertEquals ("method.name", "Longitude rotation", method.getName().getCode());
+        assertEquals ("method.identifier", "9601", getSingleton(method.getIdentifiers()).getCode());
+        assertEquals ("method.formula", "Target_longitude = Source_longitude + longitude_offset.",
method.getFormula().getFormula().toString());
+
+        final ParameterDescriptor<?> descriptor = (ParameterDescriptor<?>) getSingleton(method.getParameters().descriptors());
+        assertEquals("descriptor.name",       "Longitude offset", descriptor.getName().getCode());
+        assertEquals("descriptor.identifier", "8602", getSingleton(descriptor.getIdentifiers()).getCode());
+        assertEquals("descriptor.valueClass", Double.class, descriptor.getValueClass());
+
+        final ParameterValueGroup parameters = c.getParameterValues();
+        assertNotNull("parameters", parameters);
+        assertSame("parameters.descriptors", method.getParameters(), parameters.getDescriptor());
+
+        final ParameterValue<?> parameter = (ParameterValue<?>) getSingleton(parameters.values());
+        assertSame  ("parameters.descriptor", descriptor,  parameter.getDescriptor());
+        assertEquals("parameters.unit",       NonSI.GRADE, parameter.getUnit());
+        assertEquals("parameters.value",      2.5969213,   parameter.getValue());
+
+        final CoordinateReferenceSystem sourceCRS = c.getSourceCRS();
+        assertInstanceOf("sourceCRS",            GeodeticCRS.class,  sourceCRS);
+        assertEquals    ("sourceCRS.name",       "NTF (Paris)",      sourceCRS.getName().getCode());
+        assertEquals    ("sourceCRS.scope",      "Geodetic survey.", sourceCRS.getScope().toString());
+        assertEquals    ("sourceCRS.identifier", "4807",             getSingleton(sourceCRS.getIdentifiers()).getCode());
+
+        final CoordinateReferenceSystem targetCRS = c.getTargetCRS();
+        assertInstanceOf("targetCRS",            GeodeticCRS.class,  targetCRS);
+        assertEquals    ("targetCRS.name",       "NTF",              targetCRS.getName().getCode());
+        assertEquals    ("targetCRS.scope",      "Geodetic survey.", targetCRS.getScope().toString());
+        assertEquals    ("targetCRS.identifier", "4275",             getSingleton(targetCRS.getIdentifiers()).getCode());
     }
 }



Mime
View raw message