sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1700628 - in /sis/branches/JDK8/core: sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/ sis-referencing/src/main/java/org/apache/sis/parameter/ sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/ s...
Date Tue, 01 Sep 2015 17:53:46 GMT
Author: desruisseaux
Date: Tue Sep  1 17:53:45 2015
New Revision: 1700628

URL: http://svn.apache.org/r1700628
Log:
Add test for CC_OperationParameterGroup JAXB adapter.

Added:
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CC_OperationParameterGroupTest.java
  (with props)
Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_GeneralOperationParameter.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_OperationParameterGroup.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptorGroup.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValueGroup.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterValueList.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CC_GeneralOperationParameterTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/OperationMarshallingTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/CorruptedObjectException.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_GeneralOperationParameter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_GeneralOperationParameter.java?rev=1700628&r1=1700627&r2=1700628&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_GeneralOperationParameter.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_GeneralOperationParameter.java
[UTF-8] Tue Sep  1 17:53:45 2015
@@ -32,6 +32,7 @@ import org.apache.sis.parameter.DefaultP
 import org.apache.sis.parameter.Parameters;
 import org.apache.sis.referencing.IdentifiedObjects;
 import org.apache.sis.util.collection.Containers;
+import org.apache.sis.util.CorruptedObjectException;
 import org.apache.sis.internal.util.CollectionsExt;
 import org.apache.sis.internal.jaxb.gco.PropertyType;
 import org.apache.sis.internal.jaxb.Context;
@@ -255,7 +256,9 @@ public final class CC_GeneralOperationPa
                 GeneralParameterDescriptor predefined = complete.descriptor(p.getName().getCode());
                 if (predefined != null) {   // Safety in case 'complete' is a user's implementation.
                     canSubstitute &= (provided[i] = replacement(p, predefined)) == predefined;
-                    included.add(predefined);
+                    if (!included.add(predefined)) {
+                        throw new CorruptedObjectException(predefined);  // Broken hashCode/equals,
or object mutated.
+                    }
                     continue;
                 }
             } catch (ParameterNotFoundException e) {

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_OperationParameterGroup.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_OperationParameterGroup.java?rev=1700628&r1=1700627&r2=1700628&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_OperationParameterGroup.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_OperationParameterGroup.java
[UTF-8] Tue Sep  1 17:53:45 2015
@@ -19,13 +19,13 @@ package org.apache.sis.internal.jaxb.ref
 import java.util.Map;
 import java.util.List;
 import java.util.LinkedHashMap;
-import java.util.ConcurrentModificationException;
 import javax.xml.bind.annotation.XmlElement;
 import org.opengis.parameter.ParameterDescriptor;
 import org.opengis.parameter.ParameterDescriptorGroup;
 import org.opengis.parameter.GeneralParameterDescriptor;
 import org.apache.sis.internal.jaxb.gco.PropertyType;
 import org.apache.sis.parameter.DefaultParameterDescriptorGroup;
+import org.apache.sis.util.CorruptedObjectException;
 import org.apache.sis.util.collection.Containers;
 import org.apache.sis.util.resources.Errors;
 
@@ -104,8 +104,8 @@ public final class CC_OperationParameter
      * The descriptors are:
      *
      * <ol>
-     *   <li>The descriptors declared explicitely in the descriptor group.</li>
-     *   <li>The descriptors declared in the parameter values.</li>
+     *   <li>The descriptors declared explicitely in the {@code ParameterDescriptorGroup}.</li>
+     *   <li>The descriptors declared in the {@code ParameterValue} instances of the
{@code ParameterValueGroup}.</li>
      * </ol>
      *
      * The later are more complete than the former, because they allow us to infer the {@code
valueClass} property.
@@ -115,15 +115,20 @@ public final class CC_OperationParameter
      * {@link DefaultParameterDescriptorGroup} class in the hope to reduce the amount of
code
      * processed by the JVM in the common case where JAXB (un)marshalling is not needed.</div>
      *
-     * @param  descriptors The descriptors declared in the {@code ParameterDescriptorGroup}.
-     * @param  parameters  The descriptors declared in the {@code ParameterValue}.
-     * @return A single set containing the two given set of parameters.
-     */
-    public static GeneralParameterDescriptor[] merge(final List<GeneralParameterDescriptor>
descriptors,
-            final GeneralParameterDescriptor[] parameters)
+     * @param  descriptors  The descriptors declared in the {@code ParameterDescriptorGroup}.
+     * @param  fromValues   The descriptors declared in the {@code ParameterValue} instances.
+     *                      They are said "valid" because they contain the mandatory {@code
valueClass} property.
+     * @param  replacements An {@code IdentityHashMap} where to store the replacements that
the caller needs
+     *                      to apply in the {@code GeneralParameterValue} instances.
+     * @return A sequence containing the merged set of parameter descriptors.
+     */
+    public static GeneralParameterDescriptor[] merge(
+            final List<GeneralParameterDescriptor> descriptors,
+            final GeneralParameterDescriptor[] fromValues,
+            final Map<GeneralParameterDescriptor,GeneralParameterDescriptor> replacements)
     {
         if (descriptors.isEmpty()) {
-            return parameters;
+            return fromValues;
         }
         final Map<String,GeneralParameterDescriptor> union =
                 new LinkedHashMap<>(Containers.hashMapCapacity(descriptors.size()));
@@ -136,27 +141,27 @@ public final class CC_OperationParameter
         for (final GeneralParameterDescriptor p : descriptors) {
             final String name = p.getName().getCode();
             if (union.put(name, p) != null) {
-                throw new ConcurrentModificationException(Errors.format(Errors.Keys.UnexpectedChange_1,
name));
+                throw new CorruptedObjectException(name);
             }
         }
         /*
-         * Verify if any descriptors found in the ParameterValue instances could replace
the current descriptors.
-         * We give precedence to the descriptors having a non-null 'valueClass' property,
which normally are the
-         * descriptors from the 'parameters' array.
+         * Verify if any descriptors found in the ParameterValue instances could replace
the descriptors in the group.
+         * We give precedence to the descriptors having a non-null 'valueClass' property,
which normally appear in the
+         * 'valids' array.
          */
-        for (GeneralParameterDescriptor replacement : parameters) {
-            final String name = replacement.getName().getCode();
-            GeneralParameterDescriptor previous = union.put(name, replacement);
+        for (GeneralParameterDescriptor valid : fromValues) {
+            final String name = valid.getName().getCode();
+            GeneralParameterDescriptor previous = union.put(name, valid);
             if (previous != null) {
                 if (previous instanceof ParameterDescriptor<?>) {
-                    verifyEquivalence(name, replacement instanceof ParameterDescriptor<?>);
+                    verifyEquivalence(name, valid instanceof ParameterDescriptor<?>);
                     final Class<?> valueClass = ((ParameterDescriptor<?>) previous).getValueClass();
                     if (valueClass != null) {
-                        final Class<?> r = ((ParameterDescriptor<?>) replacement).getValueClass();
+                        final Class<?> r = ((ParameterDescriptor<?>) valid).getValueClass();
                         if (r != null) {
                             /*
                              * Should never happen unless the same (according its name) ParameterValue
appears
-                             * more than once in the 'parameters' array, or unless this method
is invoked more
+                             * more than once in the 'valids' array, or unless this method
is invoked more
                              * often than expected.
                              */
                             verifyEquivalence(name, valueClass == r);
@@ -167,22 +172,23 @@ public final class CC_OperationParameter
                              * may depend on JAXB implementation, we are better to check
for such case.
                              * Restore the previous value in the map and swap 'previous'
with 'replacement'.
                              */
-                            previous = union.put(name, replacement = previous);
+                            previous = union.put(name, valid = previous);
                         }
                     }
                 } else if (previous instanceof ParameterDescriptorGroup) {
-                    verifyEquivalence(name, replacement instanceof ParameterDescriptorGroup);
+                    verifyEquivalence(name, valid instanceof ParameterDescriptorGroup);
                 }
                 /*
                  * Verify that the replacement contains at least all the information provided
by the previous
                  * descriptor. The replacement is allowed to contain more information however.
                  */
-                final GeneralParameterDescriptor r = CC_GeneralOperationParameter.replacement(previous,
replacement);
-                if (r != replacement) {
-                    union.put(name, r);
-
-                    // TODO: We should instead update DefaultParameterValue descriptor here.
-                    verifyEquivalence(name, false);
+                final GeneralParameterDescriptor replacement = CC_GeneralOperationParameter.replacement(previous,
valid);
+                if (replacement != valid) {
+                    union.put(name, replacement);
+                    if (replacements.put(valid, replacement) != null) {
+                        // Should never happen, unless the parameter name changed during
execution of this loop.
+                        throw new CorruptedObjectException(name);
+                    }
                 }
             }
         }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptorGroup.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptorGroup.java?rev=1700628&r1=1700627&r2=1700628&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptorGroup.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptorGroup.java
[UTF-8] Tue Sep  1 17:53:45 2015
@@ -31,6 +31,7 @@ import org.opengis.parameter.GeneralPara
 import org.opengis.parameter.ParameterNotFoundException;
 import org.opengis.parameter.InvalidParameterNameException;
 import org.apache.sis.internal.jaxb.referencing.CC_OperationParameterGroup;
+import org.apache.sis.internal.referencing.ReferencingUtilities;
 import org.apache.sis.referencing.IdentifiedObjects;
 import org.apache.sis.internal.util.UnmodifiableArrayList;
 import org.apache.sis.util.resources.Errors;
@@ -432,25 +433,39 @@ public class DefaultParameterDescriptorG
     }
 
     /**
-     * Invoked by JAXB or by {@link DefaultParameterValueGroup} for setting the unmarshalled
parameters.
-     * If parameters already exist, then this method computes the union of the two parameter
collections
-     * with the new parameters having precedence over the old ones.
+     * Invoked by JAXB for setting the unmarshalled parameter descriptors.
+     */
+    private void setDescriptors(final GeneralParameterDescriptor[] parameters) {
+        if (ReferencingUtilities.canSetProperty(DefaultParameterValue.class,
+                "setDescriptors", "parameter", !descriptors.isEmpty()))
+        {
+            verifyNames(null, parameters);
+            descriptors = asList(parameters);
+        }
+    }
+
+    /**
+     * Merges the given parameter descriptors with the descriptors currently in this group.
+     * The descriptors are set twice during {@link DefaultParameterValueGroup} unmarshalling:
      *
-     * <div class="note"><b>Rational:</b>
-     * this method is invoked twice during {@link DefaultParameterValueGroup} unmarshalling:
      * <ol>
-     *   <li>First, this method is invoked during unmarshalling of this {@code DefaultParameterDescriptorGroup}.
+     *   <li>First, the descriptors are set during unmarshalling of this {@code DefaultParameterDescriptorGroup}.
      *       But the value class of {@code ParameterDescriptor} components are unknown because
this information
      *       is not part of GML.</li>
      *   <li>Next, this method is invoked during unmarshalling of the {@code DefaultParameterValueGroup}
enclosing
      *       element with the descriptors found inside the {@code ParameterValue} components.
The later do have the
      *       {@code valueClass} information, so we want to use them in replacement of descriptors
of step 1.</li>
      * </ol>
-     * </div>
+     *
+     * @param fromValues Descriptors declared in the {@code ParameterValue} instances of
a {@code ParameterValueGroup}.
+     * @param replacements An {@code IdentityHashMap} where to store the replacements that
the caller needs
+     *                     to apply in the {@code GeneralParameterValue} instances.
      */
-    final void setDescriptors(GeneralParameterDescriptor[] parameters) {
-        parameters = CC_OperationParameterGroup.merge(descriptors, parameters);
-        verifyNames(null, parameters);
-        descriptors = asList(parameters);
+    final void merge(GeneralParameterDescriptor[] fromValues,
+            final Map<GeneralParameterDescriptor,GeneralParameterDescriptor> replacements)
+    {
+        fromValues = CC_OperationParameterGroup.merge(descriptors, fromValues, replacements);
+        verifyNames(null, fromValues);
+        descriptors = asList(fromValues);
     }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java?rev=1700628&r1=1700627&r2=1700628&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java
[UTF-8] Tue Sep  1 17:53:45 2015
@@ -1090,10 +1090,12 @@ public class DefaultParameterValue<T> ex
 
     /**
      * Invoked by JAXB at unmarshalling time.
+     * May also be invoked by {@link DefaultParameterValueGroup} if the descriptor as been
completed
+     * with additional information provided in the {@code <gml:group>} element of a
descriptor group.
      *
      * @see #getDescriptor()
      */
-    private void setDescriptor(final ParameterDescriptor<T> descriptor) {
+    final void setDescriptor(final ParameterDescriptor<T> descriptor) {
         this.descriptor = descriptor;
         assert (value == null) || descriptor.getValueClass().isInstance(value) : this;
     }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValueGroup.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValueGroup.java?rev=1700628&r1=1700627&r2=1700628&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValueGroup.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValueGroup.java
[UTF-8] Tue Sep  1 17:53:45 2015
@@ -18,7 +18,8 @@ package org.apache.sis.parameter;
 
 import java.util.List;
 import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.Map;
+import java.util.IdentityHashMap;
 import java.io.Serializable;
 import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.XmlElement;
@@ -522,19 +523,56 @@ public class DefaultParameterValueGroup
      * implementation, because the property type is an array (it would not work with a list).
      */
     private void setValues(final GeneralParameterValue[] parameters) {
-        final GeneralParameterDescriptor[] descriptors = new GeneralParameterDescriptor[parameters.length];
-        for (int i=0; i<descriptors.length; i++) {
-            descriptors[i] = parameters[i].getDescriptor();
+        final GeneralParameterDescriptor[] fromValues = new GeneralParameterDescriptor[parameters.length];
+        for (int i=0; i<parameters.length; i++) {
+            fromValues[i] = parameters[i].getDescriptor();
         }
-        if (values == null) {
+        ParameterValueList addTo = values;
+        if (addTo == null) {
             // Should never happen, unless the XML document is invalid and does not have
a 'group' element.
-            values = new ParameterValueList(new DefaultParameterDescriptorGroup());
+            addTo = new ParameterValueList(new DefaultParameterDescriptorGroup());
+        } else {
+            addTo.clear();  // Because references to parameter descriptors have changed.
         }
-        // We known that the descriptor is an instance of our DefaultParameterDescriptorGroup
-        // implementation because this is what we declare to the JAXBContext and in adapters.
-        ((DefaultParameterDescriptorGroup) values.descriptor).setDescriptors(descriptors);
-        values.clear();  // Because references to parameter descriptors have changed.
-        values.addAll(Arrays.asList(parameters));
+        /*
+         * Merge the descriptors declared in the <gml:group> element with the descriptors
given in each
+         * <gml:parameterValue> element. The implementation is known to be DefaultParameterDescriptorGroup
+         * because this is the type declared in the JAXBContext and in adapters.
+         */
+        final Map<GeneralParameterDescriptor,GeneralParameterDescriptor> replacements
= new IdentityHashMap<>(4);
+        ((DefaultParameterDescriptorGroup) addTo.descriptor).merge(fromValues, replacements);
+        addAll(parameters, replacements, addTo);
+    }
+
+    /**
+     * Appends all parameter values. In this process, we may need to update the descriptor
of some values
+     * if those descriptors changed as a result of the above merge process.
+     *
+     * @param parameters   The parameters to add, or {@code null} for {@link #values}.
+     * @param replacements The replacements to apply in the {@code GeneralParameterValue}
instances.
+     * @param addTo        Where to store the new values.
+     */
+    @SuppressWarnings({"unchecked", "AssignmentToCollectionOrArrayFieldFromParameter"})
+    private void addAll(GeneralParameterValue[] parameters,
+            final Map<GeneralParameterDescriptor,GeneralParameterDescriptor> replacements,
+            final ParameterValueList addTo)
+    {
+        if (parameters == null) {
+            parameters = values.toArray();
+        }
+        for (final GeneralParameterValue p : parameters) {
+            final GeneralParameterDescriptor replacement = replacements.get(p.getDescriptor());
+            if (replacement != null) {
+                if (p instanceof DefaultParameterValue<?>) {
+                    ((DefaultParameterValue<?>) p).setDescriptor((ParameterDescriptor)
replacement);
+                } else if (p instanceof DefaultParameterValueGroup) {
+                    ((DefaultParameterValueGroup) p).addAll(null, replacements,
+                            new ParameterValueList((ParameterDescriptorGroup) replacement));
+                }
+            }
+            addTo.add(p);
+        }
+        values = addTo;
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterValueList.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterValueList.java?rev=1700628&r1=1700627&r2=1700628&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterValueList.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterValueList.java
[UTF-8] Tue Sep  1 17:53:45 2015
@@ -310,6 +310,14 @@ final class ParameterValueList extends A
     }
 
     /**
+     * Returns the parameters in an array.
+     */
+    @Override
+    public GeneralParameterValue[] toArray() {
+        return Arrays.copyOf(values, size);
+    }
+
+    /**
      * Returns a string representation of this list.
      */
     @Override

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CC_GeneralOperationParameterTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CC_GeneralOperationParameterTest.java?rev=1700628&r1=1700627&r2=1700628&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CC_GeneralOperationParameterTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CC_GeneralOperationParameterTest.java
[UTF-8] Tue Sep  1 17:53:45 2015
@@ -23,9 +23,9 @@ import javax.xml.bind.JAXBException;
 import org.opengis.parameter.ParameterDescriptor;
 import org.opengis.parameter.ParameterDescriptorGroup;
 import org.opengis.parameter.GeneralParameterDescriptor;
-import org.apache.sis.internal.system.Loggers;
 import org.apache.sis.parameter.DefaultParameterDescriptor;
 import org.apache.sis.parameter.DefaultParameterDescriptorGroup;
+import org.apache.sis.internal.system.Loggers;
 import org.apache.sis.xml.Namespaces;
 import org.apache.sis.test.XMLTestCase;
 import org.apache.sis.test.DependsOn;

Added: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CC_OperationParameterGroupTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CC_OperationParameterGroupTest.java?rev=1700628&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CC_OperationParameterGroupTest.java
(added)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CC_OperationParameterGroupTest.java
[UTF-8] Tue Sep  1 17:53:45 2015
@@ -0,0 +1,128 @@
+/*
+ * 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 java.util.List;
+import java.util.Map;
+import java.util.IdentityHashMap;
+import javax.xml.bind.JAXBException;
+import javax.measure.unit.NonSI;
+import org.opengis.parameter.ParameterDescriptor;
+import org.opengis.parameter.ParameterDescriptorGroup;
+import org.opengis.parameter.GeneralParameterDescriptor;
+import org.apache.sis.parameter.DefaultParameterDescriptorGroup;
+import org.apache.sis.parameter.ParameterBuilder;
+import org.apache.sis.test.XMLTestCase;
+import org.apache.sis.test.DependsOn;
+import org.apache.sis.xml.Namespaces;
+import org.junit.Test;
+
+import static org.apache.sis.metadata.iso.citation.Citations.EPSG;
+import static org.junit.Assert.*;
+
+
+/**
+ * Tests {@link CC_GeneralOperationParameter} static methods.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.6
+ * @version 0.6
+ * @module
+ */
+@DependsOn(CC_GeneralOperationParameterTest.class)
+public final strictfp class CC_OperationParameterGroupTest extends XMLTestCase {
+    /**
+     * Creates a parameter descriptor group as unmarshalled by JAXB, without {@code valueClass}.
+     *
+     * @throws JAXBException if this method failed to create test data.
+     */
+    private DefaultParameterDescriptorGroup unmarshal() throws JAXBException {
+        return unmarshal(DefaultParameterDescriptorGroup.class,
+                "<gml:OperationParameterGroup xmlns:gml=\"" + Namespaces.GML + "\">\n"
+              + "  <gml:name>Mercator (1SP)</gml:name>\n"
+              + "  <gml:parameter>\n"
+              + "    <gml:OperationParameter gml:id=\"epsg-parameter-8801\">\n"
+              + "      <gml:identifier codeSpace=\"IOGP\">urn:ogc:def:parameter:EPSG::8801</gml:identifier>\n"
+              + "      <gml:name codeSpace=\"EPSG\">Latitude of natural origin</gml:name>\n"
+              + "    </gml:OperationParameter>\n"
+              + "  </gml:parameter>\n"
+              + "  <gml:parameter>\n"
+              + "    <gml:OperationParameter gml:id=\"epsg-parameter-8802\">\n"
+              + "      <gml:identifier codeSpace=\"IOGP\">urn:ogc:def:parameter:EPSG::8802</gml:identifier>\n"
+              + "      <gml:name codeSpace=\"EPSG\">Longitude of natural origin</gml:name>\n"
+              + "    </gml:OperationParameter>\n"
+              + "  </gml:parameter>\n"
+              //   There is more parameters in a Mercator projection, but 2 is enough for
this test.
+              + "</gml:OperationParameterGroup>");
+    }
+
+    /**
+     * Creates a parameter descriptor equivalent to the result of {@link #unmarshal()}
+     * but with arbitrary default values.
+     */
+    private static ParameterDescriptorGroup create() {
+        final ParameterBuilder builder = new ParameterBuilder();
+        builder.setCodeSpace(EPSG, "EPSG").setRequired(true);
+        ParameterDescriptor<?>[] parameters = {
+            builder.addIdentifier("8801").addName("Latitude of natural origin") .create(
40, NonSI.DEGREE_ANGLE),
+            builder.addIdentifier("8802").addName("Longitude of natural origin").create(-60,
NonSI.DEGREE_ANGLE),
+        };
+        builder.addName("Mercator (1SP)");
+        return builder.createGroup(parameters);
+    }
+
+    /**
+     * Tests the substitution of unmarshalled descriptors by more complete descriptors.
+     * No merging should be done in this test.
+     *
+     * @throws JAXBException if this method failed to create test data.
+     */
+    @Test
+    public void testSubtitution() throws JAXBException {
+        final ParameterDescriptorGroup provided = unmarshal();
+        final ParameterDescriptorGroup complete = create();
+
+        // Normal usage: merge to existing descriptors the more complete information found
in parameter values.
+        verifySubtitution(provided.descriptors(), complete.descriptors(), complete.descriptors());
+
+        // Unusual case, tested for safety: the existing descriptors were actually more complete.
+        verifySubtitution(complete.descriptors(), provided.descriptors(), complete.descriptors());
+    }
+
+    /**
+     * Implementation of {@link #testSubtitution()}.
+     *
+     * @param descriptors Simulates the descriptors already present in a {@code ParameterDescriptorGroup}.
+     * @param fromValues  Simulates the descriptors created from {@code ParameterValue} instances.
+     * @param expected    The expected descriptors.
+     */
+    private static void verifySubtitution(
+            final List<GeneralParameterDescriptor> descriptors,
+            final List<GeneralParameterDescriptor> fromValues,
+            final List<GeneralParameterDescriptor> expected)
+    {
+        final Map<GeneralParameterDescriptor,GeneralParameterDescriptor> replacements
= new IdentityHashMap<>(4);
+        final GeneralParameterDescriptor[] merged = CC_OperationParameterGroup.merge(descriptors,
+                fromValues.toArray(new GeneralParameterDescriptor[fromValues.size()]), replacements);
+
+        assertTrue("Expected no replacement.", replacements.isEmpty());
+        assertEquals("Number of parameters", 2, merged.length);
+        for (int i=0; i<merged.length; i++) {
+            assertSame(expected.get(i), merged[i]);
+        }
+    }
+}

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

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

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=1700628&r1=1700627&r2=1700628&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] Tue Sep  1 17:53:45 2015
@@ -59,7 +59,7 @@ public final strictfp class OperationMar
             builder.addIdentifier("8802").addName("Longitude of natural origin").create(0,
NonSI.DEGREE_ANGLE)
             // There is more parameters for a Mercator projection, but 2 is enough for this
test.
         };
-        builder.addName(null, "Mercator");
+        builder.addName(null, "Mercator (1SP)");
         final ParameterDescriptorGroup descriptor = builder.createGroup(parameters);
         final Map<String,Object> properties = new HashMap<>(4);
         properties.put(DefaultOperationMethod.NAME_KEY, descriptor.getName());
@@ -76,7 +76,7 @@ public final strictfp class OperationMar
     public void testOperationMethod() throws JAXBException {
         final String xml = XML.marshal(createMercatorMethod());
         assertXmlEquals("<gml:OperationMethod xmlns:gml=\"" + Namespaces.GML + "\">\n"
-                      + "  <gml:name>Mercator</gml:name>\n"
+                      + "  <gml:name>Mercator (1SP)</gml:name>\n"
                       + "  <gml:formula>See EPSG guide.</gml:formula>\n"
                       + "  <gml:sourceDimensions>2</gml:sourceDimensions>\n"
                       + "  <gml:targetDimensions>2</gml:targetDimensions>\n"
@@ -101,12 +101,12 @@ public final strictfp class OperationMar
      * Verifies the unmarshalled parameter descriptors.
      */
     private static void verifyMethod(final DefaultOperationMethod method) {
-        assertIdentifierEquals("name", null, null, null, "Mercator", method.getName());
+        assertIdentifierEquals("name", null, null, null, "Mercator (1SP)", method.getName());
         assertEquals("formula", "See EPSG guide.", method.getFormula().getFormula().toString());
         assertEquals("sourceDimensions", Integer.valueOf(2), method.getSourceDimensions());
         assertEquals("targetDimensions", Integer.valueOf(2), method.getTargetDimensions());
         final ParameterDescriptorGroup parameters = method.getParameters();
-        assertEquals("parameters.name", "Mercator", parameters.getName().getCode());
+        assertEquals("parameters.name", "Mercator (1SP)", parameters.getName().getCode());
         final Iterator<GeneralParameterDescriptor> it = parameters.descriptors().iterator();
         verifyIncompleteDescriptor("Latitude of natural origin",  it.next());
         verifyIncompleteDescriptor("Longitude of natural origin", it.next());

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java?rev=1700628&r1=1700627&r2=1700628&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] Tue Sep  1 17:53:45 2015
@@ -72,6 +72,7 @@ import org.junit.BeforeClass;
     org.apache.sis.parameter.MapProjectionParametersTest.class,
     org.apache.sis.parameter.ParameterMarshallingTest.class,
     org.apache.sis.internal.jaxb.referencing.CC_GeneralOperationParameterTest.class,
+    org.apache.sis.internal.jaxb.referencing.CC_OperationParameterGroupTest.class,
 
     // Test transforms other than map projections.
     org.apache.sis.referencing.operation.transform.CoordinateDomainTest.class,

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/CorruptedObjectException.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/CorruptedObjectException.java?rev=1700628&r1=1700627&r2=1700628&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/CorruptedObjectException.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/CorruptedObjectException.java
[UTF-8] Tue Sep  1 17:53:45 2015
@@ -16,6 +16,8 @@
  */
 package org.apache.sis.util;
 
+import org.opengis.referencing.IdentifiedObject;
+
 
 /**
  * May be thrown on attempt to use an object which has been corrupted by a previous operation.
@@ -57,7 +59,7 @@ package org.apache.sis.util;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.5
- * @version 0.5
+ * @version 0.6
  * @module
  */
 public class CorruptedObjectException extends RuntimeException {
@@ -81,4 +83,15 @@ public class CorruptedObjectException ex
     public CorruptedObjectException(final String message) {
         super(message);
     }
+
+    /**
+     * Constructs a new exception with the name of the given object.
+     *
+     * @param object The corrupted object, or {@code null} if unknown.
+     *
+     * @since 0.6
+     */
+    public CorruptedObjectException(final IdentifiedObject object) {
+        super(object != null ? String.valueOf(object.getName()) : null);
+    }
 }



Mime
View raw message