sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1567067 - in /sis/branches/JDK7/core: sis-metadata/src/main/java/org/apache/sis/io/wkt/ sis-referencing/src/main/java/org/apache/sis/parameter/ sis-referencing/src/main/java/org/apache/sis/referencing/crs/ sis-referencing/src/main/java/org...
Date Tue, 11 Feb 2014 11:46:51 GMT
Author: desruisseaux
Date: Tue Feb 11 11:46:50 2014
New Revision: 1567067

URL: http://svn.apache.org/r1567067
Log:
Implemented WKT in DefaultParameterValue.

Modified:
    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/parameter/DefaultParameterValue.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/DefaultGeocentricCRS.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.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/test/java/org/apache/sis/parameter/DefaultParameterValueTest.java

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=1567067&r1=1567066&r2=1567067&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] Tue Feb 11 11:46:50 2014
@@ -515,10 +515,10 @@ public class Formatter implements Locali
         String keyword = object.formatTo(this);
         if (keyword == null) {
             if (info != null) {
-                setInvalidWKT(info);
+                setInvalidWKT(info, null);
                 keyword = getName(info.getClass());
             } else {
-                setInvalidWKT(object.getClass());
+                setInvalidWKT(object.getClass(), null);
                 keyword = invalidElement;
             }
         }
@@ -1116,16 +1116,23 @@ public class Formatter implements Locali
      * to format is more complex than what the WKT specification allows.
      * Applications can test {@link #isInvalidWKT()} later for checking WKT validity.
      *
+     * <p>If any {@code setInvalidWKT(…)} method is invoked more than once during
formatting,
+     * then only information about the first failure will be retained.</p>
+     *
      * @param unformattable The object that can not be formatted,
+     * @param cause The cause for the failure to format, or {@code null} if the cause is
not an exception.
      */
-    public void setInvalidWKT(final IdentifiedObject unformattable) {
+    public void setInvalidWKT(final IdentifiedObject unformattable, final Exception cause)
{
         ArgumentChecks.ensureNonNull("unformattable", unformattable);
-        String name;
-        final ReferenceIdentifier id = unformattable.getName();
-        if (id == null || (name = id.getCode()) == null) {
-            name = getName(unformattable.getClass());
+        if (invalidElement == null) {
+            String name;
+            final ReferenceIdentifier id = unformattable.getName();
+            if (id == null || (name = id.getCode()) == null) {
+                name = getName(unformattable.getClass());
+            }
+            invalidElement = name;
+            errorCause     = cause;
         }
-        invalidElement = name;
         highlightError = true;
     }
 
@@ -1134,11 +1141,18 @@ public class Formatter implements Locali
      * This method can be used as an alternative to {@link #setInvalidWKT(IdentifiedObject)}
when the problematic
      * object is not an instance of {@code IdentifiedObject}.
      *
+     * <p>If any {@code setInvalidWKT(…)} method is invoked more than once during
formatting,
+     * then only information about the first failure will be retained.</p>
+     *
      * @param unformattable The class of the object that can not be formatted,
+     * @param cause The cause for the failure to format, or {@code null} if the cause is
not an exception.
      */
-    public void setInvalidWKT(final Class<?> unformattable) {
+    public void setInvalidWKT(final Class<?> unformattable, final Exception cause)
{
         ArgumentChecks.ensureNonNull("unformattable", unformattable);
-        invalidElement = getName(unformattable);
+        if (invalidElement == null) {
+            invalidElement = getName(unformattable);
+            errorCause     = cause;
+        }
         highlightError = true;
     }
 

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java?rev=1567067&r1=1567066&r2=1567067&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java
[UTF-8] Tue Feb 11 11:46:50 2014
@@ -31,6 +31,8 @@ import org.opengis.parameter.InvalidPara
 import org.opengis.parameter.InvalidParameterValueException;
 import org.apache.sis.io.wkt.FormattableObject;
 import org.apache.sis.io.wkt.Formatter;
+import org.apache.sis.io.wkt.ElementKind;
+import org.apache.sis.internal.referencing.WKTUtilities;
 import org.apache.sis.internal.util.Numerics;
 import org.apache.sis.util.Numbers;
 import org.apache.sis.util.resources.Errors;
@@ -686,8 +688,40 @@ public class DefaultParameterValue<T> ex
         }
     }
 
+    /**
+     * Formats this parameter as a <cite>Well Known Text</cite>.
+     *
+     * @return The {@code "PARAMETER"} keyword.
+     */
     @Override
     protected String formatTo(final Formatter formatter) {
-        return null;
+        Unit<?> unit = descriptor.getUnit();
+        if (unit != null && !Unit.ONE.equals(unit)) {
+            final Unit<?> linearUnit = formatter.getLinearUnit();
+            if (linearUnit != null && unit.isCompatible(linearUnit)) {
+                unit = linearUnit;
+            } else {
+                final Unit<?> angularUnit = formatter.getAngularUnit();
+                if (angularUnit != null && unit.isCompatible(angularUnit)) {
+                    unit = angularUnit;
+                }
+            }
+        }
+        WKTUtilities.appendName(descriptor, formatter, ElementKind.PARAMETER);
+        if (unit != null) {
+            double value;
+            try {
+                value = doubleValue(unit);
+            } catch (IllegalStateException exception) {
+                // May happen if a parameter is mandatory (e.g. "semi-major")
+                // but no value has been set for this parameter.
+                formatter.setInvalidWKT(descriptor, exception);
+                value = Double.NaN;
+            }
+            formatter.append(value);
+        } else {
+            formatter.appendAny(getValue());
+        }
+        return "PARAMETER";
     }
 }

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=1567067&r1=1567066&r2=1567067&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] Tue Feb 11 11:46:50 2014
@@ -423,7 +423,7 @@ public class AbstractCRS extends Abstrac
             formatter.append(cs.getAxis(i));
         }
         if (unit == null) {
-            formatter.setInvalidWKT(cs);
+            formatter.setInvalidWKT(cs, null);
         }
         return keyword;
     }

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java?rev=1567067&r1=1567066&r2=1567067&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java
[UTF-8] Tue Feb 11 11:46:50 2014
@@ -230,7 +230,7 @@ public class DefaultGeocentricCRS extend
             if (cs instanceof CartesianCS) {
                 cs = Legacy.forGeocentricCRS((CartesianCS) cs, true);
             } else {
-                formatter.setInvalidWKT(cs);
+                formatter.setInvalidWKT(cs, null);
             }
         }
         final int dimension = cs.getDimension();
@@ -238,7 +238,7 @@ public class DefaultGeocentricCRS extend
             formatter.append(cs.getAxis(i));
         }
         if (unit == null) {
-            formatter.setInvalidWKT(this);
+            formatter.setInvalidWKT(this, null);
         }
         return "GEOCCS";
     }

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java?rev=1567067&r1=1567066&r2=1567067&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java
[UTF-8] Tue Feb 11 11:46:50 2014
@@ -238,7 +238,7 @@ public class DefaultGeographicCRS extend
             formatter.append(cs.getAxis(i));
         }
         if (!unit.equals(getUnit())) {
-            formatter.setInvalidWKT(this);
+            formatter.setInvalidWKT(this, null);
         }
         formatter.setAngularUnit(oldUnit);
         return "GEOGCS";

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=1567067&r1=1567066&r2=1567067&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] Tue Feb 11 11:46:50 2014
@@ -641,7 +641,7 @@ public class BursaWolfParameters extends
         if (isToWGS84()) {
             return "TOWGS84";
         }
-        formatter.setInvalidWKT(BursaWolfParameters.class);
+        formatter.setInvalidWKT(BursaWolfParameters.class, null);
         String name = IdentifiedObjects.getUnicodeIdentifier(targetDatum);
         if (name == null) {
             name = "Unknown";

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=1567067&r1=1567066&r2=1567067&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] Tue Feb 11 11:46:50 2014
@@ -240,7 +240,7 @@ public class DefaultImageDatum extends A
     protected String formatTo(final Formatter formatter) {
         super.formatTo(formatter);
         formatter.append(pixelInCell);
-        formatter.setInvalidWKT(this);
+        formatter.setInvalidWKT(this, null);
         return "GENDATUM"; // Generic datum (WKT 2)
     }
 }

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueTest.java?rev=1567067&r1=1567066&r2=1567067&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueTest.java
[UTF-8] Tue Feb 11 11:46:50 2014
@@ -31,8 +31,8 @@ import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
 import static java.lang.StrictMath.*;
-import static org.apache.sis.test.Assert.*;
 import static org.opengis.test.Validators.*;
+import static org.apache.sis.test.MetadataAssert.*;
 
 
 /**
@@ -510,4 +510,13 @@ public final strictfp class DefaultParam
         final DefaultParameterValue<Double> parameter = create("Serialization test",
3, SI.METRE);
         assertNotSame(parameter, assertSerializedEquals(parameter));
     }
+
+    /**
+     * Tests WKT formatting.
+     */
+    @Test
+    public void testWKT() {
+        assertWktEquals("PARAMETER[“WKT test”, 4]", createOptional("WKT test", 4));
+        assertWktEquals("PARAMETER[“WKT test”, 30.0]", create("WKT test", 30, SI.CENTIMETRE));
+    }
 }



Mime
View raw message