sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1550045 - in /sis/branches/JDK7/core: sis-metadata/src/main/java/org/apache/sis/metadata/iso/ sis-referencing/src/main/java/org/apache/sis/geometry/ sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/ sis-referencing/sr...
Date Wed, 11 Dec 2013 04:09:56 GMT
Author: desruisseaux
Date: Wed Dec 11 04:09:56 2013
New Revision: 1550045

URL: http://svn.apache.org/r1550045
Log:
Minor consolidation in JAXB annotations, and complete JAXB binding on
AbstractIdentifiedObject with capability to (un)marshall more than one name.

Added:
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/Code.java
      - copied, changed from r1548994, sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/RS_Identifier.java
Modified:
    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/geometry/AbstractDirectPosition.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralDirectPosition.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/RS_Identifier.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/RS_IdentifierSingleton.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/NamedIdentifier.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/RS_IdentifierTest.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/iso/AbstractName.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultLocalName.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultScopedName.java

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=1550045&r1=1550044&r2=1550045&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 Dec 11 04:09:56 2013
@@ -21,7 +21,6 @@ import java.util.Locale;
 import java.io.Serializable;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 import org.opengis.metadata.Identifier;
 import org.opengis.metadata.citation.Citation;
 import org.opengis.parameter.InvalidParameterValueException;
@@ -32,8 +31,6 @@ 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.jaxb.metadata.CI_Citation;
-import org.apache.sis.internal.jaxb.gco.StringAdapter;
 import org.apache.sis.internal.simple.SimpleIdentifiedObject;
 
 import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
@@ -76,7 +73,6 @@ public class ImmutableIdentifier impleme
      * @see #getCode()
      */
     @XmlElement(required = true)
-    @XmlJavaTypeAdapter(StringAdapter.class)
     private final String code;
 
     /**
@@ -86,7 +82,6 @@ public class ImmutableIdentifier impleme
      * @see #getCodeSpace()
      */
     @XmlElement(required = true)
-    @XmlJavaTypeAdapter(StringAdapter.class)
     private final String codeSpace;
 
     /**
@@ -96,7 +91,6 @@ public class ImmutableIdentifier impleme
      * @see #getAuthority()
      */
     @XmlElement(required = true)
-    @XmlJavaTypeAdapter(CI_Citation.class)
     private final Citation authority;
 
     /**

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java?rev=1550045&r1=1550044&r2=1550045&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java
[UTF-8] Wed Dec 11 04:09:56 2013
@@ -66,6 +66,8 @@ public abstract class AbstractDirectPosi
     /**
      * Returns always {@code this}, the direct position for this
      * {@linkplain org.opengis.geometry.coordinate.Position position}.
+     *
+     * @return {@code this}.
      */
     @Override
     public final DirectPosition getDirectPosition() {

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralDirectPosition.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralDirectPosition.java?rev=1550045&r1=1550044&r2=1550045&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralDirectPosition.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralDirectPosition.java
[UTF-8] Wed Dec 11 04:09:56 2013
@@ -274,6 +274,8 @@ public class GeneralDirectPosition exten
 
     /**
      * Returns a deep copy of this position.
+     *
+     * @return A copy of this direct position.
      */
     @Override
     public GeneralDirectPosition clone() {

Copied: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/Code.java
(from r1548994, sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/RS_Identifier.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/Code.java?p2=sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/Code.java&p1=sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/RS_Identifier.java&r1=1548994&r2=1550045&rev=1550045&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/RS_Identifier.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/Code.java
[UTF-8] Wed Dec 11 04:09:56 2013
@@ -18,47 +18,16 @@ package org.apache.sis.internal.jaxb.ref
 
 import javax.xml.bind.annotation.XmlValue;
 import javax.xml.bind.annotation.XmlAttribute;
-import javax.xml.bind.annotation.adapters.XmlAdapter;
 import org.opengis.metadata.citation.Citation;
 import org.opengis.referencing.ReferenceIdentifier;
-import org.apache.sis.metadata.iso.citation.Citations;
-import org.apache.sis.metadata.iso.ImmutableIdentifier;
+import javax.xml.bind.annotation.XmlType;
 import org.apache.sis.internal.util.URIParser;
+import org.apache.sis.metadata.iso.ImmutableIdentifier;
+import org.apache.sis.metadata.iso.citation.Citations;
 
 
 /**
- * JAXB adapter mapping the GeoAPI {@link ReferenceIdentifier} to an implementation class
that can
- * be marshalled. See the package documentation for more information about JAXB and interfaces.
- *
- * <p>Note that a class of the same name is defined in the {@link org.apache.sis.internal.jaxb.metadata}
- * package, which serve the same purpose (wrapping exactly the same interface) but using
the ISO 19139
- * syntax instead. The ISO 19139 syntax represents the code and codespace as XML elements,
while in this
- * GML representation the code is a XML value and the codespace is a XML attribute.</p>
- *
- * {@section Marshalling}
- * Identifiers are typically marshalled as below:
- *
- * {@preformat xml
- *   <gml:identifier codeSpace="EPSG">4326</gml:identifier>
- * }
- *
- * If the {@code ReferenceIdentifier} to marshal contains a {@linkplain ReferenceIdentifier#getVersion()
version},
- * then this adapter concatenates the version to the codespace in a "URI-like" way like below:
- *
- * {@preformat xml
- *   <gml:identifier codeSpace="EPSG:8.3">4326</gml:identifier>
- * }
- *
- * {@section Unmarshalling}
- * Some data producers put a URN instead than a simple code value, as in the example below:
- *
- * {@preformat xml
- *   <gml:identifier codeSpace="OGP">urn:ogc:def:crs:EPSG::4326</gml:identifier>
- * }
- *
- * In such case this class takes the codespace as the {@linkplain ReferenceIdentifier#getAuthority()
authority}
- * ("OGP" in above example), and the 3 last URI elements are parsed as the codespace, version
(optional) and
- * code values respectively.
+ * The {@code gml:CodeType}, which is made of a code space and a code value.
  *
  * @author  Guilhem Legal (Geomatys)
  * @author  Cédric Briançon (Geomatys)
@@ -67,110 +36,80 @@ import org.apache.sis.internal.util.URIP
  * @version 0.4
  * @module
  */
-public final class RS_Identifier extends XmlAdapter<RS_Identifier.Value, ReferenceIdentifier>
{
+@XmlType(name = "CodeType")
+public final class Code {
     /**
-     * The wrapper for GML identifier marshalled as a code value with a codespace attribute.
-     * Defined in a separated class because JAXB does not allow usage of {@code XmlValue}
in
-     * a class that inherit an other class.
+     * The identifier code.
+     *
+     * <p><b>Note:</b> GML (the target of this class) represents that code
as an XML value, while
+     * {@link org.apache.sis.metadata.iso.ImmutableIdentifier} represents it as an XML element.</p>
      */
-    public static final class Value {
-        /**
-         * The identifier code.
-         *
-         * <p><b>Note:</b> GML (the target of this class) represents that
code as an XML value, while
-         * {@link org.apache.sis.metadata.iso.ImmutableIdentifier} represents it as an XML
element.</p>
-         */
-        @XmlValue
-        String code;
-
-        /**
-         * The code space, which is often {@code "EPSG"} with the version in use.
-         *
-         * <p><b>Note:</b> GML (the target of this class) represents that
code as an XML attribute, while
-         * {@link org.apache.sis.metadata.iso.ImmutableIdentifier} represents it as an XML
element.</p>
-         */
-        @XmlAttribute
-        String codeSpace;
-
-        /**
-         * Empty constructor for JAXB only.
-         */
-        public Value() {
-        }
+    @XmlValue
+    String code;
 
-        /**
-         * Creates a wrapper initialized to the values of the given identifier.
-         * Version number, if presents, will be appended after the codespace with a semicolon
separator.
-         * The {@link #getIdentifier()} method shall be able to perform the opposite operation
(split the
-         * above in separated codespace and version attributes).
-         *
-         * @param identifier The identifier from which to get the values.
-         */
-        Value(final ReferenceIdentifier identifier) {
-            code      = identifier.getCode();
-            codeSpace = identifier.getCodeSpace();
-            String version = identifier.getVersion();
-            if (version != null) {
-                final StringBuilder buffer = new StringBuilder();
-                if (codeSpace != null) {
-                    buffer.append(codeSpace);
-                }
-                codeSpace = buffer.append(URIParser.SEPARATOR).append(version).toString();
-            }
-        }
+    /**
+     * The code space, which is often {@code "EPSG"} with the version in use.
+     *
+     * <p><b>Note:</b> GML (the target of this class) represents that code
as an XML attribute, while
+     * {@link org.apache.sis.metadata.iso.ImmutableIdentifier} represents it as an XML element.</p>
+     */
+    @XmlAttribute
+    String codeSpace;
 
-        /**
-         * Returns the identifier for this value. This method is the converse of the constructor.
-         * If the {@link #codeSpace} contains a semicolon, then the part after the last semicolon
-         * will be taken as the authority version number. This is for consistency with what
the
-         * constructor does.
-         */
-        ReferenceIdentifier getIdentifier() {
-            String c = code;
-            if (c == null) {
-                return null;
-            }
-            Citation authority = null;
-            String version = null, cs = codeSpace;
-            final URIParser parsed = URIParser.parse(c);
-            if (parsed != null) {
-                authority = Citations.fromName(cs); // May be null.
-                cs        = parsed.authority;
-                version   = parsed.version;
-                c         = parsed.code;
-            } else if (cs != null) {
-                final int s = cs.lastIndexOf(URIParser.SEPARATOR);
-                if (s >= 0) {
-                    version = cs.substring(s+1);
-                    cs = cs.substring(0, s);
-                }
-                authority = Citations.fromName(cs);
-            }
-            return new ImmutableIdentifier(authority, cs, c, version, null);
-        }
+    /**
+     * Empty constructor for JAXB only.
+     */
+    public Code() {
     }
 
     /**
-     * Substitutes the wrapper value read from an XML stream by the object which will
-     * represents the identifier. JAXB calls automatically this method at unmarshalling time.
+     * Creates a wrapper initialized to the values of the given identifier.
+     * Version number, if presents, will be appended after the codespace with a semicolon
separator.
+     * The {@link #getIdentifier()} method shall be able to perform the opposite operation
(split the
+     * above in separated codespace and version attributes).
      *
-     * @param  value The wrapper for this metadata value.
-     * @return An identifier which represents the value.
+     * @param identifier The identifier from which to get the values.
      */
-    @Override
-    public ReferenceIdentifier unmarshal(final Value value) {
-        return (value != null) ? value.getIdentifier() : null;
+    Code(final ReferenceIdentifier identifier) {
+        code      = identifier.getCode();
+        codeSpace = identifier.getCodeSpace();
+        String version = identifier.getVersion();
+        if (version != null) {
+            final StringBuilder buffer = new StringBuilder();
+            if (codeSpace != null) {
+                buffer.append(codeSpace);
+            }
+            codeSpace = buffer.append(URIParser.SEPARATOR).append(version).toString();
+        }
     }
 
     /**
-     * Substitutes the identifier by the wrapper to be marshalled into an XML file or stream.
-     * JAXB calls automatically this method at marshalling time.
-     *
-     * @param  value The metadata value.
-     * @return The adapter for the given metadata.
+     * Returns the identifier for this value. This method is the converse of the constructor.
+     * If the {@link #codeSpace} contains a semicolon, then the part after the last semicolon
+     * will be taken as the authority version number. This is for consistency with what the
+     * constructor does.
      */
-    @Override
-    public Value marshal(final ReferenceIdentifier value) {
-        return (value != null) ? new Value(value) : null;
+    ReferenceIdentifier getIdentifier() {
+        String c = code;
+        if (c == null) {
+            return null;
+        }
+        Citation authority = null;
+        String version = null, cs = codeSpace;
+        final URIParser parsed = URIParser.parse(c);
+        if (parsed != null) {
+            authority = Citations.fromName(cs); // May be null.
+            cs        = parsed.authority;
+            version   = parsed.version;
+            c         = parsed.code;
+        } else if (cs != null) {
+            final int s = cs.lastIndexOf(URIParser.SEPARATOR);
+            if (s >= 0) {
+                version = cs.substring(s+1);
+                cs = cs.substring(0, s);
+            }
+            authority = Citations.fromName(cs);
+        }
+        return new ImmutableIdentifier(authority, cs, c, version, null);
     }
 }

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/RS_Identifier.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/RS_Identifier.java?rev=1550045&r1=1550044&r2=1550045&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/RS_Identifier.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/RS_Identifier.java
[UTF-8] Wed Dec 11 04:09:56 2013
@@ -16,14 +16,8 @@
  */
 package org.apache.sis.internal.jaxb.referencing;
 
-import javax.xml.bind.annotation.XmlValue;
-import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.adapters.XmlAdapter;
-import org.opengis.metadata.citation.Citation;
 import org.opengis.referencing.ReferenceIdentifier;
-import org.apache.sis.metadata.iso.citation.Citations;
-import org.apache.sis.metadata.iso.ImmutableIdentifier;
-import org.apache.sis.internal.util.URIParser;
 
 
 /**
@@ -67,89 +61,7 @@ import org.apache.sis.internal.util.URIP
  * @version 0.4
  * @module
  */
-public final class RS_Identifier extends XmlAdapter<RS_Identifier.Value, ReferenceIdentifier>
{
-    /**
-     * The wrapper for GML identifier marshalled as a code value with a codespace attribute.
-     * Defined in a separated class because JAXB does not allow usage of {@code XmlValue}
in
-     * a class that inherit an other class.
-     */
-    public static final class Value {
-        /**
-         * The identifier code.
-         *
-         * <p><b>Note:</b> GML (the target of this class) represents that
code as an XML value, while
-         * {@link org.apache.sis.metadata.iso.ImmutableIdentifier} represents it as an XML
element.</p>
-         */
-        @XmlValue
-        String code;
-
-        /**
-         * The code space, which is often {@code "EPSG"} with the version in use.
-         *
-         * <p><b>Note:</b> GML (the target of this class) represents that
code as an XML attribute, while
-         * {@link org.apache.sis.metadata.iso.ImmutableIdentifier} represents it as an XML
element.</p>
-         */
-        @XmlAttribute
-        String codeSpace;
-
-        /**
-         * Empty constructor for JAXB only.
-         */
-        public Value() {
-        }
-
-        /**
-         * Creates a wrapper initialized to the values of the given identifier.
-         * Version number, if presents, will be appended after the codespace with a semicolon
separator.
-         * The {@link #getIdentifier()} method shall be able to perform the opposite operation
(split the
-         * above in separated codespace and version attributes).
-         *
-         * @param identifier The identifier from which to get the values.
-         */
-        Value(final ReferenceIdentifier identifier) {
-            code      = identifier.getCode();
-            codeSpace = identifier.getCodeSpace();
-            String version = identifier.getVersion();
-            if (version != null) {
-                final StringBuilder buffer = new StringBuilder();
-                if (codeSpace != null) {
-                    buffer.append(codeSpace);
-                }
-                codeSpace = buffer.append(URIParser.SEPARATOR).append(version).toString();
-            }
-        }
-
-        /**
-         * Returns the identifier for this value. This method is the converse of the constructor.
-         * If the {@link #codeSpace} contains a semicolon, then the part after the last semicolon
-         * will be taken as the authority version number. This is for consistency with what
the
-         * constructor does.
-         */
-        ReferenceIdentifier getIdentifier() {
-            String c = code;
-            if (c == null) {
-                return null;
-            }
-            Citation authority = null;
-            String version = null, cs = codeSpace;
-            final URIParser parsed = URIParser.parse(c);
-            if (parsed != null) {
-                authority = Citations.fromName(cs); // May be null.
-                cs        = parsed.authority;
-                version   = parsed.version;
-                c         = parsed.code;
-            } else if (cs != null) {
-                final int s = cs.lastIndexOf(URIParser.SEPARATOR);
-                if (s >= 0) {
-                    version = cs.substring(s+1);
-                    cs = cs.substring(0, s);
-                }
-                authority = Citations.fromName(cs);
-            }
-            return new ImmutableIdentifier(authority, cs, c, version, null);
-        }
-    }
-
+public final class RS_Identifier extends XmlAdapter<Code, ReferenceIdentifier> {
     /**
      * Substitutes the wrapper value read from an XML stream by the object which will
      * represents the identifier. JAXB calls automatically this method at unmarshalling time.
@@ -158,7 +70,7 @@ public final class RS_Identifier extends
      * @return An identifier which represents the value.
      */
     @Override
-    public ReferenceIdentifier unmarshal(final Value value) {
+    public ReferenceIdentifier unmarshal(final Code value) {
         return (value != null) ? value.getIdentifier() : null;
     }
 
@@ -170,7 +82,7 @@ public final class RS_Identifier extends
      * @return The adapter for the given metadata.
      */
     @Override
-    public Value marshal(final ReferenceIdentifier value) {
-        return (value != null) ? new Value(value) : null;
+    public Code marshal(final ReferenceIdentifier value) {
+        return (value != null) ? new Code(value) : null;
     }
 }

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/RS_IdentifierSingleton.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/RS_IdentifierSingleton.java?rev=1550045&r1=1550044&r2=1550045&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/RS_IdentifierSingleton.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/RS_IdentifierSingleton.java
[UTF-8] Wed Dec 11 04:09:56 2013
@@ -34,7 +34,7 @@ import static java.util.Collections.sing
  * @version 0.4
  * @module
  */
-public final class RS_IdentifierSingleton extends XmlAdapter<RS_Identifier.Value, Set<ReferenceIdentifier>>
{
+public final class RS_IdentifierSingleton extends XmlAdapter<Code, Set<ReferenceIdentifier>>
{
     /**
      * Substitutes the wrapper value read from an XML stream by the object which will
      * represents the identifier. JAXB calls automatically this method at unmarshalling time.
@@ -43,7 +43,7 @@ public final class RS_IdentifierSingleto
      * @return An identifier which represents the value.
      */
     @Override
-    public Set<ReferenceIdentifier> unmarshal(final RS_Identifier.Value value) {
+    public Set<ReferenceIdentifier> unmarshal(final Code value) {
         return (value != null) ? singleton(value.getIdentifier()) : null;
     }
 
@@ -55,11 +55,11 @@ public final class RS_IdentifierSingleto
      * @return The adapter for the given metadata.
      */
     @Override
-    public RS_Identifier.Value marshal(final Set<ReferenceIdentifier> value) {
+    public Code marshal(final Set<ReferenceIdentifier> value) {
         if (value != null) {
             final Iterator<ReferenceIdentifier> it = value.iterator();
             if (it.hasNext()) {
-                return new RS_Identifier.Value(it.next());
+                return new Code(it.next());
             }
         }
         return null;

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=1550045&r1=1550044&r2=1550045&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 Dec 11 04:09:56 2013
@@ -18,6 +18,7 @@ package org.apache.sis.referencing;
 
 import java.util.Map;
 import java.util.Set;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
@@ -50,7 +51,6 @@ import org.apache.sis.util.resources.Err
 
 import static org.apache.sis.util.ArgumentChecks.*;
 import static org.apache.sis.util.Utilities.deepEquals;
-import static org.apache.sis.internal.util.Citations.iterator;
 import static org.apache.sis.internal.util.CollectionsExt.nonNull;
 import static org.apache.sis.internal.util.CollectionsExt.nonEmpty;
 import static org.apache.sis.internal.util.CollectionsExt.immutableSet;
@@ -107,7 +107,7 @@ import java.util.Objects;
 @ThreadSafe
 @XmlType(name="IdentifiedObjectType", propOrder={
     "identifiers",
-    "name",
+    "names",
     "remarks"
 })
 @XmlSeeAlso({
@@ -125,19 +125,25 @@ public class AbstractIdentifiedObject ex
     private static final long serialVersionUID = -5173281694258483264L;
 
     /**
-     * The name for this object or code. Should never be {@code null}.
+     * The name for this object or code. Shall never be {@code null}.
+     *
+     * <p><b>Consider this field as final!</b>
+     * This field is modified only at unmarshalling time by {@link #setNames(Collection)}</p>
      *
      * @see #getName()
+     * @see #getNames()
      */
-    @XmlElement
-    private final ReferenceIdentifier name;
+    private ReferenceIdentifier name;
 
     /**
      * An alternative name by which this object is identified, or {@code null} if none.
      * We must be prepared to handle either null or an empty set for "no alias" because
      * we may get both on unmarshalling.
+     *
+     * <p><b>Consider this field as final!</b>
+     * This field is modified only at unmarshalling time by {@link #setNames(Collection)}</p>
      */
-    private final Collection<GenericName> alias;
+    private Collection<GenericName> alias;
 
     /**
      * An identifier which references elsewhere the object's defining information.
@@ -172,8 +178,6 @@ public class AbstractIdentifiedObject ex
      * reserved to JAXB, which will assign values to the fields using reflexion.
      */
     AbstractIdentifiedObject() {
-        name        = null;
-        alias       = null;
         identifiers = null;
         remarks     = null;
     }
@@ -361,35 +365,10 @@ public class AbstractIdentifiedObject ex
          * We will iterate over the identifiers first. Only after the iteration is over,
          * if we found no suitable ID, then we will use the primary name as a last resort.
          */
-        Iterator<ReferenceIdentifier> it = iterator(identifiers);
-        do {
-            final ReferenceIdentifier identifier;
-            if (it != null && it.hasNext()) {
-                identifier = it.next();
-            } else {
-                it = null;
-                identifier = name;
-            }
-            if (identifier != null) {
-                boolean codeSpace = true;
-                do { // Executed exactly twice: once for codespace, then once for code.
-                    final String part = codeSpace ? identifier.getCodeSpace() : identifier.getCode();
-                    if (part != null) {
-                        /*
-                         * Found a codespace (in the first iteration) or a code (in the second
iteration).
-                         * Append to the buffer only the characters that are valid for a
Unicode identifier.
-                         */
-                        for (int i=0; i<part.length();) {
-                            final int c = part.codePointAt(i);
-                            if (id.length() == 0 ? Character.isUnicodeIdentifierStart(c)
-                                                 : Character.isUnicodeIdentifierPart(c))
-                            {
-                                id.appendCodePoint(c);
-                            }
-                            i += Character.charCount(c);
-                        }
-                    }
-                } while ((codeSpace = !codeSpace) == false);
+        if (identifiers != null) {
+            for (final ReferenceIdentifier identifier : identifiers) {
+                appendID(id, identifier.getCodeSpace());
+                appendID(id, identifier.getCode());
                 if (id.length() != 0) {
                     /*
                      * TODO: If we want to check for ID uniqueness or any other condition
before to accept the ID,
@@ -399,8 +378,30 @@ public class AbstractIdentifiedObject ex
                     return id.toString();
                 }
             }
-        } while (it != null);
-        return null;
+        }
+        // In last ressort, append code without codespace since the name are often verbose.
+        appendID(id, name.getCode());
+        if (id.length() == 0) {
+            return null;
+        }
+        return id.toString();
+    }
+
+    /**
+     * Appends only the characters that are valid for a Unicode identifier.
+     */
+    private static void appendID(final StringBuilder buffer, final String text) {
+        if (text != null) {
+            for (int i=0; i<text.length();) {
+                final int c = text.codePointAt(i);
+                if (buffer.length() == 0 ? Character.isUnicodeIdentifierStart(c)
+                                         : Character.isUnicodeIdentifierPart(c))
+                {
+                    buffer.appendCodePoint(c);
+                }
+                i += Character.charCount(c);
+            }
+        }
     }
 
     /**
@@ -416,6 +417,45 @@ public class AbstractIdentifiedObject ex
     }
 
     /**
+     * Returns the {@link #name} and all aliases which are also instance of {@lik ReferenceIdentifier}.
+     * The later happen often in SIS implementation since many aliases are instance of {@link
NamedIdentifier}.
+     */
+    @XmlElement(name = "name")
+    final Collection<ReferenceIdentifier> getNames() {
+        // Unconditionally creates a modifiable list because some JAXB implementations modify
it.
+        final Collection<ReferenceIdentifier> names = new ArrayList<>(nonNull(alias).size()
+ 1);
+        names.add(name);
+        if (alias != null) {
+            for (final GenericName c : alias) {
+                if (c != name && (c instanceof ReferenceIdentifier)) {
+                    names.add((ReferenceIdentifier) c);
+                }
+            }
+        }
+        return names;
+    }
+
+    /**
+     * Sets the first element as the {@link #name} and all remaining elements as {@link #alias}.
+     * This method is invoked by JAXB at unmarshalling time. It should not be invoked anymore
+     * after the object has been made available to the user.
+     */
+    private void setNames(final Collection<ReferenceIdentifier> names) {
+        if (names != null) {
+            final Iterator<ReferenceIdentifier> it = names.iterator();
+            if (it.hasNext()) {
+                name = it.next();
+                if (it.hasNext()) {
+                    alias = new ArrayList<>(4); // There is generally few aliases.
+                    do {
+                        alias.add(new NamedIdentifier(it.next()));
+                    } while (it.hasNext());
+                }
+            }
+        }
+    }
+
+    /**
      * Returns alternative names by which this object is identified.
      *
      * @return The aliases, or an empty collection if there is none.
@@ -618,17 +658,17 @@ public class AbstractIdentifiedObject ex
         switch (mode) {
             case STRICT: {
                 final AbstractIdentifiedObject that = (AbstractIdentifiedObject) object;
-                return Objects.equals(        name,                 that.name)         &&
-                       Objects.equals(nonNull(alias),       nonNull(that.alias))       &&
-                       Objects.equals(nonNull(identifiers), nonNull(that.identifiers)) &&
-                       Objects.equals(        remarks,              that.remarks);
+                return Objects.equals(name, that.name) &&
+                       nonNull(alias).equals(nonNull(that.alias)) &&
+                       nonNull(identifiers).equals(nonNull(that.identifiers)) &&
+                       Objects.equals(remarks, that.remarks);
             }
             case BY_CONTRACT: {
                 final IdentifiedObject that = (IdentifiedObject) object;
-                return deepEquals(        getName(),                 that.getName(),    
    mode) &&
-                       deepEquals(nonNull(getAlias()),       nonNull(that.getAlias()),  
    mode) &&
-                       deepEquals(nonNull(getIdentifiers()), nonNull(that.getIdentifiers()),
mode) &&
-                       deepEquals(        getRemarks(),              that.getRemarks(), 
    mode);
+                return deepEquals(getName(),        that.getName(),        mode) &&
+                       deepEquals(getAlias(),       that.getAlias(),       mode) &&
+                       deepEquals(getIdentifiers(), that.getIdentifiers(), mode) &&
+                       deepEquals(getRemarks(),     that.getRemarks(),     mode);
             }
             case IGNORE_METADATA:
             case APPROXIMATIVE:

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/NamedIdentifier.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/NamedIdentifier.java?rev=1550045&r1=1550044&r2=1550045&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/NamedIdentifier.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/NamedIdentifier.java
[UTF-8] Wed Dec 11 04:09:56 2013
@@ -40,12 +40,21 @@ import java.util.Objects;
 
 
 /**
- * An identification of a CRS object which is both an {@link Identifier} and a {@link GenericName}.
- * The main interface implemented by this class is {@link ReferenceIdentifier}.
- * However, this class also implements {@link GenericName} in order to make it possible to
reuse
- * the same identifiers in the list of {@linkplain AbstractIdentifiedObject#getAlias() aliases}.
- * Casting an alias from {@code GenericName} to a {@code ReferenceIdentifier} gives access
to more informations,
- * like the authority URL.
+ * An identification of a CRS object which is both a {@link ReferenceIdentifier} and a {@link
GenericName}.
+ * This class implements both interfaces in order to allow usage of the same instance either
as an object
+ * {@linkplain AbstractIdentifiedObject#getName() name} or {@linkplain AbstractIdentifiedObject#getAlias()
alias}.
+ * This flexibility make easier to uses object's names in two different models:
+ *
+ * <ul>
+ *   <li>In the ISO 19111 model, objects have a single name of type {@code RS_Identifier}
and an arbitrary amount
+ *       of aliases of type {@code GenericName}.</li>
+ *   <li>In the GML model, objects have an arbitrary amount of names of type {@code
gml:CodeType},
+ *       but do not have any alias.</li>
+ * </ul>
+ *
+ * By using this {@code NamedIdentifier} class, users can declare supplemental object's names
as
+ * {@linkplain AbstractIdentifiedObject#getAlias() aliases} and have those names used in
contexts
+ * where {@code ReferenceIdentifier} instances are required, like GML marshalling time.
  *
  * {@section Name inference}
  * The generic name will be inferred from {@code ReferenceIdentifier} attributes.

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/RS_IdentifierTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/RS_IdentifierTest.java?rev=1550045&r1=1550044&r2=1550045&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/RS_IdentifierTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/RS_IdentifierTest.java
[UTF-8] Wed Dec 11 04:09:56 2013
@@ -42,7 +42,7 @@ public final strictfp class RS_Identifie
     @Test
     public void testSimple() {
         final ReferenceIdentifier id = new ImmutableIdentifier(HardCodedCitations.OGP, "EPSG",
"4326");
-        final RS_Identifier.Value value = new RS_Identifier.Value(id);
+        final Code value = new Code(id);
         assertEquals("codeSpace", "EPSG", value.codeSpace);
         assertEquals("code",      "4326", value.code);
         /*
@@ -63,7 +63,7 @@ public final strictfp class RS_Identifie
     @DependsOnMethod("testSimple")
     public void testWithVersion() {
         final ReferenceIdentifier id = new ImmutableIdentifier(HardCodedCitations.OGP, "EPSG",
"4326", "8.2", null);
-        final RS_Identifier.Value value = new RS_Identifier.Value(id);
+        final Code value = new Code(id);
         assertEquals("codeSpace", "EPSG:8.2", value.codeSpace);
         assertEquals("code",      "4326",     value.code);
         /*
@@ -85,7 +85,7 @@ public final strictfp class RS_Identifie
     @Test
     @DependsOnMethod("testWithVersion")
     public void testURN() {
-        final RS_Identifier.Value value = new RS_Identifier.Value();
+        final Code value = new Code();
         value.codeSpace = "OGP";
         value.code = "urn:ogc:def:crs:EPSG:8.2:4326";
         final ReferenceIdentifier actual = value.getIdentifier();

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java?rev=1550045&r1=1550044&r2=1550045&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java
[UTF-8] Wed Dec 11 04:09:56 2013
@@ -16,16 +16,21 @@
  */
 package org.apache.sis.referencing;
 
+import java.util.Set;
 import java.util.Map;
 import java.util.HashMap;
 import java.util.Locale;
+import java.util.Collections;
 import org.opengis.test.Validators;
+import org.opengis.referencing.ReferenceIdentifier;
+import org.apache.sis.metadata.iso.ImmutableIdentifier;
 import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
 import static org.apache.sis.test.Assert.*;
+import static org.apache.sis.test.TestUtilities.getSingleton;
 import static org.apache.sis.metadata.iso.citation.HardCodedCitations.EPSG;
 
 
@@ -47,22 +52,39 @@ public final strictfp class AbstractIden
      */
     @Test
     public void testCreateFromMap() {
-        final Map<String,Object> properties = new HashMap<>(10);
-        assertNull(properties.put("name",       "This is a name"));
-        assertNull(properties.put("remarks",    "There is remarks"));
-        assertNull(properties.put("remarks_fr", "Voici des remarques"));
+        final Map<String,Object> properties = new HashMap<>(8);
+        assertNull(properties.put("name",       "GRS 1980"));
+        assertNull(properties.put("codespace",  "EPSG"));
+        assertNull(properties.put("version",    "8.3"));
+        assertNull(properties.put("alias",      "International 1979"));//7019
+        assertNull(properties.put("remarks",    "Adopted by IUGG 1979 Canberra"));
+        assertNull(properties.put("remarks_fr", "Adopté par IUGG 1979 Canberra"));
+        validate(new AbstractIdentifiedObject(properties), Collections.<ReferenceIdentifier>emptySet(),
"GRS1980");
+        /*
+         * Adds an identifier. This should change the choice made by AbstractIdentifiedObject.getID().
+         */
+        final ReferenceIdentifier identifier = new ImmutableIdentifier(null, "EPSG", "4326");
+        assertNull(properties.put("identifiers", identifier));
+        validate(new AbstractIdentifiedObject(properties), Collections.singleton(identifier),
"EPSG4326");
+    }
 
-        final AbstractIdentifiedObject object = new AbstractIdentifiedObject(properties);
+    /**
+     * Validates the given object created by {@link #testCreateFromMap()}.
+     */
+    private static void validate(final AbstractIdentifiedObject object,
+            final Set<ReferenceIdentifier> identifiers, final String gmlID)
+    {
         Validators.validate(object);
-
-        assertEquals("name",       "This is a name",      object.getName().getCode());
-        assertNull  ("codeSpace",                         object.getName().getCodeSpace());
-        assertNull  ("version",                           object.getName().getVersion());
-        assertTrue  ("aliases",                           object.getAlias().isEmpty());
-        assertTrue  ("identifiers",                       object.getIdentifiers().isEmpty());
-        assertEquals("ID",         "Thisisaname",         object.getID());
-        assertEquals("remarks",    "There is remarks",    object.getRemarks().toString(Locale.ENGLISH));
-        assertEquals("remarks_fr", "Voici des remarques", object.getRemarks().toString(Locale.FRENCH));
+        final ReferenceIdentifier name = object.getName();
+        assertEquals("name",        "GRS 1980",                      name.getCode());
+        assertEquals("codespace",   "EPSG",                          name.getCodeSpace());
+        assertEquals("version",     "8.3",                           name.getVersion());
+        assertEquals("aliases",     "International 1979",            getSingleton(object.getAlias()).toString());
+        assertEquals("names",       Collections.singletonList(name), object.getNames());
+        assertEquals("identifiers", identifiers,                     object.getIdentifiers());
+        assertEquals("ID",          gmlID,                           object.getID());
+        assertEquals("remarks",     "Adopted by IUGG 1979 Canberra", object.getRemarks().toString(Locale.ENGLISH));
+        assertEquals("remarks_fr",  "Adopté par IUGG 1979 Canberra", object.getRemarks().toString(Locale.FRENCH));
     }
 
     /**
@@ -70,7 +92,6 @@ public final strictfp class AbstractIden
      *
      * <ul>
      *   <li>{@link AbstractIdentifiedObject#getIdentifiers()}</li>
-     *   <li>{@link AbstractIdentifiedObject#getIdentifier()}</li>
      *   <li>{@link AbstractIdentifiedObject#getID()}</li>
      * </ul>
      *

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/iso/AbstractName.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/iso/AbstractName.java?rev=1550045&r1=1550044&r2=1550045&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/iso/AbstractName.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/iso/AbstractName.java
[UTF-8] Wed Dec 11 04:09:56 2013
@@ -57,7 +57,7 @@ import java.util.Objects;
  * @version 0.3
  * @module
  */
-@XmlType(name = "GenericName")
+@XmlType(name = "GenericName") // Actually 'gml:CodeType', but the later is used elsewhere.
 public abstract class AbstractName implements GenericName, Serializable {
     /**
      * Serial number for inter-operability with different versions.

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultLocalName.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultLocalName.java?rev=1550045&r1=1550044&r2=1550045&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultLocalName.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultLocalName.java
[UTF-8] Wed Dec 11 04:09:56 2013
@@ -20,6 +20,7 @@ import java.util.List;
 import java.util.Collections;
 import java.util.Locale;
 import java.io.ObjectStreamException;
+import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
@@ -58,6 +59,7 @@ import java.util.Objects;
  * @module
  */
 @Immutable
+@XmlType(name = "LocalName") // Actually 'gml:CodeType', but the later is used elsewhere.
 @XmlRootElement(name = "LocalName")
 public class DefaultLocalName extends AbstractName implements LocalName {
     /**

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultScopedName.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultScopedName.java?rev=1550045&r1=1550044&r2=1550045&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultScopedName.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultScopedName.java
[UTF-8] Wed Dec 11 04:09:56 2013
@@ -20,6 +20,7 @@ import java.util.List;
 import java.util.Iterator;
 import java.util.ConcurrentModificationException;
 import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
 import org.opengis.util.NameSpace;
 import org.opengis.util.LocalName;
 import org.opengis.util.ScopedName;
@@ -48,6 +49,7 @@ import org.apache.sis.internal.util.Unmo
  * @module
  */
 @Immutable
+@XmlType(name = "ScopedName") // Actually 'gml:CodeType', but the later is used elsewhere.
 @XmlRootElement(name = "ScopedName")
 public class DefaultScopedName extends AbstractName implements ScopedName {
     /**



Mime
View raw message