sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1570196 - in /sis/branches/JDK7/core: sis-metadata/src/main/java/org/apache/sis/internal/metadata/ sis-metadata/src/main/java/org/apache/sis/io/wkt/ sis-referencing/src/main/java/org/apache/sis/internal/referencing/ sis-referencing/src/mai...
Date Thu, 20 Feb 2014 14:13:18 GMT
Author: desruisseaux
Date: Thu Feb 20 14:13:18 2014
New Revision: 1570196

URL: http://svn.apache.org/r1570196
Log:
Be more specific in the choice of 'castOrCopy' static method to invoke depending on the object
type.
This is necessary for avoiding never-ending loop if the user choose to implement both CoordinateSystem
and CoordinateReferenceSystem interfaces in the same object.

Modified:
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WKTUtilities.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultCompoundCRS.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeodeticCRS.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java?rev=1570196&r1=1570195&r2=1570196&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
[UTF-8] Thu Feb 20 14:13:18 2014
@@ -28,6 +28,7 @@ import org.apache.sis.metadata.iso.exten
 import org.apache.sis.metadata.iso.extent.DefaultSpatialTemporalExtent;
 import org.apache.sis.internal.system.SystemListener;
 import org.apache.sis.internal.system.Modules;
+import org.apache.sis.io.wkt.FormattableObject;
 import org.apache.sis.util.resources.Errors;
 
 
@@ -126,7 +127,7 @@ public abstract class ReferencingService
      *
      * @since 0.4
      */
-    public abstract IdentifiedObject toFormattableObject(IdentifiedObject object);
+    public abstract FormattableObject toFormattableObject(IdentifiedObject object);
 
     /**
      * Sets a geographic bounding box from the specified envelope. If the envelope contains

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java?rev=1570196&r1=1570195&r2=1570196&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
[UTF-8] Thu Feb 20 14:13:18 2014
@@ -751,23 +751,6 @@ public class Formatter implements Locali
     }
 
     /**
-     * Appends the given {@code IdentifiedObject}.
-     *
-     * <p>The default implementation delegates to {@link #append(FormattableObject)},
-     * after wrapping the given object in an adapter if necessary.</p>
-     *
-     * @param object The identified object to append to the WKT, or {@code null} if none.
-     */
-    public void append(IdentifiedObject object) {
-        if (object != null) {
-            if (!(object instanceof FormattableObject)) {
-                object = ReferencingServices.getInstance().toFormattableObject(object);
-            }
-            append((FormattableObject) object);
-        }
-    }
-
-    /**
      * Appends the given geographic bounding box in a {@code BBOX[…]} element.
      * Longitude and latitude values will be formatted in decimal degrees.
      * Longitudes are relative to the Greenwich meridian, with values increasing toward East.
@@ -1174,8 +1157,11 @@ public class Formatter implements Locali
      * @return {@code true} on success, or {@code false} if the given type is not recognized.
      */
     final boolean appendElement(final Object value) {
-             if (value instanceof FormattableObject)     append((FormattableObject)     value);
-        else if (value instanceof IdentifiedObject)      append((IdentifiedObject)      value);
+        if (value instanceof FormattableObject) {
+            append((FormattableObject) value);
+        } else if (value instanceof IdentifiedObject) {
+            append(ReferencingServices.getInstance().toFormattableObject((IdentifiedObject)
value));
+        }
         else if (value instanceof GeographicBoundingBox) append((GeographicBoundingBox) value,
BBOX_ACCURACY);
         else if (value instanceof MathTransform)         append((MathTransform)         value);
         else if (value instanceof Matrix)                append((Matrix)                value);

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WKTUtilities.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WKTUtilities.java?rev=1570196&r1=1570195&r2=1570196&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WKTUtilities.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WKTUtilities.java
[UTF-8] Thu Feb 20 14:13:18 2014
@@ -20,7 +20,21 @@ import org.opengis.parameter.ParameterVa
 import org.opengis.parameter.ParameterValueGroup;
 import org.opengis.parameter.GeneralParameterValue;
 import org.opengis.referencing.IdentifiedObject;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.opengis.referencing.cs.CoordinateSystem;
+import org.opengis.referencing.cs.CoordinateSystemAxis;
+import org.opengis.referencing.datum.Datum;
+import org.opengis.referencing.datum.GeodeticDatum;
+import org.opengis.referencing.datum.PrimeMeridian;
+import org.opengis.referencing.datum.Ellipsoid;
 import org.apache.sis.referencing.IdentifiedObjects;
+import org.apache.sis.referencing.crs.AbstractCRS;
+import org.apache.sis.referencing.cs.AbstractCS;
+import org.apache.sis.referencing.cs.DefaultCoordinateSystemAxis;
+import org.apache.sis.referencing.datum.AbstractDatum;
+import org.apache.sis.referencing.datum.DefaultGeodeticDatum;
+import org.apache.sis.referencing.datum.DefaultPrimeMeridian;
+import org.apache.sis.referencing.datum.DefaultEllipsoid;
 import org.apache.sis.parameter.DefaultParameterValue;
 import org.apache.sis.io.wkt.ElementKind;
 import org.apache.sis.io.wkt.FormattableObject;
@@ -32,6 +46,11 @@ import org.apache.sis.util.resources.Voc
 /**
  * Utility methods for referencing WKT formatting.
  *
+ * This class provides a set of {@code toFormattable(…)} for various {@link IdentifiedObject}
subtypes.
+ * It is important to <strong>not</strong> provide a generic {@code toFormattable(IdentifiedObject)}
+ * method, because the user may choose to implement more than one GeoAPI interface for the
same object.
+ * We need to be specific in order to select the right "aspect" of the given object.
+ *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.4
  * @version 0.4
@@ -45,6 +64,104 @@ public final class WKTUtilities extends 
     }
 
     /**
+     * Returns the given coordinate reference system as a formattable object.
+     *
+     * @param  object The coordinate reference system, or {@code null}.
+     * @return The given coordinate reference system as a formattable object, or {@code null}.
+     */
+    public static FormattableObject toFormattable(final CoordinateReferenceSystem object)
{
+        if (object instanceof FormattableObject) {
+            return (FormattableObject) object;
+        } else {
+            return AbstractCRS.castOrCopy(object);
+        }
+    }
+
+    /**
+     * Returns the given coordinate system as a formattable object.
+     *
+     * @param  object The coordinate system, or {@code null}.
+     * @return The given coordinate system as a formattable object, or {@code null}.
+     */
+    public static FormattableObject toFormattable(final CoordinateSystem object) {
+        if (object instanceof FormattableObject) {
+            return (FormattableObject) object;
+        } else {
+            return AbstractCS.castOrCopy(object);
+        }
+    }
+
+    /**
+     * Returns the given coordinate system axis as a formattable object.
+     *
+     * @param  object The coordinate system axis, or {@code null}.
+     * @return The given coordinate system axis as a formattable object, or {@code null}.
+     */
+    public static FormattableObject toFormattable(final CoordinateSystemAxis object) {
+        if (object instanceof FormattableObject) {
+            return (FormattableObject) object;
+        } else {
+            return DefaultCoordinateSystemAxis.castOrCopy(object);
+        }
+    }
+
+    /**
+     * Returns the given datum as a formattable object.
+     *
+     * @param  object The datum, or {@code null}.
+     * @return The given datum as a formattable object, or {@code null}.
+     */
+    public static FormattableObject toFormattable(final Datum object) {
+        if (object instanceof FormattableObject) {
+            return (FormattableObject) object;
+        } else {
+            return AbstractDatum.castOrCopy(object);
+        }
+    }
+
+    /**
+     * Returns the given geodetic datum as a formattable object.
+     *
+     * @param  object The datum, or {@code null}.
+     * @return The given datum as a formattable object, or {@code null}.
+     */
+    public static FormattableObject toFormattable(final GeodeticDatum object) {
+        if (object instanceof FormattableObject) {
+            return (FormattableObject) object;
+        } else {
+            return DefaultGeodeticDatum.castOrCopy(object);
+        }
+    }
+
+    /**
+     * Returns the ellipsoid as a formattable object.
+     *
+     * @param  object The ellipsoid, or {@code null}.
+     * @return The given ellipsoid as a formattable object, or {@code null}.
+     */
+    public static FormattableObject toFormattable(final Ellipsoid object) {
+        if (object instanceof FormattableObject) {
+            return (FormattableObject) object;
+        } else {
+            return DefaultEllipsoid.castOrCopy(object);
+        }
+    }
+
+    /**
+     * Returns the given prime meridian as a formattable object.
+     *
+     * @param  object The prime meridian, or {@code null}.
+     * @return The given prime meridian as a formattable object, or {@code null}.
+     */
+    public static FormattableObject toFormattable(final PrimeMeridian object) {
+        if (object instanceof FormattableObject) {
+            return (FormattableObject) object;
+        } else {
+            return DefaultPrimeMeridian.castOrCopy(object);
+        }
+    }
+
+    /**
      * Appends the name of the given object to the formatter.
      *
      * @param object    The object from which to get the name.

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java?rev=1570196&r1=1570195&r2=1570196&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java
[UTF-8] Thu Feb 20 14:13:18 2014
@@ -38,6 +38,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;
 
 // Related to JDK7
@@ -424,7 +425,7 @@ public class AbstractCRS extends Abstrac
         final Unit<?> unit    = ReferencingUtilities.getUnit(cs);
         final Unit<?> oldUnit = formatter.addContextualUnit(unit);
         formatter.newLine();
-        formatter.append(getDatum());
+        formatter.append(toFormattable(getDatum()));
         formatter.newLine();
         if (isWKT1) { // WKT 1 writes unit before axes, while WKT 2 writes them after axes.
             formatter.append(unit);
@@ -432,13 +433,13 @@ public class AbstractCRS extends Abstrac
                 formatter.setInvalidWKT(this, null);
             }
         } else {
-            formatter.append(cs); // The concept of CoordinateSystem was not explicit in
WKT 1.
+            formatter.append(toFormattable(cs)); // The concept of CoordinateSystem was not
explicit in WKT 1.
             formatter.indent(+1);
         }
         final int dimension = cs.getDimension();
         for (int i=0; i<dimension; i++) {
             formatter.newLine();
-            formatter.append(cs.getAxis(i));
+            formatter.append(toFormattable(cs.getAxis(i)));
         }
         if (!isWKT1) { // WKT 2 writes unit after axes, while WKT 1 wrote them before axes.
             formatter.newLine();

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultCompoundCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultCompoundCRS.java?rev=1570196&r1=1570195&r2=1570196&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultCompoundCRS.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultCompoundCRS.java
[UTF-8] Thu Feb 20 14:13:18 2014
@@ -44,6 +44,7 @@ import org.apache.sis.io.wkt.Convention;
 
 import static org.apache.sis.util.ArgumentChecks.*;
 import static org.apache.sis.util.Utilities.deepEquals;
+import static org.apache.sis.internal.referencing.WKTUtilities.toFormattable;
 
 
 /**
@@ -408,7 +409,7 @@ public class DefaultCompoundCRS extends 
                 (isWKT1 || convention == Convention.INTERNAL) ? components : singles)
         {
             formatter.newLine();
-            formatter.append(element);
+            formatter.append(toFormattable(element));
         }
         formatter.newLine(); // For writing the ID[…] element on its own line.
         return isWKT1 ? "Compd_CS" : "CompoundCRS";

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeodeticCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeodeticCRS.java?rev=1570196&r1=1570195&r2=1570196&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeodeticCRS.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeodeticCRS.java
[UTF-8] Thu Feb 20 14:13:18 2014
@@ -33,6 +33,7 @@ import org.apache.sis.referencing.Abstra
 import org.apache.sis.io.wkt.Formatter;
 
 import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
+import static org.apache.sis.internal.referencing.WKTUtilities.toFormattable;
 
 
 /**
@@ -171,10 +172,10 @@ class DefaultGeodeticCRS extends Abstrac
         final Unit<?> unit    = getUnit();
         final Unit<?> oldUnit = formatter.addContextualUnit(unit);
         formatter.newLine();
-        formatter.append(datum);
+        formatter.append(toFormattable(datum));
         formatter.newLine();
         formatter.indent(isWKT1 ? 0 : +1);
-        formatter.append(datum.getPrimeMeridian());
+        formatter.append(toFormattable(datum.getPrimeMeridian()));
         formatter.indent(isWKT1 ? 0 : -1);
         formatter.newLine();
         CoordinateSystem cs = super.getCoordinateSystem();
@@ -197,13 +198,13 @@ class DefaultGeodeticCRS extends Abstrac
                 }
             }
         } else {
-            formatter.append(cs); // The concept of CoordinateSystem was not explicit in
WKT 1.
+            formatter.append(toFormattable(cs)); // The concept of CoordinateSystem was not
explicit in WKT 1.
             formatter.indent(+1);
         }
         final int dimension = cs.getDimension();
         for (int i=0; i<dimension; i++) {
             formatter.newLine();
-            formatter.append(cs.getAxis(i));
+            formatter.append(toFormattable(cs.getAxis(i)));
         }
         if (!isWKT1) { // WKT 2 writes unit after axes, while WKT 1 wrote them before axes.
             formatter.newLine();

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java?rev=1570196&r1=1570195&r2=1570196&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java
[UTF-8] Thu Feb 20 14:13:18 2014
@@ -38,11 +38,11 @@ import org.apache.sis.internal.util.Coll
 import org.apache.sis.util.logging.Logging;
 import org.apache.sis.util.ComparisonMode;
 import org.apache.sis.io.wkt.Formatter;
-import org.apache.sis.io.wkt.FormattableObject;
 
 import static org.apache.sis.util.Utilities.deepEquals;
 import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
 import static org.apache.sis.util.ArgumentChecks.ensureNonNullElement;
+import static org.apache.sis.internal.referencing.WKTUtilities.toFormattable;
 
 // Related to JDK7
 import java.util.Objects;
@@ -522,8 +522,7 @@ public class DefaultGeodeticDatum extend
     protected String formatTo(final Formatter formatter) {
         super.formatTo(formatter);
         formatter.newLine();
-        formatter.append(ellipsoid instanceof FormattableObject ? (FormattableObject) ellipsoid
:
-                         DefaultEllipsoid.castOrCopy(ellipsoid));
+        formatter.append(toFormattable(ellipsoid));
         if (formatter.getConvention().majorVersion() == 1) {
             /*
              * Note that at the different of other datum (in particular vertical datum),



Mime
View raw message