Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
871fc14f
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,发现更多精彩内容 >>
提交
871fc14f
编写于
9月 22, 2009
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
restored parent property to accept ConversionService instead of GenericConversionService
上级
0698947e
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
42 addition
and
18 deletion
+42
-18
org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java
...mework/core/convert/support/GenericConversionService.java
+42
-18
未找到文件。
org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java
浏览文件 @
871fc14f
...
...
@@ -58,14 +58,23 @@ public class GenericConversionService implements ConversionService, ConverterReg
}
};
private
GenericConversionService
parent
;
private
final
Map
<
Class
,
Map
<
Class
,
GenericConverter
>>
sourceTypeConverters
=
new
HashMap
<
Class
,
Map
<
Class
,
GenericConverter
>>();
private
ConversionService
parent
;
private
GenericConverter
parentConverterAdapter
=
new
GenericConverter
()
{
public
Object
convert
(
Object
source
,
TypeDescriptor
sourceType
,
TypeDescriptor
targetType
)
{
return
parent
.
convert
(
source
,
sourceType
,
targetType
);
}
};
public
GenericConversionService
()
{
initGenericConverters
();
}
/**
* Registers the converters in the set provided.
* JavaBean-friendly alternative to calling {@link #addConverter(Converter)}.
...
...
@@ -91,17 +100,18 @@ public class GenericConversionService implements ConversionService, ConverterReg
/**
* Set the parent of this conversion service. This is optional.
*/
public
void
setParent
(
Generic
ConversionService
parent
)
{
public
void
setParent
(
ConversionService
parent
)
{
this
.
parent
=
parent
;
}
/**
* Returns the parent of this conversion service. Could be null.
*/
public
Generic
ConversionService
getParent
()
{
public
ConversionService
getParent
()
{
return
this
.
parent
;
}
// implementing ConverterRegistry
public
void
addConverter
(
Converter
converter
)
{
...
...
@@ -130,12 +140,14 @@ public class GenericConversionService implements ConversionService, ConverterReg
getSourceMap
(
sourceType
).
remove
(
targetType
);
}
// implementing ConversionService
public
boolean
canConvert
(
Class
<?>
sourceType
,
Class
<?>
targetType
)
{
return
canConvert
(
TypeDescriptor
.
valueOf
(
sourceType
),
TypeDescriptor
.
valueOf
(
targetType
));
}
@SuppressWarnings
(
"unchecked"
)
public
<
T
>
T
convert
(
Object
source
,
Class
<
T
>
targetType
)
{
Assert
.
notNull
(
targetType
,
"The targetType to convert to is required"
);
return
(
T
)
convert
(
source
,
TypeDescriptor
.
forObject
(
source
),
TypeDescriptor
.
valueOf
(
targetType
));
...
...
@@ -167,10 +179,12 @@ public class GenericConversionService implements ConversionService, ConverterReg
}
try
{
return
converter
.
convert
(
source
,
sourceType
,
targetType
);
}
catch
(
ConversionFailedException
e
)
{
throw
e
;
}
catch
(
Exception
e
)
{
throw
new
ConversionFailedException
(
sourceType
,
targetType
,
source
,
e
);
}
catch
(
ConversionFailedException
ex
)
{
throw
ex
;
}
catch
(
Exception
ex
)
{
throw
new
ConversionFailedException
(
sourceType
,
targetType
,
source
,
ex
);
}
}
...
...
@@ -229,17 +243,20 @@ public class GenericConversionService implements ConversionService, ConverterReg
if
(
converter
!=
null
)
{
return
converter
;
}
if
(
this
.
parent
!=
null
)
{
return
this
.
parent
.
getConverter
(
sourceType
,
targetType
);
}
else
{
else
if
(
this
.
parent
!=
null
&&
this
.
parent
.
canConvert
(
sourceType
,
targetType
))
{
return
this
.
parentConverterAdapter
;
}
else
{
if
(
sourceType
.
isAssignableTo
(
targetType
))
{
return
NO_OP_CONVERTER
;
}
else
{
}
else
{
return
null
;
}
}
}
// internal helpers
private
List
<
Class
>
getRequiredTypeInfo
(
Object
converter
)
{
...
...
@@ -281,10 +298,12 @@ public class GenericConversionService implements ConversionService, ConverterReg
if
(
typeInfo
.
size
()
==
2
)
{
return
typeInfo
;
}
}
else
if
(
Converter
.
class
.
isAssignableFrom
((
Class
)
rawType
))
{
}
else
if
(
Converter
.
class
.
isAssignableFrom
((
Class
)
rawType
))
{
return
getConverterTypeInfo
((
Class
)
rawType
);
}
}
else
if
(
Converter
.
class
.
isAssignableFrom
((
Class
)
ifc
))
{
}
else
if
(
Converter
.
class
.
isAssignableFrom
((
Class
)
ifc
))
{
return
getConverterTypeInfo
((
Class
)
ifc
);
}
}
...
...
@@ -311,7 +330,8 @@ public class GenericConversionService implements ConversionService, ConverterReg
}
Map
<
Class
,
GenericConverter
>
objectConverters
=
getConvertersForSource
(
Object
.
class
);
return
getConverter
(
objectConverters
,
targetType
);
}
else
{
}
else
{
LinkedList
<
Class
>
classQueue
=
new
LinkedList
<
Class
>();
classQueue
.
addFirst
(
sourceType
);
while
(!
classQueue
.
isEmpty
())
{
...
...
@@ -373,7 +393,8 @@ public class GenericConversionService implements ConversionService, ConverterReg
}
}
return
converters
.
get
(
Object
.
class
);
}
else
{
}
else
{
LinkedList
<
Class
>
classQueue
=
new
LinkedList
<
Class
>();
classQueue
.
addFirst
(
targetType
);
while
(!
classQueue
.
isEmpty
())
{
...
...
@@ -387,7 +408,8 @@ public class GenericConversionService implements ConversionService, ConverterReg
if
(
componentType
.
getSuperclass
()
!=
null
)
{
classQueue
.
addFirst
(
Array
.
newInstance
(
componentType
.
getSuperclass
(),
0
).
getClass
());
}
}
else
{
}
else
{
if
(
currentClass
.
getSuperclass
()
!=
null
)
{
classQueue
.
addFirst
(
currentClass
.
getSuperclass
());
}
...
...
@@ -401,6 +423,7 @@ public class GenericConversionService implements ConversionService, ConverterReg
}
}
private
static
class
ConverterAdapter
implements
GenericConverter
{
private
Converter
converter
;
...
...
@@ -409,12 +432,13 @@ public class GenericConversionService implements ConversionService, ConverterReg
this
.
converter
=
converter
;
}
@SuppressWarnings
(
"unchecked"
)
public
Object
convert
(
Object
source
,
TypeDescriptor
sourceType
,
TypeDescriptor
targetType
)
{
return
this
.
converter
.
convert
(
source
);
}
}
private
static
class
ConverterFactoryAdapter
implements
GenericConverter
{
private
ConverterFactory
converterFactory
;
...
...
@@ -423,10 +447,10 @@ public class GenericConversionService implements ConversionService, ConverterReg
this
.
converterFactory
=
converterFactory
;
}
@SuppressWarnings
(
"unchecked"
)
public
Object
convert
(
Object
source
,
TypeDescriptor
sourceType
,
TypeDescriptor
targetType
)
{
return
this
.
converterFactory
.
getConverter
(
targetType
.
getObjectType
()).
convert
(
source
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录