sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1564941 - in /sis/branches/JDK7: ./ core/sis-metadata/src/main/java/org/apache/sis/io/wkt/ core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ core/sis-metadata/src/test/java/org/apache/sis/io/wkt/ core/sis-metadata/src/test/java/...
Date Wed, 05 Feb 2014 21:32:36 GMT
Author: desruisseaux
Date: Wed Feb  5 21:32:35 2014
New Revision: 1564941

URL: http://svn.apache.org/r1564941
Log:
Moved some Formatter code to the appropriate FormattableObject subclasses,
in order to reduce the size of Formatter.

Modified:
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/FormattableObject.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/io/wkt/FormatterTest.java
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/ImmutableIdentifierTest.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.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/DefaultEngineeringCRS.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/crs/DefaultVerticalCRS.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.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/DefaultGeodeticDatum.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/simple/SimpleIdentifiedObject.java
    sis/branches/JDK7/pom.xml

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/FormattableObject.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/FormattableObject.java?rev=1564941&r1=1564940&r2=1564941&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/FormattableObject.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/FormattableObject.java
[UTF-8] Wed Feb  5 21:32:35 2014
@@ -28,7 +28,7 @@ import org.apache.sis.internal.util.X364
 
 /**
  * Base class for objects that can be formatted as <cite>Well Known Text</cite>
(WKT).
- * {@link WKTFormat} checks for this interface at formatting time for each element to format.
+ * {@link WKTFormat} checks for this class 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.
  *
@@ -38,10 +38,9 @@ import org.apache.sis.internal.util.X364
  * <ul>
  *   <li>{@link #toWKT()} returns a strictly compliant WKT or throws {@link UnformattableObjectException}
  *       if this object contains elements not defined by the ISO 19162 standard.</li>
- *   <li>{@link #toString()} returns a WKT with some rules relaxed in order to never
throw exception,
- *       using non-standard representation if necessary. In some cases {@code toString()}
may also use
- *       an alternative text representation for better readability, for example a matrix
instead of
- *       a list of {@code PARAMETER["elt_…", …]} elements for linear transforms.</li>
+ *   <li>{@link #toString()} returns a WKT with some redundant information omitted
and some constraints relaxed.
+ *       This method never throw {@code UnformattableObjectException};
+ *       it will rather use non-standard representation if necessary.</li>
  * </ul>
  *
  * {@section Syntax coloring}
@@ -55,7 +54,7 @@ import org.apache.sis.internal.util.X364
  * @module
  */
 @XmlTransient
-public class FormattableObject {
+public abstract class FormattableObject {
     /**
      * The formatter for the {@link #toWKT()} and {@link #toString()} methods. Formatters
are not
      * thread-safe, consequently we must make sure that only one thread uses a given instance.
@@ -203,22 +202,20 @@ public class FormattableObject {
      *            (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.
+     * {@section Declaring the WKT as invalid}
+     * If the implementation can not format a strictly compliant WKT, then it shall declare
the WKT
+     * as invalid using <em>one</em> of the following ways:
+     *
+     * <ul>
+     *   <li>invoke one of the {@link Formatter#setInvalidWKT(Class) Formatter#setInvalidWKT(…)}
methods, or</li>
+     *   <li>returns {@code null}.</li>
+     * </ul>
      *
      * @param  formatter The formatter where to format the inner content of this WKT element.
-     * @return The WKT element keyword (e.g. {@code "GEOGCS"}).
+     * @return The WKT element keyword (e.g. {@code "GEOGCS"}), or {@code null} if none.
      *
      * @see #toWKT()
      * @see #toString()
      */
-    protected String formatTo(final Formatter formatter) {
-        formatter.setInvalidWKT(getClass());
-        String name = formatter.invalidElement;
-        if (name == null) { // May happen if the user override Formatter.setInvalidWKT(Class).
-            name = "UNKNOWN";
-        }
-        return name;
-    }
+    protected abstract String formatTo(Formatter formatter);
 }

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=1564941&r1=1564940&r2=1564941&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] Wed Feb  5 21:32:35 2014
@@ -33,7 +33,6 @@ import javax.measure.quantity.Angle;
 import javax.measure.quantity.Length;
 
 import org.opengis.util.InternationalString;
-import org.opengis.metadata.Identifier;
 import org.opengis.metadata.citation.Citation;
 import org.opengis.metadata.extent.Extent;
 import org.opengis.metadata.extent.GeographicBoundingBox;
@@ -63,6 +62,7 @@ import org.apache.sis.internal.metadata.
 import org.apache.sis.internal.metadata.ReferencingUtilities;
 import org.apache.sis.measure.Range;
 import org.apache.sis.measure.MeasurementRange;
+import org.apache.sis.metadata.iso.ImmutableIdentifier;
 import org.apache.sis.metadata.iso.extent.Extents;
 
 
@@ -249,7 +249,7 @@ public class Formatter {
      * @see #isInvalidWKT()
      * @see #getErrorMessage()
      */
-    String invalidElement;
+    private String invalidElement;
 
     /**
      * Error that occurred during WKT formatting, or {@code null} if none.
@@ -378,12 +378,12 @@ public class Formatter {
      * @param  info The object to look for a preferred identifier, or {@code null} if none.
      * @return The preferred identifier, or {@code null} if none.
      */
-    public Identifier getIdentifier(final IdentifiedObject info) {
-        Identifier first = null;
+    public ReferenceIdentifier getIdentifier(final IdentifiedObject info) {
+        ReferenceIdentifier first = null;
         if (info != null) {
-            final Collection<? extends Identifier> identifiers = info.getIdentifiers();
+            final Collection<ReferenceIdentifier> identifiers = info.getIdentifiers();
             if (identifiers != null) {
-                for (final Identifier id : identifiers) {
+                for (final ReferenceIdentifier id : identifiers) {
                     if (Citations.identifierMatches(authority, id.getAuthority())) {
                         return id;
                     }
@@ -499,31 +499,13 @@ public class Formatter {
             return;
         }
         final StringBuffer buffer = this.buffer;
-        /*
-         * Formats the opening bracket and the object name (e.g. "NAD27").
-         * The WKT entity name (e.g. "PROJCS") will be formatted later.
-         * The result of this code portion looks like the following:
-         *
-         *         <previous text>,
-         *           ["NAD27 / Idaho Central"
-         */
-        appendSeparator(true);
+        appendSeparator(requestNewLine || !(object instanceof ReferenceIdentifier));
         int base = buffer.length();
         buffer.appendCodePoint(symbols.getOpeningBracket(0));
         final IdentifiedObject info = (object instanceof IdentifiedObject) ? (IdentifiedObject)
object : null;
-        if (info != null) {
-            final ElementKind type = ElementKind.forType(info.getClass());
-            if (type != null) {
-                setColor(type);
-            }
-            quote(getName(info));
-            if (type != null) {
-                resetColor();
-            }
-        }
         /*
-         * Formats the part after the object name, then insert the WKT element name in front
of them.
-         * The result of this code portion looks like the following:
+         * Formats the inner part, then prepend the WKT keyword.
+         * The result looks like the following:
          *
          *         <previous text>,
          *           PROJCS["NAD27 / Idaho Central",
@@ -533,6 +515,15 @@ public class Formatter {
         indent(+1);
         requestNewLine = false;
         String keyword = object.formatTo(this);
+        if (keyword == null) {
+            if (info != null) {
+                setInvalidWKT(info);
+                keyword = getName(info.getClass());
+            } else {
+                setInvalidWKT(object.getClass());
+                keyword = invalidElement;
+            }
+        }
         if (colors != null && highlightError) {
             highlightError = false;
             final String color = colors.getAnsiSequence(ElementKind.ERROR);
@@ -561,7 +552,11 @@ public class Formatter {
          *             ID["EPSG", 26769]]
          */
         if (!ID_EXCLUDE.isInstance(info)) {
-            append(getIdentifier(info));
+            ReferenceIdentifier id = getIdentifier(info);
+            if (!(id instanceof FormattableObject)) {
+                id = ImmutableIdentifier.castOrCopy(id);
+            }
+            append((FormattableObject) id);
         }
         /*
          * Format remarks if any, and close the element.
@@ -647,58 +642,6 @@ public class Formatter {
     }
 
     /**
-     * Appends the given identifier in an {@code ID[…]} (WKT 2) or {@code AUTHORITY[…]}
(WKT 1) element.
-     * The identifier may be added on the same line then the previous element or in a new
line depending
-     * on the enclosing element.
-     *
-     * {@example Identifier added on the same line:
-     * <blockquote><pre>SPHEROID["Clarke 1866", …, <b>ID["EPSG", 7008]</b>]</pre></blockquote>}
-     *
-     * {@example Identifier added on a new line:
-     * <blockquote><pre>PROJCS["NAD27 / Idaho Central",
-     *   GEOGCS[...etc...],
-     *   ...etc...
-     *   <b>ID["EPSG", 26769]</b>]</pre></blockquote>}
-     *
-     * @param identifier The identifier to append to the WKT, or {@code null} if none.
-     */
-    public void append(final Identifier identifier) {
-        if (identifier != null) {
-            final String code = identifier.getCode();
-            if (code != null) {
-                String citation  = Citations.getIdentifier(identifier.getAuthority());
-                String codeSpace = null;
-                if (identifier instanceof ReferenceIdentifier) {
-                    codeSpace = ((ReferenceIdentifier) identifier).getCodeSpace();
-                }
-                if (codeSpace == null) {
-                    codeSpace = citation;
-                    citation  = null;
-                }
-                if (codeSpace != null) {
-                    if (convention.isWKT1()) {
-                        openElement("AUTHORITY");
-                        append(codeSpace);
-                        append(code);
-                    } else {
-                        openElement("ID");
-                        append(codeSpace);
-                        appendIntegerOrText(code);
-                        if (identifier instanceof ReferenceIdentifier) {
-                            final String version = ((ReferenceIdentifier) identifier).getVersion();
-                            if (version != null) {
-                                appendIntegerOrText(version);
-                                append(citation);
-                            }
-                        }
-                    }
-                    closeElement();
-                }
-            }
-        }
-    }
-
-    /**
      * 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.
@@ -884,7 +827,7 @@ public class Formatter {
             append(((Boolean) value).booleanValue());
         } else {
             append((value instanceof InternationalString) ?
-                    ((InternationalString) value).toString(locale) : value.toString());
+                    ((InternationalString) value).toString(locale) : value.toString(), null);
         }
     }
 
@@ -907,11 +850,14 @@ public class Formatter {
      * The {@linkplain Symbols#getSeparator() element separator} will be written before the
text if needed.
      *
      * @param text The string to format to the WKT, or {@code null} if none.
+     * @param type The key of the colors to apply if syntax coloring is enabled.
      */
-    public void append(final String text) {
+    public void append(final String text, final ElementKind type) {
         if (text != null) {
             appendSeparator(false);
+            setColor(type);
             quote(text);
+            resetColor();
         }
     }
 
@@ -979,25 +925,6 @@ public class Formatter {
     }
 
     /**
-     * Appends the given text as an integer if possible, or as a text otherwise.
-     *
-     * {@note ISO 19162 specifies "number or text". In Apache SIS, we restrict the numbers
to integers
-     *        because handling version numbers like "8.2" as floating point numbers can be
confusing.}
-     */
-    private void appendIntegerOrText(final String text) {
-        if (text != null) {
-            final long n;
-            try {
-                n = Long.parseLong(text);
-            } catch (NumberFormatException e) {
-                append(text);
-                return;
-            }
-            append(n);
-        }
-    }
-
-    /**
      * Appends a date.
      * The {@linkplain Symbols#getSeparator() element separator} will be written before the
date if needed.
      *
@@ -1206,12 +1133,11 @@ public class Formatter {
     public void setInvalidWKT(final IdentifiedObject unformattable) {
         ArgumentChecks.ensureNonNull("unformattable", unformattable);
         String name = getName(unformattable);
-        if (name != null) {
-            invalidElement = name;
-            highlightError = true;
-        } else {
-            setInvalidWKT(unformattable.getClass());
+        if (name == null) {
+            name = getName(unformattable.getClass());
         }
+        invalidElement = name;
+        highlightError = true;
     }
 
     /**
@@ -1221,8 +1147,17 @@ public class Formatter {
      *
      * @param unformattable The class of the object that can not be formatted,
      */
-    public void setInvalidWKT(Class<?> unformattable) {
+    public void setInvalidWKT(final Class<?> unformattable) {
         ArgumentChecks.ensureNonNull("unformattable", unformattable);
+        invalidElement = getName(unformattable);
+        highlightError = true;
+    }
+
+    /**
+     * Returns the name of the GeoAPI interface implemented by the given class.
+     * If no GeoAPI interface is found, fallback on the class name.
+     */
+    private static String getName(Class<?> unformattable) {
         if (!unformattable.isInterface()) {
             for (final Class<?> candidate : unformattable.getInterfaces()) {
                 if (candidate.getName().startsWith("org.opengis.")) {
@@ -1231,8 +1166,7 @@ public class Formatter {
                 }
             }
         }
-        invalidElement = Classes.getShortName(unformattable);
-        highlightError = true;
+        return Classes.getShortName(unformattable);
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java?rev=1564941&r1=1564940&r2=1564941&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java
[UTF-8] Wed Feb  5 21:32:35 2014
@@ -21,17 +21,16 @@ import java.util.Locale;
 import java.io.Serializable;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
-import org.opengis.metadata.Identifier;
 import org.opengis.metadata.citation.Citation;
 import org.opengis.parameter.InvalidParameterValueException;
 import org.opengis.referencing.ReferenceIdentifier;
 import org.opengis.util.InternationalString;
-import org.apache.sis.util.Debug;
 import org.apache.sis.util.Deprecable;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.iso.Types;
 import org.apache.sis.metadata.iso.citation.Citations;
-import org.apache.sis.internal.simple.SimpleIdentifiedObject;
+import org.apache.sis.io.wkt.FormattableObject;
+import org.apache.sis.io.wkt.Formatter;
 
 import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
 import static org.apache.sis.util.CharSequences.trimWhitespaces;
@@ -125,7 +124,7 @@ import java.util.Objects;
  * @see DefaultIdentifier
  */
 @XmlRootElement(name = "RS_Identifier")
-public class ImmutableIdentifier implements ReferenceIdentifier, Deprecable, Serializable
{
+public class ImmutableIdentifier extends FormattableObject implements ReferenceIdentifier,
Deprecable, Serializable {
     /**
      * For cross-version compatibility.
      */
@@ -524,19 +523,58 @@ public class ImmutableIdentifier impleme
     }
 
     /**
-     * Returns a string representation of this identifier.
-     * The string representation is mostly for debugging purpose and may change in any future
SIS version.
-     * The default implementation returns a pseudo-WKT format.
+     * Formats a <cite>Well Known Text</cite> representation of this identifier.
      *
-     * {@note The <code>NamedIdentifier</code> subclass overrides this method
with a different behavior,
-     *        in order to be compliant with the contract of the <code>GenericName</code>
interface.}
-     *
-     * @see org.apache.sis.referencing.IdentifiedObjects#toString(Identifier)
-     * @see org.apache.sis.referencing.NamedIdentifier#toString()
+     * @param  formatter The formatter where to format the inner content of this WKT element.
+     * @return The WKT keyword: {@code "ID"} (WKT 2) or {@code "AUTHORITY"} (WKT 1).
      */
-    @Debug
     @Override
-    public String toString() {
-        return SimpleIdentifiedObject.toString("IDENTIFIER", authority, codeSpace, code,
isDeprecated());
+    protected String formatTo(Formatter formatter) {
+        String keyword = null;
+        final String code = getCode();
+        if (code != null) {
+            String citation = Citations.getIdentifier(getAuthority());
+            String codeSpace = getCodeSpace();
+            if (codeSpace == null) {
+                codeSpace = citation;
+                citation  = null;
+            }
+            if (codeSpace != null) {
+                if (formatter.getConvention().isWKT1()) {
+                    keyword = "AUTHORITY";
+                    formatter.append(codeSpace, null);
+                    formatter.append(code, null);
+                } else {
+                    keyword = "ID";
+                    formatter.append(codeSpace, null);
+                    append(formatter, code);
+                    final String version = getVersion();
+                    if (version != null) {
+                        append(formatter, version);
+                        formatter.append(citation, null);
+                    }
+                }
+            }
+        }
+        return keyword;
+    }
+
+    /**
+     * Appends the given text as an integer if possible, or as a text otherwise.
+     *
+     * {@note ISO 19162 specifies "number or text". In Apache SIS, we restrict the numbers
to integers
+     *        because handling version numbers like "8.2" as floating point numbers can be
confusing.}
+     */
+    private static void append(final Formatter formatter, final String text) {
+        if (text != null) {
+            final long n;
+            try {
+                n = Long.parseLong(text);
+            } catch (NumberFormatException e) {
+                formatter.append(text, null);
+                return;
+            }
+            formatter.append(n);
+        }
     }
 }

Modified: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/io/wkt/FormatterTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/io/wkt/FormatterTest.java?rev=1564941&r1=1564940&r2=1564941&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/io/wkt/FormatterTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/io/wkt/FormatterTest.java
[UTF-8] Wed Feb  5 21:32:35 2014
@@ -57,7 +57,7 @@ public final strictfp class FormatterTes
     }
 
     /**
-     * Tests {@link Formatter#append(Matrix)}.
+     * Tests (indirectly) {@link Formatter#append(Matrix)}.
      */
     @Test
     public void testAppendMatrix() {

Modified: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/ImmutableIdentifierTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/ImmutableIdentifierTest.java?rev=1564941&r1=1564940&r2=1564941&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/ImmutableIdentifierTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/ImmutableIdentifierTest.java
[UTF-8] Wed Feb  5 21:32:35 2014
@@ -22,14 +22,16 @@ import java.util.Locale;
 import javax.xml.bind.JAXBException;
 import org.apache.sis.metadata.iso.citation.Citations;
 import org.apache.sis.metadata.iso.citation.DefaultCitation;
+import org.apache.sis.metadata.iso.citation.HardCodedCitations;
 import org.apache.sis.util.iso.SimpleInternationalString;
+import org.apache.sis.io.wkt.Convention;
 import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.TestCase;
 import org.opengis.test.Validators;
 import org.apache.sis.test.DependsOn;
 import org.junit.Test;
 
-import static org.junit.Assert.*;
+import static org.apache.sis.test.MetadataAssert.*;
 import static org.opengis.referencing.ReferenceIdentifier.*;
 
 
@@ -167,4 +169,14 @@ public final strictfp class ImmutableIde
         final ImmutableIdentifier identifier = new ImmutableIdentifier(new DefaultCitation("EPSG"),
null, "4326");
         new DefaultIdentifierTest().testMarshal("RS_Identifier", identifier);
     }
+
+    /**
+     * Tests WKT formatting.
+     */
+    @Test
+    public void testWKT() {
+        final ImmutableIdentifier id = new ImmutableIdentifier(HardCodedCitations.OGP, "EPSG",
"4326", "8.2", null);
+        assertWktEquals(Convention.WKT2, "ID[“EPSG”, 4326, “8.2”, “OGP”]", id);
+        assertWktEquals(Convention.WKT1, "AUTHORITY[“EPSG”, “4326”]", id);
+    }
 }

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java?rev=1564941&r1=1564940&r2=1564941&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
[UTF-8] Wed Feb  5 21:32:35 2014
@@ -43,6 +43,8 @@ import org.apache.sis.internal.jaxb.refe
 import org.apache.sis.internal.util.Numerics;
 import org.apache.sis.internal.util.UnmodifiableArrayList;
 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.xml.Namespaces;
 import org.apache.sis.util.Deprecable;
 import org.apache.sis.util.ComparisonMode;
@@ -892,4 +894,40 @@ public class AbstractIdentifiedObject ex
     protected long computeHashCode() {
         return Objects.hash(name, nonNull(alias), nonNull(identifiers), remarks) ^ getInterface().hashCode();
     }
+
+    /**
+     * Formats the inner part of this <cite>Well Known Text</cite> (WKT) element
into the given formatter.
+     * The default implementation writes the following elements:
+     *
+     * <ul>
+     *   <li>The object {@linkplain #getName() name}.</li>
+     * </ul>
+     *
+     * <p>Keywords and authority codes 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", ID["EPSG", 4326]]
+     *                    ↑
+     *            (insertion point)
+     * }
+     *
+     * {@section Declaring the WKT as invalid}
+     * If the implementation can not format a strictly compliant WKT, then it shall declare
the WKT
+     * as invalid using <em>one</em> of the following ways:
+     *
+     * <ul>
+     *   <li>Invoke one of the {@link Formatter#setInvalidWKT(Class) Formatter#setInvalidWKT(…)}
methods, or</li>
+     *   <li>Returns {@code null}.</li>
+     * </ul>
+     *
+     * @param  formatter The formatter where to format the inner content of this WKT element.
+     * @return The WKT element keyword (e.g. {@code "GEOGCS"}), or {@code null} if none.
+     */
+    @Override
+    protected String formatTo(final Formatter formatter) {
+        formatter.append(formatter.getName(this), ElementKind.forType(getClass()));
+        return null;
+    }
 }

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=1564941&r1=1564940&r2=1564941&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] Wed Feb  5 21:32:35 2014
@@ -401,6 +401,7 @@ public class AbstractCRS extends Abstrac
      * The default implementation writes the following elements:
      *
      * <ul>
+     *   <li>The object {@linkplain #getName() name}.</li>
      *   <li>The datum, if any.</li>
      *   <li>The unit if all axes use the same unit. Otherwise the unit is omitted
and the WKT format
      *       is {@linkplain Formatter#setInvalidWKT(IdentifiedObject) flagged as invalid}.</li>
@@ -412,16 +413,7 @@ public class AbstractCRS extends Abstrac
      */
     @Override
     protected String formatTo(final Formatter formatter) {
-        formatDefaultWKT(formatter);
-        // Will declares the WKT as invalid.
-        return super.formatTo(formatter);
-    }
-
-    /**
-     * Default implementation of {@link #formatTo(Formatter)}.
-     * For {@link DefaultEngineeringCRS} and {@link DefaultVerticalCRS} use only.
-     */
-    final void formatDefaultWKT(final Formatter formatter) {
+        final String keyword = super.formatTo(formatter);
         formatter.append(getDatum());
         final Unit<?> unit = getUnit();
         formatter.append(unit);
@@ -433,5 +425,6 @@ public class AbstractCRS extends Abstrac
         if (unit == null) {
             formatter.setInvalidWKT(cs);
         }
+        return keyword;
     }
 }

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=1564941&r1=1564940&r2=1564941&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] Wed Feb  5 21:32:35 2014
@@ -388,6 +388,7 @@ public class DefaultCompoundCRS extends 
      */
     @Override
     protected String formatTo(final Formatter formatter) {
+        formatter.append(formatter.getName(this), null);
         for (final CoordinateReferenceSystem element : components) {
             formatter.append(element);
         }

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultEngineeringCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultEngineeringCRS.java?rev=1564941&r1=1564940&r2=1564941&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultEngineeringCRS.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultEngineeringCRS.java
[UTF-8] Wed Feb  5 21:32:35 2014
@@ -258,8 +258,8 @@ public class DefaultEngineeringCRS exten
      * @return The name of the WKT element type, which is {@code "LOCAL_CS"}.
      */
     @Override
-    public String formatTo(final Formatter formatter) { // TODO: should be protected.
-        formatDefaultWKT(formatter);
+    protected String formatTo(final Formatter formatter) {
+        super.formatTo(formatter);
         return "LOCAL_CS";
     }
 }

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=1564941&r1=1564940&r2=1564941&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] Wed Feb  5 21:32:35 2014
@@ -218,6 +218,7 @@ public class DefaultGeocentricCRS extend
      */
     @Override
     protected String formatTo(final Formatter formatter) {
+        formatter.append(formatter.getName(this), null);
         final Unit<?> unit = getUnit();
         final GeodeticDatum datum = getDatum();
         formatter.append(datum);

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=1564941&r1=1564940&r2=1564941&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] Wed Feb  5 21:32:35 2014
@@ -223,6 +223,7 @@ public class DefaultGeographicCRS extend
      */
     @Override
     protected String formatTo(final Formatter formatter) {
+        formatter.append(formatter.getName(this), null);
         final Unit<Angle> oldUnit = formatter.getAngularUnit();
         final Unit<Angle> unit = getAngularUnit(getCoordinateSystem());
         final GeodeticDatum datum = getDatum();

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultVerticalCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultVerticalCRS.java?rev=1564941&r1=1564940&r2=1564941&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultVerticalCRS.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultVerticalCRS.java
[UTF-8] Wed Feb  5 21:32:35 2014
@@ -236,7 +236,7 @@ public class DefaultVerticalCRS extends 
      */
     @Override
     protected String formatTo(final Formatter formatter) {
-        formatDefaultWKT(formatter);
+        super.formatTo(formatter);
         return "VERT_CS";
     }
 }

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java?rev=1564941&r1=1564940&r2=1564941&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java
[UTF-8] Wed Feb  5 21:32:35 2014
@@ -421,9 +421,10 @@ public class AbstractCS extends Abstract
      */
     @Override
     protected String formatTo(final Formatter formatter) {
+        final String keyword = super.formatTo(formatter);
         for (final CoordinateSystemAxis axe : axes) {
             formatter.append(axe);
         }
-        return super.formatTo(formatter);
+        return keyword;
     }
 }

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java?rev=1564941&r1=1564940&r2=1564941&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java
[UTF-8] Wed Feb  5 21:32:35 2014
@@ -693,6 +693,7 @@ public class DefaultCoordinateSystemAxis
      */
     @Override
     protected String formatTo(final Formatter formatter) {
+        super.formatTo(formatter);
         formatter.append(direction);
         return "AXIS";
     }

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=1564941&r1=1564940&r2=1564941&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] Wed Feb  5 21:32:35 2014
@@ -31,7 +31,6 @@ import org.apache.sis.referencing.Abstra
 import org.apache.sis.referencing.IdentifiedObjects;
 import org.apache.sis.io.wkt.Formatter;
 import org.apache.sis.util.iso.Types;
-import org.apache.sis.util.Classes;
 import org.apache.sis.util.ComparisonMode;
 import org.apache.sis.internal.metadata.MetadataUtilities;
 
@@ -450,7 +449,8 @@ public class AbstractDatum extends Abstr
      */
     @Override
     protected String formatTo(final Formatter formatter) {
+        final String keyword = super.formatTo(formatter);
         formatter.append(getLegacyDatumType());
-        return Classes.getShortClassName(this);
+        return keyword;
     }
 }

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=1564941&r1=1564940&r2=1564941&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] Wed Feb  5 21:32:35 2014
@@ -641,12 +641,12 @@ public class BursaWolfParameters extends
         if (isToWGS84()) {
             return "TOWGS84";
         }
-        String keyword = super.formatTo(formatter); // Declare the WKT as invalid.
-        final String name = IdentifiedObjects.getUnicodeIdentifier(targetDatum);
-        if (name != null) {
-            // We may try to build something better here in future SIS versions, if there
is a need for that.
-            keyword = "TO" + name;
+        formatter.setInvalidWKT(BursaWolfParameters.class);
+        String name = IdentifiedObjects.getUnicodeIdentifier(targetDatum);
+        if (name == null) {
+            name = "Unknown";
         }
-        return keyword;
+        // We may try to build something better here in future SIS versions, if there is
a need for that.
+        return "To" + name;
     }
 }

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=1564941&r1=1564940&r2=1564941&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] Wed Feb  5 21:32:35 2014
@@ -759,6 +759,7 @@ public class DefaultEllipsoid extends Ab
      */
     @Override
     protected String formatTo(final Formatter formatter) {
+        super.formatTo(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/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=1564941&r1=1564940&r2=1564941&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] Wed Feb  5 21:32:35 2014
@@ -39,6 +39,7 @@ import org.apache.sis.util.logging.Loggi
 import org.apache.sis.util.ComparisonMode;
 import org.apache.sis.io.wkt.Formatter;
 import org.apache.sis.io.wkt.FormattableObject;
+import org.apache.sis.io.wkt.ElementKind;
 
 import static org.apache.sis.util.Utilities.deepEquals;
 import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
@@ -506,6 +507,7 @@ public class DefaultGeodeticDatum extend
     protected String formatTo(final Formatter formatter) {
         // Do NOT invokes the super-class method, because
         // horizontal datum do not write the datum type.
+        formatter.append(formatter.getName(this), ElementKind.DATUM);
         formatter.append(ellipsoid instanceof FormattableObject ? (FormattableObject) ellipsoid
:
                          DefaultEllipsoid.castOrCopy(ellipsoid));
         if (bursaWolf != null) {

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=1564941&r1=1564940&r2=1564941&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] Wed Feb  5 21:32:35 2014
@@ -338,6 +338,7 @@ public class DefaultPrimeMeridian extend
      */
     @Override
     protected String formatTo(final Formatter formatter) {
+        super.formatTo(formatter);
         Unit<Angle> unit = formatter.getAngularUnit();
         if (unit == null) {
             unit = NonSI.DEGREE_ANGLE;

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/simple/SimpleIdentifiedObject.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/simple/SimpleIdentifiedObject.java?rev=1564941&r1=1564940&r2=1564941&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/simple/SimpleIdentifiedObject.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/simple/SimpleIdentifiedObject.java
[UTF-8] Wed Feb  5 21:32:35 2014
@@ -206,7 +206,7 @@ public class SimpleIdentifiedObject impl
     }
 
     /**
-     * Returns a pseudo-WKT representation.
+     * Returns a pseudo-WKT representation for debugging purpose.
      */
     @Override
     public String toString() {
@@ -222,23 +222,7 @@ public class SimpleIdentifiedObject impl
             codespace = null;
             authority = null;
         }
-        return toString("OBJECT", authority, codespace, code, false);
-    }
-
-    /**
-     * Returns a pseudo-WKT representation.
-     *
-     * @param  type       The WKT heading text.
-     * @param  authority  The authority to write in the {@code "ID"} element.
-     * @param  codespace  Usually an abbreviation of the authority name.
-     * @param  code       The code to write in the {@code "ID"} element, or {@code null}
if none.
-     * @param  deprecated {@code true} if the object to format is deprecated.
-     * @return The pseudo-WKT.
-     */
-    public static String toString(final String type, final Citation authority,
-            final String codespace, final String code, final boolean deprecated)
-    {
-        final StringBuilder buffer = new StringBuilder(type).append("[\"");
+        final StringBuilder buffer = new StringBuilder("OBJECT[\"");
         if (codespace != null) {
             buffer.append(codespace).append(DefaultNameSpace.DEFAULT_SEPARATOR);
         }
@@ -246,9 +230,6 @@ public class SimpleIdentifiedObject impl
         if (authority != null) {
             buffer.append(", ID[\"").append(Citations.getIdentifier(authority)).append("\"]");
         }
-        if (deprecated) {
-            buffer.append(", DEPRECATED");
-        }
         return buffer.append(']').toString();
     }
 }

Modified: sis/branches/JDK7/pom.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/pom.xml?rev=1564941&r1=1564940&r2=1564941&view=diff
==============================================================================
--- sis/branches/JDK7/pom.xml (original)
+++ sis/branches/JDK7/pom.xml Wed Feb  5 21:32:35 2014
@@ -676,11 +676,11 @@ Apache SIS is a free software, Java lang
             </group>
             <group>
               <title>Metadata</title>
-              <packages>org.apache.sis.metadata*:org.apache.sis.io.wkt</packages>
+              <packages>org.apache.sis.metadata*</packages>
             </group>
             <group>
               <title>Utilities</title>
-              <packages>org.apache.sis.math*:org.apache.sis.measure*:org.apache.sis.util*:org.apache.sis.io:org.apache.sis.xml*:org.apache.sis.setup*</packages>
+              <packages>org.apache.sis.math*:org.apache.sis.measure*:org.apache.sis.util*:org.apache.sis.io*:org.apache.sis.xml*:org.apache.sis.setup*</packages>
             </group>
             <group>
               <title>Profiles</title>



Mime
View raw message