sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1554066 - in /sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis: io/wkt/ referencing/cs/ referencing/datum/
Date Sun, 29 Dec 2013 20:58:16 GMT
Author: desruisseaux
Date: Sun Dec 29 20:58:15 2013
New Revision: 1554066

URL: http://svn.apache.org/r1554066
Log:
Minor API adjustment:
- BursaWolfParameters.targetDatum is optional
- Formatter.setInvalidWKT(...) accept IdentifiedObject or Class argument.

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/io/wkt/WKTFormat.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCartesianCS.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/DefaultImageDatum.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/TimeDependentBWP.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=1554066&r1=1554065&r2=1554066&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 Dec 29 20:58:15 2013
@@ -21,7 +21,6 @@ import java.io.PrintWriter;
 import javax.xml.bind.annotation.XmlTransient;
 import org.opengis.parameter.GeneralParameterValue;
 import org.apache.sis.util.Debug;
-import org.apache.sis.util.Classes;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.internal.util.X364;
 
@@ -82,7 +81,7 @@ public class FormattableObject {
      * @see org.opengis.referencing.IdentifiedObject#toWKT()
      */
     public String toWKT() throws UnformattableObjectException {
-        return formatWKT(Convention.OGC, false, true);
+        return formatWKT(Convention.OGC, WKTFormat.DEFAULT_INDENTATION, false, true);
     }
 
     /**
@@ -94,7 +93,7 @@ public class FormattableObject {
      */
     @Override
     public String toString() {
-        return formatWKT(Convention.OGC, false, false);
+        return formatWKT(Convention.OGC, WKTFormat.DEFAULT_INDENTATION, false, false);
     }
 
     /**
@@ -108,7 +107,7 @@ public class FormattableObject {
      */
     public String toString(final Convention convention) {
         ArgumentChecks.ensureNonNull("convention", convention);
-        return formatWKT(convention, false, false);
+        return formatWKT(convention, WKTFormat.DEFAULT_INDENTATION, false, false);
     }
 
     /**
@@ -123,7 +122,8 @@ public class FormattableObject {
     public void print() {
         final Console console = System.console();
         final PrintWriter out = (console != null) ? console.writer() : null;
-        final String wkt = formatWKT(Convention.OGC, (out != null) && X364.isAnsiSupported(),
false);
+        final String wkt = formatWKT(Convention.OGC, WKTFormat.DEFAULT_INDENTATION,
+                (out != null) && X364.isAnsiSupported(), false);
         if (out != null) {
             out.println(wkt);
         } else {
@@ -135,14 +135,15 @@ public class FormattableObject {
      * Returns a WKT for this object using the specified convention.
      * If {@code strict} is true, then an exception is thrown if the WKT is not standard-compliant.
      *
-     * @param  convention The convention for choosing WKT entities names.
-     * @param  colorize   {@code true} for applying syntax coloring, or {@code false} otherwise.
-     * @param  strict     {@code true} if an exception shall be thrown for unformattable
objects,
-     *                    or {@code false} for providing a non-standard formatting instead.
+     * @param  convention  The convention for choosing WKT entities names.
+     * @param  indentation The indentation to apply, or {@link WKTFormat#SINGLE_LINE}.
+     * @param  colorize    {@code true} for applying syntax coloring, or {@code false} otherwise.
+     * @param  strict      {@code true} if an exception shall be thrown for unformattable
objects,
+     *                     or {@code false} for providing a non-standard formatting instead.
      * @return The Well Known Text (WKT) or a pseudo-WKT representation of this object.
      * @throws UnformattableObjectException If {@code strict} is {@code true} and this object
can not be formatted.
      */
-    private String formatWKT(final Convention convention, final boolean colorize, final boolean
strict)
+    final String formatWKT(final Convention convention, final byte indentation, final boolean
colorize, final boolean strict)
              throws UnformattableObjectException
     {
         Formatter formatter = FORMATTER.get();
@@ -150,6 +151,7 @@ public class FormattableObject {
             formatter = new Formatter();
             FORMATTER.set(formatter);
         }
+        formatter.indentation = indentation;
         formatter.colors = colorize ? Colors.DEFAULT : null;
         formatter.setConvention(convention, null);
         try {
@@ -164,7 +166,10 @@ public class FormattableObject {
                 formatter.append(this);
             }
             if (strict) {
-                formatter.ensureValidWKT();
+                final String message = formatter.getErrorMessage();
+                if (message != null) {
+                    throw new UnformattableObjectException(message, formatter.errorCause);
+                }
             }
             return formatter.toString();
         } finally {
@@ -198,16 +203,11 @@ public class FormattableObject {
      * @see #toString()
      */
     protected String formatTo(final Formatter formatter) {
-        Class<?> type = getClass();
-        for (final Class<?> candidate : type.getInterfaces()) {
-            final String name = candidate.getName();
-            if (name.startsWith("org.opengis.") && !name.startsWith("org.opengis.util."))
{
-                type = candidate;
-                break;
-            }
+        formatter.setInvalidWKT(getClass());
+        String name = formatter.invalidElement;
+        if (name == null) { // May happen if the user override Formatter.setInvalidWKT(Class).
+            name = "UNKNOWN";
         }
-        final String name = Classes.getShortName(type);
-        formatter.setInvalidWKT(name);
         return name;
     }
 }

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=1554066&r1=1554065&r2=1554066&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 Dec 29 20:58:15 2013
@@ -41,6 +41,7 @@ import org.opengis.util.CodeList;
 
 import org.apache.sis.measure.Units;
 import org.apache.sis.math.DecimalFunctions;
+import org.apache.sis.util.Classes;
 import org.apache.sis.util.Numbers;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.ArgumentChecks;
@@ -169,7 +170,7 @@ public class Formatter {
      * The amount of spaces to use in indentation, or {@value org.apache.sis.io.wkt.WKTFormat#SINGLE_LINE}
      * if indentation is disabled.
      */
-    int indentation;
+    byte indentation;
 
     /**
      * The amount of space to write on the left side of each line. This amount is increased
@@ -185,25 +186,28 @@ public class Formatter {
     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(FormattableObject)}.
+     * {@code true} if the last formatted element was invalid WKT and shall be highlighted
with syntatic coloration.
+     * This field has no effect if {@link #colors} is null. This field is reset to {@code
false} after the invalid
+     * part has been processed by {@link #append(FormattableObject)}, in order to highlight
only the first erroneous
+     * element without clearing the {@link #invalidElement} value.
      */
-    private boolean wasInvalidWKT;
+    private boolean highlightError;
 
     /**
      * Non-null if the WKT is invalid. If non-null, then this field contains a keyword that
identify the
      * problematic part.
      *
      * @see #isInvalidWKT()
+     * @see #getErrorMessage()
      */
-    private String unformattable;
+    String invalidElement;
 
     /**
-     * Warning that may be produced during WKT formatting, or {@code null} if none.
+     * Error that occurred during WKT formatting, or {@code null} if none.
      *
-     * @see #isInvalidWKT()
+     * @see #getErrorMessage()
      */
-    private Exception warning;
+    Exception errorCause;
 
     /**
      * Creates a new formatter instance with the default symbols, no syntax coloring and
the default indentation.
@@ -222,15 +226,12 @@ public class Formatter {
      *        or {@link WKTFormat#SINGLE_LINE} for formatting the whole WKT on a single line.
      */
     public Formatter(final Convention convention, final Symbols symbols, final Colors colors,
final int indentation) {
-        ArgumentChecks.ensureNonNull("convention", convention);
-        ArgumentChecks.ensureNonNull("symbols", symbols);
-        if (indentation < WKTFormat.SINGLE_LINE) {
-            throw new IllegalArgumentException(Errors.format(
-                    Errors.Keys.IllegalArgumentValue_2, "indentation", indentation));
-        }
+        ArgumentChecks.ensureNonNull("convention",  convention);
+        ArgumentChecks.ensureNonNull("symbols",     symbols);
+        ArgumentChecks.ensureBetween("indentation", WKTFormat.SINGLE_LINE, Byte.MAX_VALUE,
indentation);
         this.convention   = convention;
         this.symbols      = symbols.immutable();
-        this.indentation  = indentation;
+        this.indentation  = (byte) indentation;
         this.numberFormat = symbols.createNumberFormat();
         this.unitFormat   = UnitFormat.getInstance(symbols.getLocale());
         this.buffer       = new StringBuffer();
@@ -441,8 +442,8 @@ public class Formatter {
         indent(+1);
         requestNewLine = false;
         String keyword = object.formatTo(this);
-        if (colors != null && wasInvalidWKT) {
-            wasInvalidWKT = false;
+        if (colors != null && highlightError) {
+            highlightError = false;
             final String color = colors.getAnsiSequence(ElementKind.ERROR);
             if (color != null) {
                 buffer.insert(base, color + BACKGROUND_DEFAULT);
@@ -572,7 +573,8 @@ public class Formatter {
                             buffer.insert(stop, BACKGROUND_DEFAULT).insert(start, c);
                         }
                     }
-                    warning = exception;
+                    setInvalidWKT(descriptor);
+                    errorCause = exception;
                     value = Double.NaN;
                 }
                 format(value);
@@ -779,7 +781,7 @@ public class Formatter {
      * @return {@code true} if the WKT is invalid.
      */
     public boolean isInvalidWKT() {
-        return unformattable != null || (buffer != null && buffer.length() == 0);
+        return (invalidElement != null) || (buffer != null && buffer.length() ==
0);
         /*
          * Note: we really use a "and" condition (not an other "or") for the buffer test
because
          *       the buffer is reset to 'null' by WKTFormat after a successfull formatting.
@@ -787,28 +789,51 @@ public class Formatter {
     }
 
     /**
-     * Sets a flag marking the current WKT as not strictly compliant to the
-     * <a href="http://www.geoapi.org/3.0/javadoc/org/opengis/referencing/doc-files/WKT.html">WKT
-     * specification</a>. This method is invoked by {@link FormattableObject#formatTo(Formatter)}
-     * methods when the object to format is more complex than what the WKT specification
allows.
+     * Marks the current WKT representation of the given object as not strictly compliant
to the WKT specification.
+     * This method can be invoked by implementations of {@link FormattableObject#formatTo(Formatter)}
when the object
+     * to format is more complex than what the WKT specification allows.
      * Applications can test {@link #isInvalidWKT()} later for checking WKT validity.
      *
-     * @param unformattable A keyword that identify the component that can not be formatted,
+     * @param unformattable The object that can not be formatted,
      */
-    public void setInvalidWKT(final String unformattable) {
+    public void setInvalidWKT(final IdentifiedObject unformattable) {
         ArgumentChecks.ensureNonNull("unformattable", unformattable);
-        this.unformattable = unformattable;
-        wasInvalidWKT = true;
+        String name = getName(unformattable);
+        if (name != null) {
+            invalidElement = name;
+            highlightError = true;
+        } else {
+            setInvalidWKT(unformattable.getClass());
+        }
     }
 
     /**
-     * Throws an exception if {@link #isInvalidWKT()} is set.
+     * Marks the current WKT representation of the given class as not strictly compliant
to the WKT specification.
+     * This method can be used as an alternative to {@link #setInvalidWKT(IdentifiedObject)}
when the problematic
+     * object is not an instance of {@code IdentifiedObject}.
+     *
+     * @param unformattable The class of the object that can not be formatted,
      */
-    final void ensureValidWKT() throws UnformattableObjectException {
-        if (isInvalidWKT()) {
-            throw new UnformattableObjectException(Errors.format(
-                    Errors.Keys.CanNotRepresentInFormat_2, "WKT", unformattable), warning);
+    public void setInvalidWKT(Class<?> unformattable) {
+        ArgumentChecks.ensureNonNull("unformattable", unformattable);
+        if (!unformattable.isInterface()) {
+            for (final Class<?> candidate : unformattable.getInterfaces()) {
+                if (candidate.getName().startsWith("org.opengis.")) {
+                    unformattable = candidate;
+                    break;
+                }
+            }
         }
+        invalidElement = Classes.getShortName(unformattable);
+        highlightError = true;
+    }
+
+    /**
+     * Returns the error message {@link #isInvalidWKT()} is set, or {@code null} otherwise.
+     * If non-null, a cause may be available in the {@link #errorCause} field.
+     */
+    final String getErrorMessage() {
+        return isInvalidWKT() ? Errors.format(Errors.Keys.CanNotRepresentInFormat_2, "WKT",
invalidElement) : null;
     }
 
     /**
@@ -822,19 +847,23 @@ public class Formatter {
     }
 
     /**
-     * Clears this formatter. All properties (including {@linkplain #getLinearUnit() unit}
-     * and {@linkplain #isInvalidWKT() WKT validity flag} are reset to their default value.
-     * After this method call, this {@code Formatter} object is ready for formatting a new
object.
+     * Clears this formatter before formatting a new object. This method clears the
+     * {@linkplain #getLinearUnit() linear unit} and {@linkplain #isInvalidWKT() WKT validity
flag}.
      */
     public void clear() {
+        /*
+         * Configuration options (indentation, colors, conventions) are left unchanged.
+         * We do not mention that fact in the Javadoc because those options do not appear
+         * in the Formatter public API (they are in the WKTFormat API instead).
+         */
         if (buffer != null) {
             buffer.setLength(0);
         }
         linearUnit     = null;
         angularUnit    = null;
-        unformattable  = null;
-        warning        = null;
-        wasInvalidWKT  = false;
+        invalidElement = null;
+        errorCause     = null;
+        highlightError = false;
         requestNewLine = false;
         margin         = 0;
     }

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/WKTFormat.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/WKTFormat.java?rev=1554066&r1=1554065&r2=1554066&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/WKTFormat.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/WKTFormat.java
[UTF-8] Sun Dec 29 20:58:15 2013
@@ -27,5 +27,5 @@ public class WKTFormat {
     /**
      * The default indentation value.
      */
-    static final int DEFAULT_INDENTATION = 2;
+    static final byte DEFAULT_INDENTATION = 2;
 }

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCartesianCS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCartesianCS.java?rev=1554066&r1=1554065&r2=1554066&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCartesianCS.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCartesianCS.java
[UTF-8] Sun Dec 29 20:58:15 2013
@@ -64,7 +64,7 @@ public class DefaultCartesianCS extends 
     private static final long serialVersionUID = -6182037957705712945L;
 
     @Deprecated
-    public static final DefaultCartesianCS GEOCENTRIC = null; // TODO: Not supported yet.
+    public static DefaultCartesianCS GEOCENTRIC = null; // TODO: Not supported yet.
 
     /**
      * Constructs a one-dimensional coordinate system from a set of properties.

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=1554066&r1=1554065&r2=1554066&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 Dec 29 20:58:15 2013
@@ -226,7 +226,7 @@ public class BursaWolfParameters extends
     public double dS;
 
     /**
-     * The target datum for this set of parameters.
+     * The target datum for this set of parameters, or {@code null} if unknown.
      * This is usually the WGS 84 datum, but other targets are allowed.
      *
      * <p>The source datum is the {@link DefaultGeodeticDatum} that contain this {@code
BursaWolfParameters}
@@ -254,12 +254,11 @@ public class BursaWolfParameters extends
      * <p>Alternatively, numerical fields can also be initialized by a call to
      * {@link #setPositionVectorTransformation(Matrix, double)}.</p>
      *
-     * @param targetDatum The target datum (usually WGS 84) for this set of parameters.
+     * @param targetDatum The target datum (usually WGS 84) for this set of parameters, or
{@code null} if unknown.
      * @param domainOfValidity Area or region in which a coordinate transformation based
on those Bursa-Wolf parameters
      *        is valid, or {@code null} is unspecified.
      */
     public BursaWolfParameters(final GeodeticDatum targetDatum, final Extent domainOfValidity)
{
-        ensureNonNull("targetDatum", targetDatum);
         this.targetDatum = targetDatum;
         this.domainOfValidity = domainOfValidity;
     }
@@ -278,13 +277,13 @@ public class BursaWolfParameters extends
     }
 
     /**
-     * Returns the target datum for this set of parameters.
+     * Returns the target datum for this set of parameters, or {@code null} if unknown.
      * This is usually the WGS 84 datum, but other targets are allowed.
      *
      * <p>The source datum is the {@link DefaultGeodeticDatum} that contain this {@code
BursaWolfParameters}
      * instance.</p>
      *
-     * @return The target datum for this set of parameters.
+     * @return The target datum for this set of parameters, or {@code null} if unknown.
      */
     public GeodeticDatum getTargetDatum() {
         return targetDatum;
@@ -298,8 +297,9 @@ public class BursaWolfParameters extends
      * @return {@code true} if the given datum is equal to WGS84 for computational purpose.
      */
     final boolean isToWGS84() {
-        return IdentifiedObjects.isHeuristicMatchForName(targetDatum, "WGS 84") ||
-               IdentifiedObjects.isHeuristicMatchForName(targetDatum, "WGS84");
+        return (targetDatum != null) &&
+               (IdentifiedObjects.isHeuristicMatchForName(targetDatum, "WGS 84") ||
+                IdentifiedObjects.isHeuristicMatchForName(targetDatum, "WGS84"));
     }
 
     /**
@@ -322,6 +322,18 @@ public class BursaWolfParameters extends
     }
 
     /**
+     * Inverts in-place the sign of rotation terms ({@link #rX}, {@link #rY}, {@link #rZ}).
+     * This method can be invoked for converting a <cite>Coordinate Frame Rotation</cite>
transformation
+     * (EPSG operation method 9607) to a <em>Position Vector</em> transformation
(EPSG operation method 9606).
+     * The later convention is used by IAG and recommended by ISO 19111.
+     */
+    public void reverseRotation() {
+        rX = -rX;
+        rY = -rY;
+        rZ = -rZ;
+    }
+
+    /**
      * Inverts in-place the transformation by inverting the sign of all numerical parameters.
      * The {@linkplain #getPositionVectorTransformation(Date) position vector transformation}
matrix
      * created from inverted Bursa-Wolf parameters will be <strong>approximatively</strong>
equals

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=1554066&r1=1554065&r2=1554066&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 Dec 29 20:58:15 2013
@@ -236,7 +236,7 @@ public class DefaultImageDatum extends A
     protected String formatTo(final Formatter formatter) {
         super.formatTo(formatter);
         formatter.append(pixelInCell);
-        formatter.setInvalidWKT("ImageDatum");
+        formatter.setInvalidWKT(this);
         return "GENDATUM"; // Generic datum (WKT 2)
     }
 }

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/TimeDependentBWP.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/TimeDependentBWP.java?rev=1554066&r1=1554065&r2=1554066&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/TimeDependentBWP.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/TimeDependentBWP.java
[UTF-8] Sun Dec 29 20:58:15 2013
@@ -217,6 +217,20 @@ public class TimeDependentBWP extends Bu
     }
 
     /**
+     * Inverts in-place the sign of rotation terms and their derivative.
+     * This method can be invoked for converting a <cite>Coordinate Frame Rotation</cite>
transformation
+     * (EPSG operation method 9607) to a <em>Position Vector</em> transformation
(EPSG operation method 9606).
+     * The later convention is used by IAG and recommended by ISO 19111.
+     */
+    @Override
+    public void reverseRotation() {
+        super.reverseRotation();
+        drX = -drX;
+        drY = -drY;
+        drZ = -drZ;
+    }
+
+    /**
      * {@inheritDoc}
      */
     @Override



Mime
View raw message