sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1548777 [6/6] - in /sis/trunk: ./ core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/geometry/ core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/ core/sis-metadata/src/main/java/org/apache/sis/metadata/ core/sis-me...
Date Sat, 07 Dec 2013 02:00:45 GMT
Modified: sis/trunk/core/sis-utility/src/main/java/org/apache/sis/xml/PooledUnmarshaller.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/main/java/org/apache/sis/xml/PooledUnmarshaller.java?rev=1548777&r1=1548776&r2=1548777&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/main/java/org/apache/sis/xml/PooledUnmarshaller.java [UTF-8]
(original)
+++ sis/trunk/core/sis-utility/src/main/java/org/apache/sis/xml/PooledUnmarshaller.java [UTF-8]
Sat Dec  7 02:00:42 2013
@@ -20,6 +20,9 @@ import java.net.URL;
 import java.io.File;
 import java.io.Reader;
 import java.io.InputStream;
+import java.io.FileInputStream;
+import java.io.BufferedInputStream;
+import java.io.IOException;
 import javax.xml.bind.Unmarshaller;
 import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
@@ -30,28 +33,32 @@ import javax.xml.bind.annotation.adapter
 import javax.xml.bind.attachment.AttachmentUnmarshaller;
 import javax.xml.stream.XMLEventReader;
 import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.transform.Source;
 import javax.xml.validation.Schema;
 import org.w3c.dom.Node;
 import org.xml.sax.InputSource;
 import org.apache.sis.util.Decorator;
 import org.apache.sis.internal.jaxb.Context;
+import org.apache.sis.internal.system.XMLInputFactory;
 
 
 /**
  * Wraps a {@link Unmarshaller} in order to have some control on the modifications applied
on it.
- * This wrapper serves two purpose:
+ * This wrapper serves three purposes:
  *
  * <ul>
  *   <li>Save properties before modification, in order to restore them to their original
values
  *       when the unmarshaller is recycled.</li>
  *   <li>Constructs a SIS {@link Context} object on unmarshalling, in order to give
  *       additional information to the SIS object being unmarshalled.</li>
+ *   <li>Wraps the input stream in a {@link FilteredStreamReader} if the document GML
version
+ *       in not the SIS native GML version.</li>
  * </ul>
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-3.00)
- * @version 0.3
+ * @version 0.4
  * @module
  */
 @Decorator(Unmarshaller.class)
@@ -104,29 +111,92 @@ final class PooledUnmarshaller extends P
     }
 
     /**
-     * Delegates the unmarshalling to the wrapped unmarshaller.
+     * Unmarshals to the given input with on-the-fly substitution of namespaces.
+     * This method is invoked only when the user asked to marshal from a different GML version
+     * than the one supported natively by SIS, i.e. when {@link #getFilterVersion()} returns
a
+     * non-null value.
+     *
+     * @param  input   The reader created by SIS (<b>not</b> the reader given
by the user).
+     * @param  version Identify the namespace substitutions to perform.
+     * @return The unmarshalled object.
      */
-    @Override
-    public Object unmarshal(final InputStream input) throws JAXBException {
+    private Object unmarshal(XMLStreamReader input, final FilterVersion version)
+            throws XMLStreamException, JAXBException
+    {
+        input = new FilteredStreamReader(input, version);
         final Context context = begin();
+        final Object object;
         try {
-            return unmarshaller.unmarshal(input);
+            object = unmarshaller.unmarshal(input);
         } finally {
             context.finish();
         }
+        input.close(); // Despite its name, this method does not close the underlying input
stream.
+        return object;
     }
 
     /**
-     * Delegates the unmarshalling to the wrapped unmarshaller.
+     * Same as {@link #unmarshal(XMLStreamReader, FilterVersion)}, but delegating to the
unmarshaller
+     * methods returning a JAXB element instead than the one returning the object.
      */
-    @Override
-    public Object unmarshal(final URL input) throws JAXBException {
+    private <T> JAXBElement<T> unmarshal(XMLStreamReader input, final FilterVersion
version, final Class<T> declaredType)
+            throws XMLStreamException, JAXBException
+    {
+        input = new FilteredStreamReader(input, version);
         final Context context = begin();
+        final JAXBElement<T> object;
         try {
-            return unmarshaller.unmarshal(input);
+            object = unmarshaller.unmarshal(input, declaredType);
         } finally {
             context.finish();
         }
+        input.close(); // Despite its name, this method does not close the underlying input
stream.
+        return object;
+    }
+
+    /**
+     * Delegates the unmarshalling to the wrapped unmarshaller.
+     */
+    @Override
+    public Object unmarshal(final InputStream input) throws JAXBException {
+        final FilterVersion version = getFilterVersion();
+        if (version != null) try {
+            return unmarshal(XMLInputFactory.createXMLStreamReader(input), version);
+        } catch (XMLStreamException e) {
+            throw new JAXBException(e);
+        } else {
+            final Context context = begin();
+            try {
+                return unmarshaller.unmarshal(input);
+            } finally {
+                context.finish();
+            }
+        }
+    }
+
+    /**
+     * Delegates the unmarshalling to the wrapped unmarshaller.
+     */
+    @Override
+    public Object unmarshal(final URL input) throws JAXBException {
+        final FilterVersion version = getFilterVersion();
+        if (version != null) try {
+            final InputStream s = input.openStream();
+            try {
+                return unmarshal(XMLInputFactory.createXMLStreamReader(s), version);
+            } finally {
+                s.close();
+            }
+        } catch (Exception e) { // (IOException | XMLStreamException) on the JDK7 branch.
+            throw new JAXBException(e);
+        } else {
+            final Context context = begin();
+            try {
+                return unmarshaller.unmarshal(input);
+            } finally {
+                context.finish();
+            }
+        }
     }
 
     /**
@@ -134,11 +204,23 @@ final class PooledUnmarshaller extends P
      */
     @Override
     public Object unmarshal(final File input) throws JAXBException {
-        final Context context = begin();
-        try {
-            return unmarshaller.unmarshal(input);
-        } finally {
-            context.finish();
+        final FilterVersion version = getFilterVersion();
+        if (version != null) try {
+            final InputStream s = new BufferedInputStream(new FileInputStream(input));
+            try {
+                return unmarshal(XMLInputFactory.createXMLStreamReader(s), version);
+            } finally {
+                s.close();
+            }
+        } catch (Exception e) { // (IOException | XMLStreamException) on the JDK7 branch.
+            throw new JAXBException(e);
+        } else {
+            final Context context = begin();
+            try {
+                return unmarshaller.unmarshal(input);
+            } finally {
+                context.finish();
+            }
         }
     }
 
@@ -147,11 +229,18 @@ final class PooledUnmarshaller extends P
      */
     @Override
     public Object unmarshal(final Reader input) throws JAXBException {
-        final Context context = begin();
-        try {
-            return unmarshaller.unmarshal(input);
-        } finally {
-            context.finish();
+        final FilterVersion version = getFilterVersion();
+        if (version != null) try {
+            return unmarshal(XMLInputFactory.createXMLStreamReader(input), version);
+        } catch (XMLStreamException e) {
+            throw new JAXBException(e);
+        } else {
+            final Context context = begin();
+            try {
+                return unmarshaller.unmarshal(input);
+            } finally {
+                context.finish();
+            }
         }
     }
 
@@ -160,11 +249,18 @@ final class PooledUnmarshaller extends P
      */
     @Override
     public Object unmarshal(final InputSource input) throws JAXBException {
-        final Context context = begin();
-        try {
-            return unmarshaller.unmarshal(input);
-        } finally {
-            context.finish();
+        final FilterVersion version = getFilterVersion();
+        if (version != null) try {
+            return unmarshal(XMLInputFactory.createXMLStreamReader(input), version);
+        } catch (XMLStreamException e) {
+            throw new JAXBException(e);
+        } else {
+            final Context context = begin();
+            try {
+                return unmarshaller.unmarshal(input);
+            } finally {
+                context.finish();
+            }
         }
     }
 
@@ -173,11 +269,18 @@ final class PooledUnmarshaller extends P
      */
     @Override
     public Object unmarshal(final Node input) throws JAXBException {
-        final Context context = begin();
-        try {
-            return unmarshaller.unmarshal(input);
-        } finally {
-            context.finish();
+        final FilterVersion version = getFilterVersion();
+        if (version != null) try {
+            return unmarshal(XMLInputFactory.createXMLStreamReader(input), version);
+        } catch (XMLStreamException e) {
+            throw new JAXBException(e);
+        } else {
+            final Context context = begin();
+            try {
+                return unmarshaller.unmarshal(input);
+            } finally {
+                context.finish();
+            }
         }
     }
 
@@ -186,11 +289,18 @@ final class PooledUnmarshaller extends P
      */
     @Override
     public <T> JAXBElement<T> unmarshal(final Node input, final Class<T>
declaredType) throws JAXBException {
-        final Context context = begin();
-        try {
-            return unmarshaller.unmarshal(input, declaredType);
-        } finally {
-            context.finish();
+        final FilterVersion version = getFilterVersion();
+        if (version != null) try {
+            return unmarshal(XMLInputFactory.createXMLStreamReader(input), version, declaredType);
+        } catch (XMLStreamException e) {
+            throw new JAXBException(e);
+        } else {
+            final Context context = begin();
+            try {
+                return unmarshaller.unmarshal(input, declaredType);
+            } finally {
+                context.finish();
+            }
         }
     }
 
@@ -199,11 +309,18 @@ final class PooledUnmarshaller extends P
      */
     @Override
     public Object unmarshal(final Source input) throws JAXBException {
-        final Context context = begin();
-        try {
-            return unmarshaller.unmarshal(input);
-        } finally {
-            context.finish();
+        final FilterVersion version = getFilterVersion();
+        if (version != null) try {
+            return unmarshal(XMLInputFactory.createXMLStreamReader(input), version);
+        } catch (XMLStreamException e) {
+            throw new JAXBException(e);
+        } else {
+            final Context context = begin();
+            try {
+                return unmarshaller.unmarshal(input);
+            } finally {
+                context.finish();
+            }
         }
     }
 
@@ -212,11 +329,18 @@ final class PooledUnmarshaller extends P
      */
     @Override
     public <T> JAXBElement<T> unmarshal(final Source input, final Class<T>
declaredType) throws JAXBException {
-        final Context context = begin();
-        try {
-            return unmarshaller.unmarshal(input, declaredType);
-        } finally {
-            context.finish();
+        final FilterVersion version = getFilterVersion();
+        if (version != null) try {
+            return unmarshal(XMLInputFactory.createXMLStreamReader(input), version, declaredType);
+        } catch (XMLStreamException e) {
+            throw new JAXBException(e);
+        } else {
+            final Context context = begin();
+            try {
+                return unmarshaller.unmarshal(input, declaredType);
+            } finally {
+                context.finish();
+            }
         }
     }
 
@@ -224,7 +348,11 @@ final class PooledUnmarshaller extends P
      * Delegates the unmarshalling to the wrapped unmarshaller.
      */
     @Override
-    public Object unmarshal(final XMLStreamReader input) throws JAXBException {
+    public Object unmarshal(XMLStreamReader input) throws JAXBException {
+        final FilterVersion version = getFilterVersion();
+        if (version != null) {
+            input = new FilteredStreamReader(input, version);
+        }
         final Context context = begin();
         try {
             return unmarshaller.unmarshal(input);
@@ -237,7 +365,11 @@ final class PooledUnmarshaller extends P
      * Delegates the unmarshalling to the wrapped unmarshaller.
      */
     @Override
-    public <T> JAXBElement<T> unmarshal(final XMLStreamReader input, final Class<T>
declaredType) throws JAXBException {
+    public <T> JAXBElement<T> unmarshal(XMLStreamReader input, final Class<T>
declaredType) throws JAXBException {
+        final FilterVersion version = getFilterVersion();
+        if (version != null) {
+            input = new FilteredStreamReader(input, version);
+        }
         final Context context = begin();
         try {
             return unmarshaller.unmarshal(input, declaredType);
@@ -251,11 +383,18 @@ final class PooledUnmarshaller extends P
      */
     @Override
     public Object unmarshal(final XMLEventReader input) throws JAXBException {
-        final Context context = begin();
-        try {
-            return unmarshaller.unmarshal(input);
-        } finally {
-            context.finish();
+        final FilterVersion version = getFilterVersion();
+        if (version != null) try {
+            return unmarshal(XMLInputFactory.createXMLStreamReader(input), version);
+        } catch (XMLStreamException e) {
+            throw new JAXBException(e);
+        } else {
+            final Context context = begin();
+            try {
+                return unmarshaller.unmarshal(input);
+            } finally {
+                context.finish();
+            }
         }
     }
 
@@ -264,11 +403,18 @@ final class PooledUnmarshaller extends P
      */
     @Override
     public <T> JAXBElement<T> unmarshal(final XMLEventReader input, final Class<T>
declaredType) throws JAXBException {
-        final Context context = begin();
-        try {
-            return unmarshaller.unmarshal(input, declaredType);
-        } finally {
-            context.finish();
+        final FilterVersion version = getFilterVersion();
+        if (version != null) try {
+            return unmarshal(XMLInputFactory.createXMLStreamReader(input), version, declaredType);
+        } catch (XMLStreamException e) {
+            throw new JAXBException(e);
+        } else {
+            final Context context = begin();
+            try {
+                return unmarshaller.unmarshal(input, declaredType);
+            } finally {
+                context.finish();
+            }
         }
     }
 

Modified: sis/trunk/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/MeasureTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/MeasureTest.java?rev=1548777&r1=1548776&r2=1548777&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/MeasureTest.java
[UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/MeasureTest.java
[UTF-8] Sat Dec  7 02:00:42 2013
@@ -44,15 +44,21 @@ public final strictfp class MeasureTest 
         final Measure measure = new Measure();
         measure.setUOM("http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#m");
         assertEquals(SI.METRE, measure.unit);
+        assertEquals("urn:ogc:def:uom:EPSG::9001", measure.getUOM());
+        measure.asXPointer = true;
         assertEquals("http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#xpointer(//*[@gml:id='m'])",
measure.getUOM());
 
         measure.unit = null;
-        measure.setUOM("../uom/ML_gmxUom.xsd#xpointer(//*[@gml:id='deg'])");
+        measure.asXPointer = false;
+        measure.setUOM("../uom/ML_gmxUom.xml#xpointer(//*[@gml:id='deg'])");
         assertEquals(NonSI.DEGREE_ANGLE, measure.unit);
+        assertEquals("urn:ogc:def:uom:EPSG::9102", measure.getUOM());
+        measure.asXPointer = true;
         assertEquals("http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#xpointer(//*[@gml:id='deg'])",
measure.getUOM());
 
         measure.unit = null;
-        measure.setUOM("http://my.big.org/units/kg");
+        measure.asXPointer = true;
+        measure.setUOM("gmxUom.xml#kg"); // Not really an existing unit in 'gmxUom'.
         assertEquals(SI.KILOGRAM, measure.unit);
         assertEquals("http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#xpointer(//*[@gml:id='kg'])",
measure.getUOM());
     }

Modified: sis/trunk/core/sis-utility/src/test/java/org/apache/sis/internal/util/DoubleDoubleTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/test/java/org/apache/sis/internal/util/DoubleDoubleTest.java?rev=1548777&r1=1548776&r2=1548777&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/test/java/org/apache/sis/internal/util/DoubleDoubleTest.java
[UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/test/java/org/apache/sis/internal/util/DoubleDoubleTest.java
[UTF-8] Sat Dec  7 02:00:42 2013
@@ -50,16 +50,17 @@ public final strictfp class DoubleDouble
 
     /**
      * The tolerance factor (as a multiplicand) for the addition and subtraction operations.
+     * This is a tolerance factor in units of {@link DoubleDouble#value} ULP. Results smaller
+     * than 1 ULP of {@link DoubleDouble#error} will be clamped.
      */
-    private static final double ADD_TOLERANCE_FACTOR = 1;
+    private static final double ADD_TOLERANCE_FACTOR = 1E-17;
 
     /**
      * The tolerance factor (as a multiplicand) for the multiplication and division operations.
-     * This is a tolerance factor in units of {@link DoubleDouble#error} ULP, so even a "scary"
-     * factor like 1E+5 should be very small compared to the {@link DoubleDouble#value}.
-     * This is the worst case error found empirically - most errors are smaller than that.
+     * This is a tolerance factor in units of {@link DoubleDouble#value} ULP. Results smaller
+     * than 1 ULP of {@link DoubleDouble#error} will be clamped.
      */
-    private static final double PRODUCT_TOLERANCE_FACTOR = 100000;
+    private static final double PRODUCT_TOLERANCE_FACTOR = 1E-15;
 
     /**
      * Tolerance threshold for strict comparisons of floating point values.
@@ -118,7 +119,7 @@ public final strictfp class DoubleDouble
     private static void assertExtendedEquals(final BigDecimal expected, final DoubleDouble
actual, final double ef) {
         final BigDecimal value = toBigDecimal(actual);
         final double delta = abs(expected.subtract(value).doubleValue());
-        final double threshold = ulp(actual.error) * ef;
+        final double threshold = max(ulp(actual.error), ulp(actual.value) * ef);
         if (!(delta <= threshold)) { // Use ! for catching NaN values.
             fail("Arithmetic error:\n" +
                  "  Expected:   " + expected  + '\n' +

Modified: sis/trunk/core/sis-utility/src/test/java/org/apache/sis/measure/UnitsTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/test/java/org/apache/sis/measure/UnitsTest.java?rev=1548777&r1=1548776&r2=1548777&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/test/java/org/apache/sis/measure/UnitsTest.java [UTF-8]
(original)
+++ sis/trunk/core/sis-utility/src/test/java/org/apache/sis/measure/UnitsTest.java [UTF-8]
Sat Dec  7 02:00:42 2013
@@ -17,10 +17,9 @@
 package org.apache.sis.measure;
 
 import javax.measure.unit.Unit;
-import javax.measure.quantity.Quantity;
-import javax.measure.converter.UnitConverter;
+import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
-import org.junit.*;
+import org.junit.Test;
 
 import static javax.measure.unit.Unit.ONE;
 import static javax.measure.unit.SI.CELSIUS;
@@ -36,6 +35,7 @@ import static javax.measure.unit.NonSI.D
 import static javax.measure.unit.NonSI.SPHERE;
 import static javax.measure.unit.NonSI.ATMOSPHERE;
 import static javax.measure.unit.NonSI.NAUTICAL_MILE;
+import static org.apache.sis.measure.SexagesimalConverter.*;
 import static org.apache.sis.measure.Units.*;
 import static org.apache.sis.test.Assert.*;
 
@@ -45,32 +45,21 @@ import static org.apache.sis.test.Assert
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-2.5)
- * @version 0.3
+ * @version 0.4
  * @module
  */
+@DependsOn({
+    SexagesimalConverterTest.class,
+    org.apache.sis.internal.util.URIParserTest.class
+})
 public final strictfp class UnitsTest extends TestCase {
     /**
-     * Compares two values for equality.
-     */
-    private static <Q extends Quantity> void checkConversion(
-            final double expected, final Unit<Q> unitExpected,
-            final double actual,   final Unit<Q> unitActual)
-    {
-        UnitConverter converter = unitActual.getConverterTo(unitExpected);
-        assertEquals(expected, converter.convert(actual), 1E-6);
-        converter = converter.inverse();
-        assertEquals(actual, converter.convert(expected), 1E-6);
-    }
-
-    /**
-     * Checks the conversions using {@link Units#SEXAGESIMAL_DMS}.
+     * Sanity check of {@link UnitsMap}. This test fail if at least one code in the
+     * {@link UnitsMap#EPSG_CODES} static initializer is invalid.
      */
     @Test
-    public void testSexagesimal() {
-        checkConversion(10.00, DEGREE_ANGLE, 10.0000, SEXAGESIMAL_DMS);
-        checkConversion(10.01, DEGREE_ANGLE, 10.0036, SEXAGESIMAL_DMS);
-        checkConversion(10.50, DEGREE_ANGLE, 10.3000, SEXAGESIMAL_DMS);
-        checkConversion(10.99, DEGREE_ANGLE, 10.5924, SEXAGESIMAL_DMS);
+    public void testUnitsMap() {
+        assertFalse(UnitsMap.EPSG_CODES.containsKey(null));
     }
 
     /**
@@ -82,8 +71,8 @@ public final strictfp class UnitsTest ex
     @Test
     public void testSerialization() {
         assertEquals(DEGREE_ANGLE,         assertSerializedEquals(DEGREE_ANGLE));
-        assertEquals(SEXAGESIMAL_DMS,      assertSerializedEquals(SEXAGESIMAL_DMS));
-        assertEquals(DEGREE_MINUTE_SECOND, assertSerializedEquals(DEGREE_MINUTE_SECOND));
+        assertEquals(DMS,      assertSerializedEquals(DMS));
+        assertEquals(DMS_SCALED, assertSerializedEquals(DMS_SCALED));
         assertEquals(PPM,                  assertSerializedEquals(PPM));
     }
 
@@ -110,8 +99,8 @@ public final strictfp class UnitsTest ex
         // Additional units
         assertFalse(isTemporal(PPM));
         assertTrue (isTemporal(MILLISECOND));
-        assertFalse(isTemporal(SEXAGESIMAL_DMS));
-        assertFalse(isTemporal(DEGREE_MINUTE_SECOND));
+        assertFalse(isTemporal(DMS));
+        assertFalse(isTemporal(DMS_SCALED));
     }
 
     /**
@@ -137,8 +126,8 @@ public final strictfp class UnitsTest ex
         // Additional units
         assertFalse(isLinear(PPM));
         assertFalse(isLinear(MILLISECOND));
-        assertFalse(isLinear(SEXAGESIMAL_DMS));
-        assertFalse(isLinear(DEGREE_MINUTE_SECOND));
+        assertFalse(isLinear(DMS));
+        assertFalse(isLinear(DMS_SCALED));
     }
 
     /**
@@ -164,8 +153,8 @@ public final strictfp class UnitsTest ex
         // Additional units
         assertFalse(isAngular(PPM));
         assertFalse(isAngular(MILLISECOND));
-        assertTrue (isAngular(SEXAGESIMAL_DMS));
-        assertTrue (isAngular(DEGREE_MINUTE_SECOND));
+        assertTrue (isAngular(DMS));
+        assertTrue (isAngular(DMS_SCALED));
     }
 
     /**
@@ -191,8 +180,8 @@ public final strictfp class UnitsTest ex
         // Additional units
         assertTrue (isScale(PPM));
         assertFalse(isScale(MILLISECOND));
-        assertFalse(isScale(SEXAGESIMAL_DMS));
-        assertFalse(isScale(DEGREE_MINUTE_SECOND));
+        assertFalse(isScale(DMS));
+        assertFalse(isScale(DMS_SCALED));
     }
 
     /**
@@ -260,7 +249,7 @@ public final strictfp class UnitsTest ex
     }
 
     /**
-     * Tests {@link Units#valueOfEPSG(int)}.
+     * Tests {@link Units#valueOfEPSG(int)} and {@link Units#valueOf(String)} with a {@code
"EPSG:####"} syntax.
      */
     @Test
     public void testValueOfEPSG() {
@@ -268,5 +257,18 @@ public final strictfp class UnitsTest ex
         assertSame(DEGREE_ANGLE, valueOfEPSG(9102));
         assertSame(METRE,        valueOf("EPSG:9001"));
         assertSame(DEGREE_ANGLE, valueOf(" epsg : 9102"));
+        assertSame(DEGREE_ANGLE, valueOf("urn:ogc:def:uom:EPSG::9102"));
+        assertSame(METRE,        valueOf("http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#xpointer(//*[@gml:id='m'])"));
+        assertSame(METRE,        valueOf("gmxUom.xml#m"));
+    }
+
+    /**
+     * Tests {@link Units#getEpsgCode(Unit)}.
+     */
+    @Test
+    public void testGetEpsgCode() {
+        assertEquals(Integer.valueOf(9001), getEpsgCode(METRE));
+        assertEquals(Integer.valueOf(9102), getEpsgCode(DEGREE_ANGLE));
+        assertEquals(Integer.valueOf(9110), getEpsgCode(DMS));
     }
 }

Modified: sis/trunk/core/sis-utility/src/test/java/org/apache/sis/test/XMLTestCase.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/test/java/org/apache/sis/test/XMLTestCase.java?rev=1548777&r1=1548776&r2=1548777&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/test/java/org/apache/sis/test/XMLTestCase.java [UTF-8]
(original)
+++ sis/trunk/core/sis-utility/src/test/java/org/apache/sis/test/XMLTestCase.java [UTF-8]
Sat Dec  7 02:00:42 2013
@@ -16,6 +16,8 @@
  */
 package org.apache.sis.test;
 
+import java.util.Map;
+import java.util.HashMap;
 import java.util.Locale;
 import java.util.TimeZone;
 import java.io.StringReader;
@@ -25,9 +27,11 @@ import javax.xml.bind.Unmarshaller;
 import javax.xml.bind.JAXBException;
 import org.apache.sis.internal.jaxb.Context;
 import org.apache.sis.util.ArgumentChecks;
+import org.apache.sis.xml.MarshallerPool;
+import org.apache.sis.xml.XML;
 import org.junit.After;
 
-import static org.junit.Assert.*;
+import static org.opengis.test.Assert.*;
 
 
 /**
@@ -41,13 +45,23 @@ import static org.junit.Assert.*;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.3
+ * @version 0.4
  * @module
  *
  * @see XMLComparator
  */
 public abstract strictfp class XMLTestCase extends TestCase {
     /**
+     * A poll of configured {@link Marshaller} and {@link Unmarshaller} binded to the default
set of classes.
+     * The locale is set to {@link Locale#UK} (the language of ISO standards) and the timezone
is arbitrarily
+     * set to CET (Central European Time). We intentionally use a timezone different than
UTC in order to have
+     * an error of one or two hours if a code fails to take timezone offset in account.
+     *
+     * <p>This field is initially {@code null} and created when first needed.</p>
+     */
+    private static MarshallerPool defaultPool;
+
+    /**
      * The context containing locale, timezone, GML version and other information.
      * The context is initially {@code null} and can be created either explicitely,
      * or by invoking the {@link #createContext(boolean, Locale, String)} convenience method.
@@ -69,6 +83,27 @@ public abstract strictfp class XMLTestCa
     }
 
     /**
+     * Returns the default XML (un)marshaller pool potentially shared by test methods in
all sub-classes.
+     * The (un)marshallers locale is set to {@link Locale#UK} (the language of ISO standards)
and their
+     * timezone is arbitrarily set to CET (<cite>Central European Time</cite>).
+     *
+     * {@note We intentionally use a timezone different than UTC in order to have an error
of one or two hours
+     *        if a code fails to take timezone offset in account.}
+     *
+     * @return The shared (un)marshaller pool.
+     * @throws JAXBException If an error occurred while creating the JAXB marshaller.
+     */
+    protected static synchronized MarshallerPool getMarshallerPool() throws JAXBException
{
+        if (defaultPool == null) {
+            final Map<String,Object> properties = new HashMap<String,Object>(4);
+            assertNull(properties.put(XML.LOCALE, Locale.UK));
+            assertNull(properties.put(XML.TIMEZONE, "CET"));
+            defaultPool = new MarshallerPool(properties);
+        }
+        return defaultPool;
+    }
+
+    /**
      * Initializes the {@link #context} to the given locale and timezone.
      *
      * @param marshal  {@code true} for setting the {@link Context#MARSHALLING} flag.
@@ -97,15 +132,31 @@ public abstract strictfp class XMLTestCa
     }
 
     /**
+     * Marshals the given object using the {@linkplain #getMarshallerPool() test marshaller
pool}.
+     *
+     * @param  object The object to marshal.
+     * @return The marshalled object.
+     * @throws JAXBException If an error occurred while marshalling the object.
+     */
+    protected final String marshal(final Object object) throws JAXBException {
+        final MarshallerPool pool = getMarshallerPool();
+        final Marshaller marshaller = pool.acquireMarshaller();
+        final String xml = marshal(marshaller, object);
+        pool.recycle(marshaller);
+        return xml;
+    }
+
+    /**
      * Marshals the given object using the given marshaler.
      *
      * @param  marshaller The marshaller to use.
-     * @param  object     The object to marshal, or {@code null}.
-     * @return The marshalled object, or {@code null} if and only if the given {@code object}
was null.
+     * @param  object The object to marshal.
+     * @return The marshalled object.
      * @throws JAXBException If an error occurred while marshalling the object.
      */
     protected final String marshal(final Marshaller marshaller, final Object object) throws
JAXBException {
         ArgumentChecks.ensureNonNull("marshaller", marshaller);
+        ArgumentChecks.ensureNonNull("object", object);
         if (buffer == null) {
             buffer = new StringWriter();
         }
@@ -115,15 +166,34 @@ public abstract strictfp class XMLTestCa
     }
 
     /**
+     * Unmarshals the given object using the {@linkplain #getMarshallerPool() test marshaller
pool}.
+     *
+     * @param  <T>  Compile-time type of {@code type} argument.
+     * @param  type The expected type of the unmarshalled object.
+     * @param  xml  The XML representation of the object to unmarshal.
+     * @return The unmarshalled object.
+     * @throws JAXBException If an error occurred while unmarshalling the XML.
+     */
+    protected final <T> T unmarshal(final Class<T> type, final String xml) throws
JAXBException {
+        final MarshallerPool pool = getMarshallerPool();
+        final Unmarshaller unmarshaller = pool.acquireUnmarshaller();
+        final Object object = unmarshal(unmarshaller, xml);
+        pool.recycle(unmarshaller);
+        assertInstanceOf("unmarshal", type, object);
+        return type.cast(object);
+    }
+
+    /**
      * Unmarshals the given XML using the given unmarshaler.
      *
      * @param  unmarshaller The unmarshaller to use.
-     * @param  xml The XML representation of the object to unmarshal, or {@code null}.
-     * @return The unmarshalled object, or {@code null} if and only if the given {@code xml}
was null.
+     * @param  xml The XML representation of the object to unmarshal.
+     * @return The unmarshalled object.
      * @throws JAXBException If an error occurred while unmarshalling the XML.
      */
     protected final Object unmarshal(final Unmarshaller unmarshaller, final String xml) throws
JAXBException {
         ArgumentChecks.ensureNonNull("unmarshaller", unmarshaller);
+        ArgumentChecks.ensureNonNull("xml", xml);
         return unmarshaller.unmarshal(new StringReader(xml));
     }
 }

Modified: sis/trunk/core/sis-utility/src/test/java/org/apache/sis/test/mock/IdentifiedObjectMock.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/test/java/org/apache/sis/test/mock/IdentifiedObjectMock.java?rev=1548777&r1=1548776&r2=1548777&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/test/java/org/apache/sis/test/mock/IdentifiedObjectMock.java
[UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/test/java/org/apache/sis/test/mock/IdentifiedObjectMock.java
[UTF-8] Sat Dec  7 02:00:42 2013
@@ -86,9 +86,11 @@ public strictfp class IdentifiedObjectMo
      * Creates an identified object of the given alias.
      * Callers are free to assign new value to the {@link #alias} field directly.
      *
-     * @param alias The initial {@link #alias} value (can be {@code null}).
+     * @param code  The initial {@link #getCode()} value, or {@code null} if none.
+     * @param alias The initial {@link #alias} value, or {@code null} if none.
      */
-    public IdentifiedObjectMock(final GenericName alias) {
+    public IdentifiedObjectMock(final String code, final GenericName alias) {
+        this.code  = code;
         this.alias = alias;
     }
 

Modified: sis/trunk/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java?rev=1548777&r1=1548776&r2=1548777&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
[UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
[UTF-8] Sat Dec  7 02:00:42 2013
@@ -51,6 +51,7 @@ import org.junit.BeforeClass;
     org.apache.sis.util.LocalesTest.class,
     org.apache.sis.util.resources.LoaderTest.class,
     org.apache.sis.util.resources.IndexedResourceBundleTest.class,
+    org.apache.sis.util.ArgumentChecksTest.class, // Uses resources.
     org.apache.sis.util.logging.PerformanceLevelTest.class,
     org.apache.sis.util.logging.WarningListenersTest.class,
     org.apache.sis.util.logging.MonolineFormatterTest.class,
@@ -77,6 +78,7 @@ import org.junit.BeforeClass;
     org.apache.sis.internal.util.CollectionsExtTest.class,
 
     // GeoAPI most basic types.
+    org.apache.sis.internal.util.URIParserTest.class,
     org.apache.sis.util.iso.TypesTest.class,
     org.apache.sis.util.iso.SimpleInternationalStringTest.class,
     org.apache.sis.util.iso.DefaultInternationalStringTest.class,
@@ -85,6 +87,7 @@ import org.junit.BeforeClass;
     org.apache.sis.util.iso.DefaultNameFactoryTest.class,
 
     // Measurements and formatting.
+    org.apache.sis.measure.SexagesimalConverterTest.class,
     org.apache.sis.measure.UnitsTest.class,
     org.apache.sis.measure.RangeTest.class,
     org.apache.sis.measure.DateRangeTest.class,

Modified: sis/trunk/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java?rev=1548777&r1=1548776&r2=1548777&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java [UTF-8]
(original)
+++ sis/trunk/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java [UTF-8]
Sat Dec  7 02:00:42 2013
@@ -464,6 +464,17 @@ public final strictfp class CharSequence
     }
 
     /**
+     * Tests the {@link CharSequences#replace(CharSequence, CharSequence, CharSequence)}
method.
+     */
+    @Test
+    public void testReplace() {
+        final String text = "One apple, two orange oranges";
+        assertSame(text, replace(text, "pineapple", "orange"));
+        assertEquals("One orange, two orange oranges", replace(text, "apple", "orange").toString());
+        assertEquals("One apple, two apple apples",    replace(text, "orange", "apple").toString());
+    }
+
+    /**
      * Tests the {@link CharSequences#copyChars(CharSequence, int, char[], int, int)} method.
      */
     @Test

Modified: sis/trunk/core/sis-utility/src/test/java/org/apache/sis/util/iso/NameMarshallingTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/test/java/org/apache/sis/util/iso/NameMarshallingTest.java?rev=1548777&r1=1548776&r2=1548777&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/test/java/org/apache/sis/util/iso/NameMarshallingTest.java
[UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/test/java/org/apache/sis/util/iso/NameMarshallingTest.java
[UTF-8] Sat Dec  7 02:00:42 2013
@@ -63,7 +63,7 @@ public final strictfp class NameMarshall
             pool = new MarshallerPool(JAXBContext.newInstance(IdentifiedObjectMock.class),
null);
         }
         final Marshaller marshaller = pool.acquireMarshaller();
-        final String xml = marshal(marshaller, new IdentifiedObjectMock(name));
+        final String xml = marshal(marshaller, new IdentifiedObjectMock(null, name));
         pool.recycle(marshaller);
         return xml;
     }

Modified: sis/trunk/core/sis-utility/src/test/java/org/apache/sis/util/logging/MonolineFormatterTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-utility/src/test/java/org/apache/sis/util/logging/MonolineFormatterTest.java?rev=1548777&r1=1548776&r2=1548777&view=diff
==============================================================================
--- sis/trunk/core/sis-utility/src/test/java/org/apache/sis/util/logging/MonolineFormatterTest.java
[UTF-8] (original)
+++ sis/trunk/core/sis-utility/src/test/java/org/apache/sis/util/logging/MonolineFormatterTest.java
[UTF-8] Sat Dec  7 02:00:42 2013
@@ -59,8 +59,9 @@ public final strictfp class MonolineForm
      */
     private static String localize(final Level level, final String expected) {
         final String label = level.getLocalizedName();
-        return expected.replace(level.getName(), label)
-                .replace("\t", CharSequences.spaces(MonolineFormatter.levelWidth(null) -
label.length()));
+        CharSequence text = CharSequences.replace(expected, level.getName(), label);
+        text = CharSequences.replace(text, "\t", CharSequences.spaces(MonolineFormatter.levelWidth(null)
- label.length()));
+        return text.toString();
     }
 
     /**

Modified: sis/trunk/ide-project/NetBeans/build.xml
URL: http://svn.apache.org/viewvc/sis/trunk/ide-project/NetBeans/build.xml?rev=1548777&r1=1548776&r2=1548777&view=diff
==============================================================================
--- sis/trunk/ide-project/NetBeans/build.xml (original)
+++ sis/trunk/ide-project/NetBeans/build.xml Sat Dec  7 02:00:42 2013
@@ -97,6 +97,9 @@
       <fileset dir="${project.root}/core/sis-metadata/src/test/resources">
         <include name="**/*.xml"/>
       </fileset>
+      <fileset dir="${project.root}/core/sis-referencing/src/test/resources">
+        <include name="**/*.xml"/>
+      </fileset>
     </copy>
     <copy todir="${build.test.classes.dir}">
       <fileset dir="${project.root}/storage/sis-shapefile/src/test/resources">

Modified: sis/trunk/src/main/docbook/book.entities
URL: http://svn.apache.org/viewvc/sis/trunk/src/main/docbook/book.entities?rev=1548777&r1=1548776&r2=1548777&view=diff
==============================================================================
--- sis/trunk/src/main/docbook/book.entities (original)
+++ sis/trunk/src/main/docbook/book.entities Sat Dec  7 02:00:42 2013
@@ -10,5 +10,5 @@
 <!ENTITY xmlns-gmd      "http://www.isotc211.org/2005/gmd">
 <!ENTITY xmlns-gmi      "http://www.isotc211.org/2005/gmi">
 <!ENTITY xmlns-gmx      "http://www.isotc211.org/2005/gmx">
-<!ENTITY xmlns-gml      "http://www.opengis.net/gml">
+<!ENTITY xmlns-gml      "http://www.opengis.net/gml/3.2">
 <!ENTITY xmlns-xlink    "http://www.w3.org/1999/xlink">

Modified: sis/trunk/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/IOUtilitiesTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/IOUtilitiesTest.java?rev=1548777&r1=1548776&r2=1548777&view=diff
==============================================================================
--- sis/trunk/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/IOUtilitiesTest.java
[UTF-8] (original)
+++ sis/trunk/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/IOUtilitiesTest.java
[UTF-8] Sat Dec  7 02:00:42 2013
@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
+import org.apache.sis.util.CharSequences;
 import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
@@ -180,7 +181,7 @@ public final strictfp class IOUtilitiesT
         assertEquals("Path with space.", new File("/Users/name/Map with spaces.png"),
                 IOUtilities.toFile(new URL("file:/Users/name/Map with spaces.png"), encoding));
         assertEquals("Path with + sign.", new File("/Users/name/++t--++est.shp"),
-                IOUtilities.toFile(new URL("file:/Users/name/++t--++est.shp".replace("+",
plus)), encoding));
+                IOUtilities.toFile(new URL(CharSequences.replace("file:/Users/name/++t--++est.shp",
"+", plus).toString()), encoding));
     }
 
     /**



Mime
View raw message