Author: desruisseaux
Date: Tue Mar 17 16:55:20 2015
New Revision: 1667357

URL: http://svn.apache.org/r1667357
Log:
Referencing: consolidate the creation of legacy (deprecated) names and 
identifiers into the Builder base class.

Added:
    
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/DeprecatedCode.java
      - copied, changed from r1667147, 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/DeprecatedCode.java
    
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/DeprecatedName.java
      - copied, changed from r1667150, 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/DeprecatedName.java
Removed:
    
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/DeprecatedCode.java
    
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/DeprecatedName.java
Modified:
    
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Mercator1SP.java
    
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/Builder.java
    
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/NamedIdentifier.java

Modified: 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Mercator1SP.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Mercator1SP.java?rev=1667357&r1=1667356&r2=1667357&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Mercator1SP.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Mercator1SP.java
 [UTF-8] Tue Mar 17 16:55:20 2015
@@ -16,7 +16,6 @@
  */
 package org.apache.sis.internal.referencing.provider;
 
-import org.opengis.util.GenericName;
 import org.opengis.parameter.ParameterValueGroup;
 import org.opengis.parameter.ParameterDescriptor;
 import org.opengis.parameter.ParameterDescriptorGroup;
@@ -24,8 +23,6 @@ import org.opengis.referencing.operation
 import org.opengis.referencing.operation.CylindricalProjection;
 import org.apache.sis.parameter.ParameterBuilder;
 import org.apache.sis.metadata.iso.citation.Citations;
-import org.apache.sis.internal.referencing.DeprecatedCode;
-import org.apache.sis.internal.referencing.DeprecatedName;
 
 
 /**
@@ -142,10 +139,10 @@ public final class Mercator1SP extends M
             .addIdentifier("9804")              // The ellipsoidal case
             .addIdentifier("1026")              // The spherical case
             .addName("Mercator (variant A)")    // Starting from EPSG version 
7.6
-            .addName("Mercator (Spherical)")
-            .addIdentifier(        new DeprecatedCode((short) 9841, (short) 
1026))      // The spherical (1SP) case
-            .addName((GenericName) new DeprecatedName("Mercator (1SP)"))       
         // Prior to EPSG version 7.6
-            .addName((GenericName) new DeprecatedName("Mercator (1SP) 
(Spherical)"))
+            .addName("Mercator (Spherical)")    // Starting from EPSG version 
7.6
+            .addDeprecatedIdentifier("9841",                 "1026")           
         // The spherical (1SP) case
+            .addDeprecatedName("Mercator (1SP)",             "Mercator 
(variant A)")    // Prior to EPSG version 7.6
+            .addDeprecatedName("Mercator (1SP) (Spherical)", "Mercator 
(Spherical)")    // Prior to EPSG version 7.6
             .addName(Citations.OGC,     "Mercator_1SP")
             .addName(Citations.GEOTIFF, "CT_Mercator")
             .addName(Citations.PROJ4,   "merc")

Modified: 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/Builder.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/Builder.java?rev=1667357&r1=1667356&r2=1667357&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/Builder.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/Builder.java
 [UTF-8] Tue Mar 17 16:55:20 2015
@@ -178,7 +178,7 @@ import java.util.Objects;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.4
- * @version 0.5
+ * @version 0.6
  * @module
  */
 public abstract class Builder<B extends Builder<B>> {
@@ -282,7 +282,7 @@ public abstract class Builder<B extends
      */
     private NameSpace namespace() {
         if (namespace == null) {
-            final String codespace = (String) 
properties.get(Identifier.CODESPACE_KEY);
+            final String codespace = getCodeSpace();
             if (codespace != null) {
                 namespace = NAMES.createNameSpace(NAMES.createLocalName(null, 
codespace), null);
             }
@@ -291,6 +291,30 @@ public abstract class Builder<B extends
     }
 
     /**
+     * Returns the value of the first argument given by the last call to 
{@link #setCodeSpace(Citation, String)},
+     * or {@code null} if none. The default value is {@code null}.
+     *
+     * @return The citation specified by the last call to {@code 
setCodeSpace(…)}, or {@code null} if none.
+     *
+     * @since 0.6
+     */
+    private Citation getAuthority() {
+        return (Citation) properties.get(Identifier.AUTHORITY_KEY);
+    }
+
+    /**
+     * Returns the value of the last argument given by the last call to {@link 
#setCodeSpace(Citation, String)},
+     * or {@code null} if none. The default value is {@code null}.
+     *
+     * @return The string specified by the last call to {@code 
setCodeSpace(…)}, or {@code null} if none.
+     *
+     * @since 0.6
+     */
+    private String getCodeSpace() {
+        return (String) properties.get(Identifier.CODESPACE_KEY);
+    }
+
+    /**
      * Sets the {@code Identifier} authority and code space.
      * The code space is often the authority's abbreviation, but not 
necessarily.
      *
@@ -327,6 +351,18 @@ public abstract class Builder<B extends
     }
 
     /**
+     * Returns the value given by the last call to {@link 
#setVersion(String)}, or {@code null} if none.
+     * The default value is {@code null}.
+     *
+     * @return The value specified by the last call to {@code setVersion(…)}, 
or {@code null} if none.
+     *
+     * @since 0.6
+     */
+    private String getVersion() {
+        return (String) properties.get(Identifier.VERSION_KEY);
+    }
+
+    /**
      * Sets the {@code Identifier} version of object definitions. This method 
is typically invoked only once,
      * since a compound object often uses the same version for all individual 
components.
      *
@@ -404,12 +440,7 @@ public abstract class Builder<B extends
      */
     public B addName(final Citation authority, final CharSequence name) {
         ensureNonNull("name", name);
-        final NamedIdentifier identifier;
-        if (name instanceof InternationalString) {
-            identifier = new NamedIdentifier(authority, (InternationalString) 
name);
-        } else {
-            identifier = new NamedIdentifier(authority, name.toString());
-        }
+        final NamedIdentifier identifier = new NamedIdentifier(authority, 
name);
         if (properties.putIfAbsent(IdentifiedObject.NAME_KEY, identifier) != 
null) {
             // A primary name is already present. Add the given name as an 
alias instead.
             aliases.add(identifier);
@@ -471,6 +502,32 @@ public abstract class Builder<B extends
     }
 
     /**
+     * Adds a deprecated name given by a {@code CharSequence}. Some objects 
have deprecated names for historical reasons.
+     * The deprecated name typically has a replacement, which can be given by 
the {@code supersededBy} argument.
+     * The later, if non-null, shall be a name specified by a previous call to 
an {@code addName(…)} method.
+     *
+     * <p>The given string will be combined with the authority, {@link 
#setCodeSpace(Citation, String) code space} and
+     * {@link #setVersion(String) version} information for creating the 
deprecated {@link NamedIdentifier} object.</p>
+     *
+     * <p><b>Lifetime:</b>
+     * all identifiers are cleared after a {@code createXXX(…)} method has 
been invoked.</p>
+     *
+     * @param  name The {@code IdentifiedObject} deprecated name.
+     * @param  supersededBy The name to use instead of this one, or {@code 
null} if none.
+     * @return {@code this}, for method call chaining.
+     *
+     * @since 0.6
+     */
+    public B addDeprecatedName(final CharSequence name, final CharSequence 
supersededBy) {
+        ensureNonNull("name", name);
+        final DeprecatedName dn = new DeprecatedName(getAuthority(), 
getCodeSpace(), name, getVersion(), supersededBy);
+        if (properties.putIfAbsent(IdentifiedObject.NAME_KEY, dn) != null) {
+            aliases.add(dn);
+        }
+        return self();
+    }
+
+    /**
      * Adds an {@code IdentifiedObject} identifier given by a {@code String}.
      * The given string will be combined with the authority, {@link 
#setCodeSpace(Citation, String) code space}
      * and {@link #setVersion(String) version} information for creating the 
{@link Identifier} object.
@@ -483,8 +540,7 @@ public abstract class Builder<B extends
      */
     public B addIdentifier(final String identifier) {
         ensureNonNull("identifier", identifier);
-        identifiers.add(new ImmutableIdentifier((Citation) 
properties.get(Identifier.AUTHORITY_KEY),
-                (String) properties.get(Identifier.CODESPACE_KEY), 
identifier));
+        identifiers.add(new ImmutableIdentifier(getAuthority(), 
getCodeSpace(), identifier, getVersion(), null));
         return self();
     }
 
@@ -503,6 +559,7 @@ public abstract class Builder<B extends
      */
     public B addIdentifier(final Citation authority, final String identifier) {
         ensureNonNull("identifier", identifier);
+        // Do not use the version information since it applies to the default 
authority rather than the given one.
         identifiers.add(new ImmutableIdentifier(authority, 
Citations.getUnicodeIdentifier(authority), identifier));
         return self();
     }
@@ -525,6 +582,30 @@ public abstract class Builder<B extends
         return self();
     }
 
+    /**
+     * Adds a deprecated identifier given by a {@code String}. Some objects 
have deprecated identifiers for
+     * historical reasons. The deprecated identifier typically has a 
replacement, which can be given by the
+     * {@code supersededBy} argument. The later, if non-null, shall be an 
identifier specified by a previous
+     * call to an {@code addIdentifier(…)} method.
+     *
+     * <p>The given string will be combined with the authority, {@link 
#setCodeSpace(Citation, String) code space}
+     * and {@link #setVersion(String) version} information for creating the 
deprecated {@link Identifier} object.</p>
+     *
+     * <p><b>Lifetime:</b>
+     * all identifiers are cleared after a {@code createXXX(…)} method has 
been invoked.</p>
+     *
+     * @param  identifier   The {@code IdentifiedObject} deprecated identifier.
+     * @param  supersededBy The identifier to use instead of this one, or 
{@code null} if none.
+     * @return {@code this}, for method call chaining.
+     *
+     * @since 0.6
+     */
+    public B addDeprecatedIdentifier(final String identifier, final String 
supersededBy) {
+        ensureNonNull("identifier", identifier);
+        identifiers.add(new DeprecatedCode(getAuthority(), getCodeSpace(), 
identifier, getVersion(), supersededBy));
+        return self();
+    }
+
     /**
      * Sets the parameter description as a {@code String} or {@code 
InternationalString} instance.
      * Calls to this method overwrite any previous value.

Copied: 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/DeprecatedCode.java
 (from r1667147, 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/DeprecatedCode.java)
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/DeprecatedCode.java?p2=sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/DeprecatedCode.java&p1=sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/DeprecatedCode.java&r1=1667147&r2=1667357&rev=1667357&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/DeprecatedCode.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/DeprecatedCode.java
 [UTF-8] Tue Mar 17 16:55:20 2015
@@ -14,24 +14,23 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sis.internal.referencing;
+package org.apache.sis.referencing;
 
-import org.opengis.util.InternationalString;
-import org.apache.sis.internal.util.Constants;
+import org.opengis.metadata.citation.Citation;
 import org.apache.sis.metadata.iso.ImmutableIdentifier;
-import org.apache.sis.metadata.iso.citation.Citations;
 import org.apache.sis.util.resources.Vocabulary;
 
 
 /**
- * A reference identifier for a deprecated EPSG codes.
+ * An identifier for a deprecated identifier.
+ * This is used mostly for deprecated EPSG codes.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.6
  * @version 0.6
  * @module
  */
-public final class DeprecatedCode extends ImmutableIdentifier {
+final class DeprecatedCode extends ImmutableIdentifier {
     /**
      * For cross-version compatibility.
      */
@@ -40,22 +39,17 @@ public final class DeprecatedCode extend
     /**
      * Creates a deprecated identifier.
      *
-     * @param code Identifier code from the EPSG authority.
      * @param supersededBy The code that replace this one.
      */
-    public DeprecatedCode(final short code, final short supersededBy) {
-        super(Citations.OGP, Constants.EPSG, Short.toString(code).intern(), 
null, remarks(supersededBy));
+    DeprecatedCode(final Citation authority, final String codeSpace,
+            final String code, final String version, final CharSequence 
supersededBy)
+    {
+        super(authority, codeSpace, code, version,
+                Vocabulary.formatInternational(Vocabulary.Keys.SupersededBy_1, 
supersededBy));
     }
 
     /**
-     * Formats a "Superseded by" international string.
-     */
-    private static InternationalString remarks(final int supersededBy) {
-        return Vocabulary.formatInternational(Vocabulary.Keys.SupersededBy_1, 
supersededBy);
-    }
-
-    /**
-     * Returns {@code true} since this code is deprecated.
+     * Returns {@code true} since this identifier is deprecated.
      *
      * @return {@code true}.
      */

Copied: 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/DeprecatedName.java
 (from r1667150, 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/DeprecatedName.java)
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/DeprecatedName.java?p2=sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/DeprecatedName.java&p1=sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/DeprecatedName.java&r1=1667150&r2=1667357&rev=1667357&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/DeprecatedName.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/DeprecatedName.java
 [UTF-8] Tue Mar 17 16:55:20 2015
@@ -14,43 +14,37 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sis.internal.referencing;
+package org.apache.sis.referencing;
 
-import org.opengis.metadata.Identifier;
-import org.apache.sis.metadata.iso.citation.Citations;
-import org.apache.sis.referencing.NamedIdentifier;
+import org.opengis.metadata.citation.Citation;
+import org.apache.sis.util.resources.Vocabulary;
 
 
 /**
- * A name which is deprecated (when associated to a given object) in the EPSG 
database.
+ * A deprecated name.
+ * This is used mostly for names which were used in legacy versions of the 
EPSG database.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.6
  * @version 0.6
  * @module
  */
-public final class DeprecatedName extends NamedIdentifier {
+final class DeprecatedName extends NamedIdentifier {
     /**
      * For cross-version compatibility.
      */
     private static final long serialVersionUID = 1792369861343798471L;
 
     /**
-     * Creates a new deprecated name with the same authority, code, version 
and remarks than the given identifier.
-     *
-     * @param identifier The identifier to deprecate.
-     */
-    public DeprecatedName(final Identifier identifier) {
-        super(identifier);
-    }
-
-    /**
      * Creates a new deprecated EPSG name.
      *
-     * @param name The EPSG name.
+     * @param supersededBy The name that replace this one.
      */
-    public DeprecatedName(final String name) {
-        super(Citations.EPSG, name);
+    DeprecatedName(final Citation authority, final String codeSpace, final 
CharSequence code, final String version,
+            final CharSequence supersededBy)
+    {
+        super(authority, codeSpace, code, version,
+                Vocabulary.formatInternational(Vocabulary.Keys.SupersededBy_1, 
supersededBy));
     }
 
     /**

Modified: 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/NamedIdentifier.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/NamedIdentifier.java?rev=1667357&r1=1667356&r2=1667357&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/NamedIdentifier.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/NamedIdentifier.java
 [UTF-8] Tue Mar 17 16:55:20 2015
@@ -36,6 +36,7 @@ import org.apache.sis.internal.system.De
 import org.apache.sis.metadata.iso.citation.Citations;  // For javadoc
 import org.apache.sis.metadata.iso.ImmutableIdentifier;
 import org.apache.sis.util.collection.WeakValueHashMap;
+import org.apache.sis.util.ArgumentChecks;
 
 import static org.apache.sis.internal.util.Citations.getUnicodeIdentifier;
 
@@ -89,7 +90,7 @@ import java.util.Objects;
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.4
- * @version 0.5
+ * @version 0.6
  * @module
  */
 public class NamedIdentifier extends ImmutableIdentifier implements 
GenericName {
@@ -160,37 +161,36 @@ public class NamedIdentifier extends Imm
     }
 
     /**
-     * Constructs an identifier from an authority and localizable code.
-     * This is a convenience constructor for commonly-used parameters.
-     *
-     * @param authority The authority (e.g. {@link Citations#OGC} or {@link 
Citations#EPSG}),
-     *                  or {@code null} if not available.
-     * @param code      The code. The {@code code.toString(Locale.ROOT)} 
return value will be used for the
-     *                  {@link #getCode() code} property, and the complete 
international string will be used
-     *                  for the {@link #getName() name} property.
-     */
-    public NamedIdentifier(final Citation authority, final InternationalString 
code) {
-        this(authority, code.toString(Locale.ROOT));
-        name = createName(authority, code);
-        isNameSupplied = true; // Because 'code' is an international string.
-    }
-
-    /**
      * Constructs an identifier from an authority and code.
      * This is a convenience constructor for commonly-used parameters.
      *
-     * @param authority The authority (e.g. {@link Citations#OGC} or {@link 
Citations#EPSG}),
-     *                  or {@code null} if not available.
-     * @param code      The code. This parameter is mandatory.
+     * <p>If the given code is an {@link InternationalString}, then the {@code 
code.toString(Locale.ROOT)}
+     * return value will be used for the {@link #getCode() code} property, and 
the complete international
+     * string will be used for the {@link #getName() name} property.</p>
+     *
+     * @param authority
+     *          Organization or party responsible for definition and 
maintenance of the code
+     *          space or code, or {@code null} if not available.
+     * @param code
+     *          Identifier code or name, optionally from a controlled list or 
pattern defined by
+     *          the authority. The code can not be null.
      */
-    public NamedIdentifier(final Citation authority, final String code) {
-        super(authority, getUnicodeIdentifier(authority), code);
+    public NamedIdentifier(final Citation authority, final CharSequence code) {
+        super(authority, getUnicodeIdentifier(authority), toString(code));
+        if (code instanceof InternationalString) {
+            name = createName(authority, code);
+            isNameSupplied = true; // Because 'code' is an international 
string.
+        }
     }
 
     /**
-     * Creates an identifier from the specified code and authority,
+     * Constructs an identifier from an authority and localizable code,
      * with an optional version number and remarks.
      *
+     * <p>If the given code is an {@link InternationalString}, then the {@code 
code.toString(Locale.ROOT)}
+     * return value will be used for the {@link #getCode() code} property, and 
the complete international
+     * string will be used for the {@link #getName() name} property.</p>
+     *
      * @param authority
      *          Organization or party responsible for definition and 
maintenance of the code
      *          space or code, or {@code null} if not available.
@@ -206,10 +206,26 @@ public class NamedIdentifier extends Imm
      * @param remarks
      *          Comments on or information about this identifier, or {@code 
null} if none.
      */
-    public NamedIdentifier(final Citation authority, final String codeSpace,
-            final String code, final String version, final InternationalString 
remarks)
+    public NamedIdentifier(final Citation authority, final String codeSpace, 
final CharSequence code,
+            final String version, final InternationalString remarks)
     {
-        super(authority, codeSpace, code, version, remarks);
+        super(authority, codeSpace, toString(code), version, remarks);
+        if (code instanceof InternationalString) {
+            name = createName(authority, code);
+            isNameSupplied = true; // Because 'code' is an international 
string.
+        }
+    }
+
+    /**
+     * Returns the unlocalized string representation of the given code.
+     */
+    private static String toString(final CharSequence code) {
+        ArgumentChecks.ensureNonNull("code", code);
+        if (code instanceof InternationalString) {
+            return ((InternationalString) code).toString(Locale.ROOT);
+        } else {
+            return code.toString();
+        }
     }
 
     /**


Reply via email to