Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
6ce33dba
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,发现更多精彩内容 >>
提交
6ce33dba
编写于
9月 21, 2009
作者:
K
Keith Donald
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
getConverter calls now throw exception and query parent
上级
5faa4d90
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
29 addition
and
24 deletion
+29
-24
org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java
...mework/core/convert/support/GenericConversionService.java
+29
-24
未找到文件。
org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java
浏览文件 @
6ce33dba
...
...
@@ -53,7 +53,13 @@ import org.springframework.util.ClassUtils;
*/
public
class
GenericConversionService
implements
ConversionService
,
ConverterRegistry
{
private
ConversionService
parent
;
private
static
final
GenericConverter
NO_OP_CONVERTER
=
new
GenericConverter
()
{
public
Object
convert
(
Object
source
,
TypeDescriptor
sourceType
,
TypeDescriptor
targetType
)
{
return
source
;
}
};
private
GenericConversionService
parent
;
private
final
Map
<
Class
,
Map
<
Class
,
GenericConverter
>>
sourceTypeConverters
=
new
HashMap
<
Class
,
Map
<
Class
,
GenericConverter
>>();
...
...
@@ -86,7 +92,7 @@ public class GenericConversionService implements ConversionService, ConverterReg
/**
* Set the parent of this conversion service. This is optional.
*/
public
void
setParent
(
ConversionService
parent
)
{
public
void
setParent
(
Generic
ConversionService
parent
)
{
this
.
parent
=
parent
;
}
...
...
@@ -142,8 +148,7 @@ public class GenericConversionService implements ConversionService, ConverterReg
if
(
targetType
==
TypeDescriptor
.
NULL
)
{
return
true
;
}
return
getConverter
(
sourceType
,
targetType
)
!=
null
||
this
.
parent
!=
null
&&
this
.
parent
.
canConvert
(
sourceType
,
targetType
);
return
getConverter
(
sourceType
,
targetType
)
!=
null
;
}
public
Object
convert
(
Object
source
,
TypeDescriptor
sourceType
,
TypeDescriptor
targetType
)
{
...
...
@@ -158,24 +163,12 @@ public class GenericConversionService implements ConversionService, ConverterReg
return
null
;
}
GenericConverter
converter
=
getConverter
(
sourceType
,
targetType
);
if
(
converter
!=
null
)
{
try
{
return
converter
.
convert
(
source
,
sourceType
,
targetType
);
}
catch
(
ConversionFailedException
e
)
{
throw
e
;
}
catch
(
Exception
e
)
{
throw
new
ConversionFailedException
(
sourceType
,
targetType
,
source
,
e
);
}
}
else
{
if
(
this
.
parent
!=
null
)
{
return
this
.
parent
.
convert
(
source
,
sourceType
,
targetType
);
}
else
{
if
(
targetType
.
isAssignableValue
(
source
))
{
return
source
;
}
else
{
throw
new
ConverterNotFoundException
(
sourceType
,
targetType
);
}
}
try
{
return
converter
.
convert
(
source
,
sourceType
,
targetType
);
}
catch
(
ConversionFailedException
e
)
{
throw
e
;
}
catch
(
Exception
e
)
{
throw
new
ConversionFailedException
(
sourceType
,
targetType
,
source
,
e
);
}
}
...
...
@@ -200,9 +193,21 @@ public class GenericConversionService implements ConversionService, ConverterReg
protected
Object
convertNull
(
TypeDescriptor
sourceType
,
TypeDescriptor
targetType
)
{
return
null
;
}
protected
GenericConverter
getConverter
(
TypeDescriptor
sourceType
,
TypeDescriptor
targetType
)
{
return
findConverterByClassPair
(
sourceType
.
getObjectType
(),
targetType
.
getObjectType
());
GenericConverter
converter
=
findConverterByClassPair
(
sourceType
.
getObjectType
(),
targetType
.
getObjectType
());
if
(
converter
!=
null
)
{
return
converter
;
}
if
(
this
.
parent
!=
null
)
{
return
this
.
parent
.
getConverter
(
sourceType
,
targetType
);
}
else
{
if
(
sourceType
.
isAssignableTo
(
targetType
))
{
return
NO_OP_CONVERTER
;
}
else
{
throw
new
ConverterNotFoundException
(
sourceType
,
targetType
);
}
}
}
// internal helpers
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录