Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
2aef75b9
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,发现更多精彩内容 >>
提交
2aef75b9
编写于
7月 09, 2009
作者:
K
Keith Donald
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
list binding tests
上级
cbe66952
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
55 addition
and
16 deletion
+55
-16
org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericFormatterRegistry.java
...ramework/ui/binding/support/GenericFormatterRegistry.java
+12
-3
org.springframework.context/src/test/java/org/springframework/ui/binding/support/GenericBinderTests.java
...pringframework/ui/binding/support/GenericBinderTests.java
+43
-10
org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericTypeConverter.java
...gframework/core/convert/support/GenericTypeConverter.java
+0
-3
未找到文件。
org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericFormatterRegistry.java
浏览文件 @
2aef75b9
...
...
@@ -52,11 +52,12 @@ public class GenericFormatterRegistry implements FormatterRegistry {
return
factory
.
getFormatter
(
a
);
}
}
Formatter
<?>
formatter
=
typeFormatters
.
get
(
propertyType
.
getType
());
Class
<?>
type
=
getType
(
propertyType
);
Formatter
<?>
formatter
=
typeFormatters
.
get
(
type
);
if
(
formatter
!=
null
)
{
return
formatter
;
}
else
{
Formatted
formatted
=
AnnotationUtils
.
findAnnotation
(
propertyType
.
getType
()
,
Formatted
.
class
);
Formatted
formatted
=
AnnotationUtils
.
findAnnotation
(
type
,
Formatted
.
class
);
if
(
formatted
!=
null
)
{
Class
formatterClass
=
formatted
.
value
();
try
{
...
...
@@ -67,7 +68,7 @@ public class GenericFormatterRegistry implements FormatterRegistry {
}
catch
(
IllegalAccessException
e
)
{
throw
new
IllegalStateException
(
e
);
}
typeFormatters
.
put
(
propertyType
.
getType
()
,
formatter
);
typeFormatters
.
put
(
type
,
formatter
);
return
formatter
;
}
else
{
return
null
;
...
...
@@ -108,6 +109,14 @@ public class GenericFormatterRegistry implements FormatterRegistry {
+
factory
.
getClass
().
getName
()
+
"]; does the factory parameterize the <A> generic type?"
);
}
private
Class
getType
(
TypeDescriptor
descriptor
)
{
if
(
descriptor
.
isArray
()
||
descriptor
.
isCollection
())
{
return
descriptor
.
getElementType
();
}
else
{
return
descriptor
.
getType
();
}
}
private
Class
getParameterClass
(
Type
parameterType
,
Class
converterClass
)
{
if
(
parameterType
instanceof
TypeVariable
)
{
parameterType
=
GenericTypeResolver
.
resolveTypeVariable
((
TypeVariable
)
parameterType
,
converterClass
);
...
...
org.springframework.context/src/test/java/org/springframework/ui/binding/support/GenericBinderTests.java
浏览文件 @
2aef75b9
...
...
@@ -4,7 +4,6 @@ import static org.junit.Assert.assertEquals;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
java.lang.annotation.Annotation
;
import
java.math.BigDecimal
;
import
java.text.ParseException
;
import
java.util.Collections
;
...
...
@@ -225,21 +224,37 @@ public class GenericBinderTests {
assertTrue
(
result
.
isFailure
());
assertEquals
(
"conversionFailed"
,
result
.
getAlert
().
getCode
());
}
@Test
public
void
bindToList
()
{
binder
.
addBinding
(
"addresses"
);
Map
<
String
,
String
[]>
values
=
new
LinkedHashMap
<
String
,
String
[]>();
values
.
put
(
"addresses"
,
new
String
[]
{
"4655 Macy Lane:Melbourne:FL:35452"
,
"1234 Rostock Circle:Palm Bay:FL:32901"
,
"1977 Bel Aire Estates:Coker:AL:12345"
});
binder
.
bind
(
values
);
Assert
.
assertEquals
(
3
,
bean
.
addresses
.
size
());
assertEquals
(
"4655 Macy Lane"
,
bean
.
addresses
.
get
(
0
).
street
);
assertEquals
(
"Melbourne"
,
bean
.
addresses
.
get
(
0
).
city
);
assertEquals
(
"FL"
,
bean
.
addresses
.
get
(
0
).
state
);
assertEquals
(
"35452"
,
bean
.
addresses
.
get
(
0
).
zip
);
}
@Test
public
void
bindToListElements
()
{
binder
.
addBinding
(
"addresses"
);
Map
<
String
,
String
>
values
=
new
LinkedHashMap
<
String
,
String
>();
values
.
put
(
"addresses[0]"
,
"4655 Macy Lane, Melbourne FL 35452"
);
values
.
put
(
"addresses[1]"
,
"1234 Rostock Circle, Palm Bay FL 32901"
);
values
.
put
(
"addresses[5]"
,
"1977 Bel Aire Estates, Coker AL 12345"
);
BindingResults
results
=
binder
.
bind
(
values
);
System
.
out
.
println
(
results
);
values
.
put
(
"addresses[0]"
,
"4655 Macy Lane:Melbourne:FL:35452"
);
values
.
put
(
"addresses[1]"
,
"1234 Rostock Circle:Palm Bay:FL:32901"
);
values
.
put
(
"addresses[5]"
,
"1977 Bel Aire Estates:Coker:AL:12345"
);
binder
.
bind
(
values
);
Assert
.
assertEquals
(
6
,
bean
.
addresses
.
size
());
assertEquals
(
"4655 Macy Lane"
,
bean
.
addresses
.
get
(
0
).
street
);
assertEquals
(
"Melbourne"
,
bean
.
addresses
.
get
(
0
).
city
);
assertEquals
(
"FL"
,
bean
.
addresses
.
get
(
0
).
state
);
assertEquals
(
"35452"
,
bean
.
addresses
.
get
(
0
).
zip
);
}
@Test
public
void
bindHandleNullValueInNestedPath
()
{
public
void
bind
ToList
HandleNullValueInNestedPath
()
{
binder
.
addBinding
(
"addresses.street"
);
binder
.
addBinding
(
"addresses.city"
);
binder
.
addBinding
(
"addresses.state"
);
...
...
@@ -289,6 +304,10 @@ public class GenericBinderTests {
BAR
,
BAZ
,
BOOP
;
}
public
static
enum
FoodGroup
{
DAIRY
,
VEG
,
FRUIT
,
BREAD
,
MEAT
}
public
static
class
TestBean
{
private
String
string
;
private
int
integer
;
...
...
@@ -297,7 +316,8 @@ public class GenericBinderTests {
private
BigDecimal
currency
;
private
List
<
FooEnum
>
foos
;
private
List
<
Address
>
addresses
;
private
Map
<
FoodGroup
,
String
>
favoriteFoodsByGroup
;
public
String
getString
()
{
return
string
;
}
...
...
@@ -355,16 +375,29 @@ public class GenericBinderTests {
this
.
addresses
=
addresses
;
}
public
Map
<
FoodGroup
,
String
>
getFavoriteFoodsByGroup
()
{
return
favoriteFoodsByGroup
;
}
public
void
setFavoriteFoodsByGroup
(
Map
<
FoodGroup
,
String
>
favoriteFoodsByGroup
)
{
this
.
favoriteFoodsByGroup
=
favoriteFoodsByGroup
;
}
}
public
static
class
AddressFormatter
implements
Formatter
<
Address
>
{
public
String
format
(
Address
address
,
Locale
locale
)
{
return
address
.
getStreet
()
+
"
"
+
address
.
getCity
()
+
", "
+
address
.
getState
()
+
"
"
+
address
.
getZip
();
return
address
.
getStreet
()
+
"
:"
+
address
.
getCity
()
+
":"
+
address
.
getState
()
+
":
"
+
address
.
getZip
();
}
public
Address
parse
(
String
formatted
,
Locale
locale
)
throws
ParseException
{
Address
address
=
new
Address
();
String
[]
fields
=
formatted
.
split
(
":"
);
address
.
setStreet
(
fields
[
0
]);
address
.
setCity
(
fields
[
1
]);
address
.
setState
(
fields
[
2
]);
address
.
setZip
(
fields
[
3
]);
return
address
;
}
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericTypeConverter.java
浏览文件 @
2aef75b9
...
...
@@ -37,10 +37,7 @@ import org.springframework.util.Assert;
/**
* Base implementation of a conversion service. Initially empty, e.g. no converters are registered by default.
*
* TODO - object to collection/map converters
* TODO - allow registration of converters to apply on presence of annotation values on setter or field
*
* @author Keith Donald
*/
@SuppressWarnings
(
"unchecked"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录