Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
9750dfc3
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,发现更多精彩内容 >>
提交
9750dfc3
编写于
8月 16, 2008
作者:
A
Andy Clement
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
hard coded support for boxing conversions. Added support for numbers (int/long) to boolean
上级
ef16bff7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
81 addition
and
31 deletion
+81
-31
org.springframework.expression/src/main/java/org/springframework/expression/spel/standard/StandardTypeConverter.java
...ework/expression/spel/standard/StandardTypeConverter.java
+81
-31
未找到文件。
org.springframework.expression/src/main/java/org/springframework/expression/spel/standard/StandardTypeConverter.java
浏览文件 @
9750dfc3
...
...
@@ -42,22 +42,47 @@ public class StandardTypeConverter implements TypeConverter {
public
boolean
canConvert
(
Class
<?>
sourceType
,
Class
<?>
targetType
)
{
Map
<
Class
<?>,
StandardIndividualTypeConverter
>
possibleConvertersToTheTargetType
=
converters
.
get
(
targetType
);
if
(
possibleConvertersToTheTargetType
==
null
&&
targetType
.
isPrimitive
())
{
if
(
targetType
==
Integer
.
TYPE
)
if
(
targetType
==
Integer
.
TYPE
)
{
if
(
sourceType
==
Integer
.
class
)
{
return
true
;
}
possibleConvertersToTheTargetType
=
converters
.
get
(
Integer
.
class
);
else
if
(
targetType
==
Boolean
.
TYPE
)
}
else
if
(
targetType
==
Boolean
.
TYPE
)
{
if
(
sourceType
==
Boolean
.
class
)
{
return
true
;
}
possibleConvertersToTheTargetType
=
converters
.
get
(
Boolean
.
class
);
else
if
(
targetType
==
Short
.
TYPE
)
}
else
if
(
targetType
==
Short
.
TYPE
)
{
if
(
sourceType
==
Short
.
class
)
{
return
true
;
}
possibleConvertersToTheTargetType
=
converters
.
get
(
Short
.
class
);
else
if
(
targetType
==
Long
.
TYPE
)
}
else
if
(
targetType
==
Long
.
TYPE
)
{
if
(
sourceType
==
Long
.
class
)
{
return
true
;
}
possibleConvertersToTheTargetType
=
converters
.
get
(
Long
.
class
);
else
if
(
targetType
==
Character
.
TYPE
)
}
else
if
(
targetType
==
Character
.
TYPE
)
{
if
(
sourceType
==
Character
.
class
)
{
return
true
;
}
possibleConvertersToTheTargetType
=
converters
.
get
(
Character
.
class
);
else
if
(
targetType
==
Double
.
TYPE
)
}
else
if
(
targetType
==
Double
.
TYPE
)
{
if
(
sourceType
==
Double
.
class
)
{
return
true
;
}
possibleConvertersToTheTargetType
=
converters
.
get
(
Double
.
class
);
else
if
(
targetType
==
Float
.
TYPE
)
}
else
if
(
targetType
==
Float
.
TYPE
)
{
if
(
sourceType
==
Float
.
class
)
{
return
true
;
}
possibleConvertersToTheTargetType
=
converters
.
get
(
Float
.
class
);
else
if
(
targetType
==
Byte
.
TYPE
)
}
else
if
(
targetType
==
Byte
.
TYPE
)
{
if
(
sourceType
==
Byte
.
class
)
{
return
true
;
}
possibleConvertersToTheTargetType
=
converters
.
get
(
Byte
.
class
);
}
}
if
(
possibleConvertersToTheTargetType
!=
null
)
{
StandardIndividualTypeConverter
aConverter
=
possibleConvertersToTheTargetType
.
get
(
sourceType
);
...
...
@@ -72,24 +97,50 @@ public class StandardTypeConverter implements TypeConverter {
public
Object
convertValue
(
Object
value
,
Class
<?>
targetType
)
throws
SpelException
{
if
(
value
==
null
||
value
.
getClass
()
==
targetType
)
return
value
;
Class
sourceType
=
value
.
getClass
();
Map
<
Class
<?>,
StandardIndividualTypeConverter
>
possibleConvertersToTheTargetType
=
converters
.
get
(
targetType
);
if
(
possibleConvertersToTheTargetType
==
null
&&
targetType
.
isPrimitive
())
{
if
(
targetType
==
Integer
.
TYPE
)
if
(
targetType
==
Integer
.
TYPE
)
{
if
(
sourceType
==
Integer
.
class
)
{
return
value
;
}
possibleConvertersToTheTargetType
=
converters
.
get
(
Integer
.
class
);
else
if
(
targetType
==
Boolean
.
TYPE
)
}
else
if
(
targetType
==
Boolean
.
TYPE
)
{
if
(
sourceType
==
Boolean
.
class
)
{
return
value
;
}
possibleConvertersToTheTargetType
=
converters
.
get
(
Boolean
.
class
);
else
if
(
targetType
==
Short
.
TYPE
)
}
else
if
(
targetType
==
Short
.
TYPE
)
{
if
(
sourceType
==
Short
.
class
)
{
return
value
;
}
possibleConvertersToTheTargetType
=
converters
.
get
(
Short
.
class
);
else
if
(
targetType
==
Long
.
TYPE
)
}
else
if
(
targetType
==
Long
.
TYPE
)
{
if
(
sourceType
==
Long
.
class
)
{
return
value
;
}
possibleConvertersToTheTargetType
=
converters
.
get
(
Long
.
class
);
else
if
(
targetType
==
Character
.
TYPE
)
}
else
if
(
targetType
==
Character
.
TYPE
)
{
if
(
sourceType
==
Character
.
class
)
{
return
value
;
}
possibleConvertersToTheTargetType
=
converters
.
get
(
Character
.
class
);
else
if
(
targetType
==
Double
.
TYPE
)
}
else
if
(
targetType
==
Double
.
TYPE
)
{
if
(
sourceType
==
Double
.
class
)
{
return
value
;
}
possibleConvertersToTheTargetType
=
converters
.
get
(
Double
.
class
);
else
if
(
targetType
==
Float
.
TYPE
)
}
else
if
(
targetType
==
Float
.
TYPE
)
{
if
(
sourceType
==
Float
.
class
)
{
return
value
;
}
possibleConvertersToTheTargetType
=
converters
.
get
(
Float
.
class
);
else
if
(
targetType
==
Byte
.
TYPE
)
}
else
if
(
targetType
==
Byte
.
TYPE
)
{
if
(
sourceType
==
Byte
.
class
)
{
return
value
;
}
possibleConvertersToTheTargetType
=
converters
.
get
(
Byte
.
class
);
}
}
Object
result
=
null
;
if
(
possibleConvertersToTheTargetType
!=
null
)
{
...
...
@@ -126,15 +177,19 @@ public class StandardTypeConverter implements TypeConverter {
private
static
class
ToBooleanConverter
implements
StandardIndividualTypeConverter
{
public
Object
convert
(
Object
value
)
throws
SpelException
{
return
((
Boolean
)
value
).
booleanValue
();
if
(
value
instanceof
Integer
)
{
return
((
Integer
)
value
).
intValue
()
!=
0
;
}
else
{
return
((
Long
)
value
).
longValue
()
!=
0
;
}
}
public
Class
<?>[]
getFrom
()
{
return
new
Class
<?>[]
{
Boolean
.
class
};
return
new
Class
<?>[]
{
Integer
.
class
,
Long
.
class
};
}
public
Class
<?>
getTo
()
{
return
Boolean
.
TYPE
;
return
Boolean
.
class
;
}
}
...
...
@@ -264,21 +319,16 @@ public class StandardTypeConverter implements TypeConverter {
private
static
class
ToIntegerConverter
implements
StandardIndividualTypeConverter
{
public
Object
convert
(
Object
value
)
throws
SpelException
{
if
(
value
instanceof
Integer
)
return
((
Integer
)
value
).
intValue
();
else
if
(
value
instanceof
Long
)
{
try
{
return
Integer
.
parseInt
(((
Long
)
value
).
toString
());
}
catch
(
NumberFormatException
nfe
)
{
throw
new
SpelException
(
SpelMessages
.
PROBLEM_DURING_TYPE_CONVERSION
,
"long value '"
+
value
+
"' cannot be represented as an int"
);
}
}
else
return
null
;
try
{
return
Integer
.
parseInt
(((
Long
)
value
).
toString
());
}
catch
(
NumberFormatException
nfe
)
{
throw
new
SpelException
(
SpelMessages
.
PROBLEM_DURING_TYPE_CONVERSION
,
"long value '"
+
value
+
"' cannot be represented as an int"
);
}
}
public
Class
<?>[]
getFrom
()
{
return
new
Class
<?>[]
{
Integer
.
class
,
Long
.
class
};
return
new
Class
<?>[]
{
Long
.
class
};
}
public
Class
<?>
getTo
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录