Author: desruisseaux
Date: Fri Mar 8 14:34:14 2013
New Revision: 1454405
URL: http://svn.apache.org/r1454405
Log:
Added IP review for DateConverter.
Added:
sis/ip-review/DateConverter.xhtml (with props)
sis/ip-review/rev/31848/
sis/ip-review/rev/31848/DateConverter.xhtml (with props)
sis/ip-review/rev/31848/HEADER.html (with props)
Added: sis/ip-review/DateConverter.xhtml
URL:
http://svn.apache.org/viewvc/sis/ip-review/DateConverter.xhtml?rev=1454405&view=auto
==============================================================================
--- sis/ip-review/DateConverter.xhtml (added)
+++ sis/ip-review/DateConverter.xhtml Fri Mar 8 14:34:14 2013
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta charset="UTF-8"/>
+ <title>DateConverter history</title>
+ <style type="text/css" media="all">
+ @import url("./reports.css");
+ </style>
+ </head>
+ <body>
+ <div>
+ <h1>DateConverter history</h1>
+ <p>Click on the commit message for inspecting the <code>diff</code> and how
the code has been rewritten.</p>
+<p><b>Command line:</b></p>
+<blockquote><code>svn log -r31996:23637
http://svn.osgeo.org/geotools/trunk/modules/library/main/src/main/java/org/geotools/util/TemporalConverterFactory.java</code></blockquote>
+<table>
+ <tr>
+ <th>Rev.</th>
+ <th>Date</th>
+ <th>Author</th>
+ <th class="last">Message</th>
+ </tr>
+<tr><td class="rev">31848</td><td>2008-11-17</td><td
class="unav">jdeolive</td><td><a
href="rev/31848/DateConverter.xhtml">GEOT-2143, converter from/to Data and
XMLGregorianCalendar</a></td></tr>
+<tr><td class="rev">31156</td><td>2008-08-08</td><td
class="unav">jgarnett</td><td><a href="rev/31848/DateConverter.xhtml">Remove
mistaken import of sub XMLCalendar; we want the one made available via xerces.
Need to use DataTypeFactory.newXMLGregorianCalendar rather than a constructor.
See GEOT-1939</a></td></tr>
+<tr><td class="rev">30976</td><td>2008-07-09</td><td
class="unav">jdeolive</td><td><a href="rev/31848/DateConverter.xhtml">Calendar
to XMLGregorianCalendar</a></td></tr>
+<tr><td class="rev">30956</td><td>2008-07-08</td><td
class="unav">jdeolive</td><td><a href="rev/31848/DateConverter.xhtml">added a
converter for XMLGregorianCalendar to Calendar</a></td></tr>
+<tr><td class="rev">30648</td><td>2008-06-12</td><td>acuster</td><td>Copyright
headers: lib/main, this time with feeling (and the el in Toolkit)</td></tr>
+<tr><td class="rev">30558</td><td>2008-06-06</td><td>acuster</td><td>Copyright
review: update headers on library/main</td></tr>
+<tr><td class="rev">30258</td><td>2008-05-08</td><td>acuster</td><td>Reshuffle
the top level repo: drop uDig, move up trunk, tags, and branches.</td></tr>
+<tr><td class="rev">30257</td><td>2008-05-08</td><td>acuster</td><td>Move
trunk/gt/ directory contents up to trunk/ and drop gt</td></tr>
+<tr><td class="rev">28922</td><td>2008-01-24</td><td>acuster</td><td>Bump the
(at)since version to 2.5 since WKTParser was cut from 2.4</td></tr>
+<tr><td class="rev">28540</td><td>2007-12-29</td><td>acuster</td><td>Hide
buttons which are not yet used</td></tr>
+<tr><td class="rev">26152</td><td>2007-07-04</td><td
class="unav">jdeolive</td><td><a
href="rev/31848/DateConverter.xhtml">conversion from java.util.Date to
java.sql.Date</a></td></tr>
+<tr><td
class="rev">25075</td><td>2007-04-09</td><td>desruisseaux</td><td>Fixed SVN
properties.</td></tr>
+<tr><td class="rev">23637</td><td>2007-01-01</td><td
class="unav">jdeolive</td><td><a
href="rev/31848/DateConverter.xhtml">javadocs</a></td></tr>
+<tr><td class="rev">23504</td><td>2006-12-18</td><td
class="unav">jdeolive</td><td><a href="rev/31848/DateConverter.xhtml">handling
of sql date types</a></td></tr>
+<tr><td class="rev">23295</td><td>2006-12-07</td><td
class="unav">jdeolive</td><td><a href="rev/31848/DateConverter.xhtml">added a
converter factory for converting among temporal types</a></td></tr>
+</table>
+ </div>
+ </body>
+</html>
Propchange: sis/ip-review/DateConverter.xhtml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sis/ip-review/DateConverter.xhtml
------------------------------------------------------------------------------
svn:mime-type = text/html
Added: sis/ip-review/rev/31848/DateConverter.xhtml
URL:
http://svn.apache.org/viewvc/sis/ip-review/rev/31848/DateConverter.xhtml?rev=1454405&view=auto
==============================================================================
--- sis/ip-review/rev/31848/DateConverter.xhtml (added)
+++ sis/ip-review/rev/31848/DateConverter.xhtml Fri Mar 8 14:34:14 2013
@@ -0,0 +1,377 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta charset="UTF-8"/>
+ <title>DateConverter at revision 31848</title>
+ <style type="text/css" media="all">
+ @import url("../../reports.css");
+ </style>
+ </head>
+ <body>
+ <div>
+ <h1>DateConverter at revision 31848</h1>
+
+<p>While the idea to provide a converter from date to other types was found in
GeoTools,
+the code has been totally rewritten and share nothing in common. The
Geotoolkit.org code
+handles only the conversions to <code>java.sql.Date</code>,
<code>Timestamp</code> and
+<code>Long</code>. Conversions from/to <code>String</code> are excluded.</p>
+
+<p>The table below compares the GeoTools code with the Geotoolkit.org one.</p>
+
+<p><b>Command line:</b></p>
+<blockquote><code>svn cat -r31848
http://svn.osgeo.org/geotools/trunk/modules/library/main/src/main/java/org/geotools/util/TemporalConverterFactory.java</code></blockquote>
+<table class="changes">
+<tr><th>Revision 31848</th><th>Geotoolkit.org</th></tr>
+<tr><td><pre><span class="add">/*
+ * GeoTools - The Open Source Java GIS Toolkit
+ * http://geotools.org
+ *
+ * (C) 2002-2008, Open Source Geospatial Foundation (OSGeo)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+package org.geotools.util;
+
+import java.math.BigInteger;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.XMLGregorianCalendar;
+
+import org.geotools.factory.Hints;
+/**
+ * Converter factory which created converting between the various temporal
types.
+ * <p>
+ * Supported converstions:
+ * <ul>
+ * <li>{@link java.util.Date} to {@link Calendar}
+ * <li>{@link java.sql.Timestamp} to {@link java.util.Calendar}
+ * <li>{@link java.sql.Time} to {@link java.util.Calendar}
+ * <li>{@link java.util.Date} to {@link java.sql.Timestamp}
+ * <li>{@link java.util.Date} to {@link java.sql.Time}
+ * <li>{@link java.util.Date} to {@link java.sql.Date}
+ * <li>{@link java.util.Calendar} to {@link java.util.Date}
+ * <li>{@link java.util.Calendar} to {@link java.sql.Timestamp}
+ * <li>{@link java.util.Calendar} to {@link java.sql.Time}
+ * <li>{@link XMLGregorianCalendar} to {@link Calendar}
+ * <li>{@link Calendar} to {@link XMLGregorianCalendar}
+ * <li>{@link XMLGregorianCalendar} to {@link Date}
+ * <li>{@link Date} to {@link XMLGregorianCalendar}
+ * </ul>
+ * </p>
+ * <p>
+ * The hint {@link #DATE_FORMAT} can be used to control the format of
converting a temporal value
+ * to a String.
+ * </p>
+ * @author Justin Deoliveira, The Open Planning Project
+ * @since 2.4
+ */
+public class TemporalConverterFactory implements ConverterFactory {
+
+ public Converter createConverter(Class source, Class target, Hints hints) {
+
+ if ( Date.class.isAssignableFrom( source ) ) {
+ // handle all of (java.util.Date,java.sql.Timestamp,and
java.sql.Time) -> java.util.Calendar
+ if ( Calendar.class.isAssignableFrom( target ) ) {
+ return new Converter() {
+ public Object convert(Object source, Class target) throws
Exception {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime( (Date) source );
+
+ return calendar;
+ }
+ };
+ }
+
+ //handle all of (java.util.Date) ->
(java.sql.Timestamp,java.sql.Time)
+ if ( Timestamp.class.isAssignableFrom( target ) ||
Time.class.isAssignableFrom( target ) ||
+ java.sql.Date.class.isAssignableFrom( target ) ) {
+
+ return new Converter() {
+
+ public Object convert(Object source, Class target) throws
Exception {
+ Date date = (Date) source;
+ return target.getConstructor( new Class[] { Long.TYPE
} )
+ .newInstance( new Object[]{ new Long(
date.getTime() ) } );
+ }
+
+ };
+ }
+
+ if ( XMLGregorianCalendar.class.isAssignableFrom( target ) ) {
+ return new Converter() {
+ public <T> T convert(Object source, Class<T>
target)
+ throws Exception {
+ Date date = (Date) source;
+ Calendar calendar = createConverter(Date.class,
Calendar.class,null)
+ .convert( date, Calendar.class);
+
+ return (T) createConverter( Calendar.class,
XMLGregorianCalendar.class, null )
+ .convert( calendar, XMLGregorianCalendar.class );
+
+ }
+ };
+ }
+// if ( String.class.equals( target ) ) {
+// final DateFormat fFormat;
+// if ( dateFormat != null ) {
+// fFormat = dateFormat;
+// }
+// else {
+// //create a default
+// fFormat = DateFormat.getDateInstance();
+// }
+//
+// return new Converter() {
+// public Object convert(Object source, Class target) throws
Exception {
+// return fFormat.format( (Date)source );
+// }
+// };
+// }
+ }
+
+ //this should handle java.util.Calendar to
(java.util.Date,java.sql.Timestamp,java.util.Time}
+ if ( Calendar.class.isAssignableFrom( source ) ) {
+ if ( Date.class.isAssignableFrom( target ) ) {
+ final Class fTarget = target;
+ return new Converter() {
+ public Object convert(Object source, Class target) throws
Exception {
+ Calendar calendar = (Calendar) source;
+
+ return target.getConstructor( new Class[] { Long.TYPE
} ).newInstance(
+ new Object[]{ new Long(
calendar.getTimeInMillis() ) }
+ );
+ }
+ };
+ }
+ if ( XMLGregorianCalendar.class.isAssignableFrom( target ) ) {
+ return new Converter() {
+ public <T> T convert(Object source, Class<T>
target)
+ throws Exception {
+ if( source instanceof GregorianCalendar ) {
+ return (T)
DatatypeFactory.newInstance().newXMLGregorianCalendar( (GregorianCalendar)
source );
+ }
+
+ return null;
+ }
+ };
+ }
+// if ( String.class.equals( target ) ) {
+// final DateFormat fFormat;
+// if ( dateTimeFormat != null ) {
+// fFormat = dateTimeFormat;
+// }
+// else {
+// //create a default
+// fFormat = DateFormat.getDateTimeInstance();
+// }
+//
+// return new Converter() {
+// public Object convert(Object source, Class target) throws
Exception {
+// Date date = ((Calendar)source).getTime();
+// return fFormat.format( date );
+// }
+// };
+// }
+ }
+
+ if ( XMLGregorianCalendar.class.isAssignableFrom( source ) ) {
+ if ( Calendar.class.isAssignableFrom( target ) ) {
+ return new Converter() {
+ public <T> T convert(Object source, Class<T>
target)
+ throws Exception {
+ XMLGregorianCalendar calendar = (XMLGregorianCalendar)
source;
+ return (T) calendar.toGregorianCalendar();
+ }
+ };
+ }
+ if ( Date.class.isAssignableFrom( target ) ) {
+ return new Converter() {
+ public <T> T convert(Object source, Class<T>
target)
+ throws Exception {
+ Calendar calendar =
createConverter(XMLGregorianCalendar.class, Calendar.class, null)
+ .convert( source, Calendar.class );
+ if ( calendar != null ) {
+ return (T) createConverter( Calendar.class,
Date.class, null )
+ .convert( calendar, Date.class );
+ }
+ return null;
+ }
+ };
+ }
+ }
+ return null;
+ }
+
+}</span></pre></td>
+<td><pre>/*
+ * Geotoolkit.org - An Open Source Java GIS Toolkit
+ * http://www.geotoolkit.org
+ *
+ * (C) 2008-2012, Open Source Geospatial Foundation (OSGeo)
+ * (C) 2009-2012, Geomatys
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+package org.geotoolkit.util.converter;
+
+import java.util.Date;
+import java.io.Serializable;
+import java.io.ObjectStreamException;
+import net.jcip.annotations.Immutable;
+
+
+/**
+ * Handles conversions from {@link java.util.Date} to various objects.
+ *
+ * {@section String representation}
+ * There is currently no converter between {@link String} and {@link
java.util.Date} because the
+ * date format is not yet defined (we are considering the ISO format for a
future Geotk version).
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @version 3.00
+ *
+ * @since 2.4
+ * @module
+ */
+@Immutable
+abstract class DateConverter<T> extends SimpleConverter<Date,T>
implements Serializable {
+ /**
+ * For cross-version compatibility.
+ */
+ private static final long serialVersionUID = -7770401534710581917L;
+
+ /**
+ * Returns the source class, which is always {@link Date}.
+ */
+ @Override
+ public final Class<Date> getSourceClass() {
+ return Date.class;
+ }
+
+ /**
+ * Converter from dates to long integers.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @version 3.00
+ *
+ * @since 2.4
+ */
+ @Immutable
+ static final class Long extends DateConverter<java.lang.Long> {
+ private static final long serialVersionUID = 3163928356094316134L;
+ public static final Long INSTANCE = new Long();
+ private Long() {
+ }
+
+ @Override
+ public Class<java.lang.Long> getTargetClass() {
+ return java.lang.Long.class;
+ }
+
+ @Override
+ public java.lang.Long convert(final Date source) {
+ if (source == null) {
+ return null;
+ }
+ return source.getTime();
+ }
+
+ /** Returns the singleton instance on deserialization. */
+ protected Object readResolve() throws ObjectStreamException {
+ return INSTANCE;
+ }
+ }
+
+ /**
+ * Converter from dates to SQL dates.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @version 3.17
+ *
+ * @since 3.17
+ */
+ @Immutable
+ static final class SQL extends DateConverter<java.sql.Date> {
+ private static final long serialVersionUID = -3644605344718636345L;
+ public static final SQL INSTANCE = new SQL();
+ private SQL() {
+ }
+
+ @Override
+ public Class<java.sql.Date> getTargetClass() {
+ return java.sql.Date.class;
+ }
+
+ @Override
+ public java.sql.Date convert(final Date source) {
+ if (source == null) {
+ return null;
+ }
+ return new java.sql.Date(source.getTime());
+ }
+
+ /** Returns the singleton instance on deserialization. */
+ protected Object readResolve() throws ObjectStreamException {
+ return INSTANCE;
+ }
+ }
+
+ /**
+ * Converter from dates to timestamps.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @version 3.00
+ *
+ * @since 3.00
+ */
+ @Immutable
+ static final class Timestamp extends
DateConverter<java.sql.Timestamp> {
+ private static final long serialVersionUID = 3798633184562706892L;
+ public static final Timestamp INSTANCE = new Timestamp();
+ private Timestamp() {
+ }
+
+ @Override
+ public Class<java.sql.Timestamp> getTargetClass() {
+ return java.sql.Timestamp.class;
+ }
+
+ @Override
+ public java.sql.Timestamp convert(final Date source) {
+ if (source == null) {
+ return null;
+ }
+ return new java.sql.Timestamp(source.getTime());
+ }
+
+ /** Returns the singleton instance on deserialization. */
+ protected Object readResolve() throws ObjectStreamException {
+ return INSTANCE;
+ }
+ }
+}</pre></td></tr>
+</table>
+ </div>
+ </body>
+</html>
Propchange: sis/ip-review/rev/31848/DateConverter.xhtml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sis/ip-review/rev/31848/DateConverter.xhtml
------------------------------------------------------------------------------
svn:mime-type = text/html
Added: sis/ip-review/rev/31848/HEADER.html
URL:
http://svn.apache.org/viewvc/sis/ip-review/rev/31848/HEADER.html?rev=1454405&view=auto
==============================================================================
--- sis/ip-review/rev/31848/HEADER.html (added)
+++ sis/ip-review/rev/31848/HEADER.html Fri Mar 8 14:34:14 2013
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta charset="UTF-8"/>
+ <title>Revision 31848</title>
+ </head>
+ <body>
+ <div>
+ <h1>Revision 31848</h1>
+<table>
+ <tr><td><b>Author:</b></td><td>jdeolive</td></tr>
+ <tr><td><b>Date:</b></td><td>2008-11-17</td></tr>
+ <tr><td><b>Message:</b></td><td>GEOT-2143, converter from/to Data and
XMLGregorianCalendar</td></tr>
+</table>
+ </div>
+ </body>
+</html>
Propchange: sis/ip-review/rev/31848/HEADER.html
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sis/ip-review/rev/31848/HEADER.html
------------------------------------------------------------------------------
svn:mime-type = text/html