You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2014/10/31 08:31:14 UTC
svn commit: r1635709 - in /sis/branches/JDK8/core:
sis-metadata/src/main/java/org/apache/sis/internal/metadata/
sis-metadata/src/main/java/org/apache/sis/metadata/iso/
sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/
sis-metadata/src...
Author: desruisseaux
Date: Fri Oct 31 07:31:13 2014
New Revision: 1635709
URL: http://svn.apache.org/r1635709
Log:
Consolidation of checks for property values in metadata objects.
Modified:
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/MetadataUtilities.java
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingUtilities.java
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultExtendedElementInformation.java
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultEnvironmentalRecord.java
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultBand.java
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultFeatureTypeInfo.java
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultImageDescription.java
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultSampleDimension.java
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultDigitalTransferOptions.java
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultMedium.java
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultRepresentativeFraction.java
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultResolution.java
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultNominalResolution.java
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultDimension.java
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGeometricObjects.java
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGridSpatialRepresentation.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SecondDefiningParameter.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/AbstractDatum.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultTemporalDatum.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultVerticalDatum.java
Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/MetadataUtilities.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/MetadataUtilities.java?rev=1635709&r1=1635708&r2=1635709&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/MetadataUtilities.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/MetadataUtilities.java [UTF-8] Fri Oct 31 07:31:13 2014
@@ -20,8 +20,10 @@ import java.util.Date;
import org.apache.sis.xml.NilReason;
import org.apache.sis.util.Static;
import org.apache.sis.util.resources.Errors;
+import org.apache.sis.metadata.iso.ISOMetadata;
import org.apache.sis.metadata.InvalidMetadataException;
import org.apache.sis.internal.jaxb.PrimitiveTypeProperties;
+import org.apache.sis.internal.jaxb.Context;
/**
@@ -83,28 +85,65 @@ public final class MetadataUtilities ext
}
/**
- * Ensures that the given argument value is {@code false}. This method is invoked by private setter methods,
- * which are themselves invoked by JAXB at unmarshalling time. Invoking this method from those setter methods
- * serves two purposes:
- *
- * <ul>
- * <li>Make sure that a singleton property is not defined twice in the XML document.</li>
- * <li>Protect ourselves against changes in immutable objects outside unmarshalling. It should
- * not be necessary since the setter methods shall not be public, but we are paranoiac.</li>
- * <li>Be a central point where we can trace all setter methods, in case we want to improve
- * warning or error messages in future SIS versions.</li>
- * </ul>
- *
- * @param name The property name, used only in case of error message to format.
- * @param isDefined Whether the property in the caller object is current defined.
- * @return {@code true} if the caller can set the property.
- * @throws IllegalStateException If {@code isDefined} is {@code true}.
- */
- public static boolean canSetProperty(final String name, final boolean isDefined) throws IllegalStateException {
- if (isDefined) {
- // Future SIS version could log a warning instead if a unmarshalling is in progress.
- throw new IllegalStateException(Errors.format(Errors.Keys.ElementAlreadyPresent_1, name));
+ * Convenience method invoked when an argument was expected to be positive, but the user gave a negative value
+ * or (in some case) zero. This method logs a warning if we are in process of (un)marshalling a XML document,
+ * or throw an exception otherwise.
+ *
+ * @param classe The caller class.
+ * @param property The property name. Method name will be inferred by the usual Java bean convention.
+ * @param strict {@code true} if the value was expected to be strictly positive, or {@code false} if 0 is accepted.
+ * @param value The invalid argument value.
+ * @throws IllegalArgumentException if we are not (un)marshalling a XML document.
+ */
+ public static void warnNonPositiveArgument(final Class<?> classe, final String property, final boolean strict,
+ final Number value) throws IllegalArgumentException
+ {
+ final String msg = logOrFormat(classe, property,
+ strict ? Errors.Keys.ValueNotGreaterThanZero_2 : Errors.Keys.NegativeArgument_2, property, value);
+ if (msg != null) {
+ throw new IllegalArgumentException(msg);
+ }
+ }
+
+ /**
+ * Convenience method invoked when an argument is outside the expected range of values. This method logs
+ * a warning if we are in process of (un)marshalling a XML document, or throw an exception otherwise.
+ *
+ * @param classe The caller class.
+ * @param property The property name. Method name will be inferred by the usual Java bean convention.
+ * @param minimum The minimal legal value.
+ * @param maximum The maximal legal value.
+ * @param value The invalid argument value.
+ * @throws IllegalArgumentException if we are not (un)marshalling a XML document.
+ */
+ public static void warnOutOfRangeArgument(final Class<?> classe, final String property,
+ final Number minimum, final Number maximum, final Number value) throws IllegalArgumentException
+ {
+ final String msg = logOrFormat(classe, property, Errors.Keys.ValueOutOfRange_4, property, minimum, maximum, value);
+ if (msg != null) {
+ throw new IllegalArgumentException(msg);
+ }
+ }
+
+ /**
+ * Formats an error message and logs it is we are (un)marshalling a document, or return the message otherwise.
+ * In the later case, it is caller's responsibility to use the message for throwing an exception.
+ *
+ * @param classe The caller class, used only in case of warning message to log.
+ * @param property The property name. Method name will be inferred by the usual Java bean convention.
+ * @param key A {@code Errors.Keys} value.
+ * @param arguments The argument to use for formatting the error message.
+ * @return {@code null} if the message has been logged, or the message to put in an exception otherwise.
+ */
+ private static String logOrFormat(final Class<?> classe, final String property, final short key, final Object... arguments) {
+ final Context context = Context.current();
+ if (context == null) {
+ return Errors.format(key, arguments);
+ } else {
+ final StringBuilder buffer = new StringBuilder(property.length() + 3).append("set").append(property);
+ buffer.setCharAt(3, Character.toUpperCase(buffer.charAt(3)));
+ Context.warningOccured(context, ISOMetadata.LOGGER, classe, buffer.toString(), Errors.class, key, arguments);
+ return null;
}
- return true;
}
}
Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingUtilities.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingUtilities.java?rev=1635709&r1=1635708&r2=1635709&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingUtilities.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingUtilities.java [UTF-8] Fri Oct 31 07:31:13 2014
@@ -17,6 +17,7 @@
package org.apache.sis.internal.metadata;
import java.util.Collection;
+import java.util.logging.Logger;
import javax.measure.unit.Unit;
import org.opengis.annotation.UML;
import org.opengis.annotation.Specification;
@@ -27,6 +28,9 @@ import org.opengis.referencing.crs.*;
import org.opengis.referencing.datum.*;
import org.opengis.referencing.operation.*;
import org.apache.sis.util.Static;
+import org.apache.sis.util.logging.Logging;
+import org.apache.sis.util.resources.Errors;
+import org.apache.sis.internal.jaxb.Context;
/**
@@ -38,11 +42,16 @@ import org.apache.sis.util.Static;
*
* @author Martin Desruisseaux (IRD, Geomatys)
* @since 0.4 (derived from geotk-2.0)
- * @version 0.4
+ * @version 0.5
* @module
*/
public final class ReferencingUtilities extends Static {
/**
+ * The logger to use for messages related to the {@code sis-referencing} module.
+ */
+ public static final Logger LOGGER = Logging.getLogger("org.apache.sis.referencing");
+
+ /**
* Subtypes of {@link IdentifiedObject} for which a URN type is defined.
* For each interface at index <var>i</var>, the URN type is {@code URN_TYPES[i]}.
*
@@ -216,4 +225,39 @@ public final class ReferencingUtilities
}
return sameContent;
}
+
+ /**
+ * Ensures that the given argument value is {@code false}. This method is invoked by private setter methods,
+ * which are themselves invoked by JAXB at unmarshalling time. Invoking this method from those setter methods
+ * serves two purposes:
+ *
+ * <ul>
+ * <li>Make sure that a singleton property is not defined twice in the XML document.</li>
+ * <li>Protect ourselves against changes in immutable objects outside unmarshalling. It should
+ * not be necessary since the setter methods shall not be public, but we are paranoiac.</li>
+ * <li>Be a central point where we can trace all setter methods, in case we want to improve
+ * warning or error messages in future SIS versions.</li>
+ * </ul>
+ *
+ * @param classe The caller class, used only in case of warning message to log.
+ * @param method The caller method, used only in case of warning message to log.
+ * @param name The property name, used only in case of error message to format.
+ * @param isDefined Whether the property in the caller object is current defined.
+ * @return {@code true} if the caller can set the property.
+ * @throws IllegalStateException If {@code isDefined} is {@code true} and we are not unmarshalling an object.
+ */
+ public static boolean canSetProperty(final Class<?> classe, final String method,
+ final String name, final boolean isDefined) throws IllegalStateException
+ {
+ if (!isDefined) {
+ return true;
+ }
+ final Context context = Context.current();
+ if (context != null) {
+ Context.warningOccured(context, LOGGER, classe, method, Errors.class, Errors.Keys.ElementAlreadyPresent_1, name);
+ return false;
+ } else {
+ throw new IllegalStateException(Errors.format(Errors.Keys.ElementAlreadyPresent_1, name));
+ }
+ }
}
Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultExtendedElementInformation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultExtendedElementInformation.java?rev=1635709&r1=1635708&r2=1635709&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultExtendedElementInformation.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultExtendedElementInformation.java [UTF-8] Fri Oct 31 07:31:13 2014
@@ -28,10 +28,11 @@ import org.opengis.metadata.citation.Res
import org.opengis.metadata.ExtendedElementInformation;
import org.opengis.util.InternationalString;
import org.apache.sis.measure.ValueRange;
-import org.apache.sis.util.ArgumentChecks;
import org.apache.sis.util.iso.Types;
import org.apache.sis.internal.metadata.LegacyPropertyAdapter;
+import static org.apache.sis.internal.metadata.MetadataUtilities.warnNonPositiveArgument;
+
/**
* New metadata element, not found in ISO 19115, which is required to describe geographic data.
@@ -196,6 +197,13 @@ public class DefaultExtendedElementInfor
* This is a <cite>shallow</cite> copy constructor, since the other metadata contained in the
* given object are not recursively copied.
*
+ * <div class="note"><b>Note on properties validation:</b>
+ * This constructor does not verify the property values of the given metadata (e.g. whether it contains
+ * unexpected negative values). This is because invalid metadata exist in practice, and verifying their
+ * validity in this copy constructor is often too late. Note that this is not the only hole, as invalid
+ * metadata instances can also be obtained by unmarshalling an invalid XML document.
+ * </div>
+ *
* @param object The metadata to copy values from, or {@code null} if none.
*
* @see #castOrCopy(ExtendedElementInformation)
@@ -427,13 +435,13 @@ public class DefaultExtendedElementInfor
/**
* Sets the maximum occurrence of the extended element.
*
- * @param newValue The new maximum occurrence.
+ * @param newValue The new maximum occurrence, or {@code null}.
* @throws IllegalArgumentException if the given value is negative.
*/
- public void setMaximumOccurrence(final Integer newValue) throws IllegalArgumentException {
+ public void setMaximumOccurrence(final Integer newValue) {
checkWritePermission();
- if (newValue != null) {
- ArgumentChecks.ensurePositive("maximumOccurrence", newValue);
+ if (newValue != null && newValue < 0) {
+ warnNonPositiveArgument(DefaultExtendedElementInformation.class, "maximumOccurrence", false, newValue);
}
maximumOccurrence = newValue;
}
Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultEnvironmentalRecord.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultEnvironmentalRecord.java?rev=1635709&r1=1635708&r2=1635709&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultEnvironmentalRecord.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultEnvironmentalRecord.java [UTF-8] Fri Oct 31 07:31:13 2014
@@ -23,7 +23,8 @@ import org.opengis.metadata.acquisition.
import org.opengis.util.InternationalString;
import org.apache.sis.measure.ValueRange;
import org.apache.sis.metadata.iso.ISOMetadata;
-import org.apache.sis.util.ArgumentChecks;
+
+import static org.apache.sis.internal.metadata.MetadataUtilities.warnOutOfRangeArgument;
/**
@@ -41,7 +42,7 @@ import org.apache.sis.util.ArgumentCheck
* @author Cédric Briançon (Geomatys)
* @author Martin Desruisseaux (Geomatys)
* @since 0.3 (derived from geotk-3.03)
- * @version 0.3
+ * @version 0.5
* @module
*/
@XmlType(name = "MI_EnvironmentalRecord_Type", propOrder = {
@@ -88,6 +89,13 @@ public class DefaultEnvironmentalRecord
* This is a <cite>shallow</cite> copy constructor, since the other metadata contained in the
* given object are not recursively copied.
*
+ * <div class="note"><b>Note on properties validation:</b>
+ * This constructor does not verify the property values of the given metadata (e.g. whether it contains
+ * unexpected negative values). This is because invalid metadata exist in practice, and verifying their
+ * validity in this copy constructor is often too late. Note that this is not the only hole, as invalid
+ * metadata instances can also be obtained by unmarshalling an invalid XML document.
+ * </div>
+ *
* @param object The metadata to copy values from, or {@code null} if none.
*
* @see #castOrCopy(EnvironmentalRecord)
@@ -163,12 +171,13 @@ public class DefaultEnvironmentalRecord
/**
* Sets the maximum relative humidity along the flight pass during the photo flight.
*
- * @param newValue The new maximum relative humidity.
+ * @param newValue The new maximum relative humidity, or {@code null}.
+ * @throws IllegalArgumentException if the given value is out of range.
*/
public void setMaxRelativeHumidity(final Double newValue) {
checkWritePermission();
- if (newValue != null) {
- ArgumentChecks.ensureBetween("maxRelativeHumidity", 0, 100, newValue);
+ if (newValue != null && !(newValue >= 0 && newValue <= 100)) { // Use '!' for catching NaN.
+ warnOutOfRangeArgument(DefaultEnvironmentalRecord.class, "maxRelativeHumidity", 0, 100, newValue);
}
maxRelativeHumidity = newValue;
}
Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultBand.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultBand.java?rev=1635709&r1=1635708&r2=1635709&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultBand.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultBand.java [UTF-8] Fri Oct 31 07:31:13 2014
@@ -29,6 +29,8 @@ import org.opengis.metadata.content.Tran
import org.apache.sis.xml.Namespaces;
import org.apache.sis.measure.ValueRange;
+import static org.apache.sis.internal.metadata.MetadataUtilities.warnNonPositiveArgument;
+
/**
* Range of wavelengths in the electromagnetic spectrum.
@@ -132,6 +134,13 @@ public class DefaultBand extends Default
* This is a <cite>shallow</cite> copy constructor, since the other metadata contained in the
* given object are not recursively copied.
*
+ * <div class="note"><b>Note on properties validation:</b>
+ * This constructor does not verify the property values of the given metadata (e.g. whether it contains
+ * unexpected negative values). This is because invalid metadata exist in practice, and verifying their
+ * validity in this copy constructor is often too late. Note that this is not the only hole, as invalid
+ * metadata instances can also be obtained by unmarshalling an invalid XML document.
+ * </div>
+ *
* @param object The metadata to copy values from, or {@code null} if none.
*
* @see #castOrCopy(Band)
@@ -178,6 +187,22 @@ public class DefaultBand extends Default
}
/**
+ * Ensures that the given property value is positive.
+ *
+ * @param property Name of the property to check.
+ * @param strict {@code false} is zero is a legal value.
+ * @param newValue The property value to verify.
+ * @throws IllegalArgumentException if the given value is negative and the problem has not been logged.
+ */
+ private static void ensurePositive(final String property, final boolean strict, final Double newValue)
+ throws IllegalArgumentException
+ {
+ if (newValue != null && !(strict ? newValue > 0 : newValue >= 0)) { // Use '!' for catching NaN.
+ warnNonPositiveArgument(DefaultBand.class, property, strict, newValue);
+ }
+ }
+
+ /**
* Returns the shortest wavelength that the sensor is capable of collecting within a designated band.
* The units of measurement is given by {@link #getBoundUnit()}.
*
@@ -196,12 +221,14 @@ public class DefaultBand extends Default
/**
* Sets the shortest wavelength that the sensor is capable of collecting within a designated band.
*
- * @param newValue The new shortest wavelength.
+ * @param newValue The new shortest wavelength, or {@code null}.
+ * @throws IllegalArgumentException if the given value is negative.
*
* @since 0.5
*/
public void setBoundMin(final Double newValue) {
checkWritePermission();
+ ensurePositive("boundMin", false, newValue);
boundMin = newValue;
}
@@ -224,12 +251,14 @@ public class DefaultBand extends Default
/**
* Sets the longest wavelength that the sensor is capable of collecting within a designated band.
*
- * @param newValue The new longest wavelength.
+ * @param newValue The new longest wavelength, or {@code null}.
+ * @throws IllegalArgumentException if the given value is negative.
*
* @since 0.5
*/
public void setBoundMax(final Double newValue) {
checkWritePermission();
+ ensurePositive("boundMax", false, newValue);
boundMax = newValue;
}
@@ -295,10 +324,12 @@ public class DefaultBand extends Default
/**
* Sets the wavelength at which the response is the highest.
*
- * @param newValue The new peak response.
+ * @param newValue The new peak response, or {@code null}.
+ * @throws IllegalArgumentException if the given value is negative.
*/
public void setPeakResponse(final Double newValue) {
checkWritePermission();
+ ensurePositive("peakResponse", false, newValue);
peakResponse = newValue;
}
@@ -339,6 +370,9 @@ public class DefaultBand extends Default
*/
public void setToneGradation(final Integer newValue) {
checkWritePermission();
+ if (newValue != null && newValue < 0) {
+ warnNonPositiveArgument(DefaultBand.class, "toneGradation", false, newValue);
+ }
toneGradation = newValue;
}
@@ -394,9 +428,11 @@ public class DefaultBand extends Default
* as specified in instrument design.
*
* @param newValue The new nominal spatial resolution.
+ * @throws IllegalArgumentException if the given value is negative.
*/
public void setNominalSpatialResolution(final Double newValue) {
checkWritePermission();
+ ensurePositive("nominalSpatialResolution", true, newValue);
nominalSpatialResolution = newValue;
}
Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultFeatureTypeInfo.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultFeatureTypeInfo.java?rev=1635709&r1=1635708&r2=1635709&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultFeatureTypeInfo.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultFeatureTypeInfo.java [UTF-8] Fri Oct 31 07:31:13 2014
@@ -23,7 +23,8 @@ import org.opengis.util.GenericName;
import org.opengis.metadata.content.FeatureTypeInfo;
import org.apache.sis.measure.ValueRange;
import org.apache.sis.metadata.iso.ISOMetadata;
-import org.apache.sis.util.ArgumentChecks;
+
+import static org.apache.sis.internal.metadata.MetadataUtilities.warnNonPositiveArgument;
/**
@@ -85,6 +86,13 @@ public class DefaultFeatureTypeInfo exte
* This is a <cite>shallow</cite> copy constructor, since the other metadata contained in the
* given object are not recursively copied.
*
+ * <div class="note"><b>Note on properties validation:</b>
+ * This constructor does not verify the property values of the given metadata (e.g. whether it contains
+ * unexpected negative values). This is because invalid metadata exist in practice, and verifying their
+ * validity in this copy constructor is often too late. Note that this is not the only hole, as invalid
+ * metadata instances can also be obtained by unmarshalling an invalid XML document.
+ * </div>
+ *
* @param object The metadata to copy values from, or {@code null} if none.
*
* @see #castOrCopy(FeatureTypeInfo)
@@ -163,10 +171,10 @@ public class DefaultFeatureTypeInfo exte
* @param newValue the new number of occurrence.
* @throws IllegalArgumentException if the given value is negative.
*/
- public void setFeatureInstanceCount(final Integer newValue) throws IllegalArgumentException {
+ public void setFeatureInstanceCount(final Integer newValue) {
checkWritePermission();
- if (newValue != null) {
- ArgumentChecks.ensurePositive("featureInstanceCount", newValue);
+ if (newValue != null && newValue < 0) {
+ warnNonPositiveArgument(DefaultFeatureTypeInfo.class, "featureInstanceCount", true, newValue);
}
featureInstanceCount = newValue;
}
Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultImageDescription.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultImageDescription.java?rev=1635709&r1=1635708&r2=1635709&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultImageDescription.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultImageDescription.java [UTF-8] Fri Oct 31 07:31:13 2014
@@ -25,6 +25,9 @@ import org.opengis.metadata.content.Imag
import org.opengis.metadata.content.ImagingCondition;
import org.apache.sis.measure.ValueRange;
+import static org.apache.sis.internal.metadata.MetadataUtilities.warnOutOfRangeArgument;
+import static org.apache.sis.internal.metadata.MetadataUtilities.warnNonPositiveArgument;
+
/**
* Information about an image's suitability for use.
@@ -42,7 +45,7 @@ import org.apache.sis.measure.ValueRange
* @author Touraïvane (IRD)
* @author Cédric Briançon (Geomatys)
* @since 0.3 (derived from geotk-2.1)
- * @version 0.4
+ * @version 0.5
* @module
*/
@XmlType(name = "MD_ImageDescription_Type", propOrder = {
@@ -141,6 +144,13 @@ public class DefaultImageDescription ext
* This is a <cite>shallow</cite> copy constructor, since the other metadata contained in the
* given object are not recursively copied.
*
+ * <div class="note"><b>Note on properties validation:</b>
+ * This constructor does not verify the property values of the given metadata (e.g. whether
+ * a value is out of range). This is because invalid metadata exist in practice, and verifying their
+ * validity in this copy constructor is often too late. Note that this is not the only hole, as invalid
+ * metadata instances can also be obtained by unmarshalling an invalid XML document.
+ * </div>
+ *
* @param object The metadata to copy values from, or {@code null} if none.
*
* @see #castOrCopy(ImageDescription)
@@ -188,6 +198,26 @@ public class DefaultImageDescription ext
}
/**
+ * Ensures that the given argument is either null or between the given minimum and maximum values.
+ *
+ * @param property Name of the property to check.
+ * @param min The minimal legal value.
+ * @param max The maximal legal value.
+ * @param newValue The value given by the user.
+ * @throws IllegalArgumentException if the given value is out of range and the problem has not been logged.
+ */
+ private static void ensureInRange(final String property, final double min, final double max, final Double newValue)
+ throws IllegalArgumentException
+ {
+ if (newValue != null) {
+ final double v = newValue;
+ if (!(v >= min && v <= max)) { // Use '!' for catching NaN.
+ warnOutOfRangeArgument(DefaultImageDescription.class, property, min, max, v);
+ }
+ }
+ }
+
+ /**
* Returns the illumination elevation measured in degrees clockwise from the target plane at
* intersection of the optical line of sight with the Earth's surface.
* For images from a scanning device, refer to the centre pixel of the image.
@@ -208,10 +238,12 @@ public class DefaultImageDescription ext
* intersection of the optical line of sight with the Earth's surface. For images from a
* scanning device, refer to the centre pixel of the image.
*
- * @param newValue The new illumination elevation angle.
+ * @param newValue The new illumination elevation angle, or {@code null}.
+ * @throws IllegalArgumentException if the given value is out of range.
*/
public void setIlluminationElevationAngle(final Double newValue) {
checkWritePermission();
+ ensureInRange("illuminationElevationAngle", -90, +90, newValue);
illuminationElevationAngle = newValue;
}
@@ -232,10 +264,12 @@ public class DefaultImageDescription ext
* Sets the illumination azimuth measured in degrees clockwise from true north at the time the
* image is taken. For images from a scanning device, refer to the centre pixel of the image.
*
- * @param newValue The new illumination azimuth angle.
+ * @param newValue The new illumination azimuth angle, or {@code null}.
+ * @throws IllegalArgumentException if the given value is out of range.
*/
public void setIlluminationAzimuthAngle(final Double newValue) {
checkWritePermission();
+ ensureInRange("illuminationAzimuthAngle", 0, 360, newValue);
illuminationAzimuthAngle = newValue;
}
@@ -296,10 +330,12 @@ public class DefaultImageDescription ext
/**
* Sets the area of the dataset obscured by clouds, expressed as a percentage of the spatial extent.
*
- * @param newValue The new cloud cover percentage.
+ * @param newValue The new cloud cover percentage, or {@code null}.
+ * @throws IllegalArgumentException if the given value is out of range.
*/
public void setCloudCoverPercentage(final Double newValue) {
checkWritePermission();
+ ensureInRange("cloudCoverPercentage", 0, 100, newValue);
cloudCoverPercentage = newValue;
}
@@ -344,9 +380,13 @@ public class DefaultImageDescription ext
* Sets the count of the number the number of lossy compression cycles performed on the image.
*
* @param newValue The new compression generation quantity.
+ * @throws IllegalArgumentException if the given value is negative.
*/
public void setCompressionGenerationQuantity(final Integer newValue) {
checkWritePermission();
+ if (newValue != null && newValue < 0) {
+ warnNonPositiveArgument(DefaultImageDescription.class, "compressionGenerationQuantity", false, newValue);
+ }
compressionGenerationQuantity = newValue;
}
Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultSampleDimension.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultSampleDimension.java?rev=1635709&r1=1635708&r2=1635709&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultSampleDimension.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultSampleDimension.java [UTF-8] Fri Oct 31 07:31:13 2014
@@ -27,6 +27,8 @@ import org.opengis.util.Record;
import org.opengis.util.RecordType;
import org.apache.sis.measure.ValueRange;
+import static org.apache.sis.internal.metadata.MetadataUtilities.warnNonPositiveArgument;
+
/**
* The characteristic of each dimension (layer) included in the resource.
@@ -135,6 +137,13 @@ public class DefaultSampleDimension exte
* This is a <cite>shallow</cite> copy constructor, since the other metadata contained in the
* given object are not recursively copied.
*
+ * <div class="note"><b>Note on properties validation:</b>
+ * This constructor does not verify the property values of the given metadata (e.g. whether it contains
+ * unexpected negative values). This is because invalid metadata exist in practice, and verifying their
+ * validity in this copy constructor is often too late. Note that this is not the only hole, as invalid
+ * metadata instances can also be obtained by unmarshalling an invalid XML document.
+ * </div>
+ *
* @param object The metadata to copy values from, or {@code null} if none.
*
* @see #castOrCopy(SampleDimension)
@@ -188,6 +197,22 @@ public class DefaultSampleDimension exte
}
/**
+ * Ensures that the given property value is positive.
+ *
+ * @param property Name of the property to check.
+ * @param strict {@code false} is zero is a legal value.
+ * @param newValue The property value to verify.
+ * @throws IllegalArgumentException if the given value is negative and the problem has not been logged.
+ */
+ private static void ensurePositive(final String property, final boolean strict, final Integer newValue)
+ throws IllegalArgumentException
+ {
+ if (newValue != null && !(strict ? newValue > 0 : newValue >= 0)) {
+ warnNonPositiveArgument(DefaultSampleDimension.class, property, strict, newValue);
+ }
+ }
+
+ /**
* Returns the minimum value of data values in each dimension included in the resource.
*
* @return Minimum value of data values in each dimension included in the resource, or {@code null} if unspecified.
@@ -256,6 +281,7 @@ public class DefaultSampleDimension exte
* @return The number of values used in a thematic classification resource, or {@code null} if none.
*/
@Override
+ @ValueRange(minimum = 0)
/// @XmlElement(name = "numberOfValues")
public Integer getNumberOfValues() {
return numberOfValues;
@@ -264,11 +290,13 @@ public class DefaultSampleDimension exte
/**
* Sets the number of values used in a thematic classification resource.
*
- * @param newValues The new number of values used in a thematic classification resource.
+ * @param newValue The new number of values used in a thematic classification resource.
+ * @throws IllegalArgumentException if the given value is negative.
*/
- public void setNumberOfValues(final Integer newValues) {
+ public void setNumberOfValues(final Integer newValue) {
checkWritePermission();
- numberOfValues = newValues;
+ ensurePositive("numberOfValues", false, newValue);
+ numberOfValues = newValue;
}
/**
@@ -374,9 +402,11 @@ public class DefaultSampleDimension exte
* for the value in each band of each pixel.
*
* @param newValue The new maximum number of significant bits.
+ * @throws IllegalArgumentException if the given value is zero or negative.
*/
public void setBitsPerValue(final Integer newValue) {
checkWritePermission();
+ ensurePositive("bitsPerValue", true, newValue);
bitsPerValue = newValue;
}
Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultDigitalTransferOptions.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultDigitalTransferOptions.java?rev=1635709&r1=1635708&r2=1635709&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultDigitalTransferOptions.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultDigitalTransferOptions.java [UTF-8] Fri Oct 31 07:31:13 2014
@@ -29,7 +29,8 @@ import org.opengis.metadata.distribution
import org.apache.sis.internal.metadata.LegacyPropertyAdapter;
import org.apache.sis.measure.ValueRange;
import org.apache.sis.metadata.iso.ISOMetadata;
-import org.apache.sis.util.ArgumentChecks;
+
+import static org.apache.sis.internal.metadata.MetadataUtilities.warnNonPositiveArgument;
/**
@@ -106,6 +107,13 @@ public class DefaultDigitalTransferOptio
* This is a <cite>shallow</cite> copy constructor, since the other metadata contained in the
* given object are not recursively copied.
*
+ * <div class="note"><b>Note on properties validation:</b>
+ * This constructor does not verify the property values of the given metadata (e.g. whether it contains
+ * unexpected negative values). This is because invalid metadata exist in practice, and verifying their
+ * validity in this copy constructor is often too late. Note that this is not the only hole, as invalid
+ * metadata instances can also be obtained by unmarshalling an invalid XML document.
+ * </div>
+ *
* @param object The metadata to copy values from, or {@code null} if none.
*
* @see #castOrCopy(DigitalTransferOptions)
@@ -185,13 +193,13 @@ public class DefaultDigitalTransferOptio
* Sets an estimated size of a unit in the specified transfer format, expressed in megabytes.
* The transfer shall be greater than zero.
*
- * @param newValue The new transfer size.
- * @throws IllegalArgumentException if the given value is negative.
+ * @param newValue The new transfer size, or {@code null}.
+ * @throws IllegalArgumentException if the given value is NaN or negative.
*/
- public void setTransferSize(final Double newValue) throws IllegalArgumentException {
+ public void setTransferSize(final Double newValue) {
checkWritePermission();
- if (newValue != null) {
- ArgumentChecks.ensurePositive("transferSize", newValue);
+ if (newValue != null && !(newValue >= 0)) { // Use '!' for catching NaN.
+ warnNonPositiveArgument(DefaultDigitalTransferOptions.class, "transferSize", true, newValue);
}
transferSize = newValue;
}
Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultMedium.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultMedium.java?rev=1635709&r1=1635708&r2=1635709&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultMedium.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultMedium.java [UTF-8] Fri Oct 31 07:31:13 2014
@@ -33,6 +33,8 @@ import org.apache.sis.metadata.iso.ISOMe
import org.apache.sis.internal.jaxb.NonMarshalledAuthority;
import org.apache.sis.internal.metadata.LegacyPropertyAdapter;
+import static org.apache.sis.internal.metadata.MetadataUtilities.warnNonPositiveArgument;
+
/**
* Information about the media on which the resource can be distributed.
@@ -110,6 +112,13 @@ public class DefaultMedium extends ISOMe
* This is a <cite>shallow</cite> copy constructor, since the other metadata contained in the
* given object are not recursively copied.
*
+ * <div class="note"><b>Note on properties validation:</b>
+ * This constructor does not verify the property values of the given metadata (e.g. whether it contains
+ * unexpected negative values). This is because invalid metadata exist in practice, and verifying their
+ * validity in this copy constructor is often too late. Note that this is not the only hole, as invalid
+ * metadata instances can also be obtained by unmarshalling an invalid XML document.
+ * </div>
+ *
* @param object The metadata to copy values from, or {@code null} if none.
*
* @see #castOrCopy(Medium)
@@ -192,11 +201,15 @@ public class DefaultMedium extends ISOMe
* The number shall be greater than zero.
*
* @param newValue The new density.
+ * @throws IllegalArgumentException if the given value is NaN, zero or negative.
*
* @since 0.5
*/
public void setDensity(final Double newValue) {
checkWritePermission();
+ if (newValue != null && !(newValue > 0)) { // Use '!' for catching NaN.
+ warnNonPositiveArgument(DefaultMedium.class, "density", true, newValue);
+ }
density = newValue;
}
@@ -279,10 +292,14 @@ public class DefaultMedium extends ISOMe
/**
* Sets the number of items in the media identified.
*
- * @param newValue The new volumes.
+ * @param newValue The new volumes, or {@code null}.
+ * @throws IllegalArgumentException if the given value is negative.
*/
public void setVolumes(final Integer newValue) {
checkWritePermission();
+ if (newValue != null && newValue < 0) {
+ warnNonPositiveArgument(DefaultMedium.class, "volumes", false, newValue);
+ }
volumes = newValue;
}
Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultRepresentativeFraction.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultRepresentativeFraction.java?rev=1635709&r1=1635708&r2=1635709&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultRepresentativeFraction.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultRepresentativeFraction.java [UTF-8] Fri Oct 31 07:31:13 2014
@@ -29,6 +29,7 @@ import org.opengis.metadata.identificati
import org.apache.sis.internal.jaxb.IdentifierMapWithSpecialCases;
import org.apache.sis.internal.jaxb.gco.GO_Integer64;
import org.apache.sis.internal.util.CheckedArrayList;
+import org.apache.sis.measure.ValueRange;
import org.apache.sis.xml.IdentifierMap;
import org.apache.sis.xml.IdentifierSpace;
import org.apache.sis.xml.IdentifiedObject;
@@ -37,6 +38,7 @@ import org.apache.sis.util.ArgumentCheck
import org.apache.sis.util.resources.Errors;
import static org.apache.sis.util.collection.Containers.isNullOrEmpty;
+import static org.apache.sis.internal.metadata.MetadataUtilities.warnNonPositiveArgument;
/**
@@ -60,7 +62,7 @@ import static org.apache.sis.util.collec
* @author Cédric Briançon (Geomatys)
* @author Martin Desruisseaux (Geomatys)
* @since 0.3 (derived from geotk-2.4)
- * @version 0.4
+ * @version 0.5
* @module
*
* @see DefaultResolution#getEquivalentScale()
@@ -96,9 +98,9 @@ public class DefaultRepresentativeFracti
* Creates a new representative fraction from the specified denominator.
*
* @param denominator The denominator as a positive number, or 0 if unspecified.
- * @throws IllegalArgumentException If the given value is not a positive number or zero.
+ * @throws IllegalArgumentException If the given value is negative.
*/
- public DefaultRepresentativeFraction(final long denominator) throws IllegalArgumentException {
+ public DefaultRepresentativeFraction(final long denominator) {
ArgumentChecks.ensurePositive("denominator", denominator);
this.denominator = denominator;
}
@@ -106,10 +108,16 @@ public class DefaultRepresentativeFracti
/**
* Constructs a new representative fraction initialized to the value of the given object.
*
- * @param object The metadata to copy values from, or {@code null} if none.
- * @throws IllegalArgumentException If the denominator of the given source is negative.
+ * <div class="note"><b>Note on properties validation:</b>
+ * This constructor does not verify the property values of the given metadata (e.g. whether it contains
+ * unexpected negative values). This is because invalid metadata exist in practice, and verifying their
+ * validity in this copy constructor is often too late. Note that this is not the only hole, as invalid
+ * metadata instances can also be obtained by unmarshalling an invalid XML document.
+ * </div>
+ *
+ * @param object The metadata to copy values from, or {@code null} if none.
*/
- public DefaultRepresentativeFraction(final RepresentativeFraction object) throws IllegalArgumentException {
+ public DefaultRepresentativeFraction(final RepresentativeFraction object) {
if (object != null) {
denominator = object.getDenominator();
}
@@ -138,6 +146,7 @@ public class DefaultRepresentativeFracti
* @return The denominator.
*/
@Override
+ @ValueRange(minimum = 0)
@XmlJavaTypeAdapter(value = GO_Integer64.class, type = long.class)
@XmlElement(name = "denominator", required = true)
public long getDenominator() {
@@ -148,26 +157,35 @@ public class DefaultRepresentativeFracti
* Sets the denominator value.
*
* @param denominator The new denominator value, or 0 if none.
- * @throws IllegalArgumentException If the given value is not a positive number or zero.
+ * @throws IllegalArgumentException if the given value is negative.
*/
- public void setDenominator(final long denominator) throws IllegalArgumentException {
- ArgumentChecks.ensurePositive("denominator", denominator);
+ public void setDenominator(final long denominator) {
+ if (denominator < 0) {
+ warnNonPositiveArgument(DefaultRepresentativeFraction.class, "denominator", false, denominator);
+ }
this.denominator = denominator;
}
/**
- * Sets the denominator from a scale in the [-1 … +1] range.
+ * Sets the denominator from a scale in the (0 … 1] range.
* The denominator is computed by {@code round(1 / scale)}.
*
- * @param scale The scale as a number between -1 and +1 inclusive, or NaN.
+ * <p>The equivalent of a {@code getScale()} method is {@link #doubleValue()}.</p>
+ *
+ * @param scale The scale as a number between 0 exclusive and 1 inclusive, or NaN.
* @throws IllegalArgumentException if the given scale is our of range.
*/
- public void setScale(final double scale) throws IllegalArgumentException {
- if (Math.abs(scale) > 1) {
- throw new IllegalArgumentException(Errors.format(
- Errors.Keys.ValueOutOfRange_4, "scale", -1, +1, scale));
+ public void setScale(final double scale) {
+ /*
+ * For the following argument check, we do not need to use a Metadatautility method because
+ * 'setScale' is never invoked at (un)marshalling time. Note also that we accept NaN values
+ * since round(NaN) == 0, which is the desired value.
+ */
+ if (scale <= 0 || scale > 1) {
+ throw new IllegalArgumentException((scale <= 0)
+ ? Errors.format(Errors.Keys.ValueNotGreaterThanZero_2, "scale", scale)
+ : Errors.format(Errors.Keys.ValueOutOfRange_4, "scale", 0, 1, scale));
}
- // round(NaN) == 0, which is the desired value.
setDenominator(Math.round(1.0 / scale));
}
Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultResolution.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultResolution.java?rev=1635709&r1=1635708&r2=1635709&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultResolution.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultResolution.java [UTF-8] Fri Oct 31 07:31:13 2014
@@ -29,6 +29,8 @@ import org.apache.sis.metadata.iso.ISOMe
import org.apache.sis.measure.ValueRange;
import org.apache.sis.util.resources.Messages;
+import static org.apache.sis.internal.metadata.MetadataUtilities.warnNonPositiveArgument;
+
/**
* Level of detail expressed as a scale factor or a ground distance.
@@ -53,7 +55,7 @@ import org.apache.sis.util.resources.Mes
* @author Touraïvane (IRD)
* @author Cédric Briançon (Geomatys)
* @since 0.3 (derived from geotk-2.1)
- * @version 0.3
+ * @version 0.5
* @module
*
* @see AbstractIdentification#getSpatialResolutions()
@@ -135,6 +137,13 @@ public class DefaultResolution extends I
* {@linkplain #getAngularDistance() angular distance} and {@linkplain #getLevelOfDetail() level of detail}
* are specified, then the first of those values is taken and the other values are silently discarded.</p>
*
+ * <div class="note"><b>Note on properties validation:</b>
+ * This constructor does not verify the property values of the given metadata (e.g. whether it contains
+ * unexpected negative values). This is because invalid metadata exist in practice, and verifying their
+ * validity in this copy constructor is often too late. Note that this is not the only hole, as invalid
+ * metadata instances can also be obtained by unmarshalling an invalid XML document.
+ * </div>
+ *
* @param object The metadata to copy values from, or {@code null} if none.
*
* @see #castOrCopy(Resolution)
@@ -187,6 +196,19 @@ public class DefaultResolution extends I
}
/**
+ * Ensures that the given property is greater than zero.
+ *
+ * @param property The name of the property to verify.
+ * @param value The property value, or {@code null}.
+ * @throws IllegalArgumentException if the property is zero or negative and the problem has not been logged.
+ */
+ private static void ensurePositive(final String property, final Double value) throws IllegalArgumentException {
+ if (value != null && !(value > 0)) { // Use '!' for catching NaN.
+ warnNonPositiveArgument(DefaultResolution.class, property, true, value);
+ }
+ }
+
+ /**
* Sets the properties identified by the {@code code} argument, if non-null.
* This discards any other properties.
*
@@ -250,9 +272,11 @@ public class DefaultResolution extends I
* If and only if the {@code newValue} is non-null, then this method automatically
* discards all other properties.
*
- * @param newValue The new distance.
+ * @param newValue The new distance, or {@code null}.
+ * @throws IllegalArgumentException if the given value is NaN, zero or negative.
*/
public void setDistance(final Double newValue) {
+ ensurePositive("distance", newValue);
setProperty(DISTANCE, newValue);
}
@@ -276,11 +300,13 @@ public class DefaultResolution extends I
* If and only if the {@code newValue} is non-null, then this method automatically
* discards all other properties.
*
- * @param newValue The new distance.
+ * @param newValue The new distance, or {@code null}.
+ * @throws IllegalArgumentException if the given value is NaN, zero or negative.
*
* @since 0.5
*/
public void setVertical(final Double newValue) {
+ ensurePositive("vertical", newValue);
setProperty(VERTICAL, newValue);
}
@@ -304,11 +330,13 @@ public class DefaultResolution extends I
* If and only if the {@code newValue} is non-null, then this method automatically
* discards all other properties.
*
- * @param newValue The new distance.
+ * @param newValue The new distance, or {@code null}.
+ * @throws IllegalArgumentException if the given value is NaN, zero or negative.
*
* @since 0.5
*/
public void setAngularDistance(final Double newValue) {
+ ensurePositive("angular", newValue);
setProperty(ANGULAR, newValue);
}
Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultNominalResolution.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultNominalResolution.java?rev=1635709&r1=1635708&r2=1635709&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultNominalResolution.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultNominalResolution.java [UTF-8] Fri Oct 31 07:31:13 2014
@@ -24,6 +24,8 @@ import org.apache.sis.metadata.iso.ISOMe
import org.apache.sis.measure.ValueRange;
import org.apache.sis.xml.Namespaces;
+import static org.apache.sis.internal.metadata.MetadataUtilities.warnNonPositiveArgument;
+
/**
* Distance between consistent parts of (centre, left side, right side) adjacent pixels.
@@ -40,7 +42,7 @@ import org.apache.sis.xml.Namespaces;
* @author Cédric Briançon (Geomatys)
* @author Martin Desruisseaux (Geomatys)
* @since 0.3 (derived from geotk-3.03)
- * @version 0.3
+ * @version 0.5
* @module
*/
@XmlType(name = "LE_NominalResolution_Type", propOrder = {
@@ -77,6 +79,13 @@ public class DefaultNominalResolution ex
* This is a <cite>shallow</cite> copy constructor, since the other metadata contained in the
* given object are not recursively copied.
*
+ * <div class="note"><b>Note on properties validation:</b>
+ * This constructor does not verify the property values of the given metadata (e.g. whether it contains
+ * unexpected negative values). This is because invalid metadata exist in practice, and verifying their
+ * validity in this copy constructor is often too late. Note that this is not the only hole, as invalid
+ * metadata instances can also be obtained by unmarshalling an invalid XML document.
+ * </div>
+ *
* @param object The metadata to copy values from, or {@code null} if none.
*
* @see #castOrCopy(NominalResolution)
@@ -115,6 +124,19 @@ public class DefaultNominalResolution ex
}
/**
+ * Ensures that the given property is greater than zero.
+ *
+ * @param property The name of the property to verify.
+ * @param value The property value, or {@code null}.
+ * @throws IllegalArgumentException if the property is zero or negative and the problem has not been logged.
+ */
+ private static void ensurePositive(final String property, final Double value) throws IllegalArgumentException {
+ if (value != null && !(value > 0)) { // Use '!' for catching NaN.
+ warnNonPositiveArgument(DefaultNominalResolution.class, property, true, value);
+ }
+ }
+
+ /**
* Returns the distance between consistent parts of (centre, left side, right side)
* adjacent pixels in the scan plane.
*
@@ -132,9 +154,11 @@ public class DefaultNominalResolution ex
* pixels in the scan plane.
*
* @param newValue The new scanning resolution value.
+ * @throws IllegalArgumentException if the given value is NaN, zero or negative.
*/
public void setScanningResolution(final Double newValue) {
checkWritePermission();
+ ensurePositive("scanningResolution", newValue);
scanningResolution = newValue;
}
@@ -156,9 +180,11 @@ public class DefaultNominalResolution ex
* in the object space.
*
* @param newValue The new ground resolution value.
+ * @throws IllegalArgumentException if the given value is NaN, zero or negative.
*/
public void setGroundResolution(final Double newValue) {
checkWritePermission();
+ ensurePositive("groundResolution", newValue);
groundResolution = newValue;
}
}
Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultDimension.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultDimension.java?rev=1635709&r1=1635708&r2=1635709&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultDimension.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultDimension.java [UTF-8] Fri Oct 31 07:31:13 2014
@@ -26,6 +26,9 @@ import org.opengis.metadata.spatial.Dime
import org.apache.sis.internal.jaxb.gco.GO_Measure;
import org.apache.sis.metadata.iso.ISOMetadata;
import org.apache.sis.measure.ValueRange;
+import org.apache.sis.util.ArgumentChecks;
+
+import static org.apache.sis.internal.metadata.MetadataUtilities.warnNonPositiveArgument;
/**
@@ -98,10 +101,12 @@ public class DefaultDimension extends IS
/**
* Creates a dimension initialized to the given type and size.
*
- * @param dimensionName The name of the axis, or {@code null} if none, or {@code null} if none.
- * @param dimensionSize The number of elements along the axis, or {@code null} if none.
+ * @param dimensionName The name of the axis, or {@code null} if none, or {@code null} if none.
+ * @param dimensionSize The number of elements along the axis, or {@code null} if none.
+ * @throws IllegalArgumentException if {@code dimensionSize} is negative.
*/
public DefaultDimension(final DimensionNameType dimensionName, final int dimensionSize) {
+ ArgumentChecks.ensurePositive("dimensionSize", dimensionSize);
this.dimensionName = dimensionName;
this.dimensionSize = dimensionSize;
}
@@ -111,6 +116,13 @@ public class DefaultDimension extends IS
* This is a <cite>shallow</cite> copy constructor, since the other metadata contained in the
* given object are not recursively copied.
*
+ * <div class="note"><b>Note on properties validation:</b>
+ * This constructor does not verify the property values of the given metadata (e.g. whether it contains
+ * unexpected negative values). This is because invalid metadata exist in practice, and verifying their
+ * validity in this copy constructor is often too late. Note that this is not the only hole, as invalid
+ * metadata instances can also be obtained by unmarshalling an invalid XML document.
+ * </div>
+ *
* @param object The metadata to copy values from, or {@code null} if none.
*
* @see #castOrCopy(Dimension)
@@ -178,7 +190,7 @@ public class DefaultDimension extends IS
* @return Number of elements along the axis, or {@code null}.
*/
@Override
- @ValueRange(minimum=0)
+ @ValueRange(minimum = 0)
@XmlElement(name = "dimensionSize", required = true)
public Integer getDimensionSize() {
return dimensionSize;
@@ -187,10 +199,14 @@ public class DefaultDimension extends IS
/**
* Sets the number of elements along the axis.
*
- * @param newValue The new dimension size.
+ * @param newValue The new dimension size, or {@code null}.
+ * @throws IllegalArgumentException if the given value is negative.
*/
public void setDimensionSize(final Integer newValue) {
checkWritePermission();
+ if (newValue != null && newValue < 0) {
+ warnNonPositiveArgument(DefaultDimension.class, "dimensionSize", false, newValue);
+ }
dimensionSize = newValue;
}
@@ -210,10 +226,14 @@ public class DefaultDimension extends IS
/**
* Sets the degree of detail in the grid dataset.
*
- * @param newValue The new resolution.
+ * @param newValue The new resolution, or {@code null}.
+ * @throws IllegalArgumentException if the given value is NaN, zero or negative.
*/
public void setResolution(final Double newValue) {
checkWritePermission();
+ if (newValue != null && !(newValue > 0)) { // Use '!' for catching NaN.
+ warnNonPositiveArgument(DefaultDimension.class, "dimensionSize", true, newValue);
+ }
resolution = newValue;
}
Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGeometricObjects.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGeometricObjects.java?rev=1635709&r1=1635708&r2=1635709&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGeometricObjects.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGeometricObjects.java [UTF-8] Fri Oct 31 07:31:13 2014
@@ -24,6 +24,8 @@ import org.opengis.metadata.spatial.Geom
import org.apache.sis.measure.ValueRange;
import org.apache.sis.metadata.iso.ISOMetadata;
+import static org.apache.sis.internal.metadata.MetadataUtilities.warnNonPositiveArgument;
+
/**
* Number of objects, listed by geometric object type, used in the dataset.
@@ -41,7 +43,7 @@ import org.apache.sis.metadata.iso.ISOMe
* @author Touraïvane (IRD)
* @author Cédric Briançon (Geomatys)
* @since 0.3 (derived from geotk-2.1)
- * @version 0.3
+ * @version 0.5
* @module
*/
@XmlType(name = "MD_GeometricObjects_Type", propOrder = {
@@ -86,6 +88,13 @@ public class DefaultGeometricObjects ext
* This is a <cite>shallow</cite> copy constructor, since the other metadata contained in the
* given object are not recursively copied.
*
+ * <div class="note"><b>Note on properties validation:</b>
+ * This constructor does not verify the property values of the given metadata (e.g. whether it contains
+ * unexpected negative values). This is because invalid metadata exist in practice, and verifying their
+ * validity in this copy constructor is often too late. Note that this is not the only hole, as invalid
+ * metadata instances can also be obtained by unmarshalling an invalid XML document.
+ * </div>
+ *
* @param object The metadata to copy values from, or {@code null} if none.
*
* @see #castOrCopy(GeometricObjects)
@@ -159,10 +168,14 @@ public class DefaultGeometricObjects ext
/**
* Sets the total number of the point or vector object type occurring in the dataset.
*
- * @param newValue The geometric object count.
+ * @param newValue The geometric object count, or {@code null}.
+ * @throws IllegalArgumentException if the given value is zero or negative.
*/
public void setGeometricObjectCount(final Integer newValue) {
checkWritePermission();
+ if (newValue != null && newValue <= 0) {
+ warnNonPositiveArgument(DefaultGeometricObjects.class, "geometricObjectCount", true, newValue);
+ }
geometricObjectCount = newValue;
}
}
Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGridSpatialRepresentation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGridSpatialRepresentation.java?rev=1635709&r1=1635708&r2=1635709&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGridSpatialRepresentation.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGridSpatialRepresentation.java [UTF-8] Fri Oct 31 07:31:13 2014
@@ -28,6 +28,8 @@ import org.opengis.metadata.spatial.Geor
import org.opengis.metadata.spatial.GridSpatialRepresentation;
import org.apache.sis.measure.ValueRange;
+import static org.apache.sis.internal.metadata.MetadataUtilities.warnNonPositiveArgument;
+
/**
* Basic information required to uniquely identify a resource or resources.
@@ -45,7 +47,7 @@ import org.apache.sis.measure.ValueRange
* @author Touraïvane (IRD)
* @author Cédric Briançon (Geomatys)
* @since 0.3 (derived from geotk-2.1)
- * @version 0.3
+ * @version 0.5
* @module
*/
@XmlType(name = "MD_GridSpatialRepresentation_Type", propOrder = {
@@ -113,6 +115,13 @@ public class DefaultGridSpatialRepresent
* This is a <cite>shallow</cite> copy constructor, since the other metadata contained in the
* given object are not recursively copied.
*
+ * <div class="note"><b>Note on properties validation:</b>
+ * This constructor does not verify the property values of the given metadata (e.g. whether it contains
+ * unexpected negative values). This is because invalid metadata exist in practice, and verifying their
+ * validity in this copy constructor is often too late. Note that this is not the only hole, as invalid
+ * metadata instances can also be obtained by unmarshalling an invalid XML document.
+ * </div>
+ *
* @param object The metadata to copy values from, or {@code null} if none.
*
* @see #castOrCopy(GridSpatialRepresentation)
@@ -172,7 +181,7 @@ public class DefaultGridSpatialRepresent
* @return Number of independent spatial-temporal axes, or {@code null}.
*/
@Override
- @ValueRange(minimum=0)
+ @ValueRange(minimum = 0)
@XmlElement(name = "numberOfDimensions", required = true)
public Integer getNumberOfDimensions() {
return numberOfDimensions;
@@ -181,10 +190,14 @@ public class DefaultGridSpatialRepresent
/**
* Sets the number of independent spatial-temporal axes.
*
- * @param newValue The new number of dimension.
+ * @param newValue The new number of dimension, or {@code null}.
+ * @throws IllegalArgumentException if the given value is negative.
*/
public void setNumberOfDimensions(final Integer newValue) {
checkWritePermission();
+ if (newValue != null && newValue < 0) {
+ warnNonPositiveArgument(DefaultGridSpatialRepresentation.class, "numberOfDimensions", false, newValue);
+ }
numberOfDimensions = newValue;
}
Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SecondDefiningParameter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SecondDefiningParameter.java?rev=1635709&r1=1635708&r2=1635709&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SecondDefiningParameter.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SecondDefiningParameter.java [UTF-8] Fri Oct 31 07:31:13 2014
@@ -23,6 +23,7 @@ import org.opengis.referencing.datum.Ell
import org.apache.sis.xml.Namespaces;
import org.apache.sis.internal.jaxb.Context;
import org.apache.sis.internal.jaxb.gco.Measure;
+import org.apache.sis.internal.metadata.ReferencingUtilities;
import org.apache.sis.util.resources.Errors;
@@ -131,7 +132,8 @@ public final class SecondDefiningParamet
*/
public void setInverseFlattening(final Measure measure) {
if (measure.setUnit(Unit.ONE)) {
- Context.warningOccured(Context.current(), Context.LOGGER, SecondDefiningParameter.class, "setInverseFlattening",
+ Context.warningOccured(Context.current(), ReferencingUtilities.LOGGER,
+ SecondDefiningParameter.class, "setInverseFlattening",
Errors.class, Errors.Keys.IncompatiblePropertyValue_1, "uom");
}
this.measure = measure;
Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java?rev=1635709&r1=1635708&r2=1635709&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java [UTF-8] Fri Oct 31 07:31:13 2014
@@ -61,7 +61,7 @@ import static org.apache.sis.internal.ut
import static org.apache.sis.internal.util.CollectionsExt.nonEmpty;
import static org.apache.sis.internal.util.CollectionsExt.immutableSet;
import static org.apache.sis.internal.util.Utilities.appendUnicodeIdentifier;
-import static org.apache.sis.internal.metadata.MetadataUtilities.canSetProperty;
+import static org.apache.sis.internal.metadata.ReferencingUtilities.canSetProperty;
// Branch-dependent imports
import java.util.Objects;
@@ -509,7 +509,9 @@ public class AbstractIdentifiedObject ex
private void setIdentifier(final Code identifier) {
if (identifier != null) {
final Identifier id = identifier.getIdentifier();
- if (id != null && canSetProperty("identifier", identifiers != null)) {
+ if (id != null && canSetProperty(AbstractIdentifiedObject.class,
+ "setIdentifier", "identifier", identifiers != null))
+ {
identifiers = Collections.singleton(id);
}
}
Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java?rev=1635709&r1=1635708&r2=1635709&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java [UTF-8] Fri Oct 31 07:31:13 2014
@@ -39,7 +39,7 @@ import org.apache.sis.io.wkt.Formatter;
import static org.apache.sis.util.Utilities.deepEquals;
import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
import static org.apache.sis.internal.referencing.WKTUtilities.toFormattable;
-import static org.apache.sis.internal.metadata.MetadataUtilities.canSetProperty;
+import static org.apache.sis.internal.metadata.ReferencingUtilities.canSetProperty;
// Branch-dependent imports
import java.util.Objects;
@@ -312,7 +312,7 @@ public class AbstractCRS extends Abstrac
* @throws IllegalStateException If the coordinate system has already been set.
*/
final void setCoordinateSystem(final String name, final CoordinateSystem cs) {
- if (cs != null && canSetProperty(name, coordinateSystem != null)) {
+ if (cs != null && canSetProperty(AbstractCRS.class, "setCoordinateSystem", name, coordinateSystem != null)) {
coordinateSystem = cs;
}
}
Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java?rev=1635709&r1=1635708&r2=1635709&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java [UTF-8] Fri Oct 31 07:31:13 2014
@@ -48,6 +48,7 @@ import org.apache.sis.internal.jaxb.Cont
import org.apache.sis.io.wkt.Formatter;
import org.apache.sis.io.wkt.Convention;
import org.apache.sis.io.wkt.ElementKind;
+import org.apache.sis.internal.metadata.ReferencingUtilities;
import static java.lang.Double.doubleToLongBits;
import static java.lang.Double.NEGATIVE_INFINITY;
@@ -55,7 +56,6 @@ import static java.lang.Double.POSITIVE_
import static org.apache.sis.util.ArgumentChecks.*;
import static org.apache.sis.util.CharSequences.trimWhitespaces;
import static org.apache.sis.util.collection.Containers.property;
-import static org.apache.sis.internal.metadata.MetadataUtilities.canSetProperty;
// Branch-dependent imports
import java.util.Objects;
@@ -457,7 +457,9 @@ public class DefaultCoordinateSystemAxis
* Invoked by JAXB at unmarshalling time for setting the minimum value.
*/
private void setMinimum(final Double value) {
- if (value != null && canSetProperty("minimumValue", minimumValue != NEGATIVE_INFINITY)) {
+ if (value != null && ReferencingUtilities.canSetProperty(DefaultCoordinateSystemAxis.class,
+ "setMinimum", "minimumValue", minimumValue != NEGATIVE_INFINITY))
+ {
final double min = value; // Apply unboxing.
if (min < maximumValue) {
minimumValue = min;
@@ -491,7 +493,9 @@ public class DefaultCoordinateSystemAxis
* Invoked by JAXB at unmarshalling time for setting the maximum value.
*/
private void setMaximum(final Double value) {
- if (value != null && canSetProperty("maximumValue", maximumValue != POSITIVE_INFINITY)) {
+ if (value != null && ReferencingUtilities.canSetProperty(DefaultCoordinateSystemAxis.class,
+ "setMaximum", "maximumValue", maximumValue != POSITIVE_INFINITY))
+ {
final double max = value; // Apply unboxing.
if (max > minimumValue) {
maximumValue = max;
@@ -509,7 +513,7 @@ public class DefaultCoordinateSystemAxis
* @param value The invalid value.
*/
private static void outOfRange(final String name, final Double value) {
- Context.warningOccured(Context.current(), Context.LOGGER, DefaultCoordinateSystemAxis.class, name,
+ Context.warningOccured(Context.current(), ReferencingUtilities.LOGGER, DefaultCoordinateSystemAxis.class, name,
Errors.class, Errors.Keys.InconsistentAttribute_2, name, value);
}
Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/AbstractDatum.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/AbstractDatum.java?rev=1635709&r1=1635708&r2=1635709&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/AbstractDatum.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/AbstractDatum.java [UTF-8] Fri Oct 31 07:31:13 2014
@@ -35,7 +35,7 @@ import org.apache.sis.internal.metadata.
import static org.apache.sis.util.Utilities.deepEquals;
import static org.apache.sis.util.collection.Containers.property;
-import static org.apache.sis.internal.metadata.MetadataUtilities.canSetProperty;
+import static org.apache.sis.internal.metadata.ReferencingUtilities.canSetProperty;
// Branch-dependent imports
import java.util.Objects;
@@ -306,7 +306,9 @@ public class AbstractDatum extends Abstr
* Invoked by JAXB only at unmarshalling time.
*/
private void setRealizationEpoch(final Date value) {
- if (value != null && canSetProperty("realizationEpoch", realizationEpoch != Long.MIN_VALUE)) {
+ if (value != null && canSetProperty(AbstractDatum.class,
+ "setRealizationEpoch", "realizationEpoch", realizationEpoch != Long.MIN_VALUE))
+ {
realizationEpoch = value.getTime();
}
}
Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java?rev=1635709&r1=1635708&r2=1635709&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java [UTF-8] Fri Oct 31 07:31:13 2014
@@ -33,6 +33,7 @@ import org.apache.sis.internal.util.Nume
import org.apache.sis.internal.jaxb.Context;
import org.apache.sis.internal.jaxb.gco.Measure;
import org.apache.sis.internal.jaxb.referencing.SecondDefiningParameter;
+import org.apache.sis.internal.metadata.ReferencingUtilities;
import org.apache.sis.internal.referencing.Formulas;
import org.apache.sis.referencing.IdentifiedObjects;
import org.apache.sis.referencing.AbstractIdentifiedObject;
@@ -579,7 +580,7 @@ public class DefaultEllipsoid extends Ab
*/
private static void warnDuplicated(final String element) {
// We cheat a bit for the "unmarshal" method name since there is not such method...
- Context.warningOccured(Context.current(), Context.LOGGER, DefaultEllipsoid.class, "unmarshal",
+ Context.warningOccured(Context.current(), ReferencingUtilities.LOGGER, DefaultEllipsoid.class, "unmarshal",
Errors.class, Errors.Keys.DuplicatedElement_1, element);
}
Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java?rev=1635709&r1=1635708&r2=1635709&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java [UTF-8] Fri Oct 31 07:31:13 2014
@@ -36,7 +36,7 @@ import org.apache.sis.util.ComparisonMod
import static org.apache.sis.util.ArgumentChecks.ensureFinite;
import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
-import static org.apache.sis.internal.metadata.MetadataUtilities.canSetProperty;
+import static org.apache.sis.internal.metadata.ReferencingUtilities.canSetProperty;
// Branch-dependent imports
import java.util.Objects;
@@ -262,7 +262,9 @@ public class DefaultPrimeMeridian extend
* Invoked by JAXB for setting the Greenwich longitude and its unit of measurement.
*/
private void setGreenwichMeasure(final Measure measure) {
- if (measure != null && canSetProperty("greenwichLongitude", greenwichLongitude != 0 || angularUnit != null)) {
+ if (measure != null && canSetProperty(DefaultPrimeMeridian.class,
+ "setGreenwichMeasure", "greenwichLongitude", greenwichLongitude != 0 || angularUnit != null))
+ {
greenwichLongitude = measure.value;
angularUnit = measure.getUnit(Angle.class);
if (angularUnit == null) {
Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultTemporalDatum.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultTemporalDatum.java?rev=1635709&r1=1635708&r2=1635709&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultTemporalDatum.java (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultTemporalDatum.java Fri Oct 31 07:31:13 2014
@@ -33,7 +33,7 @@ import org.apache.sis.io.wkt.Formatter;
import org.apache.sis.io.wkt.FormattableObject;
import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
-import static org.apache.sis.internal.metadata.MetadataUtilities.canSetProperty;
+import static org.apache.sis.internal.metadata.ReferencingUtilities.canSetProperty;
// Branch-dependent imports
import java.util.Objects;
@@ -232,7 +232,9 @@ public class DefaultTemporalDatum extend
* Invoked by JAXB only at unmarshalling time.
*/
private void setOrigin(final Date value) {
- if (value != null && canSetProperty("origin", origin != Long.MIN_VALUE)) {
+ if (value != null && canSetProperty(DefaultTemporalDatum.class,
+ "setOrigin", "origin", origin != Long.MIN_VALUE))
+ {
origin = value.getTime();
}
}
Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultVerticalDatum.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultVerticalDatum.java?rev=1635709&r1=1635708&r2=1635709&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultVerticalDatum.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultVerticalDatum.java [UTF-8] Fri Oct 31 07:31:13 2014
@@ -32,7 +32,7 @@ import org.apache.sis.internal.jaxb.Lega
import org.apache.sis.internal.referencing.VerticalDatumTypes;
import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
-import static org.apache.sis.internal.metadata.MetadataUtilities.canSetProperty;
+import static org.apache.sis.internal.metadata.ReferencingUtilities.canSetProperty;
// Branch-dependent imports
import java.util.Objects;
@@ -263,7 +263,7 @@ public class DefaultVerticalDatum extend
* Invoked by JAXB only. The vertical datum type is set only if it has not already been specified.
*/
private void setTypeElement(final VerticalDatumType t) {
- if (t != null && canSetProperty("verticalDatumType", type != null)) {
+ if (t != null && canSetProperty(DefaultVerticalDatum.class, "setTypeElement", "verticalDatumType", type != null)) {
type = t;
}
}