Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
796a457d
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
796a457d
编写于
5月 11, 2009
作者:
K
Keith Donald
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added two way converter
上级
50985d5a
变更
22
隐藏空白更改
内联
并排
Showing
22 changed file
with
62 addition
and
48 deletion
+62
-48
org.springframework.core/src/main/java/org/springframework/core/convert/ConversionExecutionException.java
...gframework/core/convert/ConversionExecutionException.java
+1
-1
org.springframework.core/src/main/java/org/springframework/core/convert/ConversionService.java
...a/org/springframework/core/convert/ConversionService.java
+1
-3
org.springframework.core/src/main/java/org/springframework/core/convert/ConvertException.java
...va/org/springframework/core/convert/ConvertException.java
+3
-3
org.springframework.core/src/main/java/org/springframework/core/convert/ConverterNotFoundException.java
...ingframework/core/convert/ConverterNotFoundException.java
+2
-2
org.springframework.core/src/main/java/org/springframework/core/convert/converter/Converter.java
...org/springframework/core/convert/converter/Converter.java
+2
-12
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToBigDecimal.java
...gframework/core/convert/converter/StringToBigDecimal.java
+1
-1
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToBigInteger.java
...gframework/core/convert/converter/StringToBigInteger.java
+1
-1
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToBoolean.java
...ringframework/core/convert/converter/StringToBoolean.java
+1
-1
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToByte.java
.../springframework/core/convert/converter/StringToByte.java
+1
-1
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToCharacter.java
...ngframework/core/convert/converter/StringToCharacter.java
+1
-1
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToDouble.java
...pringframework/core/convert/converter/StringToDouble.java
+1
-1
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToFloat.java
...springframework/core/convert/converter/StringToFloat.java
+1
-1
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToInteger.java
...ringframework/core/convert/converter/StringToInteger.java
+1
-1
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToLocale.java
...pringframework/core/convert/converter/StringToLocale.java
+1
-1
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToLong.java
.../springframework/core/convert/converter/StringToLong.java
+1
-1
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToShort.java
...springframework/core/convert/converter/StringToShort.java
+1
-1
org.springframework.core/src/main/java/org/springframework/core/convert/converter/SuperConverter.java
...pringframework/core/convert/converter/SuperConverter.java
+2
-2
org.springframework.core/src/main/java/org/springframework/core/convert/converter/SuperTwoWayConverter.java
...ramework/core/convert/converter/SuperTwoWayConverter.java
+2
-2
org.springframework.core/src/main/java/org/springframework/core/convert/converter/TwoWayConverter.java
...ringframework/core/convert/converter/TwoWayConverter.java
+25
-0
org.springframework.core/src/main/java/org/springframework/core/convert/service/GenericConversionService.java
...mework/core/convert/service/GenericConversionService.java
+7
-4
org.springframework.core/src/main/java/org/springframework/core/convert/service/ReverseConverter.java
...pringframework/core/convert/service/ReverseConverter.java
+4
-6
org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java
...mework/expression/spel/support/StandardTypeConverter.java
+2
-2
未找到文件。
org.springframework.core/src/main/java/org/springframework/core/convert/ConversionExecutionException.java
浏览文件 @
796a457d
...
...
@@ -22,7 +22,7 @@ import org.springframework.core.style.StylerUtils;
*
* @author Keith Donald
*/
public
class
ConversionExecutionException
extends
Conver
sion
Exception
{
public
class
ConversionExecutionException
extends
Conver
t
Exception
{
/**
* The value we tried to convert. Transient because we cannot guarantee that the value is Serializable.
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/ConversionService.java
浏览文件 @
796a457d
...
...
@@ -39,9 +39,7 @@ public interface ConversionService {
* @param targetType context about the target type to convert to
* @return the converted object, an instance of {@link TypeDescriptor#getType()}</code>, or <code>null</code> if a null source
* was provided
* @throws ConverterNotFoundException if no suitable conversion executor could be found to convert the
* source to an instance of targetType
* @throws ConversionException if an exception occurred during the conversion process
* @throws ConvertException if an exception occurred during the conversion process
*/
public
Object
convert
(
Object
source
,
TypeDescriptor
targetType
);
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/Conver
sion
Exception.java
→
org.springframework.core/src/main/java/org/springframework/core/convert/Conver
t
Exception.java
浏览文件 @
796a457d
...
...
@@ -20,14 +20,14 @@ package org.springframework.core.convert;
*
* @author Keith Donald
*/
public
abstract
class
Conver
sion
Exception
extends
RuntimeException
{
public
abstract
class
Conver
t
Exception
extends
RuntimeException
{
/**
* Creates a new conversion exception.
* @param message the exception message
* @param cause the cause
*/
public
Conver
sion
Exception
(
String
message
,
Throwable
cause
)
{
public
Conver
t
Exception
(
String
message
,
Throwable
cause
)
{
super
(
message
,
cause
);
}
...
...
@@ -35,7 +35,7 @@ public abstract class ConversionException extends RuntimeException {
* Creates a new conversion exception.
* @param message the exception message
*/
public
Conver
sion
Exception
(
String
message
)
{
public
Conver
t
Exception
(
String
message
)
{
super
(
message
);
}
}
org.springframework.core/src/main/java/org/springframework/core/convert/ConverterNotFoundException.java
浏览文件 @
796a457d
...
...
@@ -16,11 +16,11 @@
package
org.springframework.core.convert
;
/**
* Thrown when a
conversion executo
r could not be found in a conversion service.
* Thrown when a
suitable converte
r could not be found in a conversion service.
*
* @author Keith Donald
*/
public
class
ConverterNotFoundException
extends
Conver
sion
Exception
{
public
class
ConverterNotFoundException
extends
Conver
t
Exception
{
private
Class
<?>
sourceType
;
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/converter/Converter.java
浏览文件 @
796a457d
...
...
@@ -15,7 +15,7 @@
*/
package
org.springframework.core.convert.converter
;
import
org.springframework.core.convert.Conver
sion
Exception
;
import
org.springframework.core.convert.Conver
t
Exception
;
import
org.springframework.core.convert.ConversionService
;
/**
...
...
@@ -33,19 +33,9 @@ public interface Converter<S, 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 Exception an exception occurred performing the conversion; may be any checked exception, the conversion
* system will handle wrapping the failure in a {@link Conver
sion
Exception} that provides a consistent type
* system will handle wrapping the failure in a {@link Conver
t
Exception} that provides a consistent type
* conversion error context
*/
public
T
convert
(
S
source
)
throws
Exception
;
/**
* Convert the target of type T back to source type S.
* @param target the target object to convert, which must be an instance of T
* @return the converted object, which must be an instance of S
* @throws Exception an exception occurred performing the conversion; may be any checked exception, the conversion
* system will handle wrapping the failure in a {@link ConversionException} that provides a consistent type
* conversion error context
*/
public
S
convertBack
(
T
target
)
throws
Exception
;
}
\ No newline at end of file
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToBigDecimal.java
浏览文件 @
796a457d
...
...
@@ -22,7 +22,7 @@ import java.math.BigDecimal;
*
* @author Keith Donald
*/
public
class
StringToBigDecimal
implements
Converter
<
String
,
BigDecimal
>
{
public
class
StringToBigDecimal
implements
TwoWay
Converter
<
String
,
BigDecimal
>
{
public
BigDecimal
convert
(
String
source
)
{
return
new
BigDecimal
(
source
);
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToBigInteger.java
浏览文件 @
796a457d
...
...
@@ -22,7 +22,7 @@ import java.math.BigInteger;
*
* @author Keith Donald
*/
public
class
StringToBigInteger
implements
Converter
<
String
,
BigInteger
>
{
public
class
StringToBigInteger
implements
TwoWay
Converter
<
String
,
BigInteger
>
{
public
BigInteger
convert
(
String
source
)
{
return
new
BigInteger
(
source
);
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToBoolean.java
浏览文件 @
796a457d
...
...
@@ -23,7 +23,7 @@ import org.springframework.util.Assert;
* @see #StringToBoolean(String, String)
* @author Keith Donald
*/
public
class
StringToBoolean
implements
Converter
<
String
,
Boolean
>
{
public
class
StringToBoolean
implements
TwoWay
Converter
<
String
,
Boolean
>
{
private
String
trueString
;
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToByte.java
浏览文件 @
796a457d
...
...
@@ -20,7 +20,7 @@ package org.springframework.core.convert.converter;
*
* @author Keith Donald
*/
public
class
StringToByte
implements
Converter
<
String
,
Byte
>
{
public
class
StringToByte
implements
TwoWay
Converter
<
String
,
Byte
>
{
public
Byte
convert
(
String
source
)
{
return
Byte
.
valueOf
(
source
);
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToCharacter.java
浏览文件 @
796a457d
...
...
@@ -20,7 +20,7 @@ package org.springframework.core.convert.converter;
*
* @author Keith Donald
*/
public
class
StringToCharacter
implements
Converter
<
String
,
Character
>
{
public
class
StringToCharacter
implements
TwoWay
Converter
<
String
,
Character
>
{
public
Character
convert
(
String
source
)
{
if
(
source
.
length
()
!=
1
)
{
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToDouble.java
浏览文件 @
796a457d
...
...
@@ -20,7 +20,7 @@ package org.springframework.core.convert.converter;
*
* @author Keith Donald
*/
public
class
StringToDouble
implements
Converter
<
String
,
Double
>
{
public
class
StringToDouble
implements
TwoWay
Converter
<
String
,
Double
>
{
public
Double
convert
(
String
source
)
{
return
Double
.
valueOf
(
source
);
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToFloat.java
浏览文件 @
796a457d
...
...
@@ -20,7 +20,7 @@ package org.springframework.core.convert.converter;
*
* @author Keith Donald
*/
public
class
StringToFloat
implements
Converter
<
String
,
Float
>
{
public
class
StringToFloat
implements
TwoWay
Converter
<
String
,
Float
>
{
public
Float
convert
(
String
source
)
{
return
Float
.
valueOf
(
source
);
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToInteger.java
浏览文件 @
796a457d
...
...
@@ -20,7 +20,7 @@ package org.springframework.core.convert.converter;
*
* @author Keith Donald
*/
public
class
StringToInteger
implements
Converter
<
String
,
Integer
>
{
public
class
StringToInteger
implements
TwoWay
Converter
<
String
,
Integer
>
{
public
Integer
convert
(
String
source
)
{
return
Integer
.
valueOf
(
source
);
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToLocale.java
浏览文件 @
796a457d
...
...
@@ -24,7 +24,7 @@ import org.springframework.util.StringUtils;
*
* @author Keith Donald
*/
public
class
StringToLocale
implements
Converter
<
String
,
Locale
>
{
public
class
StringToLocale
implements
TwoWay
Converter
<
String
,
Locale
>
{
public
Locale
convert
(
String
source
)
{
return
StringUtils
.
parseLocaleString
(
source
);
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToLong.java
浏览文件 @
796a457d
...
...
@@ -20,7 +20,7 @@ package org.springframework.core.convert.converter;
*
* @author Keith Donald
*/
public
class
StringToLong
implements
Converter
<
String
,
Long
>
{
public
class
StringToLong
implements
TwoWay
Converter
<
String
,
Long
>
{
public
Long
convert
(
String
source
)
{
return
Long
.
valueOf
(
source
);
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToShort.java
浏览文件 @
796a457d
...
...
@@ -20,7 +20,7 @@ package org.springframework.core.convert.converter;
*
* @author Keith Donald
*/
public
class
StringToShort
implements
Converter
<
String
,
Short
>
{
public
class
StringToShort
implements
TwoWay
Converter
<
String
,
Short
>
{
public
Short
convert
(
String
source
)
{
return
Short
.
valueOf
(
source
);
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/converter/SuperConverter.java
浏览文件 @
796a457d
...
...
@@ -15,7 +15,7 @@
*/
package
org.springframework.core.convert.converter
;
import
org.springframework.core.convert.Conver
sion
Exception
;
import
org.springframework.core.convert.Conver
t
Exception
;
import
org.springframework.core.convert.ConversionService
;
/**
...
...
@@ -34,7 +34,7 @@ public interface SuperConverter<S, T> {
* @param targetClass the requested target class to convert to (RT), which must be equal to T or extend from T
* @return the converted object, which must be an instance of RT
* @throws Exception an exception occurred performing the conversion; may be any checked exception, the conversion
* system will handle wrapping the failure in a {@link Conver
sion
Exception} that provides a consistent type
* system will handle wrapping the failure in a {@link Conver
t
Exception} that provides a consistent type
* conversion error context
*/
public
<
RT
extends
T
>
RT
convert
(
S
source
,
Class
<
RT
>
targetClass
)
throws
Exception
;
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/converter/SuperTwoWayConverter.java
浏览文件 @
796a457d
...
...
@@ -15,7 +15,7 @@
*/
package
org.springframework.core.convert.converter
;
import
org.springframework.core.convert.Conver
sion
Exception
;
import
org.springframework.core.convert.Conver
t
Exception
;
import
org.springframework.core.convert.ConversionService
;
/**
...
...
@@ -34,7 +34,7 @@ public interface SuperTwoWayConverter<S, T> extends SuperConverter<S, T> {
* @param sourceClass the requested source class to convert to, which must be equal to S or extend from S
* @return the converted object, which must be an instance of RS
* @throws Exception an exception occurred performing the conversion; may be any checked exception, the conversion
* system will handle wrapping the failure in a {@link Conver
sion
Exception} that provides a consistent type
* system will handle wrapping the failure in a {@link Conver
t
Exception} that provides a consistent type
* conversion error context
*/
public
<
RS
extends
S
>
RS
convertBack
(
T
target
,
Class
<
RS
>
sourceClass
)
throws
Exception
;
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/converter/TwoWayConverter.java
0 → 100644
浏览文件 @
796a457d
package
org.springframework.core.convert.converter
;
import
org.springframework.core.convert.ConversionService
;
import
org.springframework.core.convert.ConvertException
;
/**
* A converter that can also convert a target object of type T to a source of class S.
* <p>
* Implementations of this interface are thread-safe and can be shared. Converters are typically registered with and
* accessed through a {@link ConversionService}.
* </p>
* @author Keith Donald
*/
public
interface
TwoWayConverter
<
S
,
T
>
extends
Converter
<
S
,
T
>
{
/**
* Convert the target of type T back to source type S.
* @param target the target object to convert, which must be an instance of T
* @return the converted object, which must be an instance of S
* @throws Exception an exception occurred performing the conversion; may be any checked exception, the conversion
* system will handle wrapping the failure in a {@link ConvertException} that provides a consistent type
* conversion error context
*/
public
S
convertBack
(
T
target
)
throws
Exception
;
}
org.springframework.core/src/main/java/org/springframework/core/convert/service/GenericConversionService.java
浏览文件 @
796a457d
...
...
@@ -33,6 +33,7 @@ import org.springframework.core.convert.converter.Converter;
import
org.springframework.core.convert.converter.ConverterInfo
;
import
org.springframework.core.convert.converter.SuperConverter
;
import
org.springframework.core.convert.converter.SuperTwoWayConverter
;
import
org.springframework.core.convert.converter.TwoWayConverter
;
import
org.springframework.util.Assert
;
/**
...
...
@@ -89,9 +90,11 @@ public class GenericConversionService implements ConversionService {
// index forward
Map
sourceMap
=
getSourceMap
(
sourceType
);
sourceMap
.
put
(
targetType
,
converter
);
// index reverse
sourceMap
=
getSourceMap
(
targetType
);
sourceMap
.
put
(
sourceType
,
new
ReverseConverter
(
converter
));
if
(
converter
instanceof
TwoWayConverter
)
{
// index reverse
sourceMap
=
getSourceMap
(
targetType
);
sourceMap
.
put
(
sourceType
,
new
ReverseConverter
((
TwoWayConverter
)
converter
));
}
}
/**
...
...
@@ -228,7 +231,7 @@ public class GenericConversionService implements ConversionService {
for
(
Type
genericInterface
:
genericInterfaces
)
{
if
(
genericInterface
instanceof
ParameterizedType
)
{
ParameterizedType
pInterface
=
(
ParameterizedType
)
genericInterface
;
if
(
Converter
.
class
.
equals
(
pInterface
.
getRawType
())
if
(
Converter
.
class
.
isAssignableFrom
((
Class
)
pInterface
.
getRawType
())
||
SuperConverter
.
class
.
isAssignableFrom
((
Class
)
pInterface
.
getRawType
()))
{
Class
s
=
getParameterClass
(
pInterface
.
getActualTypeArguments
()[
0
],
converter
.
getClass
());
Class
t
=
getParameterClass
(
pInterface
.
getActualTypeArguments
()[
1
],
converter
.
getClass
());
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/service/ReverseConverter.java
浏览文件 @
796a457d
...
...
@@ -16,6 +16,7 @@
package
org.springframework.core.convert.service
;
import
org.springframework.core.convert.converter.Converter
;
import
org.springframework.core.convert.converter.TwoWayConverter
;
/**
* A converter that reverses another converter.
...
...
@@ -24,17 +25,14 @@ import org.springframework.core.convert.converter.Converter;
@SuppressWarnings
(
"unchecked"
)
class
ReverseConverter
implements
Converter
{
private
Converter
converter
;
private
TwoWay
Converter
converter
;
public
ReverseConverter
(
Converter
converter
)
{
public
ReverseConverter
(
TwoWay
Converter
converter
)
{
this
.
converter
=
converter
;
}
public
Object
convert
(
Object
source
)
throws
Exception
{
return
converter
.
convertBack
(
source
);
}
public
Object
convertBack
(
Object
target
)
throws
Exception
{
throw
new
IllegalStateException
(
"Should not be called"
);
}
}
org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java
浏览文件 @
796a457d
...
...
@@ -16,7 +16,7 @@
package
org.springframework.expression.spel.support
;
import
org.springframework.core.convert.Conver
sion
Exception
;
import
org.springframework.core.convert.Conver
t
Exception
;
import
org.springframework.core.convert.ConverterNotFoundException
;
import
org.springframework.core.convert.ConversionService
;
import
org.springframework.core.convert.TypeDescriptor
;
...
...
@@ -55,7 +55,7 @@ public class StandardTypeConverter implements TypeConverter {
return
conversionService
.
convert
(
value
,
typeDescriptor
);
}
catch
(
ConverterNotFoundException
cenfe
)
{
throw
new
SpelException
(
cenfe
,
SpelMessages
.
TYPE_CONVERSION_ERROR
,
value
.
getClass
(),
typeDescriptor
.
asString
());
}
catch
(
Conver
sion
Exception
ce
)
{
}
catch
(
Conver
t
Exception
ce
)
{
throw
new
SpelException
(
ce
,
SpelMessages
.
TYPE_CONVERSION_ERROR
,
value
.
getClass
(),
typeDescriptor
.
asString
());
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录