sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1555310 - in /sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis: internal/referencing/ referencing/ referencing/cs/ referencing/datum/
Date Sat, 04 Jan 2014 02:04:28 GMT
Author: desruisseaux
Date: Sat Jan  4 02:04:28 2014
New Revision: 1555310

URL: http://svn.apache.org/r1555310
Log:
Added safety checks against accidental changes of immutable objects.

Modified:
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/NilReferencingObject.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractReferenceSystem.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/AbstractDatum.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultTemporalDatum.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultVerticalDatum.java

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/NilReferencingObject.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/NilReferencingObject.java?rev=1555310&r1=1555309&r2=1555310&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/NilReferencingObject.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/NilReferencingObject.java
[UTF-8] Sat Jan  4 02:04:28 2014
@@ -20,8 +20,9 @@ import java.util.Set;
 import java.util.Collection;
 import org.opengis.util.GenericName;
 import org.opengis.util.InternationalString;
-import org.opengis.referencing.IdentifiedObject;
+import org.opengis.referencing.ReferenceSystem;
 import org.opengis.referencing.ReferenceIdentifier;
+import org.opengis.metadata.extent.Extent;
 import org.apache.sis.xml.NilReason;
 import org.apache.sis.xml.NilObject;
 import org.apache.sis.io.wkt.UnformattableObjectException;
@@ -38,7 +39,7 @@ import org.apache.sis.io.wkt.Unformattab
  * @version 0.4
  * @module
  */
-public final class NilReferencingObject implements NilObject, IdentifiedObject {
+public final class NilReferencingObject implements NilObject, ReferenceSystem {
     /**
      * The unique instance.
      */
@@ -67,6 +68,8 @@ public final class NilReferencingObject 
     @Override public Collection<GenericName>  getAlias()       {return null;}
     @Override public Set<ReferenceIdentifier> getIdentifiers() {return null;}
     @Override public InternationalString      getRemarks()     {return null;}
+    @Override public InternationalString      getScope()       {return null;}
+    @Override public Extent getDomainOfValidity()              {return null;}
 
     /**
      * Throws the exception in all cases.
@@ -78,11 +81,4 @@ public final class NilReferencingObject 
     public String toWKT() throws UnformattableObjectException {
         throw new UnformattableObjectException();
     }
-
-    /**
-     * Returns the unique instance on deserialization.
-     */
-    private Object readResolve() {
-        return INSTANCE;
-    }
 }

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java?rev=1555310&r1=1555309&r2=1555310&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java
[UTF-8] Sat Jan  4 02:04:28 2014
@@ -16,6 +16,7 @@
  */
 package org.apache.sis.internal.referencing;
 
+import javax.measure.unit.Unit;
 import org.opengis.parameter.*;
 import org.opengis.referencing.*;
 import org.opengis.referencing.cs.*;
@@ -23,6 +24,7 @@ import org.opengis.referencing.crs.*;
 import org.opengis.referencing.datum.*;
 import org.opengis.referencing.operation.*;
 import org.apache.sis.referencing.operation.matrix.MatrixSIS;
+import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.Static;
 
 
@@ -99,6 +101,57 @@ public final class ReferencingUtilities 
     }
 
     /**
+     * Returns the unit used for all axes in the given coordinate system.
+     * If not all axes use the same unit, then this method returns {@code null}.
+     * This convenience method is often used for Well Know Text (WKT) version 1 formatting.
+     *
+     * @param cs The coordinate system for which to get the unit, or {@code null}.
+     * @return The unit for all axis in the given coordinate system, or {@code null}.
+     */
+    public static Unit<?> getUnit(final CoordinateSystem cs) {
+        Unit<?> unit = null;
+        if (cs != null) {
+            for (int i=cs.getDimension(); --i>=0;) {
+                final Unit<?> candidate = cs.getAxis(i).getUnit();
+                if (candidate != null) {
+                    if (unit == null) {
+                        unit = candidate;
+                    } else if (!unit.equals(candidate)) {
+                        return null;
+                    }
+                }
+            }
+        }
+        return unit;
+    }
+
+    /**
+     * 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));
+        }
+        return true;
+    }
+
+    /**
      * Returns the URN type for the given class, or {@code null} if unknown.
      * See {@link org.apache.sis.internal.util.DefinitionURI} javadoc for a list of URN types.
      *

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java?rev=1555310&r1=1555309&r2=1555310&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
[UTF-8] Sat Jan  4 02:04:28 2014
@@ -56,6 +56,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.referencing.ReferencingUtilities.canSetProperty;
 
 // Related to JDK7
 import java.util.Objects;
@@ -158,7 +159,7 @@ public class AbstractIdentifiedObject ex
      * Alternatively an identifier by which this object can be referenced.
      *
      * <p><b>Consider this field as final!</b>
-     * This field is modified only at unmarshalling time by {@link #setIdentifier(ReferenceIdentifier)}</p>
+     * This field is modified only at unmarshalling time by {@link #setIdentifier(Code)}</p>
      *
      * @see #getIdentifiers()
      * @see #getIdentifier()
@@ -185,8 +186,7 @@ public class AbstractIdentifiedObject ex
      * reserved to JAXB, which will assign values to the fields using reflexion.
      */
     AbstractIdentifiedObject() {
-        identifiers = null;
-        remarks     = null;
+        remarks = null;
     }
 
     /**
@@ -445,7 +445,7 @@ public class AbstractIdentifiedObject ex
     private void setIdentifier(final Code identifier) {
         if (identifier != null) {
             final ReferenceIdentifier id = identifier.getIdentifier();
-            if (id != null) {
+            if (id != null && canSetProperty("identifier", identifiers != null))
{
                 identifiers = Collections.singleton(id);
             }
         }
@@ -476,11 +476,11 @@ public class AbstractIdentifiedObject ex
      * after the object has been made available to the user.
      */
     private void setNames(final Collection<ReferenceIdentifier> names) {
-        if (names != null) {
+        if (names != null && canSetProperty("name", name != null)) {
             final Iterator<ReferenceIdentifier> it = names.iterator();
             if (it.hasNext()) {
                 name = it.next();
-                if (it.hasNext()) {
+                if (it.hasNext() && canSetProperty("alias", alias != null)) {
                     alias = new ArrayList<>(4); // There is generally few aliases.
                     do {
                         alias.add(new NamedIdentifier(it.next()));

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractReferenceSystem.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractReferenceSystem.java?rev=1555310&r1=1555309&r2=1555310&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractReferenceSystem.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractReferenceSystem.java
[UTF-8] Sat Jan  4 02:04:28 2014
@@ -18,6 +18,7 @@ package org.apache.sis.referencing;
 
 import java.util.Map;
 import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlTransient;
 import org.opengis.util.GenericName;
 import org.opengis.util.InternationalString;
 import org.opengis.referencing.ReferenceSystem;
@@ -60,6 +61,7 @@ import java.util.Objects;
  * @version 0.4
  * @module
  */
+@XmlTransient
 public class AbstractReferenceSystem extends AbstractIdentifiedObject implements ReferenceSystem
{
     /**
      * Serial number for inter-operability with different versions.

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java?rev=1555310&r1=1555309&r2=1555310&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java
[UTF-8] Sat Jan  4 02:04:28 2014
@@ -23,6 +23,7 @@ import javax.measure.unit.Unit;
 import javax.measure.unit.NonSI;
 import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlSeeAlso;
 import org.opengis.util.GenericName;
 import org.opengis.util.InternationalString;
@@ -68,6 +69,7 @@ import static org.apache.sis.util.Utilit
  * @see org.apache.sis.referencing.crs.AbstractCRS
  */
 @XmlType(name = "AbstractCoordinateSystemType")
+@XmlRootElement(name = "AbstractCoordinateSystem")
 @XmlSeeAlso({
     DefaultAffineCS.class,
     DefaultCartesianCS.class, // Not an AffineCS subclass in GML schema.
@@ -103,9 +105,9 @@ public class AbstractCS extends Abstract
     private final CoordinateSystemAxis[] axes;
 
     /**
-     * Constructs a new object in which every attributes are set to a null value.
-     * <strong>This is not a valid object.</strong> This constructor is strictly
-     * reserved to JAXB, which will assign values to the fields using reflexion.
+     * Constructs a new object in which every attributes are set to a null or empty value.
+     * <strong>This is not a valid object.</strong> This constructor is strictly
reserved
+     * to JAXB, which will assign values to the fields using reflexion.
      */
     AbstractCS() {
         super(org.apache.sis.internal.referencing.NilReferencingObject.INSTANCE);

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java?rev=1555310&r1=1555309&r2=1555310&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java
[UTF-8] Sat Jan  4 02:04:28 2014
@@ -44,8 +44,12 @@ import org.apache.sis.util.resources.Err
 import org.apache.sis.internal.jaxb.Context;
 import org.apache.sis.io.wkt.Formatter;
 
+import static java.lang.Double.doubleToLongBits;
+import static java.lang.Double.NEGATIVE_INFINITY;
+import static java.lang.Double.POSITIVE_INFINITY;
 import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
 import static org.apache.sis.util.CharSequences.trimWhitespaces;
+import static org.apache.sis.internal.referencing.ReferencingUtilities.canSetProperty;
 
 // Related to JDK7
 import java.util.Objects;
@@ -156,7 +160,9 @@ public class DefaultCoordinateSystemAxis
     /**
      * Minimal and maximal value for this axis, or negative/positive infinity if none.
      *
-     * Consider this field as final. It is not final only for XML unmarshalling.
+     * <p><b>Consider this field as final!</b>
+     * This field is modified only at unmarshalling time by {@link #setMinimum(Double)}
+     * or {@link #setMaximum(Double)}</p>
      */
     private double minimumValue, maximumValue;
 
@@ -177,8 +183,8 @@ public class DefaultCoordinateSystemAxis
         direction    = null;
         unit         = null;
         rangeMeaning = null;
-        minimumValue = Double.NEGATIVE_INFINITY;
-        maximumValue = Double.POSITIVE_INFINITY;
+        minimumValue = NEGATIVE_INFINITY;
+        maximumValue = POSITIVE_INFINITY;
     }
 
     /**
@@ -244,7 +250,7 @@ public class DefaultCoordinateSystemAxis
         if (!(minimumValue < maximumValue)) { // Use '!' for catching NaN
             throw new IllegalArgumentException(Errors.format(Errors.Keys.IllegalRange_2,
minimumValue, maximumValue));
         }
-        if ((minimumValue != Double.NEGATIVE_INFINITY) || (maximumValue != Double.POSITIVE_INFINITY))
{
+        if ((minimumValue != NEGATIVE_INFINITY) || (maximumValue != POSITIVE_INFINITY)) {
             ensureNonNull("rangeMeaning", rangeMeaning);
         } else {
             rangeMeaning = null;
@@ -276,8 +282,8 @@ public class DefaultCoordinateSystemAxis
         ensureNonNull("abbreviation", abbreviation);
         ensureNonNull("direction",    direction);
         ensureNonNull("unit",         unit);
-        double min = Double.NEGATIVE_INFINITY;
-        double max = Double.POSITIVE_INFINITY;
+        double min = NEGATIVE_INFINITY;
+        double max = POSITIVE_INFINITY;
         RangeMeaning r = null;
         if (Units.isAngular(unit)) {
             final UnitConverter fromDegrees = NonSI.DEGREE_ANGLE.getConverterTo(unit.asType(Angle.class));
@@ -411,14 +417,14 @@ public class DefaultCoordinateSystemAxis
      */
     @XmlElement(name = "minimumValue")
     private Double getMinimum() {
-        return (minimumValue != Double.NEGATIVE_INFINITY) ? minimumValue : null;
+        return (minimumValue != NEGATIVE_INFINITY) ? minimumValue : null;
     }
 
     /**
      * Invoked by JAXB at unmarshalling time for setting the minimum value.
      */
     private void setMinimum(final Double value) {
-        if (value != null) {
+        if (value != null && canSetProperty("minimumValue", minimumValue != NEGATIVE_INFINITY))
{
             final double min = value.doubleValue();
             if (min < maximumValue) {
                 minimumValue = min;
@@ -445,14 +451,14 @@ public class DefaultCoordinateSystemAxis
      */
     @XmlElement(name = "maximumValue")
     private Double getMaximum() {
-        return (maximumValue != Double.POSITIVE_INFINITY) ? maximumValue : null;
+        return (maximumValue != POSITIVE_INFINITY) ? maximumValue : null;
     }
 
     /**
      * Invoked by JAXB at unmarshalling time for setting the maximum value.
      */
     private void setMaximum(final Double value) {
-        if (value != null) {
+        if (value != null && canSetProperty("maximumValue", maximumValue != POSITIVE_INFINITY))
{
             final double max = value.doubleValue();
             if (max > minimumValue) {
                 maximumValue = max;
@@ -591,8 +597,8 @@ public class DefaultCoordinateSystemAxis
         if (compareMetadata) {
             if (!Objects.equals(this.abbreviation, that.abbreviation) ||
                 !Objects.equals(this.rangeMeaning, that.rangeMeaning) ||
-                Double.doubleToLongBits(minimumValue) != Double.doubleToLongBits(that.minimumValue)
||
-                Double.doubleToLongBits(maximumValue) != Double.doubleToLongBits(that.maximumValue))
+                doubleToLongBits(minimumValue) != doubleToLongBits(that.minimumValue) ||
+                doubleToLongBits(maximumValue) != doubleToLongBits(that.maximumValue))
             {
                 return false;
             }
@@ -652,7 +658,7 @@ public class DefaultCoordinateSystemAxis
     @Override
     protected long computeHashCode() {
         return super.computeHashCode() + Objects.hashCode(unit) + Objects.hashCode(direction)
-                + Double.doubleToLongBits(minimumValue) + 31*Double.doubleToLongBits(maximumValue);
+                + doubleToLongBits(minimumValue) + 31*doubleToLongBits(maximumValue);
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/AbstractDatum.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/AbstractDatum.java?rev=1555310&r1=1555309&r2=1555310&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/AbstractDatum.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/AbstractDatum.java
[UTF-8] Sat Jan  4 02:04:28 2014
@@ -19,8 +19,9 @@ package org.apache.sis.referencing.datum
 import java.util.Date;
 import java.util.Map;
 import javax.xml.bind.annotation.XmlType;
-import javax.xml.bind.annotation.XmlSeeAlso;
 import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlSeeAlso;
 import org.opengis.util.GenericName;
 import org.opengis.util.InternationalString;
 import org.opengis.metadata.extent.Extent;
@@ -36,6 +37,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.referencing.ReferencingUtilities.canSetProperty;
 
 // Related to JDK7
 import java.util.Objects;
@@ -67,6 +69,7 @@ import java.util.Objects;
  * @see org.apache.sis.referencing.crs.AbstractCRS
  */
 @XmlType(name = "AbstractDatumType")
+@XmlRootElement(name = "AbstractDatum")
 @XmlSeeAlso({
     DefaultGeodeticDatum.class,
     DefaultVerticalDatum.class,
@@ -97,7 +100,8 @@ public class AbstractDatum extends Abstr
      * (e.g. 1997 for IRTF97) or merely a year (e.g. 1983 for NAD83). If the time is
      * not defined, then the value is {@link Long#MIN_VALUE}.
      *
-     * <p>Consider this field as final. It is non-final only for the need of XML unmarshalling.</p>
+     * <p><b>Consider this field as final!</b>
+     * This field is modified only at unmarshalling time by {@link #setRealizationEpoch(Date)}</p>
      */
     private long realizationEpoch;
 
@@ -298,7 +302,9 @@ public class AbstractDatum extends Abstr
      * Invoked by JAXB only at unmarshalling time.
      */
     private void setRealizationEpoch(final Date value) {
-        realizationEpoch = MetadataUtilities.toMilliseconds(value);
+        if (value != null && canSetProperty("realizationEpoch", realizationEpoch
!= Long.MIN_VALUE)) {
+            realizationEpoch = value.getTime();
+        }
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java?rev=1555310&r1=1555309&r2=1555310&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java
[UTF-8] Sat Jan  4 02:04:28 2014
@@ -35,6 +35,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.referencing.ReferencingUtilities.canSetProperty;
 
 // Related to JDK7
 import java.util.Objects;
@@ -94,14 +95,16 @@ public class DefaultPrimeMeridian extend
     /**
      * Longitude of the prime meridian measured from the Greenwich meridian, positive eastward.
      *
-     * <p>Consider this field as final. It is declared non-final only for JAXB unmarshalling.</p>
+     * <p><b>Consider this field as final!</b>
+     * This field is modified only at unmarshalling time by {@link #setGreenwichMeasure(Measure)}</p>
      */
     private double greenwichLongitude;
 
     /**
      * The angular unit of the {@linkplain #getGreenwichLongitude() Greenwich longitude}.
      *
-     * <p>Consider this field as final. It is declared non-final only for JAXB unmarshalling.</p>
+     * <p><b>Consider this field as final!</b>
+     * This field is modified only at unmarshalling time by {@link #setGreenwichMeasure(Measure)}</p>
      */
     private Unit<Angle> angularUnit;
 
@@ -256,18 +259,20 @@ public class DefaultPrimeMeridian extend
      * Invoked by JAXB for setting the Greenwich longitude and its unit of measurement.
      */
     private void setGreenwichMeasure(final Measure measure) {
-        greenwichLongitude = measure.value;
-        angularUnit = measure.getUnit(Angle.class);
-        if (angularUnit == null) {
-            /*
-             * Missing unit: if the Greenwich longitude is zero, any angular unit gives the
same result
-             * (assuming that the missing unit was not applying an offset), so we can select
a default.
-             * If the Greenwich longitude is not zero, we can not guess. Our object will
be invalid.
-             */
-            if (greenwichLongitude == 0) {
-                angularUnit = NonSI.DEGREE_ANGLE;
-            } else {
-                Measure.missingUOM(DefaultPrimeMeridian.class, "setGreenwichMeasure");
+        if (measure != null && canSetProperty("greenwichLongitude", greenwichLongitude
!= 0 || angularUnit != null)) {
+            greenwichLongitude = measure.value;
+            angularUnit = measure.getUnit(Angle.class);
+            if (angularUnit == null) {
+                /*
+                 * Missing unit: if the Greenwich longitude is zero, any angular unit gives
the same result
+                 * (assuming that the missing unit was not applying an offset), so we can
select a default.
+                 * If the Greenwich longitude is not zero, we can not guess. Our object will
be invalid.
+                 */
+                if (greenwichLongitude == 0) {
+                    angularUnit = NonSI.DEGREE_ANGLE;
+                } else {
+                    Measure.missingUOM(DefaultPrimeMeridian.class, "setGreenwichMeasure");
+                }
             }
         }
     }

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultTemporalDatum.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultTemporalDatum.java?rev=1555310&r1=1555309&r2=1555310&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultTemporalDatum.java
(original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultTemporalDatum.java
Sat Jan  4 02:04:28 2014
@@ -31,6 +31,7 @@ import org.apache.sis.internal.metadata.
 import org.apache.sis.util.ComparisonMode;
 
 import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
+import static org.apache.sis.internal.referencing.ReferencingUtilities.canSetProperty;
 
 // Related to JDK7
 import java.util.Objects;
@@ -87,7 +88,8 @@ public class DefaultTemporalDatum extend
      * This information is mandatory, but SIS is tolerant to missing value is case a XML
      * fragment was incomplete.
      *
-     * <p>Consider this field as final. It is non-final only for the need of XML unmarshalling.</p>
+     * <p><b>Consider this field as final!</b>
+     * This field is modified only at unmarshalling time by {@link #setOrigin(Date)}</p>
      */
     private long origin;
 
@@ -224,7 +226,9 @@ public class DefaultTemporalDatum extend
      * Invoked by JAXB only at unmarshalling time.
      */
     private void setOrigin(final Date value) {
-        origin = MetadataUtilities.toMilliseconds(value);
+        if (value != null && canSetProperty("origin", origin != Long.MIN_VALUE))
{
+            origin = value.getTime();
+        }
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultVerticalDatum.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultVerticalDatum.java?rev=1555310&r1=1555309&r2=1555310&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultVerticalDatum.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultVerticalDatum.java
[UTF-8] Sat Jan  4 02:04:28 2014
@@ -32,6 +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.referencing.ReferencingUtilities.canSetProperty;
 
 // Related to JDK7
 import java.util.Objects;
@@ -87,7 +88,7 @@ public class DefaultVerticalDatum extend
     private static final long serialVersionUID = 380347456670516572L;
 
     /**
-     * The type of this vertical datum. Consider this field as final.
+     * The type of this vertical datum.
      * If {@code null}, a value will be inferred from the name by {@link #type()}.
      */
     private VerticalDatumType type;
@@ -260,10 +261,9 @@ 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 (type != null) {
-            throw new IllegalStateException();
+        if (t != null && canSetProperty("verticalDatumType", type != null)) {
+            type = t;
         }
-        type = t;
     }
 
     /**



Mime
View raw message