Polishing

This commit is contained in:
Juergen Hoeller
2013-12-20 00:40:14 +01:00
parent 08aa22ff1f
commit 551364f668
7 changed files with 98 additions and 83 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2013 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.
@@ -19,10 +19,10 @@ package org.springframework.expression;
import org.springframework.core.convert.TypeDescriptor;
/**
* A type converter can convert values between different types encountered
* during expression evaluation. This is an SPI for the expression parser;
* see {@link org.springframework.core.convert.ConversionService} for the
* primary user API to Spring's conversion facilities.
* A type converter can convert values between different types encountered during
* expression evaluation. This is an SPI for the expression parser; see
* {@link org.springframework.core.convert.ConversionService} for the primary
* user API to Spring's conversion facilities.
*
* @author Andy Clement
* @author Juergen Hoeller
@@ -31,7 +31,8 @@ import org.springframework.core.convert.TypeDescriptor;
public interface TypeConverter {
/**
* Return true if the type converter can convert the specified type to the desired target type.
* Return {@code true} if the type converter can convert the specified type
* to the desired target type.
* @param sourceType a type descriptor that describes the source type
* @param targetType a type descriptor that describes the requested result type
* @return true if that conversion can be performed
@@ -39,12 +40,15 @@ public interface TypeConverter {
boolean canConvert(TypeDescriptor sourceType, TypeDescriptor targetType);
/**
* Convert (may coerce) a value from one type to another, for example from a boolean to a string.
* The typeDescriptor parameter enables support for typed collections - if the caller really wishes they
* can have a List<Integer> for example, rather than simply a List.
* Convert (may coerce) a value from one type to another, for example from a boolean
* to a string. The typeDescriptor parameter enables support for typed collections -
* if the caller really wishes they can have a List<Integer> for example, rather
* than simply a List.
* @param value the value to be converted
* @param sourceType a type descriptor that supplies extra information about the source object
* @param targetType a type descriptor that supplies extra information about the requested result type
* @param sourceType a type descriptor that supplies extra information about the
* source object
* @param targetType a type descriptor that supplies extra information about the
* requested result type
* @return the converted value
* @throws EvaluationException if conversion is not possible
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 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.
@@ -27,8 +27,8 @@ import org.springframework.expression.spel.SpelMessage;
import org.springframework.util.Assert;
/**
* Default implementation of the {@link TypeConverter} interface,
* delegating to a core Spring {@link ConversionService}.
* Default implementation of the {@link TypeConverter} interface, delegating to a core
* Spring {@link ConversionService}.
*
* @author Juergen Hoeller
* @author Andy Clement
@@ -65,11 +65,13 @@ public class StandardTypeConverter implements TypeConverter {
try {
return this.conversionService.convert(value, sourceType, targetType);
}
catch (ConverterNotFoundException cenfe) {
throw new SpelEvaluationException(cenfe, SpelMessage.TYPE_CONVERSION_ERROR, sourceType.toString(), targetType.toString());
catch (ConverterNotFoundException ex) {
throw new SpelEvaluationException(
ex, SpelMessage.TYPE_CONVERSION_ERROR, sourceType.toString(), targetType.toString());
}
catch (ConversionException ce) {
throw new SpelEvaluationException(ce, SpelMessage.TYPE_CONVERSION_ERROR, sourceType.toString(), targetType.toString());
catch (ConversionException ex) {
throw new SpelEvaluationException(
ex, SpelMessage.TYPE_CONVERSION_ERROR, sourceType.toString(), targetType.toString());
}
}