default date/time converters
This commit is contained in:
parent
d868785b5f
commit
381d1d5a94
|
|
@ -46,7 +46,7 @@
|
||||||
<dependency org="org.aspectj" name="com.springsource.org.aspectj.weaver" rev="1.6.5.RELEASE" conf="optional, aspectj->compile"/>
|
<dependency org="org.aspectj" name="com.springsource.org.aspectj.weaver" rev="1.6.5.RELEASE" conf="optional, aspectj->compile"/>
|
||||||
<dependency org="org.beanshell" name="com.springsource.bsh" rev="2.0.0.b4" conf="optional, beanshell->compile"/>
|
<dependency org="org.beanshell" name="com.springsource.bsh" rev="2.0.0.b4" conf="optional, beanshell->compile"/>
|
||||||
<dependency org="org.codehaus.groovy" name="com.springsource.org.codehaus.groovy" rev="1.6.3" conf="optional, groovy->compile"/>
|
<dependency org="org.codehaus.groovy" name="com.springsource.org.codehaus.groovy" rev="1.6.3" conf="optional, groovy->compile"/>
|
||||||
<dependency org="org.joda" name="com.springsource.org.joda.time" rev="1.6.0" />
|
<dependency org="org.joda" name="com.springsource.org.joda.time" rev="1.6.0" conf="optional->compile"/>
|
||||||
<dependency org="org.jruby" name="com.springsource.org.jruby" rev="1.2.0" conf="optional, jruby->compile"/>
|
<dependency org="org.jruby" name="com.springsource.org.jruby" rev="1.2.0" conf="optional, jruby->compile"/>
|
||||||
<dependency org="org.springframework" name="org.springframework.asm" rev="latest.integration" conf="compile->compile"/>
|
<dependency org="org.springframework" name="org.springframework.asm" rev="latest.integration" conf="compile->compile"/>
|
||||||
<dependency org="org.springframework" name="org.springframework.aop" rev="latest.integration" conf="compile->compile"/>
|
<dependency org="org.springframework" name="org.springframework.aop" rev="latest.integration" conf="compile->compile"/>
|
||||||
|
|
|
||||||
|
|
@ -15,5 +15,6 @@
|
||||||
<classpathentry kind="var" path="IVY_CACHE/org.codehaus.woodstox/com.springsource.com.ctc.wstx/3.2.7/com.springsource.com.ctc.wstx-3.2.7.jar" sourcepath="/IVY_CACHE/org.codehaus.woodstox/com.springsource.com.ctc.wstx/3.2.7/com.springsource.com.ctc.wstx-sources-3.2.7.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/org.codehaus.woodstox/com.springsource.com.ctc.wstx/3.2.7/com.springsource.com.ctc.wstx-3.2.7.jar" sourcepath="/IVY_CACHE/org.codehaus.woodstox/com.springsource.com.ctc.wstx/3.2.7/com.springsource.com.ctc.wstx-sources-3.2.7.jar"/>
|
||||||
<classpathentry kind="lib" path="/org.springframework.asm/target/artifacts/org.springframework.asm.jar" sourcepath="/org.springframework.asm/target/artifacts/org.springframework.asm-sources.jar"/>
|
<classpathentry kind="lib" path="/org.springframework.asm/target/artifacts/org.springframework.asm.jar" sourcepath="/org.springframework.asm/target/artifacts/org.springframework.asm-sources.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/org.jboss.vfs/com.springsource.org.jboss.virtual/2.1.0.GA/com.springsource.org.jboss.virtual-2.1.0.GA.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/org.jboss.vfs/com.springsource.org.jboss.virtual/2.1.0.GA/com.springsource.org.jboss.virtual-2.1.0.GA.jar"/>
|
||||||
|
<classpathentry kind="var" path="IVY_CACHE/org.joda/com.springsource.org.joda.time/1.6.0/com.springsource.org.joda.time-1.6.0.jar" sourcepath="/IVY_CACHE/org.joda/com.springsource.org.joda.time/1.6.0/com.springsource.org.joda.time-sources-1.6.0.jar"/>
|
||||||
<classpathentry kind="output" path="target/classes"/>
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@
|
||||||
<dependency org="org.apache.log4j" name="com.springsource.org.apache.log4j" rev="1.2.15" conf="optional, log4j->compile"/>
|
<dependency org="org.apache.log4j" name="com.springsource.org.apache.log4j" rev="1.2.15" conf="optional, log4j->compile"/>
|
||||||
<dependency org="org.aspectj" name="com.springsource.org.aspectj.weaver" rev="1.6.5.RELEASE" conf="optional, aspectj->compile"/>
|
<dependency org="org.aspectj" name="com.springsource.org.aspectj.weaver" rev="1.6.5.RELEASE" conf="optional, aspectj->compile"/>
|
||||||
<dependency org="org.jboss.vfs" name="com.springsource.org.jboss.virtual" rev="2.1.0.GA" conf="optional->compile"/>
|
<dependency org="org.jboss.vfs" name="com.springsource.org.jboss.virtual" rev="2.1.0.GA" conf="optional->compile"/>
|
||||||
|
<dependency org="org.joda" name="com.springsource.org.joda.time" rev="1.6.0" conf="optional->compile"/>
|
||||||
<dependency org="org.springframework" name="org.springframework.asm" rev="latest.integration" conf="optional->compile"/>
|
<dependency org="org.springframework" name="org.springframework.asm" rev="latest.integration" conf="optional->compile"/>
|
||||||
<!-- test dependencies -->
|
<!-- test dependencies -->
|
||||||
<dependency org="javax.servlet" name="com.springsource.javax.servlet" rev="2.5.0" conf="test->compile"/>
|
<dependency org="javax.servlet" name="com.springsource.javax.servlet" rev="2.5.0" conf="test->compile"/>
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,12 @@
|
||||||
<artifactId>aspectjweaver</artifactId>
|
<artifactId>aspectjweaver</artifactId>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>joda-time</groupId>
|
||||||
|
<artifactId>joda-time</artifactId>
|
||||||
|
<version>1.6</version>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jboss.vfs</groupId>
|
<groupId>org.jboss.vfs</groupId>
|
||||||
<artifactId>com.springsource.org.jboss.virtual</artifactId>
|
<artifactId>com.springsource.org.jboss.virtual</artifactId>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2002-2009 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.core.convert.support;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.springframework.core.convert.converter.Converter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts from a java.util.Calendar to a java.util.Date.
|
||||||
|
* @author Keith Donald
|
||||||
|
*/
|
||||||
|
final class CalendarToDateConverter implements Converter<Calendar, Date> {
|
||||||
|
|
||||||
|
public Date convert(Calendar source) {
|
||||||
|
return source.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2002-2009 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.core.convert.support;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.springframework.core.convert.converter.Converter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts from a java.util.Date to a java.util.Calendar.
|
||||||
|
* @author Keith Donald
|
||||||
|
*/
|
||||||
|
final class DateToCalendarConverter implements Converter<Date, Calendar> {
|
||||||
|
|
||||||
|
public Calendar convert(Date source) {
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
cal.setTime(source);
|
||||||
|
return cal;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
package org.springframework.core.convert.support;
|
package org.springframework.core.convert.support;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -36,6 +38,9 @@ public class DefaultConversionService extends GenericConversionService {
|
||||||
addConverter(String.class, Character.class, new StringToCharacterConverter());
|
addConverter(String.class, Character.class, new StringToCharacterConverter());
|
||||||
addConverter(String.class, Locale.class, new StringToLocaleConverter());
|
addConverter(String.class, Locale.class, new StringToLocaleConverter());
|
||||||
addConverter(Number.class, Character.class, new NumberToCharacterConverter());
|
addConverter(Number.class, Character.class, new NumberToCharacterConverter());
|
||||||
|
addConverter(Date.class, Calendar.class, new DateToCalendarConverter());
|
||||||
|
addConverter(Calendar.class, Date.class, new CalendarToDateConverter());
|
||||||
|
JodaTimeConverters.addConverters(this);
|
||||||
addConverter(Object.class, String.class, new ObjectToStringConverter());
|
addConverter(Object.class, String.class, new ObjectToStringConverter());
|
||||||
addConverterFactory(String.class, Number.class, new StringToNumberConverterFactory());
|
addConverterFactory(String.class, Number.class, new StringToNumberConverterFactory());
|
||||||
addConverterFactory(String.class, Enum.class, new StringToEnumConverterFactory());
|
addConverterFactory(String.class, Enum.class, new StringToEnumConverterFactory());
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,130 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2002-2009 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.core.convert.support;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.joda.time.DateMidnight;
|
||||||
|
import org.joda.time.DateTime;
|
||||||
|
import org.joda.time.LocalDate;
|
||||||
|
import org.joda.time.LocalDateTime;
|
||||||
|
import org.joda.time.LocalTime;
|
||||||
|
import org.springframework.core.convert.converter.Converter;
|
||||||
|
import org.springframework.util.ClassUtils;
|
||||||
|
|
||||||
|
class JodaTimeConverters {
|
||||||
|
|
||||||
|
public static void addConverters(GenericConversionService registry) {
|
||||||
|
if (!isJodaTimePresent()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
registry.addConverter(DateTime.class, LocalDate.class, new DateTimeToLocalDateConverter());
|
||||||
|
registry.addConverter(LocalDate.class, DateTime.class, new LocalDateToDateTimeConverter());
|
||||||
|
|
||||||
|
registry.addConverter(DateTime.class, LocalTime.class, new DateTimeToLocalTimeConverter());
|
||||||
|
registry.addConverter(LocalTime.class, DateTime.class, new LocalTimeToDateTimeConverter());
|
||||||
|
|
||||||
|
registry.addConverter(DateTime.class, LocalDateTime.class, new DateTimeToLocalDateTimeConverter());
|
||||||
|
registry.addConverter(LocalDateTime.class, DateTime.class, new LocalDateTimeToDateTimeConverter());
|
||||||
|
|
||||||
|
registry.addConverter(DateTime.class, DateMidnight.class, new DateTimeToDateMidnightConverter());
|
||||||
|
registry.addConverter(DateMidnight.class, Date.class, new DateMidnightToDateTimeConverter());
|
||||||
|
|
||||||
|
registry.addConverter(DateTime.class, Date.class, new DateTimeToDateConverter());
|
||||||
|
registry.addConverter(Date.class, DateTime.class, new DateToDateTimeConverter());
|
||||||
|
|
||||||
|
registry.addConverter(DateTime.class, Calendar.class, new DateTimeToCalendarConverter());
|
||||||
|
registry.addConverter(Calendar.class, DateTime.class, new CalendarToDateTimeConverter());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isJodaTimePresent() {
|
||||||
|
return ClassUtils.isPresent("org.joda.time.DateTime", JodaTimeConverters.class.getClassLoader());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class DateTimeToLocalDateConverter implements Converter<DateTime, LocalDate> {
|
||||||
|
public LocalDate convert(DateTime source) {
|
||||||
|
return source.toLocalDate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class LocalDateToDateTimeConverter implements Converter<LocalDate, DateTime> {
|
||||||
|
public DateTime convert(LocalDate source) {
|
||||||
|
return source.toDateTimeAtStartOfDay();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class DateTimeToLocalTimeConverter implements Converter<DateTime, LocalTime> {
|
||||||
|
public LocalTime convert(DateTime source) {
|
||||||
|
return source.toLocalTime();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class LocalTimeToDateTimeConverter implements Converter<LocalTime, DateTime> {
|
||||||
|
public DateTime convert(LocalTime source) {
|
||||||
|
return source.toDateTimeToday();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class DateTimeToLocalDateTimeConverter implements Converter<DateTime, LocalDateTime> {
|
||||||
|
public LocalDateTime convert(DateTime source) {
|
||||||
|
return source.toLocalDateTime();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class LocalDateTimeToDateTimeConverter implements Converter<LocalDateTime, DateTime> {
|
||||||
|
public DateTime convert(LocalDateTime source) {
|
||||||
|
return source.toDateTime();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class DateTimeToDateMidnightConverter implements Converter<DateTime, DateMidnight> {
|
||||||
|
public DateMidnight convert(DateTime source) {
|
||||||
|
return source.toDateMidnight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class DateMidnightToDateTimeConverter implements Converter<DateMidnight, DateTime> {
|
||||||
|
public DateTime convert(DateMidnight source) {
|
||||||
|
return source.toDateTime();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class DateTimeToDateConverter implements Converter<DateTime, Date> {
|
||||||
|
public Date convert(DateTime source) {
|
||||||
|
return source.toDate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class DateToDateTimeConverter implements Converter<Date, DateTime> {
|
||||||
|
public DateTime convert(Date source) {
|
||||||
|
return new DateTime(source);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class DateTimeToCalendarConverter implements Converter<DateTime, Calendar> {
|
||||||
|
public Calendar convert(DateTime source) {
|
||||||
|
return source.toGregorianCalendar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class CalendarToDateTimeConverter implements Converter<Calendar, DateTime> {
|
||||||
|
public DateTime convert(Calendar source) {
|
||||||
|
return new DateTime(source);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -10,6 +10,7 @@ Import-Template:
|
||||||
org.springframework.asm.*;version="[3.0.0, 3.0.1)";resolution:=optional,
|
org.springframework.asm.*;version="[3.0.0, 3.0.1)";resolution:=optional,
|
||||||
org.apache.log4j.*;version="[1.2.15, 2.0.0)";resolution:=optional,
|
org.apache.log4j.*;version="[1.2.15, 2.0.0)";resolution:=optional,
|
||||||
org.aspectj.*;version="[1.5.4, 2.0.0)";resolution:=optional,
|
org.aspectj.*;version="[1.5.4, 2.0.0)";resolution:=optional,
|
||||||
|
org.joda.*;version="[1.6.0, 2.0.0)";resolution:=optional,
|
||||||
org.jboss.virtual.*;version="[2.1.0.GA, 3.0.0)";resolution:=optional,
|
org.jboss.virtual.*;version="[2.1.0.GA, 3.0.0)";resolution:=optional,
|
||||||
org.xml.sax.*;version="0";resolution:=optional,
|
org.xml.sax.*;version="0";resolution:=optional,
|
||||||
org.w3c.dom.*;version="0";resolution:=optional
|
org.w3c.dom.*;version="0";resolution:=optional
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue