sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1551630 - in /sis/branches/JDK7/core: sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/ sis-metadata/src/test/java/org/apache/sis/internal/jaxb/gml/ sis-utility/src/main/java/org/apache/sis/internal/jaxb/ sis-utility/src/main/ja...
Date Tue, 17 Dec 2013 17:06:27 GMT
Author: desruisseaux
Date: Tue Dec 17 17:06:27 2013
New Revision: 1551630

URL: http://svn.apache.org/r1551630
Log:
Parsing of dates need to take in account the XML.TIMEZONE value (patch by Guilhem Legal).

Modified:
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/TM_Primitive.java
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/gml/TimePeriodTest.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/XmlUtilities.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_DateTime.java

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/TM_Primitive.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/TM_Primitive.java?rev=1551630&r1=1551629&r2=1551630&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/TM_Primitive.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/TM_Primitive.java
[UTF-8] Tue Dec 17 17:06:27 2013
@@ -108,8 +108,9 @@ public final class TM_Primitive extends 
     public void setTimePeriod(final TimePeriod period) {
         metadata = null; // Cleaned first in case of failure.
         if (period != null) {
-            final Date begin = toDate(period.begin);
-            final Date end   = toDate(period.end);
+            final Context context = Context.current();
+            final Date begin = toDate(context, period.begin);
+            final Date end   = toDate(context, period.end);
             if (begin != null || end != null) {
                 if (begin != null && end != null && end.before(begin)) {
                     /*
@@ -118,7 +119,7 @@ public final class TM_Primitive extends 
                      * TemporalPrimitive as the source class, since it is the closest we
can get
                      * to a public API.
                      */
-                    Context.warningOccured(Context.current(), TemporalPrimitive.class, "setTimePeriod",
+                    Context.warningOccured(context, TemporalPrimitive.class, "setTimePeriod",
                             Errors.class, Errors.Keys.IllegalRange_2, begin, end);
                 } else try {
                     metadata = TemporalUtilities.createPeriod(begin, end);
@@ -139,7 +140,7 @@ public final class TM_Primitive extends 
     public void setTimeInstant(final TimeInstant instant) {
         metadata = null; // Cleaned first in case of failure.
         if (instant != null) {
-            final Date position = XmlUtilities.toDate(instant.timePosition);
+            final Date position = XmlUtilities.toDate(Context.current(), instant.timePosition);
             if (position != null) try {
                 metadata = TemporalUtilities.createInstant(position);
                 instant.copyIdTo(metadata);
@@ -152,8 +153,8 @@ public final class TM_Primitive extends 
     /**
      * Returns the date of the given bounds, or {@code null} if none.
      */
-    private static Date toDate(final TimePeriodBound bound) {
-        return (bound != null) ? XmlUtilities.toDate(bound.calendar()) : null;
+    private static Date toDate(final Context context, final TimePeriodBound bound) {
+        return (bound != null) ? XmlUtilities.toDate(context, bound.calendar()) : null;
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/gml/TimePeriodTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/gml/TimePeriodTest.java?rev=1551630&r1=1551629&r2=1551630&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/gml/TimePeriodTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/gml/TimePeriodTest.java
[UTF-8] Tue Dec 17 17:06:27 2013
@@ -55,8 +55,7 @@ public final strictfp class TimePeriodTe
 
     /**
      * Set the marshalling context to a fixed locale and timezone before to create the
-     * JAXB wrappers for temporal objects. Callers shall invoke {@link #clearContext()}
-     * after this method.
+     * JAXB wrappers for temporal objects.
      */
     private void createContext() {
         createContext(true, Locale.FRANCE, "CET");
@@ -88,17 +87,6 @@ public final strictfp class TimePeriodTe
     }
 
     /**
-     * Creates a new time instant for the given date.
-     */
-    private TimeInstant createTimeInstant(final String date) throws DatatypeConfigurationException
{
-        final TimeInstant instant = new TimeInstant();
-        createContext();
-        instant.timePosition = XmlUtilities.toXML(context, date(date));
-        clearContext();
-        return instant;
-    }
-
-    /**
      * Tests time instant. The test is executed using an arbitrary locale and timezone.
      *
      * @throws JAXBException If an error occurred while marshalling.
@@ -106,10 +94,11 @@ public final strictfp class TimePeriodTe
      */
     @Test
     public void testTimeInstant() throws JAXBException, DatatypeConfigurationException {
+        createContext();
         final Marshaller   marshaller   = pool.acquireMarshaller();
         final Unmarshaller unmarshaller = pool.acquireUnmarshaller();
-
-        final TimeInstant instant = createTimeInstant("1992-01-01 00:00:00");
+        final TimeInstant  instant      = new TimeInstant();
+        instant.timePosition = XmlUtilities.toXML(context, date("1992-01-01 00:00:00"));
         final String actual = marshal(marshaller, instant);
         assertXmlEquals(
                 "<gml:TimeInstant xmlns:gml=\"" + Namespaces.GML + "\">\n" +
@@ -117,7 +106,7 @@ public final strictfp class TimePeriodTe
                 "</gml:TimeInstant>\n", actual, "xmlns:*");
 
         final TimeInstant test = (TimeInstant) unmarshal(unmarshaller, actual);
-        assertEquals("1992-01-01 00:00:00", format(XmlUtilities.toDate(test.timePosition)));
+        assertEquals("1992-01-01 00:00:00", format(XmlUtilities.toDate(context, test.timePosition)));
 
         pool.recycle(marshaller);
         pool.recycle(unmarshaller);
@@ -134,7 +123,6 @@ public final strictfp class TimePeriodTe
         createContext();
         final TimePeriodBound begin = new TimePeriodBound.GML2(new DummyInstant(date("1992-01-01
00:00:00")));
         final TimePeriodBound end   = new TimePeriodBound.GML2(new DummyInstant(date("2007-12-31
00:00:00")));
-        clearContext();
         testPeriod(begin, end,
                 "<gml:TimePeriod xmlns:gml=\"" + Namespaces.GML + "\">\n" +
                 "  <gml:begin>\n" +
@@ -162,15 +150,15 @@ public final strictfp class TimePeriodTe
     {
         final Marshaller   marshaller   = pool.acquireMarshaller();
         final Unmarshaller unmarshaller = pool.acquireUnmarshaller();
-        final TimePeriod period = new TimePeriod();
+        final TimePeriod   period       = new TimePeriod();
         period.begin = begin;
         period.end   = end;
         final String actual = marshal(marshaller, period);
         assertXmlEquals(expected, actual, "xmlns:*");
         final TimePeriod test = (TimePeriod) unmarshal(unmarshaller, actual);
         if (verifyValues) {
-            assertEquals("1992-01-01 00:00:00", format(XmlUtilities.toDate(test.begin.calendar())));
-            assertEquals("2007-12-31 00:00:00", format(XmlUtilities.toDate(test.end  .calendar())));
+            assertEquals("1992-01-01 00:00:00", format(XmlUtilities.toDate(context, test.begin.calendar())));
+            assertEquals("2007-12-31 00:00:00", format(XmlUtilities.toDate(context, test.end
 .calendar())));
         }
         pool.recycle(marshaller);
         pool.recycle(unmarshaller);
@@ -187,7 +175,6 @@ public final strictfp class TimePeriodTe
         createContext();
         final TimePeriodBound begin = new TimePeriodBound.GML3(new DummyInstant(date("1992-01-01
00:00:00")), "before");
         final TimePeriodBound end   = new TimePeriodBound.GML3(new DummyInstant(date("2007-12-31
00:00:00")), "after");
-        clearContext();
         testPeriod(begin, end,
                 "<gml:TimePeriod xmlns:gml=\"" + Namespaces.GML + "\">\n" +
                 "  <gml:beginPosition>1992-01-01T01:00:00+01:00</gml:beginPosition>\n"
+
@@ -206,7 +193,6 @@ public final strictfp class TimePeriodTe
         createContext();
         final TimePeriodBound begin = new TimePeriodBound.GML3(new DummyInstant(date("1992-01-01
23:00:00")), "before");
         final TimePeriodBound end   = new TimePeriodBound.GML3(new DummyInstant(date("2007-12-30
23:00:00")), "after");
-        clearContext();
         testPeriod(begin, end,
                 "<gml:TimePeriod xmlns:gml=\"" + Namespaces.GML + "\">\n" +
                 "  <gml:beginPosition>1992-01-02</gml:beginPosition>\n" +
@@ -225,7 +211,6 @@ public final strictfp class TimePeriodTe
         createContext();
         final TimePeriodBound begin = new TimePeriodBound.GML3(null, "before");
         final TimePeriodBound end   = new TimePeriodBound.GML3(new DummyInstant(date("2007-12-30
23:00:00")), "after");
-        clearContext();
         testPeriod(begin, end,
                 "<gml:TimePeriod xmlns:gml=\"" + Namespaces.GML + "\">\n" +
                 "  <gml:beginPosition indeterminatePosition=\"before\"/>\n" +
@@ -244,7 +229,6 @@ public final strictfp class TimePeriodTe
         createContext();
         final TimePeriodBound begin = new TimePeriodBound.GML3(new DummyInstant(date("1992-01-01
23:00:00")), "before");
         final TimePeriodBound end   = new TimePeriodBound.GML3(null, "after");
-        clearContext();
         testPeriod(begin, end,
                 "<gml:TimePeriod xmlns:gml=\"" + Namespaces.GML + "\">\n" +
                 "  <gml:beginPosition>1992-01-02</gml:beginPosition>\n" +

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/XmlUtilities.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/XmlUtilities.java?rev=1551630&r1=1551629&r2=1551630&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/XmlUtilities.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/XmlUtilities.java
[UTF-8] Tue Dec 17 17:06:27 2013
@@ -177,10 +177,21 @@ public final class XmlUtilities extends 
     /**
      * Converts the given XML Gregorian calendar to a date.
      *
+     * @param  context The current (un)marshalling context, or {@code null} if none.
      * @param  xml The XML calendar to convert to a date, or {@code null}.
      * @return The date, or {@code null} if {@code xml} was null.
      */
-    public static Date toDate(final XMLGregorianCalendar xml) {
-        return (xml != null) ? xml.toGregorianCalendar().getTime() : null;
+    public static Date toDate(final Context context, final XMLGregorianCalendar xml) {
+        if (xml != null) {
+            final GregorianCalendar calendar =  xml.toGregorianCalendar();
+            if (context != null && xml.getTimezone() == FIELD_UNDEFINED) {
+                final TimeZone timezone = context.getTimeZone();
+                if (timezone != null) {
+                    calendar.setTimeZone(timezone);
+                }
+            }
+            return calendar.getTime();
+        }
+        return null;
     }
 }

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_DateTime.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_DateTime.java?rev=1551630&r1=1551629&r2=1551630&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_DateTime.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_DateTime.java
[UTF-8] Tue Dec 17 17:06:27 2013
@@ -80,11 +80,11 @@ public final class GO_DateTime extends X
     }
 
     /**
-     * Returns the current date, or {@code null} if none. IF both fields are defined,
+     * Returns the current date, or {@code null} if none. If both fields are defined,
      * then {@link #dateTime} has precedence since it is assumed more accurate.
      */
     final Date getDate() {
-        return XmlUtilities.toDate(dateTime != null ? dateTime : date);
+        return XmlUtilities.toDate(Context.current(), dateTime != null ? dateTime : date);
     }
 
     /**



Mime
View raw message