From 87e939a4e9f7148a1e8a41091f45f5d8f55e2b19 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 17 Sep 2009 10:24:08 +0000 Subject: [PATCH] adapted to Converter signature change --- .../FormattingConversionServiceAdapter.java | 14 ++++++++++++-- .../core/convert/converter/Converter.java | 3 ++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/org.springframework.context/src/main/java/org/springframework/ui/format/support/FormattingConversionServiceAdapter.java b/org.springframework.context/src/main/java/org/springframework/ui/format/support/FormattingConversionServiceAdapter.java index c0b7346aa1..ed97b58bff 100644 --- a/org.springframework.context/src/main/java/org/springframework/ui/format/support/FormattingConversionServiceAdapter.java +++ b/org.springframework.context/src/main/java/org/springframework/ui/format/support/FormattingConversionServiceAdapter.java @@ -16,6 +16,8 @@ package org.springframework.ui.format.support; +import java.text.ParseException; + import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.TypeDescriptor; @@ -66,6 +68,9 @@ public class FormattingConversionServiceAdapter extends GenericConversionService } + /** + * Adapter that exposes the Converter interface on top of a given Formatter. + */ private static class FormattingConverter implements Converter { private final Formatter formatter; @@ -74,8 +79,13 @@ public class FormattingConversionServiceAdapter extends GenericConversionService this.formatter = formatter; } - public Object convert(String source) throws Exception { - return this.formatter.parse(source, LocaleContextHolder.getLocale()); + public Object convert(String source) { + try { + return this.formatter.parse(source, LocaleContextHolder.getLocale()); + } + catch (ParseException ex) { + throw new IllegalArgumentException("Could not convert formatted value '" + source + "'", ex); + } } } diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/converter/Converter.java b/org.springframework.core/src/main/java/org/springframework/core/convert/converter/Converter.java index 5430723c32..f936b08b53 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/converter/Converter.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/converter/Converter.java @@ -19,6 +19,7 @@ package org.springframework.core.convert.converter; /** * A converter converts a source object of type S to a target of type T. * Implementations of this interface are thread-safe and can be shared. + * * @author Keith Donald * @since 3.0 */ @@ -28,7 +29,7 @@ public interface Converter { * Convert the source of type S to target type T. * @param source the source object to convert, which must be an instance of S * @return the converted object, which must be an instance of T - * @throws IllegalArgumentException if the source could not be converted + * @throws IllegalArgumentException if the source could not be converted to the desired target type */ T convert(S source);