sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1731491 - in /sis/branches/JDK8/core: sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/ sis-referencing/src/main/java/org/apache/sis/parameter/ sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/...
Date Sat, 20 Feb 2016 22:31:20 GMT
Author: desruisseaux
Date: Sat Feb 20 22:31:20 2016
New Revision: 1731491

URL: http://svn.apache.org/viewvc?rev=1731491&view=rev
Log:
Temporarily suspend parameter verifications in some circumstances:
 - When it is too late for verifying parameter validity and we are supposed to just record
whatever value they have.
 - When creating a projected CRS which has been deprecated precisely because of invalid parameter,
but may still be in usage.

Added:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameter.java
  (with props)
Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Equirectangular.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/MapProjection.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/Verifier.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/Initializer.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameters.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/CoordinateReferenceSystems.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/Semaphores.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/UnmodifiableArrayList.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Equirectangular.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Equirectangular.java?rev=1731491&r1=1731490&r2=1731491&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Equirectangular.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Equirectangular.java
[UTF-8] Sat Feb 20 22:31:20 2016
@@ -224,6 +224,8 @@ public final class Equirectangular exten
 
     /**
      * Gets a parameter value identified by the given descriptor and stores it only if different
than zero.
+     * This method performs the same work than {@code Initializer.getAndStore(ParameterDescriptor)}
in the
+     * {@link org.apache.sis.referencing.operation.projection} package.
      *
      * @param  source     The parameters from which to read the value.
      * @param  target     Where to store the parameter values.
@@ -235,7 +237,7 @@ public final class Equirectangular exten
             final ParameterDescriptor<Double> descriptor) throws IllegalArgumentException
     {
         final double value = source.doubleValue(descriptor);    // Apply a unit conversion
if needed.
-        MapProjection.validate(descriptor, value);              // Unconditional validation
for semi-axes.
+        MapProjection.validate(descriptor, value);              // Unconditional validation
for all parameters.
         if (value != 0) {                                       // All default values in
this class are zero.
             target.parameter(descriptor.getName().getCode()).setValue(value);
         }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/MapProjection.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/MapProjection.java?rev=1731491&r1=1731490&r2=1731491&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/MapProjection.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/MapProjection.java
[UTF-8] Sat Feb 20 22:31:20 2016
@@ -21,6 +21,7 @@ import java.util.HashMap;
 import java.util.NoSuchElementException;
 import javax.xml.bind.annotation.XmlTransient;
 import javax.measure.unit.SI;
+import javax.measure.unit.Unit;
 import org.opengis.util.FactoryException;
 import org.opengis.util.InternationalString;
 import org.opengis.metadata.Identifier;
@@ -142,7 +143,11 @@ public abstract class MapProjection exte
     }
 
     /**
-     * Validates the given parameter value.
+     * Validates the given parameter value. This method duplicates the verification already
+     * done by {@link org.apache.sis.parameter.DefaultParameterValue#setValue(Object, Unit)}.
+     * But we check again because we have no guarantee that the parameters given by the user
+     * were instances of {@code DefaultParameterValue}, or that the descriptor associated
to
+     * the user-specified {@code ParameterValue} has sufficient information.
      *
      * @param  descriptor The descriptor that specify the parameter to validate.
      * @param  value The parameter value in the units given by the descriptor.

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=1731491&r1=1731490&r2=1731491&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] Sat Feb 20 22:31:20 2016
@@ -120,7 +120,7 @@ import java.nio.file.Path;
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.4
- * @version 0.6
+ * @version 0.7
  * @module
  *
  * @see DefaultParameterDescriptor
@@ -152,16 +152,20 @@ public class DefaultParameterValue<T> ex
     /**
      * The value, or {@code null} if undefined.
      * Except for the constructors, the {@link #equals(Object)} and the {@link #hashCode()}
methods,
-     * this field shall be read only by {@link #getValue()} and written by {@link #setValue(Object,
Unit)}.
+     * this field should be read only by {@link #getValue()} and written only by {@link #setValue(Object,
Unit)}.
+     *
+     * @since 0.7
      */
-    private T value;
+    protected T value;
 
     /**
      * The unit of measure for the value, or {@code null} if it does not apply.
      * Except for the constructors, the {@link #equals(Object)} and the {@link #hashCode()}
methods,
-     * this field shall be read only by {@link #getUnit()} and written by {@link #setValue(Object,
Unit)}.
+     * this field should be read only by {@link #getUnit()} and written only by {@link #setValue(Object,
Unit)}.
+     *
+     * @since 0.7
      */
-    private Unit<?> unit;
+    protected Unit<?> unit;
 
     /**
      * Creates a parameter value from the specified descriptor.
@@ -724,17 +728,19 @@ public class DefaultParameterValue<T> ex
      * @param  unit  The unit associated to the new parameter value, or {@code null}.
      * @throws InvalidParameterValueException if the type of {@code value} is inappropriate
for this parameter,
      *         or if the value is illegal for some other reason (for example the value is
numeric and out of range).
+     *
+     * @see #validate(Object)
      */
     @SuppressWarnings("unchecked")
     protected void setValue(final Object value, final Unit<?> unit) throws InvalidParameterValueException
{
         final T convertedValue = Verifier.ensureValidValue(descriptor, value, unit);
         if (value != null) {
             validate(convertedValue);
-            this.value = (T) value; // Type has been verified by Verifier.ensureValidValue(…).
+            this.value = (T) value;                 // Type has been verified by Verifier.ensureValidValue(…).
         } else {
             this.value = descriptor.getDefaultValue();
         }
-        this.unit = unit; // Assign only on success.
+        this.unit = unit;                           // Assign only on success.
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/Verifier.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/Verifier.java?rev=1731491&r1=1731490&r2=1731491&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/Verifier.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/Verifier.java
[UTF-8] Sat Feb 20 22:31:20 2016
@@ -18,6 +18,8 @@ package org.apache.sis.parameter;
 
 import java.util.Map;
 import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
 import java.lang.reflect.Array;
 import javax.measure.unit.Unit;
 import javax.measure.converter.UnitConverter;
@@ -27,9 +29,12 @@ import org.opengis.parameter.ParameterDe
 import org.opengis.parameter.GeneralParameterDescriptor;
 import org.opengis.parameter.InvalidParameterValueException;
 import org.apache.sis.internal.referencing.EPSGParameterDomain;
+import org.apache.sis.internal.system.Semaphores;
+import org.apache.sis.internal.system.Loggers;
 import org.apache.sis.measure.Range;
 import org.apache.sis.measure.Units;
 import org.apache.sis.util.Numbers;
+import org.apache.sis.util.logging.Logging;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.resources.Vocabulary;
 
@@ -180,7 +185,7 @@ final class Verifier {
         }
         /*
          * At this point the user's value has been fully converted to the unit of measurement
specified
-         * by the ParameterDescriptor. Now compares the converted value to the restricting
given by the
+         * by the ParameterDescriptor.  Now compare the converted value to the restriction
given by the
          * descriptor (set of valid values and range of value domain).
          */
         if (convertedValue != null) {
@@ -193,10 +198,23 @@ final class Verifier {
                 error = ensureValidValue(valueClass, validValues,
                         descriptor.getMinimumValue(), descriptor.getMaximumValue(), convertedValue);
             }
+            /*
+             * If we found an error, we will usually throw an exception. An exception to
this rule is
+             * when EPSGDataAccess is creating a deprecated ProjectedCRS in which some parameters
are
+             * known to be invalid (the CRS was deprecated precisely for that reason). In
such cases,
+             * we will log a warning instead than throwing an exception.
+             */
             if (error != null) {
                 error.convertRange(converter);
                 final String name = getDisplayName(descriptor);
-                throw new InvalidParameterValueException(error.message(null, name, value),
name, value);
+                final String message = error.message(null, name, value);
+                if (!Semaphores.query(Semaphores.SUSPEND_PARAMETER_CHECK)) {
+                    throw new InvalidParameterValueException(message, name, value);
+                } else {
+                    final LogRecord record = new LogRecord(Level.WARNING, message);
+                    record.setLoggerName(Loggers.COORDINATE_OPERATION);
+                    Logging.log(DefaultParameterValue.class, "setValue", record);
+                }
             }
         }
         return valueClass.cast(convertedValue);

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java?rev=1731491&r1=1731490&r2=1731491&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
[UTF-8] Sat Feb 20 22:31:20 2016
@@ -74,6 +74,7 @@ import org.apache.sis.internal.referenci
 import org.apache.sis.internal.referencing.EPSGParameterDomain;
 import org.apache.sis.internal.referencing.Formulas;
 import org.apache.sis.internal.system.Loggers;
+import org.apache.sis.internal.system.Semaphores;
 import org.apache.sis.internal.util.Constants;
 import org.apache.sis.internal.util.CollectionsExt;
 import org.apache.sis.metadata.iso.ImmutableIdentifier;
@@ -1368,23 +1369,65 @@ addURIs:    for (int i=0; ; i++) {
                         ensureNoCycle(ProjectedCRS.class, epsg);
                         try {
                             final CartesianCS cs = owner.createCartesianCS(csCode);
-                            final GeographicCRS baseCRS;
-                            if (deprecated) try {
-                                quiet = true;
-                                replaceDeprecatedCS = true;
-                                baseCRS = createGeographicCRS(geoCode);                 //
Do not cache that CRS.
-                            } finally {
-                                quiet = false;
-                                replaceDeprecatedCS = false;
-                            } else {
-                                baseCRS = owner.createGeographicCRS(geoCode);
+                            final Conversion op;
+                            try {
+                                op = (Conversion) owner.createCoordinateOperation(opCode);
+                            } catch (ClassCastException e) {
+                                // Should never happen in a well-formed EPSG database.
+                                // If happen anyway, the ClassCastException cause will give
more hints than just the message.
+                                throw (NoSuchAuthorityCodeException) noSuchAuthorityCode(Projection.class,
opCode).initCause(e);
                             }
-                            final CoordinateOperation op = owner.createCoordinateOperation(opCode);
-                            if (op instanceof Conversion) {
-                                crs = crsFactory.createProjectedCRS(createProperties("Coordinate
Reference System",
-                                        name, epsg, area, scope, remarks, deprecated), baseCRS,
(Conversion) op, cs);
+                            final CoordinateReferenceSystem baseCRS;
+                            final boolean resumeParamChecks;
+                            if (!deprecated) {
+                                baseCRS = owner.createCoordinateReferenceSystem(geoCode);
+                                resumeParamChecks = false;
                             } else {
-                                throw noSuchAuthorityCode(Projection.class, opCode);
+                                /*
+                                 * If the ProjectedCRS is deprecated, one reason among others
may be that it uses one of
+                                 * the deprecated coordinate systems. Those deprecated CS
used non-linear units like DMS.
+                                 * Apache SIS can not instantiate a ProjectedCRS when the
baseCRS uses such units, so we
+                                 * set a flag asking to replace the deprecated CS by a supported
one. Since that baseCRS
+                                 * would not be exactly as defined by EPSG, we must not cache
it because we do not want
+                                 * 'owner.createGeographicCRS(geoCode)' to return that modified
CRS. Since the same CRS
+                                 * may be recreated every time a deprecated ProjectedCRS
is created, we temporarily
+                                 * shutdown the loggings in order to avoid the same warning
to be logged many time.
+                                 */
+                                try {
+                                    quiet = true;
+                                    replaceDeprecatedCS = true;
+                                    baseCRS = createCoordinateReferenceSystem(geoCode); 
       // Do not cache that CRS.
+                                } finally {
+                                    replaceDeprecatedCS = false;
+                                    quiet = false;
+                                }
+                                /*
+                                 * The crsFactory method calls will indirectly create a parameterized
MathTransform.
+                                 * Their constructor will try to verify the parameter validity.
But some deprecated
+                                 * CRS had invalid parameter values (they were deprecated
precisely for that reason).
+                                 * If and only if we are creating a deprecated CRS, temporarily
suspend the parameter
+                                 * checks.
+                                 */
+                                resumeParamChecks = !Semaphores.queryAndSet(Semaphores.SUSPEND_PARAMETER_CHECK);
+                                // Try block must be immediately after above line (do not
insert any code between).
+                            }
+                            try {
+                                /*
+                                 * For a ProjectedCRS, the baseCRS is always geographic.
So in theory we would not
+                                 * need the 'instanceof' check. However the EPSG dataset
version 8.9 also uses the
+                                 * "projected" type for CRS that are actually derived CRS.
See EPSG:5820 and 5821.
+                                 */
+                                final Map<String, Object> properties = createProperties("Coordinate
Reference System",
+                                                                        name, epsg, area,
scope, remarks, deprecated);
+                                if (baseCRS instanceof GeographicCRS) {
+                                    crs = crsFactory.createProjectedCRS(properties, (GeographicCRS)
baseCRS, op, cs);
+                                } else {
+                                    crs = crsFactory.createDerivedCRS(properties, baseCRS,
op, cs);
+                                }
+                            } finally {
+                                if (resumeParamChecks) {
+                                    Semaphores.clear(Semaphores.SUSPEND_PARAMETER_CHECK);
+                                }
                             }
                         } finally {
                             endOfRecursivity(ProjectedCRS.class, epsg);
@@ -2500,14 +2543,14 @@ next:               while (r.next()) {
                     param = parameters.parameter(name);
                 } catch (ParameterNotFoundException exception) {
                     /*
-                     * Wraps the unchecked ParameterNotFoundException into the checked NoSuchIdentifierException,
+                     * Wrap the unchecked ParameterNotFoundException into the checked NoSuchIdentifierException,
                      * which is a FactoryException subclass.  Note that in principle, NoSuchIdentifierException
is for
                      * MathTransforms rather than parameters. However we are close in spirit
here since we are setting
                      * up MathTransform's parameters. Using NoSuchIdentifierException allows
CoordinateOperationSet to
-                     * know that the failure is probably caused by a MathTransform not yet
supported in Apache SIS (or
-                     * only partially supported) rather than some more serious failure in
the database side. Callers
-                     * can use this information in order to determine if they should try
the next coordinate operation
-                     * or propagate the exception.
+                     * know that the failure is probably caused by a MathTransform not yet
supported in Apache SIS
+                     * (or only partially supported) rather than some more serious failure
in the database side.
+                     * Callers can use this information in order to determine if they should
try the next coordinate
+                     * operation or propagate the exception.
                      */
                     final NoSuchIdentifierException e = new NoSuchIdentifierException(error()
                             .getString(Errors.Keys.CanNotSetParameterValue_1, name), name);

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/Initializer.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/Initializer.java?rev=1731491&r1=1731490&r2=1731491&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/Initializer.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/Initializer.java
[UTF-8] Sat Feb 20 22:31:20 2016
@@ -227,21 +227,27 @@ final class Initializer {
      */
     final double getAndStore(final ParameterDescriptor<? extends Number> descriptor)
{
         if (descriptor == null) {
-            return 0;   // Default value for all parameters except scale factor.
+            return 0;                           // Default value for all parameters except
scale factor.
         }
+        /*
+         * Get the parameter value, or its default value if the parameter was not set. That
default value
+         * (which is specified by the descriptor of the user-supplied parameters) is not
necessarily the
+         * same than the default value of the map projection implementation (which is specified
by the
+         * descriptor given in argument to this method).
+         */
         final double value = parameters.doubleValue(descriptor);    // Apply a unit conversion
if needed.
         final Number defaultValue = descriptor.getDefaultValue();
         if (defaultValue == null || !defaultValue.equals(value)) {
             MapProjection.validate(descriptor, value);
-            context.getOrCreate(descriptor).setValue(value);
+            context.parameter(descriptor.getName().getCode()).setValue(value);
         }
         return value;
     }
 
     /**
-     * Same as {@link #getAndStore(Parameters, ParameterDescriptor)}, but returns the given
default value
-     * if the parameter is not specified.  This method shall be used only for parameters
having a default
-     * value more complex than what we can represent in {@link ParameterDescriptor#getDefaultValue()}.
+     * Same as {@link #getAndStore(ParameterDescriptor)}, but returns the given default value
if the parameter
+     * is not specified.  This method shall be used only for parameters having a default
value more complex than
+     * what we can represent in {@link ParameterDescriptor#getDefaultValue()}.
      */
     final double getAndStore(final ParameterDescriptor<Double> descriptor, final double
defaultValue) {
         final Double value = parameters.getValue(descriptor);   // Apply a unit conversion
if needed.

Added: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameter.java?rev=1731491&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameter.java
(added)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameter.java
[UTF-8] Sat Feb 20 22:31:20 2016
@@ -0,0 +1,84 @@
+/*
+ * 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.referencing.operation.transform;
+
+import javax.measure.unit.Unit;
+import org.opengis.parameter.ParameterDescriptor;
+import org.apache.sis.parameter.DefaultParameterValue;
+
+
+/**
+ * A parameter value stored in {@link ContextualParameters} before they are made {@linkplain
#unmodifiable unmodifiable}.
+ * This temporary {@code ParameterValue} bypasses the validity check normally performed by
{@link DefaultParameterValue}.
+ *
+ * <div class="note"><b>Rational:</b>
+ * The intend is to skip the parameter value verification done by {@link DefaultParameterValue#setValue(Object,
Unit)}
+ * on the assumption that the value has already been verified when the user created his {@code
ParameterValueGroup}.
+ * Even if the user's {@code ParameterValue} implementation did not performed any verification,
there is chances that
+ * {@link DefaultMathTransformFactory} {@linkplain org.apache.sis.parameter.Parameters#copy
copied} the parameters in
+ * instances of the {@link org.apache.sis.parameter} package that do the checks.
+ *
+ * <p>Skipping redundant verifications allows us to avoid redundant logging messages
when
+ * the {@link org.apache.sis.internal.system.Semaphores#SUSPEND_PARAMETER_CHECK} flag is
set.
+ * Furthermore it is a little bit late for checking parameter validity here; that verification
should have been done
+ * at {@link MathTransform} construction time or even before, and the job of the {@link ContextualParameters}
class
+ * is just to record what have been used.</p></div>
+ *
+ * Note that the {@link ContextualParameters#freeze()} method will replace all {@code ParameterValue}
instances by
+ * {@code UnmodifiableParameterValue} instances anyway. So no matter which temporary instance
we used, we will end
+ * with the same objects in memory anyway.
+ *
+ * @param <T> The type of the value stored in this parameter.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.7
+ * @version 0.7
+ * @module
+ */
+final class ContextualParameter<T> extends DefaultParameterValue<T> {
+    /**
+     * For cross-version compatibility.
+     */
+    private static final long serialVersionUID = -2886149929114558478L;
+
+    /**
+     * Creates a parameter value from the specified descriptor.
+     * The value will be initialized to the default value, if any.
+     *
+     * @param descriptor The abstract definition of this parameter.
+     */
+    ContextualParameter(final ParameterDescriptor<T> descriptor) {
+        super(descriptor);
+    }
+
+    /**
+     * Sets the parameter value and its associated unit without any verification of parameter
validity
+     * (except value type).
+     *
+     * @param  value The parameter value, or {@code null} to restore the default.
+     * @param  unit  The unit associated to the new parameter value, or {@code null}.
+     */
+    @Override
+    protected void setValue(final Object value, final Unit<?> unit) {
+        if (value != null) {
+            this.value = getDescriptor().getValueClass().cast(value);
+        } else {
+            this.value = getDescriptor().getDefaultValue();
+        }
+        this.unit = unit;
+    }
+}

Propchange: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameter.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameters.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameters.java?rev=1731491&r1=1731490&r2=1731491&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameters.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameters.java
[UTF-8] Sat Feb 20 22:31:20 2016
@@ -603,19 +603,18 @@ public class ContextualParameters extend
             throw parameterNotFound(name);
         }
         /*
-         * Search for existing parameter instance. This implementation does not scale,
-         * but should be okay since the amount of parameters is typically very small
-         * (rarely more than 6 parameters in map projections).
+         * Search for existing parameter instance. This implementation does not scale, but
should be okay since
+         * the amount of parameters is typically very small (rarely more than 6 parameters
in map projections).
          */
         for (int i=0; i < values.length; i++) {
             ParameterValue<?> p = values[i];
             if (p == null) {
-                p = ((ParameterDescriptor<?>) desc).createValue();
-                values[i] = p;
-            } else if (p.getDescriptor() != desc) {  // Identity comparison should be okay
here.
-                continue;
+                values[i] = p = new ContextualParameter<>((ParameterDescriptor<?>)
desc);
+                return p;
+            }
+            if (p.getDescriptor() == desc) {                    // Identity comparison should
be okay here.
+                return p;
             }
-            return p;   // Found or created a parameter.
         }
         /*
          * We may reach this point if map projection construction is completed (i.e. 'completeTransform(…)'
has

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=1731491&r1=1731490&r2=1731491&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] Sat Feb 20 22:31:20 2016
@@ -36,6 +36,8 @@ import org.opengis.parameter.ParameterVa
 import org.opengis.parameter.ParameterValueGroup;
 import org.opengis.parameter.ParameterDescriptorGroup;
 import org.opengis.parameter.ParameterNotFoundException;
+import org.opengis.parameter.InvalidParameterNameException;
+import org.opengis.parameter.InvalidParameterValueException;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.opengis.referencing.cs.CoordinateSystem;
 import org.opengis.referencing.cs.EllipsoidalCS;
@@ -624,11 +626,17 @@ public class DefaultMathTransformFactory
          * The intend is to make sure that we have room for the parameters that {@code setEllipsoids(…)}
          * may write.
          *
+         * <p>A side effect of this method is that the copy operation may perform a
check of
+         * parameter value validity. This may result in an {@link InvalidParameterNameException}
+         * or {@link InvalidParameterValueException} to be thrown.</p>
+         *
          * @param writable {@code true} if this method should also check that the parameters
group is not
          *        an instance of {@link UnmodifiableParameterValueGroup}. Current implementation
assumes
          *        that modifiable parameters are instances of {@link DefaultParameterValueGroup}.
+         * @throws IllegalArgumentException if the copy can not be performed because a parameter
has
+         *         a unrecognized name or an illegal value.
          */
-        private void ensureCompatibleParameters(final boolean writable) {
+        private void ensureCompatibleParameters(final boolean writable) throws IllegalArgumentException
{
             final ParameterDescriptorGroup expected = provider.getParameters();
             if (parameters.getDescriptor() != expected ||
                     (writable &&  (parameters instanceof Parameters)
@@ -781,8 +789,10 @@ public class DefaultMathTransformFactory
          * @return The exception if the operation failed, or {@code null} if none. This exception
is not thrown now
          *         because the caller may succeed in creating the transform anyway, or otherwise
may produce a more
          *         informative exception.
+         * @throws IllegalArgumentException if the operation fails because a parameter has
a unrecognized name or an
+         *         illegal value.
          */
-        final RuntimeException setEllipsoids(final OperationMethod method) {
+        final RuntimeException setEllipsoids(final OperationMethod method) throws IllegalArgumentException
{
             ensureCompatibleParameters(false);
             int n;
             if (method instanceof AbstractProvider) {
@@ -905,21 +915,21 @@ public class DefaultMathTransformFactory
                         Errors.Keys.UnsupportedImplementation_1, Classes.getClass(method)),
methodName);
             }
             /*
-             * If the user's parameters do not contain semi-major and semi-minor axis lengths,
infer
-             * them from the ellipsoid. We have to do that because those parameters are often
omitted,
-             * since the standard place where to provide this information is in the ellipsoid
object.
-             */
-            if (context != null) {
-                context.provider   = method;
-                context.parameters = parameters;
-                failure = context.setEllipsoids(method);
-                parameters = context.parameters;
-            }
-            /*
-             * Catch only exceptions which may be the result of improper parameter usage
(e.g. a value out of range).
-             * Do not catch exception caused by programming errors (e.g. null pointer exception).
+             * Will catch only exceptions that may be the result of improper parameter usage
(e.g. a value out
+             * of range). Do not catch exceptions caused by programming errors (e.g. null
pointer exception).
              */
             try {
+                /*
+                 * If the user's parameters do not contain semi-major and semi-minor axis
lengths, infer
+                 * them from the ellipsoid. We have to do that because those parameters are
often omitted,
+                 * since the standard place where to provide this information is in the ellipsoid
object.
+                 */
+                if (context != null) {
+                    context.provider   = method;
+                    context.parameters = parameters;
+                    failure = context.setEllipsoids(method);
+                    parameters = context.parameters;
+                }
                 transform = ((MathTransformProvider) method).createMathTransform(this, parameters);
             } catch (IllegalArgumentException | IllegalStateException exception) {
                 throw new InvalidGeodeticParameterException(exception.getLocalizedMessage(),
exception);

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/CoordinateReferenceSystems.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/CoordinateReferenceSystems.java?rev=1731491&r1=1731490&r2=1731491&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/CoordinateReferenceSystems.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/CoordinateReferenceSystems.java
[UTF-8] Sat Feb 20 22:31:20 2016
@@ -285,7 +285,6 @@ public final strictfp class CoordinateRe
         rd("Nivellement General du Luxembourg",                           "Nivellement Général
Corse / France / Nouvelle-Calédonie / Polynésie Française / Luxembourd / Guyanais");
         rd("Nivellement General Guyanais 1977",                           "Nivellement Général
Corse / France / Nouvelle-Calédonie / Polynésie Française / Luxembourd / Guyanais");
         rd("NGO 1948 (Oslo)",                                             "NGO 1948");
-        rd("NAD27 Michigan",                                              "North American
Datum 1927 — Michigan");
         rd("NAD83 (High Accuracy Reference Network)",                     "North American
Datum 1983 — High Accuracy Reference Network");
         rd("NAD83 (National Spatial Reference System 2007)",              "North American
Datum 1983 — National Spatial Reference System 2007");
         rd("NAD83 Canadian Spatial Reference System",                     "North American
Datum 1983 — Canadian Spatial Reference System");

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/Semaphores.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/Semaphores.java?rev=1731491&r1=1731490&r2=1731491&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/Semaphores.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/Semaphores.java
[UTF-8] Sat Feb 20 22:31:20 2016
@@ -24,7 +24,7 @@ package org.apache.sis.internal.system;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.5
- * @version 0.6
+ * @version 0.7
  * @module
  */
 public final class Semaphores {
@@ -53,6 +53,16 @@ public final class Semaphores {
     public static final byte NULL_COLLECTION = 4;
 
     /**
+     * A flag to indicate that a parameter value outside its domain of validity should not
cause an exception
+     * to be thrown. This flag is set only when creating a deprecated operation from the
EPSG database.
+     * Typically the operation is deprecated precisely because it used invalid parameter
values,
+     * but SIS should still be able to create those deprecated objects if a user request
them.
+     *
+     * <p><b>Example:</b> EPSG:3752 was a Mercator (variant A) projection
but set the latitude of origin to 41°S.</p>
+     */
+    public static final byte SUSPEND_PARAMETER_CHECK = 8;
+
+    /**
      * The flags per running thread.
      */
     private static final ThreadLocal<Semaphores> FLAGS = new ThreadLocal<>();

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/UnmodifiableArrayList.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/UnmodifiableArrayList.java?rev=1731491&r1=1731490&r2=1731491&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/UnmodifiableArrayList.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/UnmodifiableArrayList.java
[UTF-8] Sat Feb 20 22:31:20 2016
@@ -91,7 +91,7 @@ public class UnmodifiableArrayList<E> ex
      *
      * @param array The array to wrap.
      */
-    protected UnmodifiableArrayList(final E[] array) { // NOT "E..." - see javadoc.
+    protected UnmodifiableArrayList(final E[] array) {                          // NOT "E..."
- see javadoc.
         this.array = Objects.requireNonNull(array);
     }
 
@@ -115,7 +115,7 @@ public class UnmodifiableArrayList<E> ex
      * @return The given array wrapped in an unmodifiable list, or {@code null} if the given
      *         array was null.
      */
-    public static <E> UnmodifiableArrayList<E> wrap(final E[] array) { // NOT
"E..." - see javadoc.
+    public static <E> UnmodifiableArrayList<E> wrap(final E[] array) {      
   // NOT "E..." - see javadoc.
         return (array != null) ? new UnmodifiableArrayList<>(array) : null;
     }
 




Mime
View raw message