sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1550853 - in /sis/branches/JDK6/core/sis-referencing/src: main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java
Date Fri, 13 Dec 2013 23:52:19 GMT
Author: desruisseaux
Date: Fri Dec 13 23:52:19 2013
New Revision: 1550853

URL: http://svn.apache.org/r1550853
Log:
Workaround for what seems to be a JAXB 2.1.10 in JDK 1.6.0_65 bug.
JAXB 2.2.4-2 in JDK 1.7.0_25 does not show this issue.

Modified:
    sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
    sis/branches/JDK6/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java

Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java?rev=1550853&r1=1550852&r2=1550853&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
[UTF-8] Fri Dec 13 23:52:19 2013
@@ -107,7 +107,7 @@ import org.apache.sis.internal.jdk7.Obje
 @ThreadSafe
 @XmlType(name="IdentifiedObjectType", propOrder={
     "identifiers",
-    "names",
+    "name", // This is 'names' on the JDK7 branch.
     "remarks"
 })
 @XmlSeeAlso({
@@ -127,23 +127,25 @@ public class AbstractIdentifiedObject ex
     /**
      * 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>
+     * <p><b>Difference between JDK6 and JDK7 branches:</b> in the JDK6
branch, this field is annotated directly.
+     * In the JDK7 branch, a {@code getNames()} method is annotated instead in order to marshal
name and aliases
+     * in a single list, because GML does that way. We couldn't keep the getter/setter methods
pair in the JDK6
+     * branch because JAXB 2.1.10 does not invoke the setter, while JAXB 2.2.4-2 does as
expected. The price is
+     * that aliases are lost on the JDK6 branch, while they are present on the JDK7 branch.</p>
      *
      * @see #getName()
-     * @see #getNames()
      */
-    private ReferenceIdentifier name;
+    @XmlElement(name = "name")
+    private final 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>
+     * <p><b>Difference between JDK6 and JDK7 branches:</b> See comment
for {@link #name}.</p>
      */
-    private Collection<GenericName> alias;
+    private final Collection<GenericName> alias;
 
     /**
      * An identifier which references elsewhere the object's defining information.
@@ -178,6 +180,8 @@ 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;
     }
@@ -416,44 +420,22 @@ public class AbstractIdentifiedObject ex
         return name;
     }
 
-    /**
-     * 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}.
+    /* -----------------------------------------------------------------------
+     *              DIFFERENCE BETWEEN THE JDK6 AND JDK7 BRANCHES
+     * -----------------------------------------------------------------------
+     * The JDK7 branch provides two private methods here:
+     *
+     *    - Collection<ReferenceIdentifier> getNames();
+     *    - void setNames(Collection<ReferenceIdentifier> names);
+     *
+     * The getter is annotated with @XmlElement(name = "name"), which replace
+     * the annotation on this.name field. The intend is to merge the primary
+     * name and aliases in a single list, because GML is specified that way.
+     * However JAXB 2.1.10 in JDK 1.6.0_65 does not invoke the setter method
+     * while JAXB 2.2.4-2 in 1.7.0_25 does. Because of this bug, we annotate
+     * the field instead in the JDK6 branch. The consequence is that aliases
+     * are lost.
      */
-    @XmlElement(name = "name")
-    final Collection<ReferenceIdentifier> getNames() {
-        // Unconditionally creates a modifiable list because some JAXB implementations modify
it.
-        final Collection<ReferenceIdentifier> names = new ArrayList<ReferenceIdentifier>(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<GenericName>(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.

Modified: sis/branches/JDK6/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java?rev=1550853&r1=1550852&r2=1550853&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java
[UTF-8] Fri Dec 13 23:52:19 2013
@@ -80,7 +80,7 @@ public final strictfp class AbstractIden
         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("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));



Mime
View raw message