Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
dffec3cd
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,发现更多精彩内容 >>
提交
dffec3cd
编写于
5月 15, 2009
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
quick attempt to fix core.convert breakage
上级
eb3ece42
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
27 addition
and
25 deletion
+27
-25
org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java
...mework/expression/spel/support/StandardTypeConverter.java
+14
-12
org.springframework.expression/src/test/java/org/springframework/expression/spel/ExpressionTestsUsingCoreConversionService.java
...ssion/spel/ExpressionTestsUsingCoreConversionService.java
+13
-13
未找到文件。
org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java
浏览文件 @
dffec3cd
...
...
@@ -18,9 +18,8 @@ package org.springframework.expression.spel.support;
import
org.springframework.core.convert.ConvertException
;
import
org.springframework.core.convert.ConverterNotFoundException
;
import
org.springframework.core.convert.ConversionService
;
import
org.springframework.core.convert.TypeDescriptor
;
import
org.springframework.core.convert.s
ervice
.DefaultConversionService
;
import
org.springframework.core.convert.s
upport
.DefaultConversionService
;
import
org.springframework.expression.EvaluationException
;
import
org.springframework.expression.TypeConverter
;
import
org.springframework.expression.spel.SpelException
;
...
...
@@ -34,28 +33,31 @@ import org.springframework.util.Assert;
*/
public
class
StandardTypeConverter
implements
TypeConverter
{
private
ConversionService
conversionService
;
private
org
.
springframework
.
core
.
convert
.
TypeConverter
typeConverter
;
public
StandardTypeConverter
()
{
conversionService
=
new
DefaultConversionService
();
this
.
typeConverter
=
new
DefaultConversionService
();
}
public
StandardTypeConverter
(
ConversionService
conversionService
)
{
Assert
.
notNull
(
conversionService
,
"The conversionService
must not be null"
);
this
.
conversionService
=
conversionService
;
public
StandardTypeConverter
(
org
.
springframework
.
core
.
convert
.
TypeConverter
typeConverter
)
{
Assert
.
notNull
(
typeConverter
,
"TypeConverter
must not be null"
);
this
.
typeConverter
=
typeConverter
;
}
@SuppressWarnings
(
"unchecked"
)
public
<
T
>
T
convertValue
(
Object
value
,
Class
<
T
>
targetType
)
throws
EvaluationException
{
return
(
T
)
convertValue
(
value
,
TypeDescriptor
.
valueOf
(
targetType
));
return
(
T
)
convertValue
(
value
,
TypeDescriptor
.
valueOf
(
targetType
));
}
@SuppressWarnings
(
"unchecked"
)
public
Object
convertValue
(
Object
value
,
TypeDescriptor
typeDescriptor
)
throws
EvaluationException
{
try
{
return
conversionService
.
convert
(
value
,
typeDescriptor
);
}
catch
(
ConverterNotFoundException
cenfe
)
{
return
this
.
typeConverter
.
convert
(
value
,
typeDescriptor
);
}
catch
(
ConverterNotFoundException
cenfe
)
{
throw
new
SpelException
(
cenfe
,
SpelMessages
.
TYPE_CONVERSION_ERROR
,
value
.
getClass
(),
typeDescriptor
.
asString
());
}
catch
(
ConvertException
ce
)
{
}
catch
(
ConvertException
ce
)
{
throw
new
SpelException
(
ce
,
SpelMessages
.
TYPE_CONVERSION_ERROR
,
value
.
getClass
(),
typeDescriptor
.
asString
());
}
}
...
...
@@ -65,7 +67,7 @@ public class StandardTypeConverter implements TypeConverter {
}
public
boolean
canConvert
(
Class
<?>
sourceType
,
TypeDescriptor
targetType
)
{
return
conversionService
.
canConvert
(
sourceType
,
targetType
);
return
this
.
typeConverter
.
canConvert
(
sourceType
,
targetType
);
}
}
org.springframework.expression/src/test/java/org/springframework/expression/spel/ExpressionTestsUsingCoreConversionService.java
浏览文件 @
dffec3cd
...
...
@@ -20,8 +20,8 @@ import java.util.ArrayList;
import
java.util.List
;
import
org.springframework.core.convert.TypeDescriptor
;
import
org.springframework.core.convert.s
ervice
.DefaultConversionService
;
import
org.springframework.core.convert.s
ervice
.GenericConversionService
;
import
org.springframework.core.convert.s
upport
.DefaultConversionService
;
import
org.springframework.core.convert.s
upport
.GenericConversionService
;
import
org.springframework.expression.EvaluationException
;
import
org.springframework.expression.Expression
;
import
org.springframework.expression.TypeConverter
;
...
...
@@ -64,14 +64,14 @@ public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCas
// ArrayList containing List<Integer> to List<String>
Class
<?>
clazz
=
typeDescriptorForListOfString
.
getElementType
();
assertEquals
(
String
.
class
,
clazz
);
List
l
=
(
List
)
tcs
.
convert
(
listOfInteger
,
typeDescriptorForListOfString
);
List
l
=
(
List
)
tcs
.
convert
Value
(
listOfInteger
,
typeDescriptorForListOfString
);
assertNotNull
(
l
);
// ArrayList containing List<String> to List<Integer>
clazz
=
typeDescriptorForListOfInteger
.
getElementType
();
assertEquals
(
Integer
.
class
,
clazz
);
l
=
(
List
)
tcs
.
convert
(
listOfString
,
typeDescriptorForListOfString
);
l
=
(
List
)
tcs
.
convert
Value
(
listOfString
,
typeDescriptorForListOfString
);
assertNotNull
(
l
);
}
...
...
@@ -89,29 +89,29 @@ public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCas
/**
* Type convert
o
r that uses the core conversion service.
* Type convert
e
r that uses the core conversion service.
*/
private
static
class
TypeConvertorUsingConversionService
extends
DefaultConversionService
implements
TypeConverter
{
private
static
class
TypeConvertorUsingConversionService
implements
TypeConverter
{
private
final
DefaultConversionService
service
=
new
DefaultConversionService
();
public
boolean
canConvert
(
Class
<?>
sourceType
,
Class
<?>
targetType
)
{
return
super
.
canConvert
(
sourceType
,
TypeDescriptor
.
valueOf
(
targetType
));
return
this
.
service
.
canConvert
(
sourceType
,
TypeDescriptor
.
valueOf
(
targetType
));
}
public
boolean
canConvert
(
Class
<?>
sourceType
,
TypeDescriptor
typeDescriptor
)
{
return
super
.
canConvert
(
sourceType
,
typeDescriptor
);
return
this
.
service
.
canConvert
(
sourceType
,
typeDescriptor
);
}
@SuppressWarnings
(
"unchecked"
)
public
<
T
>
T
convertValue
(
Object
value
,
Class
<
T
>
targetType
)
throws
EvaluationException
{
return
(
T
)
super
.
convert
(
value
,
TypeDescriptor
.
valueOf
(
targetType
));
return
(
T
)
this
.
service
.
convert
(
value
,
TypeDescriptor
.
valueOf
(
targetType
));
}
@SuppressWarnings
(
"unchecked"
)
public
Object
convertValue
(
Object
value
,
TypeDescriptor
typeDescriptor
)
throws
EvaluationException
{
return
super
.
convert
(
value
,
typeDescriptor
);
public
Object
convertValue
(
Object
value
,
TypeDescriptor
typeDescriptor
)
throws
EvaluationException
{
return
this
.
service
.
convert
(
value
,
typeDescriptor
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录