sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1508124 - in /sis/branches/JDK7/core: sis-metadata/src/test/java/org/apache/sis/xml/ sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/
Date Mon, 29 Jul 2013 16:19:37 GMT
Author: desruisseaux
Date: Mon Jul 29 16:19:37 2013
New Revision: 1508124

URL: http://svn.apache.org/r1508124
Log:
Support NilReason for Float and Double types.

Added:
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Decimal32.java
      - copied, changed from r1508080, sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Decimal.java
Modified:
    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_Decimal.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/GO_Real.java

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=1508124&r1=1508123&r2=1508124&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 16:19:37 2013
@@ -17,6 +17,7 @@
 package org.apache.sis.xml;
 
 import javax.xml.bind.JAXBException;
+import org.opengis.metadata.content.Band;
 import org.opengis.metadata.citation.Series;
 import org.opengis.metadata.citation.Citation;
 import org.opengis.metadata.spatial.Dimension;
@@ -100,9 +101,7 @@ public final strictfp class NilReasonMar
         assertNotNull("Expected a sentinel value.", pass);
         assertEquals ("Nil value shall be false.",  Boolean.FALSE, pass);
         assertNotSame("Expected a sentinel value.", Boolean.FALSE, pass);
-
-        final NilReason reason = NilReason.forObject(pass);
-        assertSame("nilReason", NilReason.MISSING, reason);
+        assertSame("nilReason", NilReason.MISSING, NilReason.forObject(pass));
 
         final String actual = XML.marshal(result);
         assertXmlEquals(expected, actual, "xmlns:*");
@@ -131,9 +130,39 @@ public final strictfp class NilReasonMar
         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);
+        assertSame("nilReason", NilReason.UNKNOWN, NilReason.forObject(size));
+
+        final String actual = XML.marshal(result);
+        assertXmlEquals(expected, actual, "xmlns:*");
+        assertEquals(result, XML.unmarshal(actual));
+    }
 
-        final NilReason reason = NilReason.forObject(size);
-        assertSame("nilReason", NilReason.UNKNOWN, reason);
+    /**
+     * Tests a missing double value.
+     *
+     * @throws JAXBException Should never happen.
+     */
+    @Test
+    @DependsOnMethod("testMissing")
+    public void testMissingDouble() throws JAXBException {
+        final String expected =
+                "<gmd:MD_Band xmlns:gmd=\"" + Namespaces.GMD + '"' +
+                            " xmlns:gco=\"" + Namespaces.GCO + "\">\n" +
+                "  <gmd:minValue gco:nilReason=\"unknown\"/>\n" +
+                "  <gmd:peakResponse gco:nilReason=\"missing\"/>\n" +
+                "</gmd:MD_Band>";
+
+        final Band result = (Band) XML.unmarshal(expected);
+
+        final Double minValue = result.getMinValue();
+        assertNotNull("Expected a sentinel value.", minValue);
+        assertTrue("Nil value shall be NaN.", minValue.isNaN());
+        assertSame("nilReason", NilReason.UNKNOWN, NilReason.forObject(minValue));
+
+        final Double peakResponse = result.getMinValue();
+        assertNotNull("Expected a sentinel value.", peakResponse);
+        assertTrue("Nil value shall be NaN.", peakResponse.isNaN());
+        assertSame("nilReason", NilReason.UNKNOWN, NilReason.forObject(peakResponse));
 
         final String actual = XML.marshal(result);
         assertXmlEquals(expected, actual, "xmlns:*");

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Decimal.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Decimal.java?rev=1508124&r1=1508123&r2=1508124&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Decimal.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Decimal.java
[UTF-8] Mon Jul 29 16:19:37 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;
 
 
 /**
@@ -35,31 +34,9 @@ import javax.xml.bind.annotation.adapter
  * @module
  *
  * @see GO_Real
- * @see AsFloat
+ * @see GO_Decimal32
  */
-public final class GO_Decimal extends XmlAdapter<GO_Decimal, Double> {
-    /**
-     * Frequently used constants.
-     */
-    private static final GO_Decimal
-            P0   = new GO_Decimal(   0.0),
-            P1   = new GO_Decimal(   1.0),
-            N1   = new GO_Decimal(  -1.0),
-            P45  = new GO_Decimal(  45.0),
-            N45  = new GO_Decimal( -45.0),
-            P90  = new GO_Decimal(  90.0),
-            N90  = new GO_Decimal( -90.0),
-            P180 = new GO_Decimal( 180.0),
-            N180 = new GO_Decimal(-180.0),
-            P360 = new GO_Decimal( 360.0),
-            N360 = new GO_Decimal(-360.0);
-
-    /**
-     * The double value to handle.
-     */
-    @XmlElement(name = "Decimal")
-    public Double value;
-
+public final class GO_Decimal extends PropertyType<GO_Decimal, Double> {
     /**
      * Empty constructor used only by JAXB.
      */
@@ -67,23 +44,20 @@ public final class GO_Decimal extends Xm
     }
 
     /**
-     * Constructs an adapter for the given value.
+     * Constructs a wrapper for the given value.
      *
      * @param value The value.
      */
     private GO_Decimal(final Double value) {
-        this.value = value;
+        super(value, value.isNaN());
     }
 
     /**
-     * Allows JAXB to generate a Double object using the value found in the adapter.
-     *
-     * @param value The value wrapped in an adapter.
-     * @return The double value extracted from the adapter.
+     * Returns the Java type which is bound by this adapter.
      */
     @Override
-    public Double unmarshal(final GO_Decimal value) {
-        return (value != null) ? value.value : null;
+    protected Class<Double> getBoundType() {
+        return Double.class;
     }
 
     /**
@@ -95,94 +69,26 @@ public final class GO_Decimal extends Xm
      *         by {@code <gco:Decimal>} element.
      */
     @Override
-    public GO_Decimal marshal(final Double value) {
-        if (value == null) {
-            return null;
-        }
-        final GO_Decimal c;
-        final int index = value.intValue();
-        if (index == value.doubleValue()) {
-            switch (index) {
-                case    0: c = P0;   break;
-                case    1: c = P1;   break;
-                case   -1: c = N1;   break;
-                case   45: c = P45;  break;
-                case  -45: c = N45;  break;
-                case   90: c = P90;  break;
-                case  -90: c = N90;  break;
-                case  180: c = P180; break;
-                case -180: c = N180; break;
-                case  360: c = P360; break;
-                case -360: c = N360; break;
-                default: c = new GO_Decimal(value);
-            }
-        } else {
-            c = new GO_Decimal(value);
-        }
-        assert value.equals(c.value) : value;
-        return c;
+    public GO_Decimal wrap(final Double value) {
+        return new GO_Decimal(value);
     }
 
-
-
+    /**
+     * Invoked by JAXB at marshalling time for getting the actual value to write.
+     *
+     * @return The value to be marshalled.
+     */
+    @XmlElement(name = "Decimal")
+    public Double getElement() {
+        return skip() ? null : metadata;
+    }
 
     /**
-     * Surrounds float values by {@code <gco:Decimal>}.
-     * 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 AsFloat extends XmlAdapter<AsFloat, Float> {
-        /**
-         * The float value to handle.
-         */
-        @XmlElement(name = "Decimal")
-        public Float value;
-
-        /**
-         * Empty constructor used only by JAXB.
-         */
-        public AsFloat() {
-        }
-
-        /**
-         * Constructs an adapter for the given value.
-         *
-         * @param value The value.
-         */
-        private AsFloat(final Float value) {
-            this.value = value;
-        }
-
-        /**
-         * Allows JAXB to generate a Float object using the value found in the adapter.
-         *
-         * @param value The value wrapped in an adapter.
-         * @return The float value extracted from the adapter.
-         */
-        @Override
-        public Float unmarshal(final AsFloat 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 float value we want to surround by an element representing its
type.
-         * @return An adaptation of the float value, that is to say a float value surrounded
-         *         by {@code <gco:Decimal>} element.
-         */
-        @Override
-        public AsFloat marshal(final Float value) {
-            return (value != null) ? new AsFloat(value) : null;
-        }
+     * @param metadata The unmarshalled value.
+     */
+    public void setElement(final Double metadata) {
+        this.metadata = metadata;
     }
 }

Copied: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Decimal32.java
(from r1508080, sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Decimal.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Decimal32.java?p2=sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Decimal32.java&p1=sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Decimal.java&r1=1508080&r2=1508124&rev=1508124&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Decimal.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Decimal32.java
[UTF-8] Mon Jul 29 16:19:37 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 double values by {@code <gco:Decimal>}.
+ * Surrounds float values by {@code <gco:Decimal>}.
  * 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,160 +28,63 @@ 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 GO_Real
- * @see AsFloat
  */
-public final class GO_Decimal extends XmlAdapter<GO_Decimal, Double> {
-    /**
-     * Frequently used constants.
-     */
-    private static final GO_Decimal
-            P0   = new GO_Decimal(   0.0),
-            P1   = new GO_Decimal(   1.0),
-            N1   = new GO_Decimal(  -1.0),
-            P45  = new GO_Decimal(  45.0),
-            N45  = new GO_Decimal( -45.0),
-            P90  = new GO_Decimal(  90.0),
-            N90  = new GO_Decimal( -90.0),
-            P180 = new GO_Decimal( 180.0),
-            N180 = new GO_Decimal(-180.0),
-            P360 = new GO_Decimal( 360.0),
-            N360 = new GO_Decimal(-360.0);
-
-    /**
-     * The double value to handle.
-     */
-    @XmlElement(name = "Decimal")
-    public Double value;
-
+public final class GO_Decimal32 extends PropertyType<GO_Decimal32, Float> {
     /**
      * Empty constructor used only by JAXB.
      */
-    public GO_Decimal() {
+    public GO_Decimal32() {
     }
 
     /**
-     * Constructs an adapter for the given value.
+     * Constructs a wrapper for the given value.
      *
      * @param value The value.
      */
-    private GO_Decimal(final Double value) {
-        this.value = value;
+    private GO_Decimal32(final Float value) {
+        super(value, value.isNaN());
     }
 
     /**
-     * Allows JAXB to generate a Double object using the value found in the adapter.
-     *
-     * @param value The value wrapped in an adapter.
-     * @return The double value extracted from the adapter.
+     * Returns the Java type which is bound by this adapter.
      */
     @Override
-    public Double unmarshal(final GO_Decimal value) {
-        return (value != null) ? value.value : null;
+    protected Class<Float> getBoundType() {
+        return Float.class;
     }
 
     /**
      * 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 double value we want to surround by an element representing its type.
-     * @return An adaptation of the double value, that is to say a double value surrounded
+     * @param value The float value we want to surround by an element representing its type.
+     * @return An adaptation of the float value, that is to say a float value surrounded
      *         by {@code <gco:Decimal>} element.
      */
     @Override
-    public GO_Decimal marshal(final Double value) {
-        if (value == null) {
-            return null;
-        }
-        final GO_Decimal c;
-        final int index = value.intValue();
-        if (index == value.doubleValue()) {
-            switch (index) {
-                case    0: c = P0;   break;
-                case    1: c = P1;   break;
-                case   -1: c = N1;   break;
-                case   45: c = P45;  break;
-                case  -45: c = N45;  break;
-                case   90: c = P90;  break;
-                case  -90: c = N90;  break;
-                case  180: c = P180; break;
-                case -180: c = N180; break;
-                case  360: c = P360; break;
-                case -360: c = N360; break;
-                default: c = new GO_Decimal(value);
-            }
-        } else {
-            c = new GO_Decimal(value);
-        }
-        assert value.equals(c.value) : value;
-        return c;
+    public GO_Decimal32 wrap(final Float value) {
+        return new GO_Decimal32(value);
     }
 
-
-
+    /**
+     * Invoked by JAXB at marshalling time for getting the actual value to write.
+     *
+     * @return The value to be marshalled.
+     */
+    @XmlElement(name = "Decimal")
+    public Float getElement() {
+        return skip() ? null : metadata;
+    }
 
     /**
-     * Surrounds float values by {@code <gco:Decimal>}.
-     * 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 AsFloat extends XmlAdapter<AsFloat, Float> {
-        /**
-         * The float value to handle.
-         */
-        @XmlElement(name = "Decimal")
-        public Float value;
-
-        /**
-         * Empty constructor used only by JAXB.
-         */
-        public AsFloat() {
-        }
-
-        /**
-         * Constructs an adapter for the given value.
-         *
-         * @param value The value.
-         */
-        private AsFloat(final Float value) {
-            this.value = value;
-        }
-
-        /**
-         * Allows JAXB to generate a Float object using the value found in the adapter.
-         *
-         * @param value The value wrapped in an adapter.
-         * @return The float value extracted from the adapter.
-         */
-        @Override
-        public Float unmarshal(final AsFloat 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 float value we want to surround by an element representing its
type.
-         * @return An adaptation of the float value, that is to say a float value surrounded
-         *         by {@code <gco:Decimal>} element.
-         */
-        @Override
-        public AsFloat marshal(final Float value) {
-            return (value != null) ? new AsFloat(value) : null;
-        }
+     * @param metadata The unmarshalled value.
+     */
+    public void setElement(final Float metadata) {
+        this.metadata = metadata;
     }
 }

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=1508124&r1=1508123&r2=1508124&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 16:19:37 2013
@@ -33,7 +33,7 @@ import javax.xml.bind.annotation.XmlElem
  * @version 0.4
  * @module
  *
- * @see AsLong
+ * @see GO_Integer64
  */
 public final class GO_Integer extends PropertyType<GO_Integer, Integer> {
     /**

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Real.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Real.java?rev=1508124&r1=1508123&r2=1508124&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Real.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Real.java
[UTF-8] Mon Jul 29 16:19:37 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;
 
 
 /**
@@ -35,13 +34,7 @@ import javax.xml.bind.annotation.adapter
  *
  * @see GO_Decimal
  */
-public final class GO_Real extends XmlAdapter<GO_Real, Double> {
-    /**
-     * The double value to handle.
-     */
-    @XmlElement(name = "Real")
-    public Double value;
-
+public final class GO_Real extends PropertyType<GO_Real, Double> {
     /**
      * Empty constructor used only by JAXB.
      */
@@ -49,23 +42,20 @@ public final class GO_Real extends XmlAd
     }
 
     /**
-     * Constructs an adapter for this value.
+     * Constructs a wrapper for the given value.
      *
      * @param value The value.
      */
     private GO_Real(final Double value) {
-        this.value = value;
+        super(value, value.isNaN());
     }
 
     /**
-     * Allows JAXB to generate a Double object using the value found in the adapter.
-     *
-     * @param value The value extract from the adapter.
-     * @return A double object.
+     * Returns the Java type which is bound by this adapter.
      */
     @Override
-    public Double unmarshal(final GO_Real value) {
-        return (value != null) ? value.value : null;
+    protected Class<Double> getBoundType() {
+        return Double.class;
     }
 
     /**
@@ -77,7 +67,26 @@ public final class GO_Real extends XmlAd
      *         by {@code <gco:Real>} element.
      */
     @Override
-    public GO_Real marshal(final Double value) {
-        return (value != null) ? new GO_Real(value) : null;
+    public GO_Real wrap(final Double value) {
+        return new GO_Real(value);
+    }
+
+    /**
+     * Invoked by JAXB at marshalling time for getting the actual value to write.
+     *
+     * @return The value to be marshalled.
+     */
+    @XmlElement(name = "Real")
+    public Double getElement() {
+        return skip() ? null : metadata;
+    }
+
+    /**
+     * Invoked by JAXB at unmarshalling time for storing the result temporarily.
+     *
+     * @param metadata The unmarshalled value.
+     */
+    public void setElement(final Double metadata) {
+        this.metadata = metadata;
     }
 }



Mime
View raw message