sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1565282 - in /sis/branches/JDK7/core: sis-metadata/src/main/java/org/apache/sis/io/wkt/ sis-metadata/src/main/java/org/apache/sis/metadata/iso/ sis-referencing/src/main/java/org/apache/sis/internal/referencing/ sis-referencing/src/main/jav...
Date Thu, 06 Feb 2014 14:40:09 GMT
Author: desruisseaux
Date: Thu Feb  6 14:40:09 2014
New Revision: 1565282

URL: http://svn.apache.org/r1565282
Log:
Simplification attempt of Formatter: remove the GeneralParameterValue special case
(this case will be handled by the 'formatTo' method of implementation class) and
remove 'getName(IdentifiedObject)' (case now handled by implementation class).

Added:
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WKTUtilities.java
  (with props)
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/io/wkt/Symbols.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/WKTFormat.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.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/DefaultCompoundCRS.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/DefaultGeodeticDatum.java

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=1565282&r1=1565281&r2=1565282&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] Thu Feb  6 14:40:09 2014
@@ -20,7 +20,6 @@ import java.io.Console;
 import java.io.PrintWriter;
 import java.util.concurrent.atomic.AtomicReference;
 import javax.xml.bind.annotation.XmlTransient;
-import org.opengis.parameter.GeneralParameterValue;
 import org.apache.sis.util.Debug;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.internal.util.X364;
@@ -48,6 +47,16 @@ import org.apache.sis.internal.util.X364
  * {@code System.out.println(this)} except that syntax coloring is automatically applied
  * if the terminal seems to support the ANSI escape codes.
  *
+ * {@section Non-standard WKT}
+ * If this object can not be formatted without violating some WKT constraints,
+ * then the behavior depends on the method invoked:
+ *
+ * <ul>
+ *   <li>{@link #toWKT()} will throw a {@link UnformattableObjectException}.</li>
+ *   <li>{@link #toString()} will ignore the problem and uses non-standard elements
if needed.</li>
+ *   <li>{@link #print()} will show the non-standard elements in red if syntax coloring
is enabled.</li>
+ * </ul>
+ *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.4 (derived from geotk-2.0)
  * @version 0.4
@@ -90,7 +99,7 @@ public abstract class FormattableObject 
      * @see org.opengis.referencing.IdentifiedObject#toWKT()
      */
     public String toWKT() throws UnformattableObjectException {
-        return formatWKT(Convention.DEFAULT, WKTFormat.DEFAULT_INDENTATION, false, true);
+        return formatWKT(Convention.DEFAULT, false, true);
     }
 
     /**
@@ -104,7 +113,7 @@ public abstract class FormattableObject 
      */
     @Override
     public String toString() {
-        return formatWKT(Convention.DEFAULT_SIMPLIFIED, WKTFormat.DEFAULT_INDENTATION, false,
false);
+        return formatWKT(Convention.DEFAULT_SIMPLIFIED, false, false);
     }
 
     /**
@@ -116,7 +125,7 @@ public abstract class FormattableObject 
      */
     public String toString(final Convention convention) {
         ArgumentChecks.ensureNonNull("convention", convention);
-        return formatWKT(convention, WKTFormat.DEFAULT_INDENTATION, false, false);
+        return formatWKT(convention, false, false);
     }
 
     /**
@@ -133,8 +142,7 @@ public abstract class FormattableObject 
     public void print() {
         final Console console = System.console();
         final PrintWriter out = (console != null) ? console.writer() : null;
-        final String wkt = formatWKT(Convention.DEFAULT_SIMPLIFIED, WKTFormat.DEFAULT_INDENTATION,
-                (out != null) && X364.isAnsiSupported(), false);
+        final String wkt = formatWKT(Convention.DEFAULT_SIMPLIFIED, (out != null) &&
X364.isAnsiSupported(), false);
         if (out != null) {
             out.println(wkt);
         } else {
@@ -147,33 +155,23 @@ public abstract class FormattableObject 
      * If {@code strict} is true, then an exception is thrown if the WKT is not standard-compliant.
      *
      * @param  convention  The convention for choosing WKT element 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.
      */
-    final String formatWKT(final Convention convention, final byte indentation, final boolean
colorize, final boolean strict)
+    final String formatWKT(final Convention convention, final boolean colorize, final boolean
strict)
              throws UnformattableObjectException
     {
         Formatter formatter = FORMATTER.getAndSet(null);
         if (formatter == null) {
             formatter = new Formatter();
         }
-        formatter.configure(convention, null, colorize ? Colors.CONSOLE : null, indentation);
+        formatter.configure(convention, null, colorize ? Colors.CONSOLE : null, WKTFormat.DEFAULT_INDENTATION);
         final String wkt;
         try {
-            /*
-             * Special processing for parameter values, which is formatted
-             * directly in 'Formatter'. Note that in GeoAPI, that interface
-             * doesn't share the same parent interface than other interfaces.
-             */
-            if (this instanceof GeneralParameterValue) {
-                formatter.append((GeneralParameterValue) this);
-            } else {
-                formatter.append(this);
-            }
+            formatter.append(this);
             if (strict) {
                 final String message = formatter.getErrorMessage();
                 if (message != null) {
@@ -192,27 +190,28 @@ public abstract class FormattableObject 
      * Formats the inner part of this <cite>Well Known Text</cite> (WKT) element
into the given formatter.
      * This method is automatically invoked by {@link WKTFormat} when a formattable element
is found.
      *
-     * <p>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>
+     * <p>Keywords, opening and closing brackets shall not be formatted here.
+     * For example if this formattable element is for a {@code ID[…]} element,
+     * then this method shall write the content starting at the insertion point shown below:</p>
      *
      * {@preformat text
-     *     GEOGCS["WGS 84", ID["EPSG", 4326]]
-     *                    ↑
-     *            (insertion point)
+     *        ID[ ]
+     *           ↑
+     *   (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>
+     * {@section Formatting non-standard WKT}
+     * If the implementation can not represent this object without violating some WKT constraints,
+     * it can uses its own (non-standard) keywords but shall declare that it did so by invoking
one
+     * of the {@link Formatter#setInvalidWKT(IdentifiedObject) Formatter.setInvalidWKT(…)}
methods.
+     *
+     * <p>Alternatively, the implementation may also have no WKT keyword for this object.
+     * This happen frequently when an abstract class defines a base implementation,
+     * but the keyword is defined by the concrete subclasses.
+     * In such case, the method in the abstract class shall return {@code null}.</p>
      *
      * @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.
+     * @return The WKT element keyword, or {@code null} if none.
      *
      * @see #toWKT()
      * @see #toString()

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=1565282&r1=1565281&r2=1565282&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] Thu Feb  6 14:40:09 2014
@@ -36,10 +36,6 @@ import org.opengis.util.InternationalStr
 import org.opengis.metadata.citation.Citation;
 import org.opengis.metadata.extent.Extent;
 import org.opengis.metadata.extent.GeographicBoundingBox;
-import org.opengis.parameter.GeneralParameterValue;
-import org.opengis.parameter.ParameterDescriptor;
-import org.opengis.parameter.ParameterValue;
-import org.opengis.parameter.ParameterValueGroup;
 import org.opengis.referencing.IdentifiedObject;
 import org.opengis.referencing.ReferenceIdentifier;
 import org.opengis.referencing.ReferenceSystem;
@@ -54,12 +50,12 @@ 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.Localized;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.internal.util.Citations;
 import org.apache.sis.internal.metadata.ReferencingServices;
-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;
@@ -77,8 +73,6 @@ import org.apache.sis.metadata.iso.exten
  *   <li>A series of {@code append(…)} methods to be invoked by the {@code formatTo(Formatter)}
implementations.</li>
  *   <li>Contextual information. In particular, the {@linkplain #getLinearUnit() linear
unit} and the
  *       {@linkplain #getAngularUnit() angular unit} depend on the enclosing WKT element.</li>
- *   <li>Convenience methods for fetching relevant information from the object to format,
like
- *       {@linkplain #getName(IdentifiedObject) name} and {@linkplain #getIdentifier(IdentifiedObject)
identifier}.</li>
  *   <li>A flag for declaring the object unformattable.</li>
  * </ul>
  *
@@ -87,7 +81,7 @@ import org.apache.sis.metadata.iso.exten
  * @version 0.4
  * @module
  */
-public class Formatter {
+public class Formatter implements Localized {
     /**
      * Do not format an {@code ID[…]} element for instance of this class.
      */
@@ -344,29 +338,33 @@ public class Formatter {
     }
 
     /**
-     * Returns the preferred name for the specified object.
-     * If the specified object contains a name from the preferred authority, then this name
is returned.
-     * Otherwise, the first name found is returned.
+     * Returns the preferred authority for choosing the projection and parameter names.
      *
      * <p>The preferred authority can be set by the {@link WKTFormat#setNameAuthority(Citation)}
method.
-     * This is not necessarily the authority of the given {@linkplain IdentifiedObject#getName()
object name}.</p>
+     * This is not necessarily the authority who created the object to format.</p>
      *
      * {@example The EPSG name of the <code>EPSG:6326</code> datum is "<cite>World
Geodetic System 1984</cite>".
-     *           However if the preferred authority is OGC, then this method usually returns
"<cite>WGS84</cite>"
-     *           (the exact string to be returned depends on the object aliases).}
+     *           However if the preferred authority is OGC, then the formatted datum name
will rather look like
+     *           "<cite>WGS84</cite>" (the exact string depends on the object
aliases).}
      *
-     * @param  object The object to look for a preferred name.
-     * @return The preferred name, or {@code null} if the given object has no name.
+     * @return The authority for projection and parameter names.
      *
      * @see WKTFormat#getNameAuthority()
      * @see org.apache.sis.referencing.IdentifiedObjects#getName(IdentifiedObject, Citation)
      */
-    public String getName(final IdentifiedObject object) {
-        String name = ReferencingUtilities.getName(object, authority, null);
-        if (name == null) {
-            name = ReferencingUtilities.getName(object, null, null);
-        }
-        return name;
+    public Citation getNameAuthority() {
+        return authority;
+    }
+
+    /**
+     * Returns the locale to use for localizing {@link InternationalString} instances.
+     * This is <em>not</em> the locale for formatting dates and numbers.
+     *
+     * @return The locale to use for localizing international strings.
+     */
+    @Override
+    public Locale getLocale() {
+        return locale;
     }
 
     /**
@@ -739,99 +737,6 @@ public class Formatter {
     }
 
     /**
-     * Appends a {@linkplain ParameterValue parameter} in a {@code PARAMETER[…]} element.
-     * If the supplied parameter is actually a {@linkplain ParameterValueGroup parameter
group},
-     * all contained parameters will flattened in a single list.
-     *
-     * @param parameter The parameter to append to the WKT, or {@code null} if none.
-     */
-    public void append(final GeneralParameterValue parameter) {
-        if (parameter instanceof ParameterValueGroup) {
-            for (final GeneralParameterValue param : ((ParameterValueGroup)parameter).values())
{
-                append(param);
-            }
-        }
-        if (parameter instanceof ParameterValue<?>) {
-            final ParameterValue<?> param = (ParameterValue<?>) parameter;
-            final ParameterDescriptor<?> descriptor = param.getDescriptor();
-            Unit<?> unit = descriptor.getUnit();
-            if (unit != null && !Unit.ONE.equals(unit)) {
-                if (linearUnit != null && unit.isCompatible(linearUnit)) {
-                    unit = linearUnit;
-                } else {
-                    if (angularUnit != null && unit.isCompatible(angularUnit)) {
-                        unit = angularUnit;
-                    }
-                }
-            }
-            appendSeparator(true);
-            final StringBuffer buffer = this.buffer;
-            final int start = buffer.length();
-            final int stop = buffer.append("PARAMETER").length();
-            buffer.appendCodePoint(symbols.getOpeningBracket(0));
-            setColor(ElementKind.PARAMETER);
-            quote(getName(descriptor));
-            resetColor();
-            if (unit != null) {
-                double value;
-                try {
-                    value = param.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.
-                    if (colors != null) {
-                        final String c = colors.getAnsiSequence(ElementKind.ERROR);
-                        if (c != null) {
-                            buffer.insert(stop, BACKGROUND_DEFAULT).insert(start, c);
-                        }
-                    }
-                    setInvalidWKT(descriptor);
-                    errorCause = exception;
-                    value = Double.NaN;
-                }
-                append(value);
-            } else {
-                appendObject(param.getValue());
-            }
-            buffer.appendCodePoint(symbols.getClosingBracket(0));
-            requestNewLine = true;
-        }
-    }
-
-    /**
-     * Appends the specified value to a string buffer. If the value is an array, then the
-     * array elements are appended recursively (i.e. the array may contains sub-array).
-     */
-    private void appendObject(final Object value) {
-        if (value == null) {
-            appendSeparator(false);
-            buffer.append("null");
-        } else if (value.getClass().isArray()) {
-            appendSeparator(false);
-            buffer.appendCodePoint(symbols.getOpenSequence());
-            final int length = Array.getLength(value);
-            for (int i=0; i<length; i++) {
-                appendObject(Array.get(value, i));
-            }
-            buffer.appendCodePoint(symbols.getCloseSequence());
-        } else if (value instanceof CodeList<?>) {
-            append((CodeList<?>) value);
-        } else if (value instanceof Number) {
-            final Number number = (Number) value;
-            if (Numbers.isInteger(number.getClass())) {
-                append(number.longValue());
-            } else {
-                append(number.doubleValue());
-            }
-        } else if (value instanceof Boolean) {
-            append(((Boolean) value).booleanValue());
-        } else {
-            append((value instanceof InternationalString) ?
-                    ((InternationalString) value).toString(locale) : value.toString(), null);
-        }
-    }
-
-    /**
      * Appends a code list.
      *
      * @param code The code list to append to the WKT, or {@code null} if none.
@@ -1045,6 +950,54 @@ public class Formatter {
     }
 
     /**
+     * Appends an object or an array of objects.
+     * This method performs the following choices:
+     *
+     * <ul>
+     *   <li>If the given value is {@code null}, then this method appends the "{@code
null}" string (without quotes).</li>
+     *   <li>Otherwise if the given value is an array, then this method appends the
opening sequence symbol, formats all
+     *       elements by invoking this method recursively, then appends the closing sequence
symbol.</li>
+     *   <li>Otherwise if the value type is assignable to the argument type of one
of the {@code append(…)} methods
+     *       in this class, then the formatting will be delegated to that method.</li>
+     *   <li>Otherwise the given value is appended as a quoted text with its {@code
toString()} representation.</li>
+     * </ul>
+     *
+     * @param value The value to append to the WKT, or {@code null}.
+     */
+    public void appendAny(final Object value) {
+        if (value == null) {
+            appendSeparator(false);
+            buffer.append("null");
+        } else if (value.getClass().isArray()) {
+            appendSeparator(false);
+            buffer.appendCodePoint(symbols.getOpenSequence());
+            final int length = Array.getLength(value);
+            for (int i=0; i<length; i++) {
+                appendAny(Array.get(value, i));
+            }
+            buffer.appendCodePoint(symbols.getCloseSequence());
+        } else if (value instanceof Number) {
+            final Number number = (Number) value;
+            if (Numbers.isInteger(number.getClass())) {
+                append(number.longValue());
+            } else {
+                append(number.doubleValue());
+            }
+        }
+        else if (value instanceof CodeList<?>)           append((CodeList<?>)
          value);
+        else if (value instanceof Date)                  append((Date)                  value);
+        else if (value instanceof Boolean)               append((Boolean)               value);
+        else if (value instanceof Unit<?>)               append((Unit<?>)   
           value);
+        else if (value instanceof FormattableObject)     append((FormattableObject)     value);
+        else if (value instanceof IdentifiedObject)      append((IdentifiedObject)      value);
+        else if (value instanceof GeographicBoundingBox) append((GeographicBoundingBox) value,
BBOX_ACCURACY);
+        else if (value instanceof MathTransform)         append((MathTransform)         value);
+        else if (value instanceof Matrix)                append((Matrix)                value);
+        else append((value instanceof InternationalString) ?
+                ((InternationalString) value).toString(locale) : value.toString(), null);
+    }
+
+    /**
      * Returns the linear unit for expressing lengths, or {@code null} for the default unit
of each WKT element.
      * If {@code null}, then the default value depends on the object to format.
      *
@@ -1132,8 +1085,9 @@ public class Formatter {
      */
     public void setInvalidWKT(final IdentifiedObject unformattable) {
         ArgumentChecks.ensureNonNull("unformattable", unformattable);
-        String name = getName(unformattable);
-        if (name == null) {
+        String name;
+        final ReferenceIdentifier id = unformattable.getName();
+        if (id == null || (name = id.getCode()) == null) {
             name = getName(unformattable.getClass());
         }
         invalidElement = name;

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Symbols.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Symbols.java?rev=1565282&r1=1565281&r2=1565282&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Symbols.java [UTF-8]
(original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Symbols.java [UTF-8]
Thu Feb  6 14:40:09 2014
@@ -29,38 +29,39 @@ import static org.apache.sis.util.Argume
 
 /**
  * The set of symbols to use for <cite>Well Known Text</cite> (WKT) parsing and
formatting.
- * This class allows to specify the following properties:
+ * The two constants defined in this class, namely {@link #SQUARE_BRACKETS} and {@link #CURLY_BRACKETS},
+ * define the symbols for ISO 19162 compliant WKT formatting. Their properties are:
  *
- * <table class="sis">
- *   <tr>
- *     <th>Property</th>
- *     <th>Standard value</th>
- *     <th>Remarks</th>
- *   </tr>
+ * <blockquote><table class="compact">
  *   <tr>
- *     <td>Locale for number format</td>
+ *     <td>Locale for number format:</td>
  *     <td>{@link Locale#ROOT}</td>
- *     <td></td>
  *   </tr>
  *   <tr>
- *     <td>Bracket symbols</td>
+ *     <td>Bracket symbols:</td>
  *     <td>{@code [}…{@code ]} or {@code (}…{@code )}</td>
- *     <td>The former is more common in referencing WKT, while the later is more common
in geometry WKT.</td>
  *   </tr>
  *   <tr>
- *     <td>Quote symbols</td>
+ *     <td>Quote symbols:</td>
  *     <td>{@code "}…{@code "}</td>
- *     <td>Apache SIS also accepts {@code “}…{@code ”}, but this is non-standard.</td>
  *   </tr>
- *   <tr><td>Separator</td>
+ *   <tr>
+ *     <td>Sequence symbols:</td>
+ *     <td><code>{</code>…<code>}</code></td>
+ *   </tr>
+ *   <tr>
+ *     <td>Separator:</td>
  *     <td>{@code ,}</td>
- *     <td></td>
  *   </tr>
- * </table>
+ * </table></blockquote>
  *
- * The two constants defined in this class, namely {@link #SQUARE_BRACKETS} and {@link #CURLY_BRACKETS},
- * define the symbols for ISO 19162 compliant WKT formatting. Parsing can be made tolerant
to alternative
- * forms by optionally specifying additional bracket and quote symbols.
+ * {@note The <code>[…]</code> brackets are common in referencing WKT,
+ *        while the <code>(…)</code> brackets are common in geometry WKT.}
+ *
+ * {@note Apache SIS also accepts <code>“…”</code> quotes for more readable
<code>String</code> literals
+ *        in Java code, but this is non-standard.}
+ *
+ * Users can create their own {@code Symbols} instance for parsing or formatting a WKT with
different symbols.
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.4 (derived from geotk-2.1)

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/WKTFormat.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/WKTFormat.java?rev=1565282&r1=1565281&r2=1565282&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/WKTFormat.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/WKTFormat.java
[UTF-8] Thu Feb  6 14:40:09 2014
@@ -29,7 +29,6 @@ import javax.measure.unit.Unit;
 import javax.measure.unit.UnitFormat;
 import org.opengis.metadata.citation.Citation;
 import org.opengis.metadata.extent.GeographicBoundingBox;
-import org.opengis.parameter.GeneralParameterValue;
 import org.opengis.referencing.IdentifiedObject;
 import org.opengis.referencing.operation.Matrix;
 import org.opengis.referencing.operation.MathTransform;
@@ -47,7 +46,7 @@ import org.apache.sis.util.resources.Err
  * <ul>
  *   <li>The {@linkplain Symbols symbols} to use (curly braces or brackets, <i>etc</i>).</li>
  *   <li>The preferred authority of {@linkplain IdentifiedObject#getName() object name}
to
- *       format (see {@link Formatter#getName(IdentifiedObject)} for more information).</li>
+ *       format (see {@link Formatter#getNameAuthority()} for more information).</li>
  *   <li>Whatever ANSI X3.64 colors are allowed or not (default is not).</li>
  *   <li>The indentation.</li>
  * </ul>
@@ -274,7 +273,7 @@ public class WKTFormat extends CompoundF
      * @return The authority for projection and parameter names.
      *
      * @see Convention#getNameAuthority()
-     * @see Formatter#getName(IdentifiedObject)
+     * @see Formatter#getNameAuthority()
      */
     public Citation getNameAuthority() {
         Citation result = authority;
@@ -292,7 +291,7 @@ public class WKTFormat extends CompoundF
      *
      * @param authority The new authority, or {@code null} for inferring it from the convention.
      *
-     * @see Formatter#getName(IdentifiedObject)
+     * @see Formatter#getNameAuthority()
      */
     public void setNameAuthority(final Citation authority) {
         this.authority = authority;
@@ -348,7 +347,7 @@ public class WKTFormat extends CompoundF
     /**
      * Formats the specified object as a Well Know Text. The given object shall be an instance
of one of
      * {@link FormattableObject}, {@link IdentifiedObject}, {@link GeographicBoundingBox},
-     * {@link MathTransform}, {@link GeneralParameterValue} or {@link Matrix}.
+     * {@link MathTransform} or {@link Matrix}.
      *
      * @param  object     The object to format.
      * @param  toAppendTo Where the text is to be appended.
@@ -390,12 +389,6 @@ public class WKTFormat extends CompoundF
                 formatter.append((IdentifiedObject) object);
             } else if (object instanceof MathTransform) {
                 formatter.append((MathTransform) object);
-            } else if (object instanceof GeneralParameterValue) {
-                /*
-                 * Special processing for parameter values, which is formatted directly in
'Formatter'.
-                 * Note that this interface doesn't share the same parent interface than
other interfaces.
-                 */
-                formatter.append((GeneralParameterValue) object);
             } else if (object instanceof Matrix) {
                 formatter.append((Matrix) object);
             } else if (object instanceof GeographicBoundingBox) {

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=1565282&r1=1565281&r2=1565282&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] Thu Feb  6 14:40:09 2014
@@ -72,9 +72,10 @@ import java.util.Objects;
  * }
  *
  * </li><li><p><b><cite>Well Known Text</cite> (WKT)
version 2</b></p>
- * The WKT 2 format contains the {@linkplain #getCodeSpace() code space}, the {@linkplain
#getCode() code} and
- * the {@linkplain #getVersion() version} if available. The WKT can optionally provides a
{@code URI} element,
- * which expresses the same information in a different way (the URN syntax is described in
the next item below).
+ * The WKT 2 format contains the {@linkplain #getCodeSpace() code space}, the {@linkplain
#getCode() code},
+ * the {@linkplain #getVersion() version} and the {@linkplain #getAuthority() authority}
title if available.
+ * The WKT can optionally provides a {@code URI} element, which expresses the same information
in a different way
+ * (the URN syntax is described in the next item below).
  * Example:
  *
  * {@preformat wkt
@@ -524,6 +525,7 @@ public class ImmutableIdentifier extends
 
     /**
      * Formats a <cite>Well Known Text</cite> representation of this identifier.
+     * See class javadoc for more information on the WKT format.
      *
      * @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).

Added: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WKTUtilities.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WKTUtilities.java?rev=1565282&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WKTUtilities.java
(added)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WKTUtilities.java
[UTF-8] Thu Feb  6 14:40:09 2014
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.referencing;
+
+import org.opengis.parameter.ParameterValue;
+import org.opengis.parameter.ParameterValueGroup;
+import org.opengis.parameter.GeneralParameterValue;
+import org.opengis.referencing.IdentifiedObject;
+import org.apache.sis.referencing.IdentifiedObjects;
+import org.apache.sis.io.wkt.ElementKind;
+import org.apache.sis.io.wkt.FormattableObject;
+import org.apache.sis.io.wkt.Formatter;
+import org.apache.sis.util.Static;
+import org.apache.sis.util.resources.Vocabulary;
+
+
+/**
+ * Utility methods for referencing WKT formatting.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.4
+ * @version 0.4
+ * @module
+ */
+public final class WKTUtilities extends Static {
+    /**
+     * Do not allow instantiation of this class.
+     */
+    private WKTUtilities() {
+    }
+
+    /**
+     * Appends the name of the given object to the formatter.
+     *
+     * @param object    The object from which to get the name.
+     * @param formatter The formatter where to append the name.
+     * @param type      The key of colors to apply if syntax colors are enabled.
+     */
+    public static void appendName(final IdentifiedObject object, final Formatter formatter,
final ElementKind type) {
+        String name = IdentifiedObjects.getName(object, formatter.getNameAuthority());
+        if (name == null) {
+            name = IdentifiedObjects.getName(object, null);
+            if (name == null) {
+                name = Vocabulary.getResources(formatter.getLocale()).getString(Vocabulary.Keys.Unnamed);
+            }
+        }
+        formatter.append(name, type);
+    }
+
+    /**
+     * Appends a {@linkplain ParameterValue parameter} in a {@code PARAMETER[…]} element.
+     * If the supplied parameter is actually a {@linkplain ParameterValueGroup parameter
group},
+     * all contained parameters will be flattened in a single list.
+     *
+     * @param parameter The parameter to append to the WKT, or {@code null} if none.
+     * @param formatter The formatter where to append the parameter.
+     */
+    public static void append(final GeneralParameterValue parameter, final Formatter formatter)
{
+        if (parameter instanceof ParameterValueGroup) {
+            for (final GeneralParameterValue param : ((ParameterValueGroup) parameter).values())
{
+                append(param, formatter);
+            }
+        }
+        if (parameter instanceof ParameterValue<?>) {
+            if (!(parameter instanceof FormattableObject)) {
+                // TODO - wrap in a SIS implementation.
+            }
+            formatter.append((FormattableObject) parameter);
+        }
+    }
+}

Propchange: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WKTUtilities.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WKTUtilities.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

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=1565282&r1=1565281&r2=1565282&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] Thu Feb  6 14:40:09 2014
@@ -42,6 +42,7 @@ import org.apache.sis.internal.metadata.
 import org.apache.sis.internal.jaxb.referencing.Code;
 import org.apache.sis.internal.util.Numerics;
 import org.apache.sis.internal.util.UnmodifiableArrayList;
+import org.apache.sis.internal.referencing.WKTUtilities;
 import org.apache.sis.io.wkt.FormattableObject;
 import org.apache.sis.io.wkt.Formatter;
 import org.apache.sis.io.wkt.ElementKind;
@@ -903,31 +904,42 @@ public class AbstractIdentifiedObject ex
      *   <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>
-     *
+     * Keywords and metadata (scope, extent, identifier and remarks) shall not be formatted
here.
+     * For example if this formattable element is for a {@code GEOGCS[…]} element,
+     * then subclasses shall write the content starting at the insertion point shown below:
+     *
+     * <table class="compact">
+     * <tr>
+     *   <th>WKT example</th>
+     *   <th>Java code example</th>
+     * </tr><tr><td>
      * {@preformat text
      *     GEOGCS["WGS 84", ID["EPSG", 4326]]
      *                    ↑
      *            (insertion point)
      * }
+     * </td><td>
+     * {@preformat java
+     *     super.formatTo(formatter);
+     *     // ... write the elements at the insertion point ...
+     *     return "GEOGCS";
+     * }
+     * </td></tr></table>
      *
-     * {@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:
+     * {@section Formatting non-standard WKT}
+     * If the implementation can not represent this object without violating some WKT constraints,
+     * it can uses its own (non-standard) keywords but shall declare that it did so by invoking
one
+     * of the {@link Formatter#setInvalidWKT(IdentifiedObject) Formatter.setInvalidWKT(…)}
methods.
      *
-     * <ul>
-     *   <li>Invoke one of the {@link Formatter#setInvalidWKT(Class) Formatter#setInvalidWKT(…)}
methods, or</li>
-     *   <li>Returns {@code null}.</li>
-     * </ul>
+     * <p>Alternatively, the implementation may also have no WKT keyword for this object.
+     * In such case, this method shall return {@code null}.</p>
      *
      * @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.
+     * @return The WKT element keyword, or {@code null} if none.
      */
     @Override
     protected String formatTo(final Formatter formatter) {
-        formatter.append(formatter.getName(this), ElementKind.forType(getClass()));
+        WKTUtilities.appendName(this, formatter, ElementKind.forType(getClass()));
         return null;
     }
 }

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=1565282&r1=1565281&r2=1565282&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] Thu Feb  6 14:40:09 2014
@@ -32,6 +32,7 @@ import org.apache.sis.referencing.cs.Axe
 import org.apache.sis.referencing.cs.DefaultCompoundCS;
 import org.apache.sis.referencing.AbstractReferenceSystem;
 import org.apache.sis.referencing.IdentifiedObjects;
+import org.apache.sis.internal.referencing.WKTUtilities;
 import org.apache.sis.internal.metadata.ReferencingUtilities;
 import org.apache.sis.internal.util.UnmodifiableArrayList;
 import org.apache.sis.util.collection.CheckedContainer;
@@ -388,7 +389,7 @@ public class DefaultCompoundCRS extends 
      */
     @Override
     protected String formatTo(final Formatter formatter) {
-        formatter.append(formatter.getName(this), null);
+        WKTUtilities.appendName(this, formatter, null);
         for (final CoordinateReferenceSystem element : components) {
             formatter.append(element);
         }

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=1565282&r1=1565281&r2=1565282&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] Thu Feb  6 14:40:09 2014
@@ -25,6 +25,7 @@ import org.opengis.referencing.cs.Coordi
 import org.opengis.referencing.crs.GeocentricCRS;
 import org.opengis.referencing.datum.GeodeticDatum;
 import org.apache.sis.io.wkt.Formatter;
+import org.apache.sis.internal.referencing.WKTUtilities;
 import org.apache.sis.internal.referencing.Legacy;
 import org.apache.sis.referencing.cs.AxesConvention;
 import org.apache.sis.referencing.AbstractReferenceSystem;
@@ -218,7 +219,7 @@ public class DefaultGeocentricCRS extend
      */
     @Override
     protected String formatTo(final Formatter formatter) {
-        formatter.append(formatter.getName(this), null);
+        WKTUtilities.appendName(this, formatter, 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=1565282&r1=1565281&r2=1565282&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] Thu Feb  6 14:40:09 2014
@@ -30,6 +30,7 @@ import org.opengis.referencing.crs.Geogr
 import org.apache.sis.referencing.cs.AxesConvention;
 import org.apache.sis.referencing.AbstractReferenceSystem;
 import org.apache.sis.internal.referencing.AxisDirections;
+import org.apache.sis.internal.referencing.WKTUtilities;
 import org.apache.sis.io.wkt.Formatter;
 import org.apache.sis.measure.Units;
 
@@ -223,7 +224,7 @@ public class DefaultGeographicCRS extend
      */
     @Override
     protected String formatTo(final Formatter formatter) {
-        formatter.append(formatter.getName(this), null);
+        WKTUtilities.appendName(this, formatter, 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/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=1565282&r1=1565281&r2=1565282&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] Thu Feb  6 14:40:09 2014
@@ -34,6 +34,7 @@ import org.apache.sis.referencing.operat
 import org.apache.sis.referencing.operation.matrix.NoninvertibleMatrixException;
 import org.apache.sis.metadata.iso.extent.Extents;
 import org.apache.sis.internal.referencing.ExtentSelector;
+import org.apache.sis.internal.referencing.WKTUtilities;
 import org.apache.sis.internal.util.CollectionsExt;
 import org.apache.sis.util.logging.Logging;
 import org.apache.sis.util.ComparisonMode;
@@ -507,7 +508,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);
+        WKTUtilities.appendName(this, formatter, ElementKind.DATUM);
         formatter.append(ellipsoid instanceof FormattableObject ? (FormattableObject) ellipsoid
:
                          DefaultEllipsoid.castOrCopy(ellipsoid));
         if (bursaWolf != null) {



Mime
View raw message