sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1554728 - in /sis/branches/JDK7/core: sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/ sis-referencing/src/main/java/org/apache/sis/referencing/cs/ sis-referencing/src/main/java/org/apache/sis/referencing/datum/ sis-...
Date Thu, 02 Jan 2014 03:18:55 GMT
Author: desruisseaux
Date: Thu Jan  2 03:18:55 2014
New Revision: 1554728

URL: http://svn.apache.org/r1554728
Log:
Added missing JAXB annotations for DefaultCoordinateSystemAxis,
and marshal its "uom" attribute in the same way than <gml:MeasureType>.

Modified:
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SecondDefiningParameter.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/package-info.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/Measure.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/UnitAdapter.java

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SecondDefiningParameter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SecondDefiningParameter.java?rev=1554728&r1=1554727&r2=1554728&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SecondDefiningParameter.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SecondDefiningParameter.java
[UTF-8] Thu Jan  2 03:18:55 2014
@@ -21,7 +21,9 @@ import javax.xml.bind.annotation.XmlRoot
 import javax.measure.unit.Unit;
 import org.opengis.referencing.datum.Ellipsoid;
 import org.apache.sis.xml.Namespaces;
+import org.apache.sis.internal.jaxb.Context;
 import org.apache.sis.internal.jaxb.gco.Measure;
+import org.apache.sis.util.resources.Errors;
 
 
 /**
@@ -128,7 +130,10 @@ public final class SecondDefiningParamet
      * @param measure The inverse flattening value.
      */
     public void setInverseFlattening(final Measure measure) {
-        measure.setUnit(Unit.ONE);
+        if (measure.setUnit(Unit.ONE)) {
+            Context.warningOccured(Context.current(), SecondDefiningParameter.class, "setInverseFlattening",
+                    Errors.class, Errors.Keys.IncompatiblePropertyValue_1, "uom");
+        }
         this.measure = measure;
     }
 }

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java?rev=1554728&r1=1554727&r2=1554728&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java
[UTF-8] Thu Jan  2 03:18:55 2014
@@ -23,8 +23,10 @@ import javax.measure.unit.Unit;
 import javax.measure.unit.NonSI;
 import javax.measure.quantity.Angle;
 import javax.measure.converter.UnitConverter;
+import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
 import org.opengis.util.GenericName;
 import org.opengis.util.InternationalString;
 import org.opengis.referencing.ReferenceIdentifier;
@@ -73,6 +75,14 @@ import java.util.Objects;
  * @see AbstractCS
  * @see Unit
  */
+@XmlType(name = "CoordinateSystemAxisType", propOrder = {
+    "abbreviation",
+    "direction",
+    "minimum",
+    "maximum",
+    "rangeMeaning"
+})
+@XmlRootElement(name = "CoordinateSystemAxis")
 public class DefaultCoordinateSystemAxis extends AbstractIdentifiedObject implements CoordinateSystemAxis
{
     /**
      * Serial number for inter-operability with different versions.

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/package-info.java?rev=1554728&r1=1554727&r2=1554728&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/package-info.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/package-info.java
[UTF-8] Thu Jan  2 03:18:55 2014
@@ -38,7 +38,7 @@
     @XmlJavaTypeAdapter(CS_AxisDirection.class),
     @XmlJavaTypeAdapter(CS_CoordinateSystemAxis.class),
     @XmlJavaTypeAdapter(CS_RangeMeaning.class),
-    @XmlJavaTypeAdapter(UnitAdapter.class)
+    @XmlJavaTypeAdapter(UnitAdapter.AsURN.class)
 })
 package org.apache.sis.referencing.cs;
 

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java?rev=1554728&r1=1554727&r2=1554728&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
[UTF-8] Thu Jan  2 03:18:55 2014
@@ -364,6 +364,9 @@ public class DefaultEllipsoid extends Ab
                 inverseFlattening = semiMajorAxis / (semiMajorAxis - semiMinorAxis);
             }
         }
+        if (unit == null) {
+            Measure.missingUOM(DefaultEllipsoid.class, "semiMajorAxis");
+        }
     }
 
     /**
@@ -529,11 +532,7 @@ public class DefaultEllipsoid extends Ab
                     ensureStrictlyPositive("inverseFlattening", inverseFlattening = value);
                 } else if (semiMinorAxis == 0) {
                     ensureStrictlyPositive("semiMinorAxis", semiMinorAxis = value);
-                    if (unit == null) {
-                        unit = measure.getUnit(Length.class);
-                    } else {
-                        harmonizeAxisUnits(measure.unit);
-                    }
+                    harmonizeAxisUnits(measure.getUnit(Length.class));
                 }
                 if (semiMajorAxis != 0) {
                     afterUnmarshal();
@@ -550,8 +549,10 @@ public class DefaultEllipsoid extends Ab
      * @throws ConversionException If semi-major and semi-minor axes use inconsistent units
      *         and we can not convert from one to the other.
      */
-    private void harmonizeAxisUnits(final Unit<?> uom) throws ConversionException {
-        if (uom != null && uom != unit) {
+    private void harmonizeAxisUnits(final Unit<Length> uom) throws ConversionException
{
+        if (unit == null) {
+            unit = uom;
+        } else if (uom != null && uom != unit) {
             semiMinorAxis = uom.getConverterToAny(unit).convert(semiMinorAxis);
         }
     }

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java?rev=1554728&r1=1554727&r2=1554728&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java
[UTF-8] Thu Jan  2 03:18:55 2014
@@ -243,6 +243,18 @@ public class DefaultPrimeMeridian extend
     private void setGreenwichMeasure(final Measure measure) {
         greenwichLongitude = measure.value;
         angularUnit = measure.getUnit(Angle.class);
+        if (angularUnit == null) {
+            /*
+             * Missing unit: if the Greenwich longitude is zero, any angular unit gives the
same result
+             * (assuming that the missing unit was not applying an offset), so we can select
a default.
+             * If the Greenwich longitude is not zero, we can not guess. Our object will
be invalid.
+             */
+            if (greenwichLongitude == 0) {
+                angularUnit = NonSI.DEGREE_ANGLE;
+            } else {
+                Measure.missingUOM(DefaultPrimeMeridian.class, "setGreenwichMeasure");
+            }
+        }
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/Measure.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/Measure.java?rev=1554728&r1=1554727&r2=1554728&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/Measure.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/Measure.java
[UTF-8] Thu Jan  2 03:18:55 2014
@@ -62,6 +62,7 @@ import org.apache.sis.measure.Units;
  * @version 0.4
  * @module
  *
+ * @see UnitAdapter
  * @see org.apache.sis.measure.Measure
  */
 public final class Measure {
@@ -104,7 +105,7 @@ public final class Measure {
 
     /**
      * Constructs a string representation of the units as defined in the ISO-19103 standard.
-     * This method is invoked during XML marshalling. For example in the units are "metre",
+     * This method is invoked during XML marshalling. For example if the units are "metre",
      * then this method returns one of the following strings, in preference order:
      *
      * {@preformat text
@@ -122,9 +123,21 @@ public final class Measure {
      * @todo Strictly speaking, the above URL should be used only for "m", "deg" and "rad"
units because they
      *       are the only ones defined in the <code>gmxUom.xml</code> file. What
should we do for other units?
      */
-    @XmlAttribute(required = true)
+    @XmlAttribute(name = "uom", required = true)
     public String getUOM() {
-        final Unit<?> unit = this.unit;
+        return getUOM(unit, asXPointer);
+    }
+
+    /**
+     * Implementation of {@link #getUOM()} as a static method for use by classes that define
their own
+     * {@code uom} attribute, instead of letting the {@code uom} attribute on the measurement
value.
+     * The main example is {@link org.apache.sis.referencing.cs.DefaultCoordinateSystemAxis}.
+     *
+     * @param  unit The unit to format.
+     * @param  asXPointer {@code true} if the units shall be formatted as {@code xpointer}.
+     * @return
+     */
+    static String getUOM(final Unit<?> unit, final boolean asXPointer) {
         if (!asXPointer) {
             final Integer code = Units.getEpsgCode(unit);
             if (code != null) {
@@ -155,32 +168,42 @@ public final class Measure {
     /**
      * Returns {@link #unit} as a unit compatible with the given quantity.
      *
-     * @todo For now, this method does not format useful error message in case of missing
unit or wrong unit type.
+     * @todo For now, this method does not format useful error message in case of wrong unit
type.
      *       We define this method merely as a placeholder for future improvement in error
handling.
      *
      * @param  <Q>  Compile-time type of the {@code type} argument.
      * @param  type The quantity for the desired unit.
-     * @return A unit compatible with the given type.
+     * @return A unit compatible with the given type, or {@code null} if none.
      */
     public <Q extends Quantity> Unit<Q> getUnit(final Class<Q> type) {
-        return unit.asType(type);
+        return (unit != null) ? unit.asType(type) : null;
     }
 
     /**
-     * Sets the unit to the given value, with a warning logged if the user specified a unit
-     * different than the previous {@link #unit} value.
+     * Sets the unit to the given value, and returns {@code true} if the current {@link #unit}
value was different.
+     * A return value of {@code true} means that the caller should log a warning.
      *
      * {@example Some users wrongly assign the "m" unit to <code>Ellipsoid.inverseFlattening</code>.
      *           The SIS adapter forces the unit to <code>Unit.ONE</code>, but
we want to let the user
      *           know that he probably did something wrong.}
      *
-     * @param newUnit The new unit (can not be null).
+     * @param  newUnit The new unit (can not be null).
+     * @return {@code true} if a different unit was defined before this method call.
      */
-    public void setUnit(final Unit<?> newUnit) {
-        if (unit != null && !unit.equals(newUnit)) {
-            Context.warningOccured(Context.current(), getClass(), "setUnit",
-                    Errors.class, Errors.Keys.IncompatiblePropertyValue_1, unit);
-        }
+    public boolean setUnit(final Unit<?> newUnit) {
+        final boolean changed = (unit != null && !unit.equals(newUnit));
         unit = newUnit;
+        return changed;
+    }
+
+    /**
+     * Sends a warning for a missing {@code "uom"} attribute.
+     *
+     * @param caller     The class of the method invoking this method.
+     * @param methodName The name of the method invoking this method.
+     */
+    public static void missingUOM(final Class<?> caller, final String methodName) {
+        Context.warningOccured(Context.current(), caller, methodName,
+                Errors.class, Errors.Keys.MandatoryAttribute_2, "uom", "Measure");
     }
 }

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/UnitAdapter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/UnitAdapter.java?rev=1554728&r1=1554727&r2=1554728&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/UnitAdapter.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/UnitAdapter.java
[UTF-8] Thu Jan  2 03:18:55 2014
@@ -27,10 +27,12 @@ import org.apache.sis.internal.jaxb.Cont
  * @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 Measure
  */
-public final class UnitAdapter extends XmlAdapter<String, Unit<?>> {
+public class UnitAdapter extends XmlAdapter<String, Unit<?>> {
     /**
      * Returns a unit for the given string.
      *
@@ -39,12 +41,9 @@ public final class UnitAdapter extends X
      * @throws IllegalArgumentException if the given symbol is unknown.
      */
     @Override
-    public Unit<?> unmarshal(String value) throws IllegalArgumentException {
-        if (value != null) {
-            final Context context = Context.current();
-            return Context.converter(context).toUnit(context, value);
-        }
-        return null;
+    public final Unit<?> unmarshal(final String value) throws IllegalArgumentException
{
+        final Context context = Context.current();
+        return Context.converter(context).toUnit(context, value);
     }
 
     /**
@@ -57,4 +56,15 @@ public final class UnitAdapter extends X
     public String marshal(final Unit<?> value) {
         return (value != null) ? value.toString() : null;
     }
+
+    /**
+     * A variant of {@link UnitAdapter} which marshal units as an URN.
+     * Example: {@code "urn:ogc:def:uom:EPSG::9001"}.
+     */
+    public static final class AsURN extends UnitAdapter {
+        @Override
+        public String marshal(final Unit<?> value) {
+            return Measure.getUOM(value, false);
+        }
+    }
 }



Mime
View raw message