Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
d7c90cff
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,发现更多精彩内容 >>
提交
d7c90cff
编写于
5月 11, 2009
作者:
K
Keith Donald
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
made ConversionExecutor internal; removed other unused operations from public SPI
上级
bf7a9475
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
109 addition
and
142 deletion
+109
-142
org.springframework.core/src/main/java/org/springframework/core/convert/ConversionService.java
...a/org/springframework/core/convert/ConversionService.java
+9
-35
org.springframework.core/src/main/java/org/springframework/core/convert/ConverterNotFoundException.java
...ingframework/core/convert/ConverterNotFoundException.java
+54
-0
org.springframework.core/src/main/java/org/springframework/core/convert/service/AbstractCollectionConverter.java
...ork/core/convert/service/AbstractCollectionConverter.java
+3
-4
org.springframework.core/src/main/java/org/springframework/core/convert/service/ArrayToCollection.java
...ringframework/core/convert/service/ArrayToCollection.java
+0
-1
org.springframework.core/src/main/java/org/springframework/core/convert/service/CollectionToArray.java
...ringframework/core/convert/service/CollectionToArray.java
+0
-1
org.springframework.core/src/main/java/org/springframework/core/convert/service/CollectionToCollection.java
...ramework/core/convert/service/CollectionToCollection.java
+0
-1
org.springframework.core/src/main/java/org/springframework/core/convert/service/ConversionExecutor.java
...ingframework/core/convert/service/ConversionExecutor.java
+4
-2
org.springframework.core/src/main/java/org/springframework/core/convert/service/DefaultConversionService.java
...mework/core/convert/service/DefaultConversionService.java
+0
-18
org.springframework.core/src/main/java/org/springframework/core/convert/service/GenericConversionService.java
...mework/core/convert/service/GenericConversionService.java
+27
-59
org.springframework.core/src/main/java/org/springframework/core/convert/service/MapToMap.java
...va/org/springframework/core/convert/service/MapToMap.java
+2
-3
org.springframework.core/src/main/java/org/springframework/core/convert/service/NoOpConversionExecutor.java
...ramework/core/convert/service/NoOpConversionExecutor.java
+0
-1
org.springframework.core/src/main/java/org/springframework/core/convert/service/StaticConversionExecutor.java
...mework/core/convert/service/StaticConversionExecutor.java
+0
-1
org.springframework.core/src/main/java/org/springframework/core/convert/service/StaticSuperConversionExecutor.java
...k/core/convert/service/StaticSuperConversionExecutor.java
+0
-1
org.springframework.core/src/test/java/org/springframework/core/convert/service/GenericConversionServiceTests.java
...k/core/convert/service/GenericConversionServiceTests.java
+5
-6
org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java
...mework/expression/spel/support/StandardTypeConverter.java
+2
-2
org.springframework.expression/src/test/java/org/springframework/expression/spel/ExpressionTestsUsingCoreConversionService.java
...ssion/spel/ExpressionTestsUsingCoreConversionService.java
+3
-7
未找到文件。
org.springframework.core/src/main/java/org/springframework/core/convert/ConversionService.java
浏览文件 @
d7c90cff
...
...
@@ -16,10 +16,10 @@
package
org.springframework.core.convert
;
/**
* A service interface for type conversion. This is the entry point into the convert system.
Call one of the
* <
i>executeConversion</i> operations to perform a thread-safe type conversion using
*
this system. Call one of the <i>getConversionExecutor</i> operations to obtain
*
a thread-safe {@link ConversionExecutor} command for later use
.
* A service interface for type conversion. This is the entry point into the convert system.
* <
p>
*
Call {@link #executeConversion(Object, TypeDescriptor)} to perform a thread-safe type conversion using
*
this system
.
*
* @author Keith Donald
*/
...
...
@@ -28,47 +28,21 @@ public interface ConversionService {
/**
* Returns true if objects of sourceType can be converted to targetType.
* @param source the source to convert from (may be null)
* @param targetType the target type to convert to
* @param targetType
context about
the target type to convert to
* @return true if a conversion can be performed, false if not
*/
public
boolean
canConvert
(
Class
<?>
sourceType
,
TypeDescriptor
targetType
);
/**
* Returns true if the source can be converted to targetType.
* @param source the source to convert from (may be null)
* @param targetType the target type to convert to
* @return true if a conversion can be performed, false if not
*/
public
boolean
canConvert
(
Object
source
,
TypeDescriptor
targetType
);
/**
* Convert the source to targetType.
* @param source the source to convert from (may be null)
* @param targetType the target type to convert to
* @return the converted object, an instance of
the <code>targetType
</code>, or <code>null</code> if a null source
* @param targetType
context about
the target type to convert to
* @return the converted object, an instance of
{@link TypeDescriptor#getType()}
</code>, or <code>null</code> if a null source
* was provided
* @throws Conver
sionExecuto
rNotFoundException if no suitable conversion executor could be found to convert the
* @throws Conver
te
rNotFoundException if no suitable conversion executor could be found to convert the
* source to an instance of targetType
* @throws ConversionException if an exception occurred during the conversion process
*/
public
Object
executeConversion
(
Object
source
,
TypeDescriptor
targetType
)
throws
ConversionExecutorNotFoundException
,
ConversionException
;
/**
* Get a ConversionExecutor that converts objects from sourceType to targetType.
* The returned ConversionExecutor is thread-safe and may safely be cached for later use by client code.
* @param sourceType the source type to convert from (required)
* @param targetType the target type to convert to (required)
* @return the executor that can execute instance type conversion, never null
* @throws ConversionExecutorNotFoundException when no suitable conversion executor could be found
*/
public
ConversionExecutor
getConversionExecutor
(
Class
<?>
sourceType
,
TypeDescriptor
targetType
)
throws
ConversionExecutorNotFoundException
;
/**
* Get a type by its name; may be the fully-qualified class name or a registered type alias such as 'int'.
* @return the class, or <code>null</code> if no such name exists
*/
public
Class
<?>
getType
(
String
name
);
public
Object
executeConversion
(
Object
source
,
TypeDescriptor
targetType
);
}
\ No newline at end of file
org.springframework.core/src/main/java/org/springframework/core/convert/ConverterNotFoundException.java
0 → 100644
浏览文件 @
d7c90cff
/*
* Copyright 2004-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
;
/**
* Thrown when a conversion executor could not be found in a conversion service.
*
* @author Keith Donald
*/
public
class
ConverterNotFoundException
extends
ConversionException
{
private
Class
<?>
sourceType
;
private
TypeDescriptor
targetType
;
/**
* Creates a new conversion executor not found exception.
* @param sourceType the source type requested to convert from
* @param targetType the target type requested to convert to
* @param message a descriptive message
*/
public
ConverterNotFoundException
(
Class
<?>
sourceType
,
TypeDescriptor
targetType
,
String
message
)
{
super
(
message
);
this
.
sourceType
=
sourceType
;
this
.
targetType
=
targetType
;
}
/**
* Returns the source type that was requested to convert from.
*/
public
Class
<?>
getSourceType
()
{
return
sourceType
;
}
/**
* Returns the target type that was requested to convert to.
*/
public
TypeDescriptor
getTargetType
()
{
return
targetType
;
}
}
org.springframework.core/src/main/java/org/springframework/core/convert/service/AbstractCollectionConverter.java
浏览文件 @
d7c90cff
...
...
@@ -16,7 +16,6 @@
package
org.springframework.core.convert.service
;
import
org.springframework.core.convert.ConversionExecutionException
;
import
org.springframework.core.convert.ConversionExecutor
;
import
org.springframework.core.convert.ConversionService
;
import
org.springframework.core.convert.TypeDescriptor
;
...
...
@@ -26,7 +25,7 @@ import org.springframework.core.convert.TypeDescriptor;
*/
abstract
class
AbstractCollectionConverter
implements
ConversionExecutor
{
private
ConversionService
conversionService
;
private
Generic
ConversionService
conversionService
;
private
ConversionExecutor
elementConverter
;
...
...
@@ -34,7 +33,7 @@ abstract class AbstractCollectionConverter implements ConversionExecutor {
private
TypeDescriptor
targetCollectionType
;
public
AbstractCollectionConverter
(
TypeDescriptor
sourceCollectionType
,
TypeDescriptor
targetCollectionType
,
ConversionService
conversionService
)
{
public
AbstractCollectionConverter
(
TypeDescriptor
sourceCollectionType
,
TypeDescriptor
targetCollectionType
,
Generic
ConversionService
conversionService
)
{
this
.
conversionService
=
conversionService
;
this
.
sourceCollectionType
=
sourceCollectionType
;
this
.
targetCollectionType
=
targetCollectionType
;
...
...
@@ -61,7 +60,7 @@ abstract class AbstractCollectionConverter implements ConversionExecutor {
return
targetCollectionType
.
getElementType
();
}
protected
ConversionService
getConversionService
()
{
protected
Generic
ConversionService
getConversionService
()
{
return
conversionService
;
}
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/service/ArrayToCollection.java
浏览文件 @
d7c90cff
...
...
@@ -18,7 +18,6 @@ package org.springframework.core.convert.service;
import
java.lang.reflect.Array
;
import
java.util.Collection
;
import
org.springframework.core.convert.ConversionExecutor
;
import
org.springframework.core.convert.TypeDescriptor
;
/**
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/service/CollectionToArray.java
浏览文件 @
d7c90cff
...
...
@@ -19,7 +19,6 @@ import java.lang.reflect.Array;
import
java.util.Collection
;
import
java.util.Iterator
;
import
org.springframework.core.convert.ConversionExecutor
;
import
org.springframework.core.convert.TypeDescriptor
;
/**
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/service/CollectionToCollection.java
浏览文件 @
d7c90cff
...
...
@@ -18,7 +18,6 @@ package org.springframework.core.convert.service;
import
java.util.Collection
;
import
java.util.Iterator
;
import
org.springframework.core.convert.ConversionExecutor
;
import
org.springframework.core.convert.TypeDescriptor
;
/**
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/ConversionExecutor.java
→
org.springframework.core/src/main/java/org/springframework/core/convert/
service/
ConversionExecutor.java
浏览文件 @
d7c90cff
...
...
@@ -13,7 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert
;
package
org.springframework.core.convert.service
;
import
org.springframework.core.convert.ConversionExecutionException
;
/**
* A command parameterized with the information necessary to perform a conversion of a source input to a
...
...
@@ -29,6 +31,6 @@ public interface ConversionExecutor {
* @param source the source to convert
* @throws ConversionExecutionException if an exception occurs during type conversion
*/
public
Object
execute
(
Object
source
)
throws
ConversionExecutionException
;
public
Object
execute
(
Object
source
);
}
\ No newline at end of file
org.springframework.core/src/main/java/org/springframework/core/convert/service/DefaultConversionService.java
浏览文件 @
d7c90cff
...
...
@@ -49,7 +49,6 @@ public class DefaultConversionService extends GenericConversionService {
*/
public
DefaultConversionService
()
{
addDefaultConverters
();
addDefaultAliases
();
}
/**
...
...
@@ -73,21 +72,4 @@ public class DefaultConversionService extends GenericConversionService {
addConverter
(
new
ObjectToString
());
}
protected
void
addDefaultAliases
()
{
addAlias
(
"string"
,
String
.
class
);
addAlias
(
"byte"
,
Byte
.
class
);
addAlias
(
"boolean"
,
Boolean
.
class
);
addAlias
(
"char"
,
Character
.
class
);
addAlias
(
"short"
,
Short
.
class
);
addAlias
(
"int"
,
Integer
.
class
);
addAlias
(
"long"
,
Long
.
class
);
addAlias
(
"float"
,
Float
.
class
);
addAlias
(
"double"
,
Double
.
class
);
addAlias
(
"bigInt"
,
BigInteger
.
class
);
addAlias
(
"bigDecimal"
,
BigDecimal
.
class
);
addAlias
(
"locale"
,
Locale
.
class
);
addAlias
(
"enum"
,
Enum
.
class
);
addAlias
(
"date"
,
Date
.
class
);
}
}
\ No newline at end of file
org.springframework.core/src/main/java/org/springframework/core/convert/service/GenericConversionService.java
浏览文件 @
d7c90cff
...
...
@@ -26,10 +26,8 @@ import java.util.List;
import
java.util.Map
;
import
org.springframework.core.GenericTypeResolver
;
import
org.springframework.core.convert.ConversionException
;
import
org.springframework.core.convert.ConversionExecutor
;
import
org.springframework.core.convert.ConversionExecutorNotFoundException
;
import
org.springframework.core.convert.ConversionService
;
import
org.springframework.core.convert.ConverterNotFoundException
;
import
org.springframework.core.convert.TypeDescriptor
;
import
org.springframework.core.convert.converter.Converter
;
import
org.springframework.core.convert.converter.ConverterInfo
;
...
...
@@ -61,11 +59,6 @@ public class GenericConversionService implements ConversionService {
*/
private
final
Map
sourceTypeSuperConverters
=
new
HashMap
();
/**
* Indexes classes by well-known aliases.
*/
private
final
Map
aliasMap
=
new
HashMap
<
String
,
Class
<?>>();
/**
* An optional parent conversion service.
*/
...
...
@@ -132,48 +125,41 @@ public class GenericConversionService implements ConversionService {
return
new
SuperTwoWayConverterConverter
(
converter
,
sourceType
,
targetType
);
}
/**
* Add a convenient alias for the target type. {@link #getType(String)} can then be used to lookup the type given
* the alias.
* @see #getType(String)
*/
public
void
addAlias
(
String
alias
,
Class
targetType
)
{
aliasMap
.
put
(
alias
,
targetType
);
}
// implementing ConversionService
public
boolean
canConvert
(
Class
<?>
sourceType
,
TypeDescriptor
targetType
)
{
try
{
getConversionExecutor
(
sourceType
,
targetType
);
ConversionExecutor
executor
=
getConversionExecutor
(
sourceType
,
targetType
);
if
(
executor
!=
null
)
{
return
true
;
}
catch
(
ConversionExecutorNotFoundException
e
)
{
return
false
;
}
}
public
boolean
canConvert
(
Object
source
,
TypeDescriptor
targetType
)
{
if
(
source
==
null
)
{
return
true
;
}
try
{
getConversionExecutor
(
source
.
getClass
(),
targetType
);
return
true
;
}
catch
(
ConversionExecutorNotFoundException
e
)
{
return
false
;
}
else
{
if
(
parent
!=
null
)
{
return
parent
.
canConvert
(
sourceType
,
targetType
);
}
else
{
return
false
;
}
}
}
public
Object
executeConversion
(
Object
source
,
TypeDescriptor
targetType
)
throws
ConversionExecutorNotFoundException
,
ConversionException
{
public
Object
executeConversion
(
Object
source
,
TypeDescriptor
targetType
)
{
if
(
source
==
null
)
{
return
null
;
}
return
getConversionExecutor
(
source
.
getClass
(),
targetType
).
execute
(
source
);
ConversionExecutor
executor
=
getConversionExecutor
(
source
.
getClass
(),
targetType
);
if
(
executor
!=
null
)
{
return
executor
.
execute
(
source
);
}
else
{
if
(
parent
!=
null
)
{
return
parent
.
executeConversion
(
source
,
targetType
);
}
else
{
throw
new
ConverterNotFoundException
(
source
.
getClass
(),
targetType
,
"No converter found that can convert from sourceType ["
+
source
.
getClass
().
getName
()
+
"] to targetType ["
+
targetType
.
getName
()
+
"]"
);
}
}
}
public
ConversionExecutor
getConversionExecutor
(
Class
sourceClass
,
TypeDescriptor
targetType
)
throws
Conver
sionExecuto
rNotFoundException
{
ConversionExecutor
getConversionExecutor
(
Class
sourceClass
,
TypeDescriptor
targetType
)
throws
Conver
te
rNotFoundException
{
Assert
.
notNull
(
sourceClass
,
"The sourceType to convert from is required"
);
Assert
.
notNull
(
targetType
,
"The targetType to convert to is required"
);
TypeDescriptor
sourceType
=
TypeDescriptor
.
valueOf
(
sourceClass
);
...
...
@@ -193,21 +179,21 @@ public class GenericConversionService implements ConversionService {
if
(
sourceType
.
isCollection
())
{
return
new
CollectionToArray
(
sourceType
,
targetType
,
this
);
}
else
{
throw
new
ConversionExecutorNotFoundException
(
sourceType
,
targetType
,
"Object to Array conversion not yet supported"
)
;
return
null
;
}
}
if
(
sourceType
.
isCollection
())
{
if
(
targetType
.
isCollection
())
{
return
new
CollectionToCollection
(
sourceType
,
targetType
,
this
);
}
else
{
throw
new
ConversionExecutorNotFoundException
(
sourceType
,
targetType
,
"Object to Collection conversion not yet supported"
)
;
return
null
;
}
}
if
(
sourceType
.
isMap
())
{
if
(
targetType
.
isMap
())
{
return
new
MapToMap
(
sourceType
,
targetType
,
this
);
}
else
{
throw
new
ConversionExecutorNotFoundException
(
sourceType
,
targetType
,
"Object to Map conversion not yet supported"
)
;
return
null
;
}
}
Converter
converter
=
findRegisteredConverter
(
sourceClass
,
targetType
.
getType
());
...
...
@@ -217,28 +203,10 @@ public class GenericConversionService implements ConversionService {
SuperConverter
superConverter
=
findRegisteredSuperConverter
(
sourceClass
,
targetType
.
getType
());
if
(
superConverter
!=
null
)
{
return
new
StaticSuperConversionExecutor
(
sourceType
,
targetType
,
superConverter
);
}
if
(
parent
!=
null
)
{
return
parent
.
getConversionExecutor
(
sourceClass
,
targetType
);
}
else
{
if
(
sourceType
.
isAssignableTo
(
targetType
))
{
return
new
StaticConversionExecutor
(
sourceType
,
targetType
,
NoOpConverter
.
INSTANCE
);
}
throw
new
ConversionExecutorNotFoundException
(
sourceType
,
targetType
,
"No ConversionExecutor found for converting from sourceType ["
+
sourceType
.
getName
()
+
"] to targetType ["
+
targetType
.
getName
()
+
"]"
);
}
}
}
public
Class
getType
(
String
name
)
throws
IllegalArgumentException
{
Class
clazz
=
(
Class
)
aliasMap
.
get
(
name
);
if
(
clazz
!=
null
)
{
return
clazz
;
}
else
{
if
(
parent
!=
null
)
{
return
parent
.
getType
(
name
);
}
else
{
return
null
;
}
}
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/service/MapToMap.java
浏览文件 @
d7c90cff
...
...
@@ -22,7 +22,6 @@ import java.util.SortedMap;
import
java.util.TreeMap
;
import
org.springframework.core.convert.ConversionExecutionException
;
import
org.springframework.core.convert.ConversionExecutor
;
import
org.springframework.core.convert.ConversionService
;
import
org.springframework.core.convert.TypeDescriptor
;
...
...
@@ -36,7 +35,7 @@ class MapToMap implements ConversionExecutor {
private
TypeDescriptor
targetType
;
private
ConversionService
conversionService
;
private
Generic
ConversionService
conversionService
;
private
EntryConverter
entryConverter
;
...
...
@@ -46,7 +45,7 @@ class MapToMap implements ConversionExecutor {
* @param targetType the target map type
* @param conversionService the conversion service
*/
public
MapToMap
(
TypeDescriptor
sourceType
,
TypeDescriptor
targetType
,
ConversionService
conversionService
)
{
public
MapToMap
(
TypeDescriptor
sourceType
,
TypeDescriptor
targetType
,
Generic
ConversionService
conversionService
)
{
this
.
sourceType
=
sourceType
;
this
.
targetType
=
targetType
;
this
.
conversionService
=
conversionService
;
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/service/NoOpConversionExecutor.java
浏览文件 @
d7c90cff
...
...
@@ -16,7 +16,6 @@
package
org.springframework.core.convert.service
;
import
org.springframework.core.convert.ConversionExecutionException
;
import
org.springframework.core.convert.ConversionExecutor
;
/**
* Conversion executor that does nothing. Access singleton at {@link #INSTANCE}.s
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/service/StaticConversionExecutor.java
浏览文件 @
d7c90cff
...
...
@@ -16,7 +16,6 @@
package
org.springframework.core.convert.service
;
import
org.springframework.core.convert.ConversionExecutionException
;
import
org.springframework.core.convert.ConversionExecutor
;
import
org.springframework.core.convert.TypeDescriptor
;
import
org.springframework.core.convert.converter.Converter
;
import
org.springframework.core.style.ToStringCreator
;
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/service/StaticSuperConversionExecutor.java
浏览文件 @
d7c90cff
...
...
@@ -16,7 +16,6 @@
package
org.springframework.core.convert.service
;
import
org.springframework.core.convert.ConversionExecutionException
;
import
org.springframework.core.convert.ConversionExecutor
;
import
org.springframework.core.convert.TypeDescriptor
;
import
org.springframework.core.convert.converter.SuperConverter
;
import
org.springframework.core.style.ToStringCreator
;
...
...
org.springframework.core/src/test/java/org/springframework/core/convert/service/GenericConversionServiceTests.java
浏览文件 @
d7c90cff
...
...
@@ -31,8 +31,7 @@ import java.util.Map;
import
org.junit.Ignore
;
import
org.junit.Test
;
import
org.springframework.core.convert.ConversionExecutionException
;
import
org.springframework.core.convert.ConversionExecutor
;
import
org.springframework.core.convert.ConversionExecutorNotFoundException
;
import
org.springframework.core.convert.ConverterNotFoundException
;
import
org.springframework.core.convert.TypeDescriptor
;
import
org.springframework.core.convert.converter.Converter
;
import
org.springframework.core.convert.converter.NumberToNumber
;
...
...
@@ -84,9 +83,9 @@ public class GenericConversionServiceTests {
@Test
public
void
convertExecutorNotFound
()
{
try
{
service
.
getConversionExecutor
(
String
.
class
,
type
(
Integer
.
class
));
service
.
executeConversion
(
"3"
,
type
(
Integer
.
class
));
fail
(
"Should have thrown an exception"
);
}
catch
(
Conver
sionExecuto
rNotFoundException
e
)
{
}
catch
(
Conver
te
rNotFoundException
e
)
{
}
}
...
...
@@ -161,9 +160,9 @@ public class GenericConversionServiceTests {
}
});
try
{
ConversionExecutor
executor
=
service
.
getConversionExecutor
(
String
.
class
,
type
(
Integer
.
class
));
service
.
executeConversion
(
"3"
,
type
(
Integer
.
class
));
fail
(
"Should have failed"
);
}
catch
(
Conver
sionExecuto
rNotFoundException
e
)
{
}
catch
(
Conver
te
rNotFoundException
e
)
{
}
}
...
...
org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java
浏览文件 @
d7c90cff
...
...
@@ -17,7 +17,7 @@
package
org.springframework.expression.spel.support
;
import
org.springframework.core.convert.ConversionException
;
import
org.springframework.core.convert.Conver
sionExecuto
rNotFoundException
;
import
org.springframework.core.convert.Conver
te
rNotFoundException
;
import
org.springframework.core.convert.ConversionService
;
import
org.springframework.core.convert.TypeDescriptor
;
import
org.springframework.core.convert.service.DefaultConversionService
;
...
...
@@ -53,7 +53,7 @@ public class StandardTypeConverter implements TypeConverter {
public
Object
convertValue
(
Object
value
,
TypeDescriptor
typeDescriptor
)
throws
EvaluationException
{
try
{
return
conversionService
.
executeConversion
(
value
,
typeDescriptor
);
}
catch
(
Conver
sionExecuto
rNotFoundException
cenfe
)
{
}
catch
(
Conver
te
rNotFoundException
cenfe
)
{
throw
new
SpelException
(
cenfe
,
SpelMessages
.
TYPE_CONVERSION_ERROR
,
value
.
getClass
(),
typeDescriptor
.
asString
());
}
catch
(
ConversionException
ce
)
{
throw
new
SpelException
(
ce
,
SpelMessages
.
TYPE_CONVERSION_ERROR
,
value
.
getClass
(),
typeDescriptor
.
asString
());
...
...
org.springframework.expression/src/test/java/org/springframework/expression/spel/ExpressionTestsUsingCoreConversionService.java
浏览文件 @
d7c90cff
...
...
@@ -19,7 +19,6 @@ package org.springframework.expression.spel;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.springframework.core.convert.ConversionExecutor
;
import
org.springframework.core.convert.TypeDescriptor
;
import
org.springframework.core.convert.service.DefaultConversionService
;
import
org.springframework.core.convert.service.GenericConversionService
;
...
...
@@ -65,17 +64,14 @@ public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCas
// ArrayList containing List<Integer> to List<String>
Class
<?>
clazz
=
typeDescriptorForListOfString
.
getElementType
();
assertEquals
(
String
.
class
,
clazz
);
ConversionExecutor
executor
=
tcs
.
getConversionExecutor
(
ArrayList
.
class
,
typeDescriptorForListOfString
);
assertNotNull
(
executor
);
List
l
=
(
List
)
executor
.
execute
(
listOfInteger
);
List
l
=
(
List
)
tcs
.
executeConversion
(
listOfInteger
,
typeDescriptorForListOfString
);
assertNotNull
(
l
);
// ArrayList containing List<String> to List<Integer>
clazz
=
typeDescriptorForListOfInteger
.
getElementType
();
assertEquals
(
Integer
.
class
,
clazz
);
executor
=
tcs
.
getConversionExecutor
(
ArrayList
.
class
,
typeDescriptorForListOfInteger
);
assertNotNull
(
executor
);
l
=
(
List
)
executor
.
execute
(
listOfString
);
l
=
(
List
)
tcs
.
executeConversion
(
listOfString
,
typeDescriptorForListOfString
);
assertNotNull
(
l
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录