sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1497272 - in /sis/branches/JDK7/core/sis-utility/src: main/java/org/apache/sis/internal/jaxb/gco/ main/java/org/apache/sis/util/iso/ test/java/org/apache/sis/util/iso/
Date Thu, 27 Jun 2013 09:52:18 GMT
Author: desruisseaux
Date: Thu Jun 27 09:52:18 2013
New Revision: 1497272

URL: http://svn.apache.org/r1497272
Log:
Fixed wrong marshalling of <gco:ScopedName> element.

Removed:
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/ScopedNameAdapter.java
Modified:
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_GenericName.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
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/iso/package-info.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/iso/NameMarshallingTest.java

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_GenericName.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_GenericName.java?rev=1497272&r1=1497271&r2=1497272&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_GenericName.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_GenericName.java
[UTF-8] Thu Jun 27 09:52:18 2013
@@ -16,20 +16,23 @@
  */
 package org.apache.sis.internal.jaxb.gco;
 
+import java.util.ConcurrentModificationException;
+import java.util.List;
+import java.util.Locale;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.adapters.XmlAdapter;
-
 import org.opengis.util.TypeName;
 import org.opengis.util.LocalName;
+import org.opengis.util.ScopedName;
 import org.opengis.util.MemberName;
 import org.opengis.util.GenericName;
-
 import org.apache.sis.util.iso.AbstractName;
 import org.apache.sis.util.iso.DefaultTypeName;
 import org.apache.sis.util.iso.DefaultMemberName;
-import org.apache.sis.util.iso.DefaultScopedName;
 import org.apache.sis.util.resources.Errors;
 
+import static org.apache.sis.internal.jaxb.gco.LocalNameAdapter.getNameFactory;
+
 
 /**
  * JAXB wrapper in order to map implementing class with the GeoAPI interface.
@@ -92,7 +95,7 @@ public final class GO_GenericName extend
      */
     @XmlElement(name = "LocalName")
     public String getLocalName() {
-        final Object name = this.name;
+        final AbstractName name = this.name;
         return (name instanceof LocalName) && !(name instanceof TypeName)
                 && !(name instanceof MemberName) ? name.toString() : null;
     }
@@ -101,19 +104,19 @@ public final class GO_GenericName extend
      * Sets the value for the {@code LocalName}.
      * This method is called at unmarshalling-time by JAXB.
      *
-     * @param  name The new name.
+     * @param  value The new name.
      * @throws IllegalStateException If a name is already defined.
      */
-    public void setLocalName(final String name) throws IllegalStateException {
+    public void setLocalName(final String value) throws IllegalStateException {
         ensureUndefined();
-        if (name == null) {
-            this.name = null;
+        if (value == null) {
+            name = null;
         } else {
             /*
              * Following cast should be safe because the getNameFactory() method asked specifically
              * for a DefaultNameFactory instance, which is known to create AbstractName instances.
              */
-            this.name = (AbstractName) LocalNameAdapter.getNameFactory().createLocalName(null,
name);
+            name = (AbstractName) getNameFactory().createLocalName(null, value);
         }
     }
 
@@ -124,21 +127,29 @@ public final class GO_GenericName extend
      * @return The current name, or {@code null} if none.
      */
     @XmlElement(name = "ScopedName")
-    public DefaultScopedName getScopedName() {
-        final Object name = this.name;
-        return (name instanceof DefaultScopedName) ? (DefaultScopedName) name : null;
+    public String getScopedName() {
+        final AbstractName name = this.name;
+        return (name instanceof ScopedName) ? name.toString() : null;
     }
 
     /**
      * Sets the value for the {@code ScopedName}.
      * This method is called at unmarshalling-time by JAXB.
      *
-     * @param  name The new name.
+     * @param  value The new name.
      * @throws IllegalStateException If a name is already defined.
      */
-    public void setScopedName(final DefaultScopedName name) throws IllegalStateException
{
+    public void setScopedName(final String value) throws IllegalStateException {
         ensureUndefined();
-        this.name = name;
+        if (value == null) {
+            name = null;
+        } else {
+            /*
+             * Following cast should be safe because the getNameFactory() method asked specifically
+             * for a DefaultNameFactory instance, which is known to create AbstractName instances.
+             */
+            name = (AbstractName) getNameFactory().parseGenericName(null, value);
+        }
     }
 
     /**
@@ -149,7 +160,7 @@ public final class GO_GenericName extend
      */
     @XmlElement(name = "TypeName")
     public DefaultTypeName getTypeName() {
-        final Object name = this.name;
+        final AbstractName name = this.name;
         return (name instanceof DefaultTypeName) ? (DefaultTypeName) name : null;
     }
 
@@ -157,12 +168,12 @@ public final class GO_GenericName extend
      * Sets the value for the {@code TypeName}.
      * This method is called at unmarshalling-time by JAXB.
      *
-     * @param  name The new name.
+     * @param  value The new name.
      * @throws IllegalStateException If a name is already defined.
      */
-    public void setTypeName(final DefaultTypeName name) throws IllegalStateException {
+    public void setTypeName(final DefaultTypeName value) throws IllegalStateException {
         ensureUndefined();
-        this.name = name;
+        name = value;
     }
 
     /**
@@ -173,7 +184,7 @@ public final class GO_GenericName extend
      */
     @XmlElement(name = "MemberName")
     public DefaultMemberName getMemberName() {
-        final Object name = this.name;
+        final AbstractName name = this.name;
         return (name instanceof MemberName) ? (DefaultMemberName) name : null;
     }
 
@@ -181,12 +192,12 @@ public final class GO_GenericName extend
      * Sets the value for the {@code MemberName}.
      * This method is called at unmarshalling-time by JAXB.
      *
-     * @param  name The new name.
+     * @param  value The new name.
      * @throws IllegalStateException If a name is already defined.
      */
-    public void setMemberName(final DefaultMemberName name) throws IllegalStateException
{
+    public void setMemberName(final DefaultMemberName value) throws IllegalStateException
{
         ensureUndefined();
-        this.name = name;
+        name = value;
     }
 
     /**
@@ -201,17 +212,31 @@ public final class GO_GenericName extend
         if (value == null) {
             return null;
         }
-        final AbstractName name;
+        final AbstractName impl;
         if (value instanceof AbstractName) {
-            name = (AbstractName) value;
+            impl = (AbstractName) value;
         } else {
             /*
+             * Recreates a new name for the given name in order to get
+             * a SIS implementation from an arbitrary implementation.
+             */
+            final List<? extends LocalName> parsedNames = value.getParsedNames();
+            final CharSequence[] names = new CharSequence[parsedNames.size()];
+            int i=0;
+            for (final LocalName component : parsedNames) {
+                // Asks for the unlocalized name, since we are going to marshal that.
+                names[i++] = component.toInternationalString().toString(Locale.ROOT);
+            }
+            if (i != names.length) {
+                throw new ConcurrentModificationException(Errors.format(Errors.Keys.UnexpectedChange_1,
"parsedNames"));
+            }
+            /*
              * Following cast should be safe because the getNameFactory() method asked specifically
              * for a DefaultNameFactory instance, which is known to create AbstractName instances.
              */
-            name = (AbstractName) ScopedNameAdapter.wrap(value, LocalNameAdapter.getNameFactory());
+            impl = (AbstractName) getNameFactory().createGenericName(value.scope(), names);
         }
-        return new GO_GenericName(name);
+        return new GO_GenericName(impl);
     }
 
     /**

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=1497272&r1=1497271&r2=1497272&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] Thu Jun 27 09:52:18 2013
@@ -72,6 +72,12 @@ public class DefaultLocalName extends Ab
 
     /**
      * The name, either as a {@link String} or an {@link InternationalString}.
+     *
+     * {@section Note on JAXB annotation}
+     * The {@link XmlElement} annotation applied here is appropriate for subclasses only
({@link DefaultTypeName}
+     * and {@link DefaultMemberName}). It is <strong>not</strong> appropriate
when (un)marshalling directly this
+     * {@code DefaultLocalName} class. In this later case, we will rather rely on the {@link
String} conversion
+     * performed by {@link org.apache.sis.internal.jaxb.gco.GO_GenericName}.
      */
     @XmlJavaTypeAdapter(CharSequenceAdapter.class)
     @XmlElement(name = "aName", namespace = Namespaces.GCO)

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=1497272&r1=1497271&r2=1497272&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] Thu Jun 27 09:52:18 2013
@@ -19,7 +19,6 @@ package org.apache.sis.util.iso;
 import java.util.List;
 import java.util.Iterator;
 import java.util.ConcurrentModificationException;
-import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 import org.opengis.util.NameSpace;
 import org.opengis.util.LocalName;
@@ -32,7 +31,6 @@ import org.apache.sis.util.resources.Err
 import org.apache.sis.internal.util.UnmodifiableArrayList;
 
 
-
 /**
  * A composite of a {@linkplain DefaultNameSpace name space} (as a {@linkplain DefaultLocalName
local name})
  * and a {@linkplain AbstractName generic name} valid in that name space.
@@ -290,7 +288,6 @@ public class DefaultScopedName extends A
      * Returns the sequence of local name for this generic name.
      */
     @Override
-    @XmlElement(name = "parsedName", required = true)
     public List<? extends LocalName> getParsedNames() {
         return parsedNames;
     }

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/iso/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/iso/package-info.java?rev=1497272&r1=1497271&r2=1497272&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/iso/package-info.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/iso/package-info.java
[UTF-8] Thu Jun 27 09:52:18 2013
@@ -132,9 +132,7 @@
 })
 @XmlAccessorType(XmlAccessType.NONE)
 @XmlJavaTypeAdapters({
-    @XmlJavaTypeAdapter(GO_GenericName.class),
-    @XmlJavaTypeAdapter(LocalNameAdapter.class),
-    @XmlJavaTypeAdapter(ScopedNameAdapter.class)
+    @XmlJavaTypeAdapter(GO_GenericName.class)
 })
 package org.apache.sis.util.iso;
 

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/iso/NameMarshallingTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/iso/NameMarshallingTest.java?rev=1497272&r1=1497271&r2=1497272&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/iso/NameMarshallingTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/iso/NameMarshallingTest.java
[UTF-8] Thu Jun 27 09:52:18 2013
@@ -20,6 +20,8 @@ import java.io.StringWriter;
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
+import org.opengis.util.TypeName;
+import org.opengis.util.LocalName;
 import org.opengis.util.GenericName;
 import org.opengis.util.NameFactory;
 import org.apache.sis.internal.system.DefaultFactories;
@@ -64,14 +66,14 @@ public final strictfp class NameMarshall
     }
 
     /**
-     * Tests XML of a {@link org.opengis.util.LocalName}.
+     * Tests XML of a {@link LocalName}.
      *
      * @throws JAXBException Should not happen.
      */
     @Test
     public void testLocalName() throws JAXBException {
         final NameFactory factory = DefaultFactories.NAMES;
-        final GenericName name = factory.createLocalName(null, "An ordinary local name");
+        final LocalName name = factory.createLocalName(null, "An ordinary local name");
         assertEquals("An ordinary local name", name.toString());
         final String expected =
                 "<gml:IO_IdentifiedObject>\n" +
@@ -84,19 +86,19 @@ public final strictfp class NameMarshall
     }
 
     /**
-     * Tests XML of a {@link org.opengis.util.LocalName} with {@code &} symbol.
+     * Tests XML of a {@link LocalName} with {@code &} symbol.
      *
      * @throws JAXBException Should not happen.
      */
     @Test
     public void testLocalNameWithAmp() throws JAXBException {
         final NameFactory factory = DefaultFactories.NAMES;
-        final GenericName name = factory.createLocalName(null, "A name with & and >
and <.");
+        final LocalName name = factory.createLocalName(null, "A name with & and >
and <.");
         assertEquals("A name with & and > and <.", name.toString());
         final String expected =
                 "<gml:IO_IdentifiedObject>\n" +
                 "  <gml:alias>\n" +
-                "      <gco:LocalName>A name with &amp; and &gt; and &lt;.</gco:LocalName>\n"
+
+                "    <gco:LocalName>A name with &amp; and &gt; and &lt;.</gco:LocalName>\n"
+
                 "  </gml:alias>\n" +
                 "</gml:IO_IdentifiedObject>\n";
         final String actual = marshall(name);
@@ -104,14 +106,14 @@ public final strictfp class NameMarshall
     }
 
     /**
-     * Tests XML of a {@link org.opengis.util.TypeName}.
+     * Tests XML of a {@link TypeName}.
      *
      * @throws JAXBException Should not happen.
      */
     @Test
     public void testTypeName() throws JAXBException {
         final NameFactory factory = DefaultFactories.NAMES;
-        final GenericName name = factory.createTypeName(null, "An other local name");
+        final TypeName name = factory.createTypeName(null, "An other local name");
         assertEquals("An other local name", name.toString());
         final String expected =
                 "<gml:IO_IdentifiedObject>\n" +
@@ -133,7 +135,6 @@ public final strictfp class NameMarshall
      * @throws JAXBException Should not happen.
      */
     @Test
-    @org.junit.Ignore("Expected XML seems wrong.")
     public void testScopedName() throws JAXBException {
         final NameFactory factory = DefaultFactories.NAMES;
         final GenericName name = factory.createGenericName(null, "myScope","myName");
@@ -141,10 +142,7 @@ public final strictfp class NameMarshall
         final String expected =
                 "<gml:IO_IdentifiedObject>\n" +
                 "  <gml:alias>\n" +
-                "    <gco:ScopedName>\n" +
-                "      <gco:parsedName>myScope</gco:parsedName>\n" +
-                "      <gco:parsedName>myName</gco:parsedName>\n" +
-                "    </gco:ScopedName>\n" +
+                "    <gco:ScopedName>myScope:myName</gco:ScopedName>\n" +
                 "  </gml:alias>\n" +
                 "</gml:IO_IdentifiedObject>\n";
         final String actual = marshall(name);



Mime
View raw message