sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1508080 - in /sis/branches/JDK7/core: sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/ sis-metadata/src/test/java/org/apache/sis/xml/ sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/ sis-utility/src/main/ja...
Date Mon, 29 Jul 2013 14:31:41 GMT
Author: desruisseaux
Date: Mon Jul 29 14:31:41 2013
New Revision: 1508080

URL: http://svn.apache.org/r1508080
Log:
Support NilReason on Integer values.

Added:
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Integer64.java
      - copied, changed from r1508068, sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Integer.java
Modified:
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultRepresentativeFraction.java
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/xml/NilReasonMarshallingTest.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Boolean.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Integer.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/PropertyType.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/NilReason.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/xml/NilReasonTest.java

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultRepresentativeFraction.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultRepresentativeFraction.java?rev=1508080&r1=1508079&r2=1508080&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultRepresentativeFraction.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultRepresentativeFraction.java
[UTF-8] Mon Jul 29 14:31:41 2013
@@ -21,7 +21,7 @@ import javax.xml.bind.annotation.XmlElem
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 import org.opengis.metadata.identification.RepresentativeFraction;
-import org.apache.sis.internal.jaxb.gco.GO_Integer;
+import org.apache.sis.internal.jaxb.gco.GO_Integer64;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.resources.Errors;
 
@@ -109,7 +109,7 @@ public class DefaultRepresentativeFracti
      * @return The denominator.
      */
     @Override
-    @XmlJavaTypeAdapter(value = GO_Integer.AsLong.class, type = long.class)
+    @XmlJavaTypeAdapter(value = GO_Integer64.class, type = long.class)
     @XmlElement(name = "denominator", required = true)
     public long getDenominator() {
         return denominator;

Modified: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/xml/NilReasonMarshallingTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/xml/NilReasonMarshallingTest.java?rev=1508080&r1=1508079&r2=1508080&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/xml/NilReasonMarshallingTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/xml/NilReasonMarshallingTest.java
[UTF-8] Mon Jul 29 14:31:41 2013
@@ -19,6 +19,7 @@ package org.apache.sis.xml;
 import javax.xml.bind.JAXBException;
 import org.opengis.metadata.citation.Series;
 import org.opengis.metadata.citation.Citation;
+import org.opengis.metadata.spatial.Dimension;
 import org.opengis.metadata.quality.ConformanceResult;
 import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.XMLTestCase;
@@ -46,9 +47,8 @@ public final strictfp class NilReasonMar
     @Test
     public void testMissing() throws JAXBException {
         final String expected =
-                "<gmd:CI_Citation xmlns:gmd=\""   + Namespaces.GMD + '"' +
-                                " xmlns:gco=\""   + Namespaces.GCO + '"' +
-                                " xmlns:xlink=\"" + Namespaces.XLINK + "\">\n" +
+                "<gmd:CI_Citation xmlns:gmd=\"" + Namespaces.GMD + '"' +
+                                " xmlns:gco=\"" + Namespaces.GCO + "\">\n" +
                 "  <gmd:title>\n" +
                 "    <gco:CharacterString>A title</gco:CharacterString>\n" +
                 "  </gmd:title>\n" +
@@ -85,9 +85,8 @@ public final strictfp class NilReasonMar
     @DependsOnMethod("testMissing")
     public void testMissingBoolean() throws JAXBException {
         final String expected =
-                "<gmd:DQ_ConformanceResult xmlns:gmd=\""   + Namespaces.GMD + '"' +
-                                         " xmlns:gco=\""   + Namespaces.GCO + '"' +
-                                         " xmlns:xlink=\"" + Namespaces.XLINK + "\">\n"
+
+                "<gmd:DQ_ConformanceResult xmlns:gmd=\"" + Namespaces.GMD + '"' +
+                                         " xmlns:gco=\"" + Namespaces.GCO + "\">\n" +
                 "  <gmd:explanation>\n" +
                 "    <gco:CharacterString>An explanation</gco:CharacterString>\n"
+
                 "  </gmd:explanation>\n" +
@@ -98,9 +97,9 @@ public final strictfp class NilReasonMar
         assertEquals("explanation", "An explanation", result.getExplanation().toString());
 
         final Boolean pass = result.pass();
-        assertNotNull("Expected a sentinal value.", pass);
+        assertNotNull("Expected a sentinel value.", pass);
         assertEquals ("Nil value shall be false.",  Boolean.FALSE, pass);
-        assertNotSame("Expected a sentinal value.", Boolean.FALSE, pass);
+        assertNotSame("Expected a sentinel value.", Boolean.FALSE, pass);
 
         final NilReason reason = NilReason.forObject(pass);
         assertSame("nilReason", NilReason.MISSING, reason);
@@ -111,6 +110,37 @@ public final strictfp class NilReasonMar
     }
 
     /**
+     * Tests a missing integer value. The {@link Boolean}, {@link Integer}, {@link Double}
and {@link String}
+     * values are implemented as special cases in {@link NilReason}, because they are final
classes on which
+     * we have no control.
+     *
+     * @throws JAXBException Should never happen.
+     */
+    @Test
+    @DependsOnMethod("testMissing")
+    public void testMissingInteger() throws JAXBException {
+        final String expected =
+                "<gmd:MD_Dimension xmlns:gmd=\"" + Namespaces.GMD + '"' +
+                                 " xmlns:gco=\"" + Namespaces.GCO + "\">\n" +
+                "  <gmd:dimensionSize gco:nilReason=\"unknown\"/>\n" +
+                "</gmd:MD_Dimension>";
+
+        final Dimension result = (Dimension) XML.unmarshal(expected);
+
+        final Integer size = result.getDimensionSize();
+        assertNotNull("Expected a sentinel value.", size);
+        assertEquals ("Nil value shall be 0.",      Integer.valueOf(0), size);
+        assertNotSame("Expected a sentinel value.", Integer.valueOf(0), size);
+
+        final NilReason reason = NilReason.forObject(size);
+        assertSame("nilReason", NilReason.UNKNOWN, reason);
+
+        final String actual = XML.marshal(result);
+        assertXmlEquals(expected, actual, "xmlns:*");
+        assertEquals(result, XML.unmarshal(actual));
+    }
+
+    /**
      * Tests a case where the nil reason is specified by an other reason.
      *
      * @throws JAXBException Should never happen.
@@ -119,9 +149,8 @@ public final strictfp class NilReasonMar
     @DependsOnMethod("testMissing")
     public void testOther() throws JAXBException {
         final String expected =
-                "<gmd:CI_Citation xmlns:gmd=\""   + Namespaces.GMD + '"' +
-                                " xmlns:gco=\""   + Namespaces.GCO + '"' +
-                                " xmlns:xlink=\"" + Namespaces.XLINK + "\">\n" +
+                "<gmd:CI_Citation xmlns:gmd=\"" + Namespaces.GMD + '"' +
+                                " xmlns:gco=\"" + Namespaces.GCO + "\">\n" +
                 "  <gmd:title>\n" +
                 "    <gco:CharacterString>A title</gco:CharacterString>\n" +
                 "  </gmd:title>\n" +
@@ -155,9 +184,8 @@ public final strictfp class NilReasonMar
     @DependsOnMethod("testMissing")
     public void testURI() throws JAXBException {
         final String expected =
-                "<gmd:CI_Citation xmlns:gmd=\""   + Namespaces.GMD + '"' +
-                                " xmlns:gco=\""   + Namespaces.GCO + '"' +
-                                " xmlns:xlink=\"" + Namespaces.XLINK + "\">\n" +
+                "<gmd:CI_Citation xmlns:gmd=\"" + Namespaces.GMD + '"' +
+                                " xmlns:gco=\"" + Namespaces.GCO + "\">\n" +
                 "  <gmd:title>\n" +
                 "    <gco:CharacterString>A title</gco:CharacterString>\n" +
                 "  </gmd:title>\n" +

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Boolean.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Boolean.java?rev=1508080&r1=1508079&r2=1508080&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Boolean.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Boolean.java
[UTF-8] Mon Jul 29 14:31:41 2013
@@ -41,7 +41,7 @@ public final class GO_Boolean extends Pr
     }
 
     /**
-     * Constructs an adapter for the given value.
+     * Constructs a wrapper for the given value.
      *
      * @param value The value.
      */

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Integer.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Integer.java?rev=1508080&r1=1508079&r2=1508080&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Integer.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Integer.java
[UTF-8] Mon Jul 29 14:31:41 2013
@@ -17,7 +17,6 @@
 package org.apache.sis.internal.jaxb.gco;
 
 import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.adapters.XmlAdapter;
 
 
 /**
@@ -31,28 +30,12 @@ import javax.xml.bind.annotation.adapter
  * @author  Cédric Briançon (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-2.5)
- * @version 0.3
+ * @version 0.4
  * @module
  *
  * @see AsLong
  */
-public final class GO_Integer extends XmlAdapter<GO_Integer, Integer> {
-    /**
-     * Frequently used constants.
-     */
-    private static final GO_Integer[] CONSTANTS = new GO_Integer[5];
-    static {
-        for (int i=0; i<CONSTANTS.length; i++) {
-            CONSTANTS[i] = new GO_Integer(i);
-        }
-    }
-
-    /**
-     * The integer value to handle.
-     */
-    @XmlElement(name = "Integer")
-    public Integer value;
-
+public final class GO_Integer extends PropertyType<GO_Integer, Integer> {
     /**
      * Empty constructor used only by JAXB.
      */
@@ -60,23 +43,20 @@ public final class GO_Integer extends Xm
     }
 
     /**
-     * Constructs an adapter for the given value.
+     * Constructs a wrapper for the given value.
      *
      * @param value The value.
      */
     private GO_Integer(final Integer value) {
-        this.value = value;
+        super(value, value.intValue() == 0);
     }
 
     /**
-     * Allows JAXB to generate an Integer object using the value found in the adapter.
-     *
-     * @param value The value wrapped in an adapter.
-     * @return The integer value extracted from the adapter.
+     * Returns the Java type which is bound by this adapter.
      */
     @Override
-    public Integer unmarshal(final GO_Integer value) {
-        return (value != null) ? value.value : null;
+    protected Class<Integer> getBoundType() {
+        return Integer.class;
     }
 
     /**
@@ -88,76 +68,26 @@ public final class GO_Integer extends Xm
      *         by {@code <gco:Integer>} element.
      */
     @Override
-    public GO_Integer marshal(final Integer value) {
-        if (value == null) {
-            return null;
-        }
-        final int i = value;
-        final GO_Integer c = (i >= 0 && i < CONSTANTS.length) ? CONSTANTS[i]
: new GO_Integer(value);
-        assert value.equals(c.value) : value;
-        return c;
+    public GO_Integer wrap(final Integer value) {
+        return new GO_Integer(value);
     }
 
-
-
+    /**
+     * Invoked by JAXB at marshalling time for getting the actual value to write.
+     *
+     * @return The value to be marshalled.
+     */
+    @XmlElement(name = "Integer")
+    public Integer getElement() {
+        return skip() ? null : metadata;
+    }
 
     /**
-     * Surrounds long values by {@code <gco:Integer>}.
-     * The ISO-19139 standard specifies that primitive types have to be surrounded by an
element
-     * which represents the type of the value, using the namespace {@code gco} linked to
the
-     * {@code http://www.isotc211.org/2005/gco} URL. The JAXB default behavior is to marshal
-     * primitive Java types directly "as is", without wrapping the value in the required
element.
-     * The role of this class is to add such wrapping.
+     * Invoked by JAXB at unmarshalling time for storing the result temporarily.
      *
-     * @author  Cédric Briançon (Geomatys)
-     * @since   0.3 (derived from geotk-2.5)
-     * @version 0.3
-     * @module
-     */
-    public static final class AsLong extends XmlAdapter<AsLong, Long> {
-        /**
-         * The long value to handle.
-         */
-        @XmlElement(name = "Integer")
-        public Long value;
-
-        /**
-         * Empty constructor used only by JAXB.
-         */
-        public AsLong() {
-        }
-
-        /**
-         * Constructs an adapter for the given value.
-         *
-         * @param value The value.
-         */
-        private AsLong(final Long value) {
-            this.value = value;
-        }
-
-        /**
-         * Allows JAXB to generate a Long object using the value found in the adapter.
-         *
-         * @param value The value wrapped in an adapter.
-         * @return The long value extracted from the adapter.
-         */
-        @Override
-        public Long unmarshal(final AsLong value) {
-            return (value != null) ? value.value : null;
-        }
-
-        /**
-         * Allows JAXB to change the result of the marshalling process, according to the
-         * ISO-19139 standard and its requirements about primitive types.
-         *
-         * @param value The integer value we want to surround by an element representing
its type.
-         * @return An adaptation of the integer value, that is to say a integer value surrounded
-         *         by {@code <gco:Integer>} element.
-         */
-        @Override
-        public AsLong marshal(final Long value) {
-            return (value != null) ? new AsLong(value) : null;
-        }
+     * @param metadata The unmarshalled value.
+     */
+    public void setElement(final Integer metadata) {
+        this.metadata = metadata;
     }
 }

Copied: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Integer64.java
(from r1508068, sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Integer.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Integer64.java?p2=sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Integer64.java&p1=sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Integer.java&r1=1508068&r2=1508080&rev=1508080&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Integer.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Integer64.java
[UTF-8] Mon Jul 29 14:31:41 2013
@@ -17,11 +17,10 @@
 package org.apache.sis.internal.jaxb.gco;
 
 import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.adapters.XmlAdapter;
 
 
 /**
- * Surrounds integer values by {@code <gco:Integer>}.
+ * Surrounds long values by {@code <gco:Integer>}.
  * The ISO-19139 standard specifies that primitive types have to be surrounded by an element
  * which represents the type of the value, using the namespace {@code gco} linked to the
  * {@code http://www.isotc211.org/2005/gco} URL. The JAXB default behavior is to marshal
@@ -29,54 +28,32 @@ import javax.xml.bind.annotation.adapter
  * The role of this class is to add such wrapping.
  *
  * @author  Cédric Briançon (Geomatys)
- * @author  Martin Desruisseaux (Geomatys)
- * @since   0.3 (derived from geotk-2.5)
- * @version 0.3
+ * @since   0.4 (derived from geotk-2.5)
+ * @version 0.4
  * @module
- *
- * @see AsLong
  */
-public final class GO_Integer extends XmlAdapter<GO_Integer, Integer> {
-    /**
-     * Frequently used constants.
-     */
-    private static final GO_Integer[] CONSTANTS = new GO_Integer[5];
-    static {
-        for (int i=0; i<CONSTANTS.length; i++) {
-            CONSTANTS[i] = new GO_Integer(i);
-        }
-    }
-
-    /**
-     * The integer value to handle.
-     */
-    @XmlElement(name = "Integer")
-    public Integer value;
-
+public final class GO_Integer64 extends PropertyType<GO_Integer64, Long> {
     /**
      * Empty constructor used only by JAXB.
      */
-    public GO_Integer() {
+    public GO_Integer64() {
     }
 
     /**
-     * Constructs an adapter for the given value.
+     * Constructs a wrapper for the given value.
      *
      * @param value The value.
      */
-    private GO_Integer(final Integer value) {
-        this.value = value;
+    private GO_Integer64(final Long value) {
+        super(value, value.longValue() == 0);
     }
 
     /**
-     * Allows JAXB to generate an Integer object using the value found in the adapter.
-     *
-     * @param value The value wrapped in an adapter.
-     * @return The integer value extracted from the adapter.
+     * Returns the Java type which is bound by this adapter.
      */
     @Override
-    public Integer unmarshal(final GO_Integer value) {
-        return (value != null) ? value.value : null;
+    protected Class<Long> getBoundType() {
+        return Long.class;
     }
 
     /**
@@ -84,80 +61,30 @@ public final class GO_Integer extends Xm
      * ISO-19139 standard and its requirements about primitive types.
      *
      * @param value The integer value we want to surround by an element representing its
type.
-     * @return An adaptation of the integer value, that is to say an integer value surrounded
+     * @return An adaptation of the integer value, that is to say a integer value surrounded
      *         by {@code <gco:Integer>} element.
      */
     @Override
-    public GO_Integer marshal(final Integer value) {
-        if (value == null) {
-            return null;
-        }
-        final int i = value;
-        final GO_Integer c = (i >= 0 && i < CONSTANTS.length) ? CONSTANTS[i]
: new GO_Integer(value);
-        assert value.equals(c.value) : value;
-        return c;
+    public GO_Integer64 wrap(final Long value) {
+        return new GO_Integer64(value);
     }
 
-
-
+    /**
+     * Invoked by JAXB at marshalling time for getting the actual value to write.
+     *
+     * @return The value to be marshalled.
+     */
+    @XmlElement(name = "Integer")
+    public Long getElement() {
+        return skip() ? null : metadata;
+    }
 
     /**
-     * Surrounds long values by {@code <gco:Integer>}.
-     * The ISO-19139 standard specifies that primitive types have to be surrounded by an
element
-     * which represents the type of the value, using the namespace {@code gco} linked to
the
-     * {@code http://www.isotc211.org/2005/gco} URL. The JAXB default behavior is to marshal
-     * primitive Java types directly "as is", without wrapping the value in the required
element.
-     * The role of this class is to add such wrapping.
+     * Invoked by JAXB at unmarshalling time for storing the result temporarily.
      *
-     * @author  Cédric Briançon (Geomatys)
-     * @since   0.3 (derived from geotk-2.5)
-     * @version 0.3
-     * @module
-     */
-    public static final class AsLong extends XmlAdapter<AsLong, Long> {
-        /**
-         * The long value to handle.
-         */
-        @XmlElement(name = "Integer")
-        public Long value;
-
-        /**
-         * Empty constructor used only by JAXB.
-         */
-        public AsLong() {
-        }
-
-        /**
-         * Constructs an adapter for the given value.
-         *
-         * @param value The value.
-         */
-        private AsLong(final Long value) {
-            this.value = value;
-        }
-
-        /**
-         * Allows JAXB to generate a Long object using the value found in the adapter.
-         *
-         * @param value The value wrapped in an adapter.
-         * @return The long value extracted from the adapter.
-         */
-        @Override
-        public Long unmarshal(final AsLong value) {
-            return (value != null) ? value.value : null;
-        }
-
-        /**
-         * Allows JAXB to change the result of the marshalling process, according to the
-         * ISO-19139 standard and its requirements about primitive types.
-         *
-         * @param value The integer value we want to surround by an element representing
its type.
-         * @return An adaptation of the integer value, that is to say a integer value surrounded
-         *         by {@code <gco:Integer>} element.
-         */
-        @Override
-        public AsLong marshal(final Long value) {
-            return (value != null) ? new AsLong(value) : null;
-        }
+     * @param metadata The unmarshalled value.
+     */
+    public void setElement(final Long metadata) {
+        this.metadata = metadata;
     }
 }

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/PropertyType.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/PropertyType.java?rev=1508080&r1=1508079&r2=1508080&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/PropertyType.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/PropertyType.java
[UTF-8] Mon Jul 29 14:31:41 2013
@@ -144,11 +144,11 @@ public abstract class PropertyType<Value
      * only if {@code check} is {@code true}.
      *
      * @param value The primitive type wrapper.
-     * @param check {@code true} if we should check for nil reasons.
+     * @param mayBeNil {@code true} if we should check for nil reasons.
      */
-    PropertyType(final BoundType value, final boolean check) {
+    PropertyType(final BoundType value, final boolean mayBeNil) {
         metadata = value;
-        if (check) {
+        if (mayBeNil) {
             final Object property = PrimitiveTypeProperties.property(value);
             if (property instanceof NilReason) {
                 reference = property.toString();

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/NilReason.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/NilReason.java?rev=1508080&r1=1508079&r2=1508080&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/NilReason.java [UTF-8]
(original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/NilReason.java [UTF-8]
Mon Jul 29 14:31:41 2013
@@ -349,13 +349,18 @@ public final class NilReason implements 
      *
      * <ul>
      *   <li><p>An <strong>interface</strong>: in such case, this
method returns an object which implement the given
-     *       interface together with the {@link NilObject} interface. The {@link NilObject#getNilReason()}
method
-     *       will return this {@code NilReason} instance, and all other methods (except the
ones inherited from
-     *       the {@code Object} class) will return an empty collection, empty array, {@code
null},
-     *       {@link Double#NaN NaN}, {@code 0} or {@code false}, in this preference order,
-     *       depending on the method return type.</p></li>
-     *   <li><p>One of {@link Boolean}, {@link Integer}, {@link Double} or {@link
String} types: in such case,
-     *       this method returns a specific instance which will be recognized as "nil" by
the XML marshaller.</p></li>
+     *       interface together with the {@link NilObject} and {@link LenientComparable}
interfaces:
+     *       <ul>
+     *         <li>The {@link NilObject#getNilReason()} method will return this {@code
NilReason} instance.</li>
+     *         <li>The {@code equals(…)} and {@code hashCode()} methods behave as
documented in {@link LenientComparable}.</li>
+     *         <li>The {@code toString()} method is unspecified (may contain debugging
information).</li>
+     *         <li>All other methods return an empty collections, empty arrays, {@code
null}, {@link Double#NaN NaN},
+     *             {@code 0} or {@code false}, in this preference order, depending on the
method return type.</li>
+     *       </ul></p>
+     *   </li>
+     *   <li><p>One of {@link Boolean}, {@link Integer}, {@link Long}, {@link
Double} or {@link String} types:
+     *       in such case, this method returns a specific instance which will be recognized
as "nil"
+     *       by the XML marshaller.</p></li>
      * </ul>
      *
      * @param  <T> The compile-time type of the {@code type} argument.
@@ -419,17 +424,19 @@ public final class NilReason implements 
     }
 
     /**
-     * Returns an {@code Boolean}, {@code Integer}, {@code Double} or {@code String} to be
considered as a nil value.
+     * Returns a {@code Boolean}, {@code Integer}, {@link Long}, {@code Double} or {@code
String}
+     * to be considered as a nil value.
      * The caller is responsible for registering the value in {@link PrimitiveTypeProperties}.
      *
      * <p><b>REMINDER:<b> If more special cases are added, do not forget
to update the {@link #mayBeNil(Object)}
-     * method and to update javadoc.</p>
+     * method and to update the {@link #createNilObject(Class)} and {@link #forObject(Object)}
javadoc.</p>
      *
      * @throws IllegalArgumentException If the given type is not a supported type.
      */
     private static Object createNilPrimitive(final Class<?> type) {
         if (type == String .class) return new String("");         // REALLY need a new instance.
         if (type == Integer.class) return new Integer(0);         // REALLY need a new instance,
not Integer.valueOf(0).
+        if (type == Long   .class) return new Long(0);            // REALLY need a new instance,
not Long.valueOf(0).
         if (type == Boolean.class) return new Boolean(false);     // REALLY need a new instance,
not Boolean.FALSE.
         if (type == Double .class) return new Double(Double.NaN); // REALLY need a new instance,
not Double.valueOf(…).
         throw new IllegalArgumentException(Errors.format(Errors.Keys.IllegalArgumentValue_2,
"type", type));
@@ -446,6 +453,7 @@ public final class NilReason implements 
         // 'instanceof' checks on instances of final classes are expected to be very fast.
         if (object instanceof String)  return ((String)  object).isEmpty();
         if (object instanceof Integer) return ((Integer) object).intValue() == 0;
+        if (object instanceof Long)    return ((Long)    object).longValue() == 0;
         if (object instanceof Boolean) return ((Boolean) object).booleanValue() == false;
         if (object instanceof Double)  return Double.isNaN(((Double) object).doubleValue());
         return false;
@@ -458,7 +466,7 @@ public final class NilReason implements 
      * <ul>
      *   <li>If the given object implements the {@link NilObject} interface, then this
method delegates
      *       to the {@link NilObject#getNilReason()} method.</li>
-     *   <li>Otherwise if the given object is one of the {@link Boolean}, {@link Integer},
{@link Double}
+     *   <li>Otherwise if the given object is one of the {@link Boolean}, {@link Integer},
{@link Long}, {@link Double}
      *       or {@link String} instances returned by {@link #createNilObject(Class)}, then
this method
      *       returns the associated reason.</li>
      *   <li>Otherwise this method returns {@code null}.</li>

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/xml/NilReasonTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/xml/NilReasonTest.java?rev=1508080&r1=1508079&r2=1508080&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/xml/NilReasonTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/xml/NilReasonTest.java
[UTF-8] Mon Jul 29 14:31:41 2013
@@ -130,6 +130,24 @@ public final strictfp class NilReasonTes
     }
 
     /**
+     * Tests {@link NilReason#createNilObject(Class)} for a long type.
+     * Opportunistically tests {@link NilReason#forObject(Object)} with the created object.
+     *
+     * @since 0.4
+     */
+    @Test
+    public void testCreateNilLong() {
+        final Long zero  = 0L;
+        final Long value = NilReason.MISSING.createNilObject(Long.class);
+        assertEquals (zero, value);
+        assertNotSame(zero, value);
+        assertSame("NilReason.forObject(…)", NilReason.MISSING, NilReason.forObject(value));
+        assertNull("NilReason.forObject(…)", NilReason.forObject(zero));
+        assertNull("NilReason.forObject(…)", NilReason.forObject(1L));
+        assertSame("Expected cached value.", value, NilReason.MISSING.createNilObject(Long.class));
+    }
+
+    /**
      * Tests {@link NilReason#createNilObject(Class)} for a double type.
      * Opportunistically tests {@link NilReason#forObject(Object)} with the created object.
      *



Mime
View raw message