Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
b465f204
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,发现更多精彩内容 >>
提交
b465f204
编写于
10月 01, 2009
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
renamed internal *GenericConverters to *Converters
上级
0543a294
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
272 addition
and
99 deletion
+272
-99
org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToArrayConverter.java
...framework/core/convert/support/ArrayToArrayConverter.java
+10
-3
org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToCollectionConverter.java
...work/core/convert/support/ArrayToCollectionConverter.java
+11
-3
org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToMapConverter.java
...ngframework/core/convert/support/ArrayToMapConverter.java
+11
-5
org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToObjectConverter.java
...ramework/core/convert/support/ArrayToObjectConverter.java
+11
-4
org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToArrayConverter.java
...work/core/convert/support/CollectionToArrayConverter.java
+11
-3
org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToCollectionConverter.java
...core/convert/support/CollectionToCollectionConverter.java
+14
-7
org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToMapConverter.java
...mework/core/convert/support/CollectionToMapConverter.java
+20
-10
org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToObjectConverter.java
...ork/core/convert/support/CollectionToObjectConverter.java
+20
-7
org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java
...mework/core/convert/support/GenericConversionService.java
+15
-15
org.springframework.core/src/main/java/org/springframework/core/convert/support/MapEntryConverter.java
...ringframework/core/convert/support/MapEntryConverter.java
+30
-7
org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToArrayConverter.java
...ngframework/core/convert/support/MapToArrayConverter.java
+11
-4
org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToCollectionConverter.java
...mework/core/convert/support/MapToCollectionConverter.java
+12
-3
org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToMapConverter.java
...ringframework/core/convert/support/MapToMapConverter.java
+28
-3
org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToObjectConverter.java
...gframework/core/convert/support/MapToObjectConverter.java
+20
-7
org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToArrayConverter.java
...ramework/core/convert/support/ObjectToArrayConverter.java
+15
-5
org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToCollectionConverter.java
...ork/core/convert/support/ObjectToCollectionConverter.java
+16
-6
org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToMapConverter.java
...gframework/core/convert/support/ObjectToMapConverter.java
+17
-7
未找到文件。
org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayTo
MapGeneric
Converter.java
→
org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayTo
Array
Converter.java
浏览文件 @
b465f204
...
...
@@ -13,18 +13,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert.support
;
import
static
org
.
springframework
.
core
.
convert
.
support
.
ConversionUtils
.
asList
;
import
org.springframework.core.convert.TypeDescriptor
;
final
class
ArrayToMapGenericConverter
implements
GenericConverter
{
/**
* Converts from a source array to a target array type.
*
* @author Keith Donald
* @since 3.0
*/
final
class
ArrayToArrayConverter
implements
GenericConverter
{
private
final
GenericConverter
helperConverter
;
public
ArrayTo
MapGeneric
Converter
(
GenericConversionService
conversionService
)
{
this
.
helperConverter
=
new
CollectionTo
MapGeneric
Converter
(
conversionService
);
public
ArrayTo
Array
Converter
(
GenericConversionService
conversionService
)
{
this
.
helperConverter
=
new
CollectionTo
Array
Converter
(
conversionService
);
}
public
Object
convert
(
Object
source
,
TypeDescriptor
sourceType
,
TypeDescriptor
targetType
)
{
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToCollection
Generic
Converter.java
→
org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToCollectionConverter.java
浏览文件 @
b465f204
...
...
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert.support
;
import
static
org
.
springframework
.
core
.
convert
.
support
.
ConversionUtils
.
invokeConverter
;
...
...
@@ -24,11 +25,17 @@ import org.springframework.core.CollectionFactory;
import
org.springframework.core.convert.ConverterNotFoundException
;
import
org.springframework.core.convert.TypeDescriptor
;
final
class
ArrayToCollectionGenericConverter
implements
GenericConverter
{
/**
* Converts from an array to a collection.
*
* @author Keith Donald
* @since 3.0
*/
final
class
ArrayToCollectionConverter
implements
GenericConverter
{
private
final
GenericConversionService
conversionService
;
public
ArrayToCollection
Generic
Converter
(
GenericConversionService
conversionService
)
{
public
ArrayToCollectionConverter
(
GenericConversionService
conversionService
)
{
this
.
conversionService
=
conversionService
;
}
...
...
@@ -41,7 +48,8 @@ final class ArrayToCollectionGenericConverter implements GenericConverter {
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
collection
.
add
(
Array
.
get
(
source
,
i
));
}
}
else
{
}
else
{
GenericConverter
converter
=
this
.
conversionService
.
getConverter
(
sourceElementType
,
targetElementType
);
if
(
converter
==
null
)
{
throw
new
ConverterNotFoundException
(
sourceElementType
,
targetElementType
);
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayTo
ArrayGeneric
Converter.java
→
org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayTo
Map
Converter.java
浏览文件 @
b465f204
...
...
@@ -13,18 +13,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert.support
;
import
static
org
.
springframework
.
core
.
convert
.
support
.
ConversionUtils
.
asLis
t
;
package
org.springframework.core.convert.suppor
t
;
import
org.springframework.core.convert.TypeDescriptor
;
import
static
org
.
springframework
.
core
.
convert
.
support
.
ConversionUtils
.*;
final
class
ArrayToArrayGenericConverter
implements
GenericConverter
{
/**
* Converts from an array to a Map.
*
* @author Keith Donald
* @since 3.0
*/
final
class
ArrayToMapConverter
implements
GenericConverter
{
private
final
GenericConverter
helperConverter
;
public
ArrayTo
ArrayGeneric
Converter
(
GenericConversionService
conversionService
)
{
this
.
helperConverter
=
new
CollectionTo
ArrayGeneric
Converter
(
conversionService
);
public
ArrayTo
Map
Converter
(
GenericConversionService
conversionService
)
{
this
.
helperConverter
=
new
CollectionTo
Map
Converter
(
conversionService
);
}
public
Object
convert
(
Object
source
,
TypeDescriptor
sourceType
,
TypeDescriptor
targetType
)
{
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToObject
Generic
Converter.java
→
org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToObjectConverter.java
浏览文件 @
b465f204
...
...
@@ -13,18 +13,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert.support
;
import
static
org
.
springframework
.
core
.
convert
.
support
.
ConversionUtils
.
asList
;
import
org.springframework.core.convert.TypeDescriptor
;
final
class
ArrayToObjectGenericConverter
implements
GenericConverter
{
/**
* Converts from an array to a single Object.
*
* @author Keith Donald
* @since 3.0
*/
final
class
ArrayToObjectConverter
implements
GenericConverter
{
private
CollectionToObjectGeneric
Converter
helperConverter
;
private
final
CollectionToObject
Converter
helperConverter
;
public
ArrayToObject
Generic
Converter
(
GenericConversionService
conversionService
)
{
this
.
helperConverter
=
new
CollectionToObject
Generic
Converter
(
conversionService
);
public
ArrayToObjectConverter
(
GenericConversionService
conversionService
)
{
this
.
helperConverter
=
new
CollectionToObjectConverter
(
conversionService
);
}
public
Object
convert
(
Object
source
,
TypeDescriptor
sourceType
,
TypeDescriptor
targetType
)
{
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToArray
Generic
Converter.java
→
org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToArrayConverter.java
浏览文件 @
b465f204
...
...
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert.support
;
import
static
org
.
springframework
.
core
.
convert
.
support
.
ConversionUtils
.
getElementType
;
...
...
@@ -25,11 +26,17 @@ import java.util.Iterator;
import
org.springframework.core.convert.ConverterNotFoundException
;
import
org.springframework.core.convert.TypeDescriptor
;
final
class
CollectionToArrayGenericConverter
implements
GenericConverter
{
/**
* Converts from a Collection to an array.
*
* @author Keith Donald
* @since 3.0
*/
final
class
CollectionToArrayConverter
implements
GenericConverter
{
private
final
GenericConversionService
conversionService
;
public
CollectionToArray
Generic
Converter
(
GenericConversionService
conversionService
)
{
public
CollectionToArrayConverter
(
GenericConversionService
conversionService
)
{
this
.
conversionService
=
conversionService
;
}
...
...
@@ -46,7 +53,8 @@ final class CollectionToArrayGenericConverter implements GenericConverter {
for
(
Iterator
it
=
sourceCollection
.
iterator
();
it
.
hasNext
();
i
++)
{
Array
.
set
(
array
,
i
,
it
.
next
());
}
}
else
{
}
else
{
GenericConverter
converter
=
this
.
conversionService
.
getConverter
(
sourceElementType
,
targetElementType
);
if
(
converter
==
null
)
{
throw
new
ConverterNotFoundException
(
sourceElementType
,
targetElementType
);
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToCollection
Generic
Converter.java
→
org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToCollectionConverter.java
浏览文件 @
b465f204
...
...
@@ -13,25 +13,31 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert.support
;
import
static
org
.
springframework
.
core
.
convert
.
support
.
ConversionUtils
.
getElementType
;
import
static
org
.
springframework
.
core
.
convert
.
support
.
ConversionUtils
.
invokeConverter
;
package
org.springframework.core.convert.support
;
import
java.util.Collection
;
import
org.springframework.core.CollectionFactory
;
import
org.springframework.core.convert.ConverterNotFoundException
;
import
org.springframework.core.convert.TypeDescriptor
;
import
static
org
.
springframework
.
core
.
convert
.
support
.
ConversionUtils
.*;
final
class
CollectionToCollectionGenericConverter
implements
GenericConverter
{
/**
* Converts from a source Collection to target Collection type.
*
* @author Keith Donald
* @since 3.0
*/
final
class
CollectionToCollectionConverter
implements
GenericConverter
{
private
final
GenericConversionService
conversionService
;
public
CollectionToCollection
Generic
Converter
(
GenericConversionService
conversionService
)
{
public
CollectionToCollectionConverter
(
GenericConversionService
conversionService
)
{
this
.
conversionService
=
conversionService
;
}
@SuppressWarnings
(
"unchecked"
)
public
Object
convert
(
Object
source
,
TypeDescriptor
sourceType
,
TypeDescriptor
targetType
)
{
Collection
sourceCollection
=
(
Collection
)
source
;
TypeDescriptor
sourceElementType
=
sourceType
.
getElementTypeDescriptor
();
...
...
@@ -42,7 +48,8 @@ final class CollectionToCollectionGenericConverter implements GenericConverter {
if
(
sourceElementType
==
TypeDescriptor
.
NULL
||
sourceElementType
.
isAssignableTo
(
targetElementType
))
{
if
(
sourceType
.
isAssignableTo
(
targetType
))
{
return
sourceCollection
;
}
else
{
}
else
{
Collection
target
=
CollectionFactory
.
createCollection
(
targetType
.
getType
(),
sourceCollection
.
size
());
target
.
addAll
(
sourceCollection
);
return
target
;
...
...
@@ -59,4 +66,4 @@ final class CollectionToCollectionGenericConverter implements GenericConverter {
return
target
;
}
}
\ No newline at end of file
}
org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToMap
Generic
Converter.java
→
org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToMapConverter.java
浏览文件 @
b465f204
...
...
@@ -13,24 +13,31 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert.support
;
import
static
org
.
springframework
.
core
.
convert
.
support
.
ConversionUtils
.
getElementType
;
package
org.springframework.core.convert.support
;
import
java.util.Collection
;
import
java.util.Map
;
import
org.springframework.core.CollectionFactory
;
import
org.springframework.core.convert.TypeDescriptor
;
import
static
org
.
springframework
.
core
.
convert
.
support
.
ConversionUtils
.*;
final
class
CollectionToMapGenericConverter
implements
GenericConverter
{
/**
* Converts from a Collection to a Map.
*
* @author Keith Donald
* @since 3.0
*/
final
class
CollectionToMapConverter
implements
GenericConverter
{
private
final
GenericConversionService
conversionService
;
public
CollectionToMap
Generic
Converter
(
GenericConversionService
conversionService
)
{
public
CollectionToMapConverter
(
GenericConversionService
conversionService
)
{
this
.
conversionService
=
conversionService
;
}
@SuppressWarnings
(
"unchecked"
)
public
Object
convert
(
Object
source
,
TypeDescriptor
sourceType
,
TypeDescriptor
targetType
)
{
Collection
sourceCollection
=
(
Collection
)
source
;
TypeDescriptor
sourceElementType
=
sourceType
.
getElementTypeDescriptor
();
...
...
@@ -56,13 +63,15 @@ final class CollectionToMapGenericConverter implements GenericConverter {
String
[]
property
=
parseProperty
((
String
)
element
);
target
.
put
(
property
[
0
],
property
[
1
]);
}
}
else
{
}
else
{
for
(
Object
element
:
sourceCollection
)
{
target
.
put
(
element
,
element
);
}
}
return
target
;
}
else
{
}
else
{
Map
target
=
CollectionFactory
.
createMap
(
targetType
.
getType
(),
sourceCollection
.
size
());
MapEntryConverter
converter
=
new
MapEntryConverter
(
sourceElementType
,
sourceElementType
,
targetKeyType
,
targetValueType
,
keysCompatible
,
valuesCompatible
,
conversionService
);
...
...
@@ -73,7 +82,8 @@ final class CollectionToMapGenericConverter implements GenericConverter {
Object
targetValue
=
converter
.
convertValue
(
property
[
1
]);
target
.
put
(
targetKey
,
targetValue
);
}
}
else
{
}
else
{
for
(
Object
element
:
sourceCollection
)
{
Object
targetKey
=
converter
.
convertKey
(
element
);
Object
targetValue
=
converter
.
convertValue
(
element
);
...
...
@@ -87,10 +97,10 @@ final class CollectionToMapGenericConverter implements GenericConverter {
private
String
[]
parseProperty
(
String
string
)
{
String
[]
property
=
string
.
split
(
"="
);
if
(
property
.
length
<
2
)
{
throw
new
IllegalArgumentException
(
"Invalid String property '"
+
property
+
"'; properties should be in the format name=value"
);
throw
new
IllegalArgumentException
(
"Invalid String property '"
+
string
+
"'; properties should be in the format name=value"
);
}
return
property
;
}
}
\ No newline at end of file
}
org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToObject
Generic
Converter.java
→
org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToObjectConverter.java
浏览文件 @
b465f204
...
...
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert.support
;
import
static
org
.
springframework
.
core
.
convert
.
support
.
ConversionUtils
.
getElementType
;
...
...
@@ -23,13 +24,19 @@ import java.util.Collection;
import
org.springframework.core.convert.ConverterNotFoundException
;
import
org.springframework.core.convert.TypeDescriptor
;
final
class
CollectionToObjectGenericConverter
implements
GenericConverter
{
/**
* Converts from a Collection to a single Object.
*
* @author Keith Donald
* @since 3.0
*/
final
class
CollectionToObjectConverter
implements
GenericConverter
{
private
static
final
String
DELIMITER
=
","
;
private
final
GenericConversionService
conversionService
;
public
CollectionToObject
Generic
Converter
(
GenericConversionService
conversionService
)
{
public
CollectionToObjectConverter
(
GenericConversionService
conversionService
)
{
this
.
conversionService
=
conversionService
;
}
...
...
@@ -38,10 +45,12 @@ final class CollectionToObjectGenericConverter implements GenericConverter {
if
(
sourceCollection
.
size
()
==
0
)
{
if
(
targetType
.
typeEquals
(
String
.
class
))
{
return
""
;
}
else
{
}
else
{
return
null
;
}
}
else
{
}
else
{
if
(
targetType
.
typeEquals
(
String
.
class
))
{
TypeDescriptor
sourceElementType
=
sourceType
.
getElementTypeDescriptor
();
if
(
sourceElementType
==
TypeDescriptor
.
NULL
)
{
...
...
@@ -58,7 +67,8 @@ final class CollectionToObjectGenericConverter implements GenericConverter {
i
++;
}
return
string
.
toString
();
}
else
{
}
else
{
GenericConverter
converter
=
this
.
conversionService
.
getConverter
(
sourceElementType
,
targetType
);
if
(
converter
==
null
)
{
throw
new
ConverterNotFoundException
(
sourceElementType
,
targetType
);
...
...
@@ -75,7 +85,8 @@ final class CollectionToObjectGenericConverter implements GenericConverter {
}
return
string
.
toString
();
}
}
else
{
}
else
{
Object
firstElement
=
sourceCollection
.
iterator
().
next
();
TypeDescriptor
sourceElementType
=
sourceType
.
getElementTypeDescriptor
();
if
(
sourceElementType
==
TypeDescriptor
.
NULL
&&
firstElement
!=
null
)
{
...
...
@@ -83,7 +94,8 @@ final class CollectionToObjectGenericConverter implements GenericConverter {
}
if
(
sourceElementType
==
TypeDescriptor
.
NULL
||
sourceElementType
.
isAssignableTo
(
targetType
))
{
return
firstElement
;
}
else
{
}
else
{
GenericConverter
converter
=
this
.
conversionService
.
getConverter
(
sourceElementType
,
targetType
);
if
(
converter
==
null
)
{
throw
new
ConverterNotFoundException
(
sourceElementType
,
targetType
);
...
...
@@ -93,4 +105,5 @@ final class CollectionToObjectGenericConverter implements GenericConverter {
}
}
}
}
org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java
浏览文件 @
b465f204
...
...
@@ -65,21 +65,21 @@ public class GenericConversionService implements ConversionService, ConverterReg
public
GenericConversionService
()
{
addGenericConverter
(
Object
[].
class
,
Object
[].
class
,
new
ArrayToArray
Generic
Converter
(
this
));
addGenericConverter
(
Object
[].
class
,
Collection
.
class
,
new
ArrayToCollection
Generic
Converter
(
this
));
addGenericConverter
(
Object
[].
class
,
Map
.
class
,
new
ArrayToMap
Generic
Converter
(
this
));
addGenericConverter
(
Object
[].
class
,
Object
.
class
,
new
ArrayToObject
Generic
Converter
(
this
));
addGenericConverter
(
Collection
.
class
,
Collection
.
class
,
new
CollectionToCollection
Generic
Converter
(
this
));
addGenericConverter
(
Collection
.
class
,
Object
[].
class
,
new
CollectionToArray
Generic
Converter
(
this
));
addGenericConverter
(
Collection
.
class
,
Map
.
class
,
new
CollectionToMap
Generic
Converter
(
this
));
addGenericConverter
(
Collection
.
class
,
Object
.
class
,
new
CollectionToObject
Generic
Converter
(
this
));
addGenericConverter
(
Map
.
class
,
Map
.
class
,
new
MapToMap
Generic
Converter
(
this
));
addGenericConverter
(
Map
.
class
,
Object
[].
class
,
new
MapToArray
Generic
Converter
(
this
));
addGenericConverter
(
Map
.
class
,
Collection
.
class
,
new
MapToCollection
Generic
Converter
(
this
));
addGenericConverter
(
Map
.
class
,
Object
.
class
,
new
MapToObject
Generic
Converter
(
this
));
addGenericConverter
(
Object
.
class
,
Object
[].
class
,
new
ObjectToArray
Generic
Converter
(
this
));
addGenericConverter
(
Object
.
class
,
Collection
.
class
,
new
ObjectToCollection
Generic
Converter
(
this
));
addGenericConverter
(
Object
.
class
,
Map
.
class
,
new
ObjectToMap
Generic
Converter
(
this
));
addGenericConverter
(
Object
[].
class
,
Object
[].
class
,
new
ArrayToArrayConverter
(
this
));
addGenericConverter
(
Object
[].
class
,
Collection
.
class
,
new
ArrayToCollectionConverter
(
this
));
addGenericConverter
(
Object
[].
class
,
Map
.
class
,
new
ArrayToMapConverter
(
this
));
addGenericConverter
(
Object
[].
class
,
Object
.
class
,
new
ArrayToObjectConverter
(
this
));
addGenericConverter
(
Collection
.
class
,
Collection
.
class
,
new
CollectionToCollectionConverter
(
this
));
addGenericConverter
(
Collection
.
class
,
Object
[].
class
,
new
CollectionToArrayConverter
(
this
));
addGenericConverter
(
Collection
.
class
,
Map
.
class
,
new
CollectionToMapConverter
(
this
));
addGenericConverter
(
Collection
.
class
,
Object
.
class
,
new
CollectionToObjectConverter
(
this
));
addGenericConverter
(
Map
.
class
,
Map
.
class
,
new
MapToMapConverter
(
this
));
addGenericConverter
(
Map
.
class
,
Object
[].
class
,
new
MapToArrayConverter
(
this
));
addGenericConverter
(
Map
.
class
,
Collection
.
class
,
new
MapToCollectionConverter
(
this
));
addGenericConverter
(
Map
.
class
,
Object
.
class
,
new
MapToObjectConverter
(
this
));
addGenericConverter
(
Object
.
class
,
Object
[].
class
,
new
ObjectToArrayConverter
(
this
));
addGenericConverter
(
Object
.
class
,
Collection
.
class
,
new
ObjectToCollectionConverter
(
this
));
addGenericConverter
(
Object
.
class
,
Map
.
class
,
new
ObjectToMapConverter
(
this
));
}
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/support/MapEntryConverter.java
浏览文件 @
b465f204
/**
*
/*
* Copyright 2002-2009 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert.support
;
import
static
org
.
springframework
.
core
.
convert
.
support
.
ConversionUtils
.
invokeConverter
;
package
org.springframework.core.convert.support
;
import
org.springframework.core.convert.ConverterNotFoundException
;
import
org.springframework.core.convert.TypeDescriptor
;
import
static
org
.
springframework
.
core
.
convert
.
support
.
ConversionUtils
.*;
/**
* Helper for converting map entries.
*
* @author Keith Donald
* @since 3.0
*/
class
MapEntryConverter
{
private
GenericConverter
keyConverter
;
...
...
@@ -22,9 +40,11 @@ class MapEntryConverter {
private
TypeDescriptor
targetValueType
;
public
MapEntryConverter
(
TypeDescriptor
sourceKeyType
,
TypeDescriptor
sourceValueType
,
TypeDescriptor
targetKeyType
,
TypeDescriptor
targetValueType
,
boolean
keysCompatible
,
boolean
valuesCompatible
,
GenericConversionService
conversionService
)
{
if
(
sourceKeyType
!=
TypeDescriptor
.
NULL
&&
targetKeyType
!=
TypeDescriptor
.
NULL
&&
!
keysCompatible
)
{
this
.
keyConverter
=
conversionService
.
getConverter
(
sourceKeyType
,
targetKeyType
);
if
(
this
.
keyConverter
==
null
)
{
...
...
@@ -43,10 +63,12 @@ class MapEntryConverter {
}
}
public
Object
convertKey
(
Object
sourceKey
)
{
if
(
sourceKey
!=
null
&&
this
.
keyConverter
!=
null
)
{
return
invokeConverter
(
this
.
keyConverter
,
sourceKey
,
this
.
sourceKeyType
,
this
.
targetKeyType
);
}
else
{
}
else
{
return
sourceKey
;
}
}
...
...
@@ -54,9 +76,10 @@ class MapEntryConverter {
public
Object
convertValue
(
Object
sourceValue
)
{
if
(
sourceValue
!=
null
&&
this
.
valueConverter
!=
null
)
{
return
invokeConverter
(
this
.
valueConverter
,
sourceValue
,
this
.
sourceValueType
,
this
.
targetValueType
);
}
else
{
}
else
{
return
sourceValue
;
}
}
}
\ No newline at end of file
}
org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToArray
Generic
Converter.java
→
org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToArrayConverter.java
浏览文件 @
b465f204
...
...
@@ -13,21 +13,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert.support
;
import
java.util.List
;
import
org.springframework.core.convert.TypeDescriptor
;
final
class
MapToArrayGenericConverter
implements
GenericConverter
{
/**
* Converts from a Map to an array.
*
* @author Keith Donald
* @since 3.0
*/
final
class
MapToArrayConverter
implements
GenericConverter
{
private
final
GenericConverter
mapToCollectionHelperConverter
;
private
final
GenericConverter
collectionToArrayHelperConverter
;
public
MapToArray
Generic
Converter
(
GenericConversionService
conversionService
)
{
this
.
mapToCollectionHelperConverter
=
new
MapToCollection
Generic
Converter
(
conversionService
);
this
.
collectionToArrayHelperConverter
=
new
CollectionToArray
Generic
Converter
(
conversionService
);
public
MapToArrayConverter
(
GenericConversionService
conversionService
)
{
this
.
mapToCollectionHelperConverter
=
new
MapToCollectionConverter
(
conversionService
);
this
.
collectionToArrayHelperConverter
=
new
CollectionToArrayConverter
(
conversionService
);
}
public
Object
convert
(
Object
source
,
TypeDescriptor
sourceType
,
TypeDescriptor
targetType
)
{
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToCollection
Generic
Converter.java
→
org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToCollectionConverter.java
浏览文件 @
b465f204
...
...
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert.support
;
import
java.util.Collection
;
...
...
@@ -21,14 +22,21 @@ import java.util.Map;
import
org.springframework.core.CollectionFactory
;
import
org.springframework.core.convert.TypeDescriptor
;
final
class
MapToCollectionGenericConverter
implements
GenericConverter
{
/**
* Converts from a Map to a Collection.
*
* @author Keith Donald
* @since 3.0
*/
final
class
MapToCollectionConverter
implements
GenericConverter
{
private
final
GenericConversionService
conversionService
;
public
MapToCollection
Generic
Converter
(
GenericConversionService
conversionService
)
{
public
MapToCollectionConverter
(
GenericConversionService
conversionService
)
{
this
.
conversionService
=
conversionService
;
}
@SuppressWarnings
(
"unchecked"
)
public
Object
convert
(
Object
source
,
TypeDescriptor
sourceType
,
TypeDescriptor
targetType
)
{
Map
sourceMap
=
(
Map
)
source
;
TypeDescriptor
sourceKeyType
=
sourceType
.
getMapKeyTypeDescriptor
();
...
...
@@ -52,7 +60,8 @@ final class MapToCollectionGenericConverter implements GenericConverter {
+
converter
.
convertValue
(
mapEntry
.
getValue
());
target
.
add
(
property
);
}
}
else
{
}
else
{
for
(
Object
value
:
sourceMap
.
values
())
{
target
.
add
(
value
);
}
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToMap
Generic
Converter.java
→
org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToMapConverter.java
浏览文件 @
b465f204
/*
* Copyright 2002-2009 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert.support
;
import
java.util.Map
;
...
...
@@ -5,14 +21,21 @@ import java.util.Map;
import
org.springframework.core.CollectionFactory
;
import
org.springframework.core.convert.TypeDescriptor
;
final
class
MapToMapGenericConverter
implements
GenericConverter
{
/**
* Converts from a source Map to a target Map type.
*
* @author Keith Donald
* @since 3.0
*/
final
class
MapToMapConverter
implements
GenericConverter
{
private
final
GenericConversionService
conversionService
;
public
MapToMap
Generic
Converter
(
GenericConversionService
conversionService
)
{
public
MapToMapConverter
(
GenericConversionService
conversionService
)
{
this
.
conversionService
=
conversionService
;
}
@SuppressWarnings
(
"unchecked"
)
public
Object
convert
(
Object
source
,
TypeDescriptor
sourceType
,
TypeDescriptor
targetType
)
{
Map
sourceMap
=
(
Map
)
source
;
TypeDescriptor
targetKeyType
=
targetType
.
getMapKeyTypeDescriptor
();
...
...
@@ -71,10 +94,12 @@ final class MapToMapGenericConverter implements GenericConverter {
return
new
TypeDescriptor
[]
{
TypeDescriptor
.
valueOf
(
keyType
),
TypeDescriptor
.
valueOf
(
valueType
)
};
}
@SuppressWarnings
(
"unchecked"
)
private
Map
compatibleMapWithoutEntryConversion
(
Map
source
,
TypeDescriptor
targetType
)
{
if
(
targetType
.
getType
().
isAssignableFrom
(
source
.
getClass
()))
{
return
source
;
}
else
{
}
else
{
Map
target
=
CollectionFactory
.
createMap
(
targetType
.
getType
(),
source
.
size
());
target
.
putAll
(
source
);
return
target
;
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToObject
Generic
Converter.java
→
org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToObjectConverter.java
浏览文件 @
b465f204
...
...
@@ -13,19 +13,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert.support
;
import
java.util.Map
;
import
org.springframework.core.convert.TypeDescriptor
;
final
class
MapToObjectGenericConverter
implements
GenericConverter
{
/**
* Converts from a Ma to a single Object.
*
* @author Keith Donald
* @since 3.0
*/
final
class
MapToObjectConverter
implements
GenericConverter
{
private
static
final
String
DELIMITER
=
" "
;
private
final
GenericConversionService
conversionService
;
public
MapToObject
Generic
Converter
(
GenericConversionService
conversionService
)
{
public
MapToObjectConverter
(
GenericConversionService
conversionService
)
{
this
.
conversionService
=
conversionService
;
}
...
...
@@ -34,10 +41,12 @@ final class MapToObjectGenericConverter implements GenericConverter {
if
(
sourceMap
.
size
()
==
0
)
{
if
(
targetType
.
typeEquals
(
String
.
class
))
{
return
""
;
}
else
{
}
else
{
return
null
;
}
}
else
{
}
else
{
if
(
targetType
.
typeEquals
(
String
.
class
))
{
TypeDescriptor
sourceKeyType
=
sourceType
.
getMapKeyTypeDescriptor
();
TypeDescriptor
sourceValueType
=
sourceType
.
getMapValueTypeDescriptor
();
...
...
@@ -62,7 +71,8 @@ final class MapToObjectGenericConverter implements GenericConverter {
i
++;
}
return
string
.
toString
();
}
else
{
}
else
{
MapEntryConverter
converter
=
new
MapEntryConverter
(
sourceKeyType
,
sourceValueType
,
targetType
,
targetType
,
keysCompatible
,
valuesCompatible
,
conversionService
);
StringBuilder
string
=
new
StringBuilder
();
...
...
@@ -80,7 +90,8 @@ final class MapToObjectGenericConverter implements GenericConverter {
}
return
string
.
toString
();
}
}
else
{
}
else
{
TypeDescriptor
sourceValueType
=
sourceType
.
getMapValueTypeDescriptor
();
boolean
valuesCompatible
=
false
;
if
(
sourceValueType
==
TypeDescriptor
.
NULL
||
sourceValueType
.
isAssignableTo
(
targetType
))
{
...
...
@@ -88,7 +99,8 @@ final class MapToObjectGenericConverter implements GenericConverter {
}
if
(
valuesCompatible
)
{
return
sourceMap
.
values
().
iterator
().
next
();
}
else
{
}
else
{
MapEntryConverter
converter
=
new
MapEntryConverter
(
sourceValueType
,
sourceValueType
,
targetType
,
targetType
,
true
,
valuesCompatible
,
conversionService
);
Object
value
=
sourceMap
.
values
().
iterator
().
next
();
...
...
@@ -97,4 +109,5 @@ final class MapToObjectGenericConverter implements GenericConverter {
}
}
}
}
org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToArray
Generic
Converter.java
→
org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToArrayConverter.java
浏览文件 @
b465f204
...
...
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert.support
;
import
static
org
.
springframework
.
core
.
convert
.
support
.
ConversionUtils
.
invokeConverter
;
...
...
@@ -23,11 +24,17 @@ import org.springframework.core.convert.ConverterNotFoundException;
import
org.springframework.core.convert.TypeDescriptor
;
import
org.springframework.util.StringUtils
;
final
class
ObjectToArrayGenericConverter
implements
GenericConverter
{
/**
* Converts from a single Object to an array.
*
* @author Keith Donald
* @since 3.0
*/
final
class
ObjectToArrayConverter
implements
GenericConverter
{
private
final
GenericConversionService
conversionService
;
public
ObjectToArray
Generic
Converter
(
GenericConversionService
conversionService
)
{
public
ObjectToArrayConverter
(
GenericConversionService
conversionService
)
{
this
.
conversionService
=
conversionService
;
}
...
...
@@ -38,7 +45,8 @@ final class ObjectToArrayGenericConverter implements GenericConverter {
String
[]
fields
=
StringUtils
.
commaDelimitedListToStringArray
(
string
);
if
(
sourceType
.
isAssignableTo
(
targetElementType
))
{
return
fields
;
}
else
{
}
else
{
Object
target
=
Array
.
newInstance
(
targetElementType
.
getType
(),
fields
.
length
);
GenericConverter
converter
=
this
.
conversionService
.
getConverter
(
sourceType
,
targetElementType
);
if
(
converter
==
null
)
{
...
...
@@ -49,11 +57,13 @@ final class ObjectToArrayGenericConverter implements GenericConverter {
}
return
target
;
}
}
else
{
}
else
{
Object
target
=
Array
.
newInstance
(
targetElementType
.
getType
(),
1
);
if
(
sourceType
.
isAssignableTo
(
targetElementType
))
{
Array
.
set
(
target
,
0
,
source
);
}
else
{
}
else
{
GenericConverter
converter
=
this
.
conversionService
.
getConverter
(
sourceType
,
targetElementType
);
if
(
converter
==
null
)
{
throw
new
ConverterNotFoundException
(
sourceType
,
targetElementType
);
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToCollection
Generic
Converter.java
→
org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToCollectionConverter.java
浏览文件 @
b465f204
...
...
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert.support
;
import
static
org
.
springframework
.
core
.
convert
.
support
.
ConversionUtils
.
invokeConverter
;
...
...
@@ -24,11 +25,17 @@ import org.springframework.core.convert.ConverterNotFoundException;
import
org.springframework.core.convert.TypeDescriptor
;
import
org.springframework.util.StringUtils
;
final
class
ObjectToCollectionGenericConverter
implements
GenericConverter
{
/**
* Converts from a single Object to a Collection.
*
* @author Keith Donald
* @since 3.0
*/
final
class
ObjectToCollectionConverter
implements
GenericConverter
{
private
final
GenericConversionService
conversionService
;
public
ObjectToCollection
Generic
Converter
(
GenericConversionService
conversionService
)
{
public
ObjectToCollectionConverter
(
GenericConversionService
conversionService
)
{
this
.
conversionService
=
conversionService
;
}
...
...
@@ -42,7 +49,8 @@ final class ObjectToCollectionGenericConverter implements GenericConverter {
for
(
int
i
=
0
;
i
<
fields
.
length
;
i
++)
{
target
.
add
(
fields
[
i
]);
}
}
else
{
}
else
{
GenericConverter
converter
=
this
.
conversionService
.
getConverter
(
sourceType
,
targetElementType
);
if
(
converter
==
null
)
{
throw
new
ConverterNotFoundException
(
sourceType
,
targetElementType
);
...
...
@@ -55,11 +63,13 @@ final class ObjectToCollectionGenericConverter implements GenericConverter {
}
return
target
;
}
else
{
}
else
{
Collection
target
=
CollectionFactory
.
createCollection
(
targetType
.
getType
(),
1
);
if
(
targetElementType
==
TypeDescriptor
.
NULL
||
sourceType
.
isAssignableTo
(
targetElementType
))
{
target
.
add
(
source
);
}
else
{
}
else
{
GenericConverter
converter
=
this
.
conversionService
.
getConverter
(
sourceType
,
targetElementType
);
if
(
converter
==
null
)
{
throw
new
ConverterNotFoundException
(
sourceType
,
targetElementType
);
...
...
@@ -70,4 +80,4 @@ final class ObjectToCollectionGenericConverter implements GenericConverter {
}
}
}
\ No newline at end of file
}
org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToMap
Generic
Converter.java
→
org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToMapConverter.java
浏览文件 @
b465f204
...
...
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert.support
;
import
java.util.Map
;
...
...
@@ -20,23 +21,31 @@ import java.util.Map;
import
org.springframework.core.CollectionFactory
;
import
org.springframework.core.convert.TypeDescriptor
;
final
class
ObjectToMapGenericConverter
implements
GenericConverter
{
/**
* Converts from a single Object to a Map.
*
* @author Keith Donald
* @since 3.0
*/
final
class
ObjectToMapConverter
implements
GenericConverter
{
private
final
GenericConversionService
conversionService
;
private
final
ArrayToMap
Generic
Converter
helperConverter
;
private
final
ArrayToMapConverter
helperConverter
;
public
ObjectToMap
Generic
Converter
(
GenericConversionService
conversionService
)
{
public
ObjectToMapConverter
(
GenericConversionService
conversionService
)
{
this
.
conversionService
=
conversionService
;
this
.
helperConverter
=
new
ArrayToMap
Generic
Converter
(
conversionService
);
this
.
helperConverter
=
new
ArrayToMapConverter
(
conversionService
);
}
@SuppressWarnings
(
"unchecked"
)
public
Object
convert
(
Object
source
,
TypeDescriptor
sourceType
,
TypeDescriptor
targetType
)
{
if
(
sourceType
.
typeEquals
(
String
.
class
))
{
String
string
=
(
String
)
source
;
String
[]
properties
=
string
.
split
(
" "
);
return
this
.
helperConverter
.
convert
(
properties
,
TypeDescriptor
.
valueOf
(
String
[].
class
),
targetType
);
}
else
{
}
else
{
Map
target
=
CollectionFactory
.
createMap
(
targetType
.
getType
(),
1
);
TypeDescriptor
targetKeyType
=
targetType
.
getMapKeyTypeDescriptor
();
TypeDescriptor
targetValueType
=
targetType
.
getMapValueTypeDescriptor
();
...
...
@@ -50,7 +59,8 @@ final class ObjectToMapGenericConverter implements GenericConverter {
}
if
(
keysCompatible
&&
valuesCompatible
)
{
target
.
put
(
source
,
source
);
}
else
{
}
else
{
MapEntryConverter
converter
=
new
MapEntryConverter
(
sourceType
,
sourceType
,
targetKeyType
,
targetValueType
,
keysCompatible
,
valuesCompatible
,
conversionService
);
Object
key
=
converter
.
convertKey
(
source
);
...
...
@@ -61,4 +71,4 @@ final class ObjectToMapGenericConverter implements GenericConverter {
}
}
}
\ No newline at end of file
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录