sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1689423 - in /sis/branches/JDK8/core: sis-metadata/src/main/java/org/apache/sis/io/wkt/ sis-metadata/src/test/java/org/apache/sis/io/wkt/ sis-referencing/src/test/java/org/apache/sis/io/wkt/
Date Mon, 06 Jul 2015 15:19:11 GMT
Author: desruisseaux
Date: Mon Jul  6 15:19:10 2015
New Revision: 1689423

URL: http://svn.apache.org/r1689423
Log:
Log a warning when a WKT can not be fully parsed.

Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/AbstractParser.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/MathTransformParser.java
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/io/wkt/ElementTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/GeodeticObjectParserTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/MathTransformParserTest.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/AbstractParser.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/AbstractParser.java?rev=1689423&r1=1689422&r2=1689423&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/AbstractParser.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/AbstractParser.java
[UTF-8] Mon Jul  6 15:19:10 2015
@@ -26,6 +26,9 @@ import java.text.NumberFormat;
 import java.text.DecimalFormat;
 import java.text.ParsePosition;
 import java.text.ParseException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.logging.LogRecord;
 import javax.measure.unit.Unit;
 import javax.measure.unit.UnitFormat;
 import org.opengis.util.FactoryException;
@@ -33,6 +36,7 @@ import org.opengis.util.InternationalStr
 import org.apache.sis.internal.util.StandardDateFormat;
 import org.apache.sis.measure.Units;
 import org.apache.sis.util.Workaround;
+import org.apache.sis.util.logging.Logging;
 
 import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
 
@@ -85,6 +89,13 @@ abstract class AbstractParser implements
     static final boolean SCIENTIFIC_NOTATION = true;
 
     /**
+     * The logger to use for reporting warnings when this parser is used through the {@link
#createFromWKT(String)}.
+     * This happen most often when the user invoke the {@link org.apache.sis.referencing.CRS#fromWKT(String)}
+     * convenience method.
+     */
+    private static final Logger LOGGER = Logging.getLogger(AbstractParser.class);
+
+    /**
      * The locale for error messages (not for number parsing), or {@code null} for the system
default.
      */
     final Locale errorLocale;
@@ -177,6 +188,12 @@ abstract class AbstractParser implements
     }
 
     /**
+     * Returns the name of the class providing the publicly-accessible {@code createFromWKT(String)}
method.
+     * This information is used for logging purpose only.
+     */
+    abstract String getPublicFacade();
+
+    /**
      * Creates the object from a string. This method is for implementation of {@code createFromWKT(String)}
      * method is SIS factories only.
      *
@@ -189,8 +206,9 @@ abstract class AbstractParser implements
      */
     @Override
     public final Object createFromWKT(final String text) throws FactoryException {
+        final Object value;
         try {
-            return parseObject(text, new ParsePosition(0));
+            value = parseObject(text, new ParsePosition(0));
         } catch (ParseException exception) {
             final Throwable cause = exception.getCause();
             if (cause instanceof FactoryException) {
@@ -198,6 +216,15 @@ abstract class AbstractParser implements
             }
             throw new FactoryException(exception.getMessage(), exception);
         }
+        final Warnings warnings = getAndClearWarnings(value);
+        if (warnings != null) {
+            final LogRecord record = new LogRecord(Level.WARNING, warnings.toString());
+            record.setSourceClassName(getPublicFacade());
+            record.setSourceMethodName("createFromWKT");
+            record.setLoggerName(LOGGER.getName());
+            LOGGER.log(record);
+        }
+        return value;
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java?rev=1689423&r1=1689422&r2=1689423&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java
[UTF-8] Mon Jul  6 15:19:10 2015
@@ -249,6 +249,15 @@ final class GeodeticObjectParser extends
     }
 
     /**
+     * Returns the name of the class providing the publicly-accessible {@code createFromWKT(String)}
method.
+     * This information is used for logging purpose only.
+     */
+    @Override
+    String getPublicFacade() {
+        return "org.apache.sis.referencing.factory.GeodeticObjectFactory";
+    }
+
+    /**
      * Parses a <cite>Well Know Text</cite> (WKT).
      *
      * @param  text The text to be parsed.

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/MathTransformParser.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/MathTransformParser.java?rev=1689423&r1=1689422&r2=1689423&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/MathTransformParser.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/MathTransformParser.java
[UTF-8] Mon Jul  6 15:19:10 2015
@@ -36,7 +36,6 @@ import org.opengis.referencing.operation
 import org.opengis.referencing.operation.MathTransformFactory;
 import org.opengis.referencing.operation.NoninvertibleTransformException;
 import org.opengis.referencing.operation.OperationMethod;
-import org.apache.sis.internal.system.DefaultFactories;
 import org.apache.sis.internal.metadata.WKTKeywords;
 import org.apache.sis.internal.metadata.ReferencingServices;
 import org.apache.sis.internal.util.LocalizedParseException;
@@ -102,13 +101,6 @@ class MathTransformParser extends Abstra
     private transient OperationMethod lastMethod;
 
     /**
-     * Creates a parser using the default set of symbols and factory.
-     */
-    public MathTransformParser() {
-        this(DefaultFactories.forBuildin(MathTransformFactory.class));
-    }
-
-    /**
      * Creates a parser for the given factory.
      *
      * <p><b>Maintenance note:</b> this constructor is invoked through
reflection by
@@ -141,6 +133,15 @@ class MathTransformParser extends Abstra
     }
 
     /**
+     * Returns the name of the class providing the publicly-accessible {@code createFromWKT(String)}
method.
+     * This information is used for logging purpose only.
+     */
+    @Override
+    String getPublicFacade() {
+        return "org.apache.sis.referencing.operation.transform.DefaultMathTransformFactory";
+    }
+
+    /**
      * Parses the next element in the specified <cite>Well Know Text</cite> (WKT)
tree.
      *
      * @param  element The element to be parsed.

Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/io/wkt/ElementTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/io/wkt/ElementTest.java?rev=1689423&r1=1689422&r2=1689423&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/io/wkt/ElementTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/io/wkt/ElementTest.java
[UTF-8] Mon Jul  6 15:19:10 2015
@@ -41,6 +41,10 @@ public final strictfp class ElementTest
      * A dummy parser to be given to the {@link Element} constructor.
      */
     private final AbstractParser parser = new AbstractParser(Symbols.SQUARE_BRACKETS, null,
null, null, Locale.ENGLISH) {
+        @Override String getPublicFacade() {
+            throw new UnsupportedOperationException();
+        }
+
         @Override Object parseObject(Element element) throws ParseException {
             throw new UnsupportedOperationException();
         }

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/GeodeticObjectParserTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/GeodeticObjectParserTest.java?rev=1689423&r1=1689422&r2=1689423&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/GeodeticObjectParserTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/GeodeticObjectParserTest.java
[UTF-8] Mon Jul  6 15:19:10 2015
@@ -35,6 +35,7 @@ import org.apache.sis.internal.metadata.
 import org.apache.sis.referencing.cs.CoordinateSystems;
 import org.apache.sis.referencing.datum.BursaWolfParameters;
 import org.apache.sis.referencing.datum.DefaultGeodeticDatum;
+import org.apache.sis.referencing.factory.GeodeticObjectFactory;
 import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
@@ -72,6 +73,7 @@ public final strictfp class GeodeticObje
      */
     private void newParser(final Convention convention) {
         parser = new GeodeticObjectParser(Symbols.getDefault(), null, null, null, convention,
Transliterator.DEFAULT, null, null);
+        assertEquals(GeodeticObjectFactory.class.getCanonicalName(), parser.getPublicFacade());
     }
 
     /**
@@ -252,13 +254,13 @@ public final strictfp class GeodeticObje
     @DependsOnMethod({"testAxis", "testDatum"})
     public void testGeographicCRS() throws ParseException {
         verifyGeographicCRS(0, parse(GeographicCRS.class,
-               "  GEOGCS[“WGS 84”,\n" +
-               "    DATUM[“World Geodetic System 1984”,\n" +
-               "      SPHEROID[“WGS84”, 6378137.0, 298.257223563]],\n" +
-               "      PRIMEM[“Greenwich”, 0.0],\n" +
-               "    UNIT[“degree”, 0.017453292519943295],\n" +
-               "    AXIS[“Longitude”, EAST],\n" +
-               "    AXIS[“Latitude”, NORTH]]"));
+               "GEOGCS[“WGS 84”,\n" +
+               "  DATUM[“World Geodetic System 1984”,\n" +
+               "    SPHEROID[“WGS84”, 6378137.0, 298.257223563]],\n" +
+               "    PRIMEM[“Greenwich”, 0.0],\n" +
+               "  UNIT[“degree”, 0.017453292519943295],\n" +
+               "  AXIS[“Longitude”, EAST],\n" +
+               "  AXIS[“Latitude”, NORTH]]"));
     }
 
     /**
@@ -270,13 +272,13 @@ public final strictfp class GeodeticObje
     @DependsOnMethod("testGeographicCRS")
     public void testGeographicWithLatLonAxes() throws ParseException {
         verifyGeographicCRS(1, parse(GeographicCRS.class,
-               "  GEOGCS[“WGS 84”,\n" +
-               "    DATUM[“World Geodetic System 1984”,\n" +
-               "      SPHEROID[“WGS84”, 6378137.0, 298.257223563]],\n" +
-               "      PRIMEM[“Greenwich”, 0.0],\n" +
-               "    UNIT[“degree”, 0.017453292519943295],\n" +
-               "    AXIS[“Latitude”, NORTH],\n" +
-               "    AXIS[“Longitude”, EAST]]"));
+               "GEOGCS[“WGS 84”,\n" +
+               "  DATUM[“World Geodetic System 1984”,\n" +
+               "    SPHEROID[“WGS84”, 6378137.0, 298.257223563]],\n" +
+               "    PRIMEM[“Greenwich”, 0.0],\n" +
+               "  UNIT[“degree”, 0.017453292519943295],\n" +
+               "  AXIS[“Latitude”, NORTH],\n" +
+               "  AXIS[“Longitude”, EAST]]"));
     }
 
     /**
@@ -290,11 +292,11 @@ public final strictfp class GeodeticObje
     @DependsOnMethod("testGeographicCRS")
     public void testGeographicWithImplicitAxes() throws ParseException {
         verifyGeographicCRS(0, parse(GeographicCRS.class,
-               "  GEOGCS[“WGS 84”,\n" +
-               "    DATUM[“World Geodetic System 1984”,\n" +
-               "      SPHEROID[“WGS84”, 6378137.0, 298.257223563]],\n" +
-               "      PRIMEM[“Greenwich”, 0.0],\n" +
-               "    UNIT[“degree”, 0.017453292519943295]]"));
+               "GEOGCS[“WGS 84”,\n" +
+               "  DATUM[“World Geodetic System 1984”,\n" +
+               "    SPHEROID[“WGS84”, 6378137.0, 298.257223563]],\n" +
+               "    PRIMEM[“Greenwich”, 0.0],\n" +
+               "  UNIT[“degree”, 0.017453292519943295]]"));
     }
 
     /**
@@ -355,13 +357,13 @@ public final strictfp class GeodeticObje
     @DependsOnMethod("testGeographicWithLatLonAxes")
     public void testGeographicWithUnorderedAxes() throws ParseException {
         verifyGeographicCRS(1, parse(GeographicCRS.class,
-               "  GEOGCS[“WGS 84”,\n" +
-               "    DATUM[“World Geodetic System 1984”,\n" +
-               "      SPHEROID[“WGS84”, 6378137.0, 298.257223563]],\n" +
-               "      PRIMEM[“Greenwich”, 0.0],\n" +
-               "    UNIT[“degree”, 0.017453292519943295],\n" +
-               "    AXIS[“Longitude”, EAST, order[2]],\n" +
-               "    AXIS[“Latitude”, NORTH, order[1]]]"));
+               "GEOGCS[“WGS 84”,\n" +
+               "  DATUM[“World Geodetic System 1984”,\n" +
+               "    SPHEROID[“WGS84”, 6378137.0, 298.257223563]],\n" +
+               "    PRIMEM[“Greenwich”, 0.0],\n" +
+               "  UNIT[“degree”, 0.017453292519943295],\n" +
+               "  AXIS[“Longitude”, EAST, order[2]],\n" +
+               "  AXIS[“Latitude”, NORTH, order[1]]]"));
     }
 
     /**
@@ -755,11 +757,11 @@ public final strictfp class GeodeticObje
         newParser(Convention.DEFAULT);
         final ParsePosition position = new ParsePosition(0);
         final GeographicCRS crs = (GeographicCRS) parser.parseObject(
-               "  GEOGCS[“WGS 84”,\n" +
-               "    DATUM[“World Geodetic System 1984”,\n" +
-               "      SPHEROID[“WGS84”, 6378137.0, 298.257223563, Ext1[“foo”], Ext2[“bla”]]],\n"
+
-               "      PRIMEM[“Greenwich”, 0.0, Intruder[“unknown”]],\n" +
-               "    UNIT[“degree”, 0.017453292519943295], Intruder[“foo”]]", position);
+               "GEOGCS[“WGS 84”,\n" +
+               "  DATUM[“World Geodetic System 1984”,\n" +
+               "    SPHEROID[“WGS84”, 6378137.0, 298.257223563, Ext1[“foo”], Ext2[“bla”]]],\n"
+
+               "    PRIMEM[“Greenwich”, 0.0, Intruder[“unknown”]],\n" +
+               "  UNIT[“degree”, 0.017453292519943295], Intruder[“foo”]]", position);
 
         verifyGeographicCRS(0, crs);
         assertEquals("errorIndex", -1, position.getErrorIndex());

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/MathTransformParserTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/MathTransformParserTest.java?rev=1689423&r1=1689422&r2=1689423&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/MathTransformParserTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/MathTransformParserTest.java
[UTF-8] Mon Jul  6 15:19:10 2015
@@ -19,9 +19,12 @@ package org.apache.sis.io.wkt;
 import java.text.ParsePosition;
 import java.text.ParseException;
 import org.opengis.referencing.operation.MathTransform;
+import org.opengis.referencing.operation.MathTransformFactory;
+import org.apache.sis.internal.system.DefaultFactories;
 import org.apache.sis.referencing.operation.matrix.Matrix2;
 import org.apache.sis.referencing.operation.matrix.Matrix3;
 import org.apache.sis.referencing.operation.transform.MathTransforms;
+import org.apache.sis.referencing.operation.transform.DefaultMathTransformFactory;
 import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
@@ -52,7 +55,8 @@ public final strictfp class MathTransfor
      */
     private MathTransform parse(final String text) throws ParseException {
         if (parser == null) {
-            parser = new MathTransformParser();
+            parser = new MathTransformParser(DefaultFactories.forBuildin(MathTransformFactory.class));
+            assertEquals(DefaultMathTransformFactory.class.getCanonicalName(), parser.getPublicFacade());
         }
         final ParsePosition position = new ParsePosition(0);
         final MathTransform mt = (MathTransform) parser.parseObject(text, position);



Mime
View raw message