sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1542818 - in /sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis: io/wkt/ referencing/datum/
Date Sun, 17 Nov 2013 21:01:48 GMT
Author: desruisseaux
Date: Sun Nov 17 21:01:47 2013
New Revision: 1542818

URL: http://svn.apache.org/r1542818
Log:
Simplification attempt: remove the Formattable interface.
This interface was initially introduced for making easier to format subclasses of java.awt.geom.AffineTransform.
However SIS will try to reduce direct dependencies to Java2D, which remove the main motivation
for Formattable interface.

Removed:
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formattable.java
Modified:
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/FormattableObject.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.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/BursaWolfParameters.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEngineeringDatum.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultImageDatum.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/DefaultVerticalDatum.java

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/FormattableObject.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/FormattableObject.java?rev=1542818&r1=1542817&r2=1542818&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/FormattableObject.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/FormattableObject.java
[UTF-8] Sun Nov 17 21:01:47 2013
@@ -27,7 +27,9 @@ import org.apache.sis.internal.util.X364
 
 /**
  * Base class for objects that can be formatted as <cite>Well Known Text</cite>
(WKT).
- * Almost every Apache SIS implementations of referencing objects extend this class.
+ * {@link WKTFormat} checks for this interface at formatting time for each element to format.
+ * When a {@code FormattableObject} element is found, its {@link #formatTo(Formatter)} method
+ * is invoked for allowing the element to control its formatting.
  *
  * <p>This class provides two methods for getting a default <cite>Well Known
Text</cite>
  * representation of this object:</p>
@@ -52,7 +54,7 @@ import org.apache.sis.internal.util.X364
  * @version 0.4
  * @module
  */
-public class FormattableObject implements Formattable {
+public class FormattableObject {
     /**
      * The formatter for the {@link #toWKT()} and {@link #toString()} methods.
      * Formatters are not thread-safe, consequently we need a different instance for each
thread.
@@ -169,17 +171,31 @@ public class FormattableObject implement
     }
 
     /**
-     * {@inheritDoc}
+     * Formats the inner part of this <cite>Well Known Text</cite> (WKT) element
into the given formatter.
+     * This method is automatically invoked by {@link WKTFormat} when a formattable element
is found.
+     *
+     * <p>Element keyword and {@linkplain org.apache.sis.referencing.IdentifiedObjects#getIdentifierCode
+     * authority code} shall not be formatted here. For example if this formattable element
is for a
+     * {@code GEOGCS} element, then this method shall write the content starting at the insertion
point
+     * shows below:</p>
+     *
+     * {@preformat text
+     *     GEOGCS["WGS 84", AUTHORITY["EPSG","4326"]]
+     *                    ↑
+     *            (insertion point)
+     * }
      *
      * The default implementation declares that this object produces an invalid WKT.
      * Subclasses shall override this method for proper WKT formatting and shall <strong>not</strong>
      * invoke {@code super.formatTo(formatter)} if they can use a standard WKT syntax.
      *
+     * @param  formatter The formatter where to format the inner content of this WKT element.
+     * @return The WKT element keyword (e.g. {@code "GEOGCS"}).
+     *
      * @see #toWKT()
      * @see #toString()
      */
-    @Override
-    public String formatTo(final Formatter formatter) {
+    protected String formatTo(final Formatter formatter) {
         Class<?> type = getClass();
         for (final Class<?> candidate : type.getInterfaces()) {
             final String name = candidate.getName();

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.java?rev=1542818&r1=1542817&r2=1542818&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.java
[UTF-8] Sun Nov 17 21:01:47 2013
@@ -178,15 +178,14 @@ public class Formatter {
     private int margin;
 
     /**
-     * {@code true} if a new line were requested during the execution of {@link #append(Formattable)}.
-     * This is used to determine if the next {@code UNIT} and {@code AUTHORITY} elements
shall appear
-     * on a new line.
+     * {@code true} if a new line were requested during the execution of {@link #append(FormattableObject)}.
+     * This is used to determine if the next {@code UNIT} and {@code AUTHORITY} elements
shall appear on a new line.
      */
     private boolean requestNewLine;
 
     /**
      * {@code true} if the last formatted element was invalid WKT. This field is for internal
use only.
-     * It is reset to {@code false} after the invalid part has been processed by {@link #append(Formattable)}.
+     * It is reset to {@code false} after the invalid part has been processed by {@link #append(FormattableObject)}.
      */
     private boolean wasInvalidWKT;
 
@@ -393,14 +392,14 @@ public class Formatter {
     }
 
     /**
-     * Appends the given {@code Formattable} object.
+     * Appends the given {@code FormattableObject}.
      * This method will automatically append the keyword (e.g. {@code "GEOCS"}), the name
and the authority code,
      * and will invoke <code>formattable.{@linkplain FormattableObject#formatTo(Formatter)
formatTo}(this)</code>
      * for completing the inner part of the WKT.
      *
      * @param object The formattable object to append to the WKT, or {@code null} if none.
      */
-    public void append(final Formattable object) {
+    public void append(final FormattableObject object) {
         if (object == null) {
             return;
         }
@@ -492,9 +491,8 @@ public class Formatter {
      */
     public void append(final IdentifiedObject object) {
         if (object != null) {
-            append((object instanceof Formattable)
-                    ? (Formattable) object
-                    : AbstractIdentifiedObject.castOrCopy(object));
+            append(object instanceof FormattableObject ? (FormattableObject) object :
+                   AbstractIdentifiedObject.castOrCopy(object));
         }
     }
 
@@ -505,11 +503,11 @@ public class Formatter {
      */
     public void append(final MathTransform transform) {
         if (transform != null) {
-            if (transform instanceof Formattable) {
-                append((Formattable) transform);
+            if (transform instanceof FormattableObject) {
+                append((FormattableObject) transform);
             } else {
                 throw new UnformattableObjectException(Errors.format(
-                        Errors.Keys.IllegalClass_2, Formattable.class, transform.getClass()));
+                        Errors.Keys.IllegalClass_2, FormattableObject.class, transform.getClass()));
             }
         }
     }

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=1542818&r1=1542817&r2=1542818&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] Sun Nov 17 21:01:47 2013
@@ -380,7 +380,7 @@ public class AbstractDatum extends Abstr
      * @return The WKT element name.
      */
     @Override
-    public String formatTo(final Formatter formatter) {
+    protected String formatTo(final Formatter formatter) {
         formatter.append(getLegacyDatumType());
         return Classes.getShortClassName(this);
     }

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/BursaWolfParameters.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/BursaWolfParameters.java?rev=1542818&r1=1542817&r2=1542818&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/BursaWolfParameters.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/BursaWolfParameters.java
[UTF-8] Sun Nov 17 21:01:47 2013
@@ -601,7 +601,7 @@ public class BursaWolfParameters extends
      * @return The WKT element name, usually {@code "TOWGS84"}.
      */
     @Override
-    public String formatTo(final Formatter formatter) {
+    protected String formatTo(final Formatter formatter) {
         formatter.append(tX);
         formatter.append(tY);
         formatter.append(tZ);

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java?rev=1542818&r1=1542817&r2=1542818&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
[UTF-8] Sun Nov 17 21:01:47 2013
@@ -715,7 +715,7 @@ public class DefaultEllipsoid extends Ab
      * @return The WKT element name, which is {@code "SPHEROID"}.
      */
     @Override
-    public String formatTo(final Formatter formatter) {
+    protected String formatTo(final Formatter formatter) {
         final double ivf = getInverseFlattening();
         formatter.append(getAxisUnit().getConverterTo(SI.METRE).convert(getSemiMajorAxis()));
         formatter.append(isInfinite(ivf) ? 0 : ivf);

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEngineeringDatum.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEngineeringDatum.java?rev=1542818&r1=1542817&r2=1542818&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEngineeringDatum.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEngineeringDatum.java
[UTF-8] Sun Nov 17 21:01:47 2013
@@ -176,7 +176,7 @@ public class DefaultEngineeringDatum ext
      * @return The WKT element name, which is {@code "LOCAL_DATUM"}.
      */
     @Override
-    public String formatTo(final Formatter formatter) {
+    protected String formatTo(final Formatter formatter) {
         super.formatTo(formatter);
         return "LOCAL_DATUM";
     }

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=1542818&r1=1542817&r2=1542818&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] Sun Nov 17 21:01:47 2013
@@ -39,7 +39,7 @@ import org.apache.sis.util.logging.Loggi
 import org.apache.sis.util.ComparisonMode;
 import org.apache.sis.util.Immutable;
 import org.apache.sis.io.wkt.Formatter;
-import org.apache.sis.io.wkt.Formattable;
+import org.apache.sis.io.wkt.FormattableObject;
 
 import static org.apache.sis.util.Utilities.deepEquals;
 import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
@@ -472,12 +472,11 @@ public class DefaultGeodeticDatum extend
      * @return The WKT element name, which is {@code "DATUM"}.
      */
     @Override
-    public String formatTo(final Formatter formatter) {
+    protected String formatTo(final Formatter formatter) {
         // Do NOT invokes the super-class method, because
         // horizontal datum do not write the datum type.
-        formatter.append((ellipsoid instanceof Formattable)
-                ? (Formattable) ellipsoid
-                : DefaultEllipsoid.castOrCopy(ellipsoid));
+        formatter.append(ellipsoid instanceof FormattableObject ? (FormattableObject) ellipsoid
:
+                         DefaultEllipsoid.castOrCopy(ellipsoid));
         if (bursaWolf != null) {
             for (final BursaWolfParameters candidate : bursaWolf) {
                 if (candidate.isToWGS84()) {

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultImageDatum.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultImageDatum.java?rev=1542818&r1=1542817&r2=1542818&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultImageDatum.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultImageDatum.java
[UTF-8] Sun Nov 17 21:01:47 2013
@@ -224,7 +224,7 @@ public class DefaultImageDatum extends A
      * @return The WKT element name.
      */
     @Override
-    public String formatTo(final Formatter formatter) {
+    protected String formatTo(final Formatter formatter) {
         super.formatTo(formatter);
         formatter.append(pixelInCell);
         formatter.setInvalidWKT("ImageDatum");

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=1542818&r1=1542817&r2=1542818&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] Sun Nov 17 21:01:47 2013
@@ -288,8 +288,7 @@ public class DefaultPrimeMeridian extend
      * @return The WKT element name, which is {@code "PRIMEM"}.
      */
     @Override
-    @SuppressWarnings("fallthrough")
-    public String formatTo(final Formatter formatter) {
+    protected String formatTo(final Formatter formatter) {
         /*
          * If the PrimeMeridian is written inside a "GEOGCS", then OGC say that it must be
          * written in the unit of the enclosing geographic coordinate system. Otherwise,

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=1542818&r1=1542817&r2=1542818&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] Sun Nov 17 21:01:47 2013
@@ -293,7 +293,7 @@ public class DefaultVerticalDatum extend
      * @return The WKT element name, which is {@code "VERT_DATUM"}.
      */
     @Override
-    public String formatTo(final Formatter formatter) {
+    protected String formatTo(final Formatter formatter) {
         super.formatTo(formatter);
         return "VERT_DATUM";
     }



Mime
View raw message