Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
46c9a003
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,发现更多精彩内容 >>
提交
46c9a003
编写于
5月 15, 2009
作者:
K
Keith Donald
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
BindingPoint to ConversionPoint, javadoc
上级
2ede4d27
变更
40
隐藏空白更改
内联
并排
Showing
40 changed file
with
229 addition
and
197 deletion
+229
-197
org.springframework.context/src/main/java/org/springframework/context/expression/BeanExpressionContextAccessor.java
...ork/context/expression/BeanExpressionContextAccessor.java
+1
-1
org.springframework.context/src/main/java/org/springframework/context/expression/BeanFactoryAccessor.java
...ringframework/context/expression/BeanFactoryAccessor.java
+1
-1
org.springframework.core/src/main/java/org/springframework/core/convert/ConversionPoint.java
...ava/org/springframework/core/convert/ConversionPoint.java
+15
-15
org.springframework.core/src/main/java/org/springframework/core/convert/TypeConverter.java
.../java/org/springframework/core/convert/TypeConverter.java
+8
-7
org.springframework.core/src/main/java/org/springframework/core/convert/converter/Converter.java
...org/springframework/core/convert/converter/Converter.java
+2
-2
org.springframework.core/src/main/java/org/springframework/core/convert/converter/ConverterFactory.java
...ingframework/core/convert/converter/ConverterFactory.java
+14
-0
org.springframework.core/src/main/java/org/springframework/core/convert/converter/ConverterRegistry.java
...ngframework/core/convert/converter/ConverterRegistry.java
+17
-0
org.springframework.core/src/main/java/org/springframework/core/convert/support/AbstractCollectionConverter.java
...ork/core/convert/support/AbstractCollectionConverter.java
+5
-5
org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToArray.java
...rg/springframework/core/convert/support/ArrayToArray.java
+2
-2
org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToCollection.java
...ringframework/core/convert/support/ArrayToCollection.java
+2
-2
org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToArray.java
...ringframework/core/convert/support/CollectionToArray.java
+3
-3
org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToCollection.java
...ramework/core/convert/support/CollectionToCollection.java
+3
-3
org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericTypeConverter.java
...gframework/core/convert/support/GenericTypeConverter.java
+7
-7
org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToMap.java
...va/org/springframework/core/convert/support/MapToMap.java
+8
-8
org.springframework.core/src/main/java/org/springframework/core/convert/support/StaticConversionExecutor.java
...mework/core/convert/support/StaticConversionExecutor.java
+4
-4
org.springframework.core/src/test/java/org/springframework/core/convert/ConversionPointTests.java
...rg/springframework/core/convert/ConversionPointTests.java
+6
-6
org.springframework.core/src/test/java/org/springframework/core/convert/support/ArrayToArrayTests.java
...ringframework/core/convert/support/ArrayToArrayTests.java
+2
-2
org.springframework.core/src/test/java/org/springframework/core/convert/support/ArrayToCollectionTests.java
...ramework/core/convert/support/ArrayToCollectionTests.java
+6
-6
org.springframework.core/src/test/java/org/springframework/core/convert/support/CollectionToArrayTests.java
...ramework/core/convert/support/CollectionToArrayTests.java
+5
-5
org.springframework.core/src/test/java/org/springframework/core/convert/support/CollectionToCollectionTests.java
...ork/core/convert/support/CollectionToCollectionTests.java
+11
-11
org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericTypeConverterTests.java
...ework/core/convert/support/GenericTypeConverterTests.java
+3
-3
org.springframework.core/src/test/java/org/springframework/core/convert/support/MapToMapTests.java
...g/springframework/core/convert/support/MapToMapTests.java
+7
-7
org.springframework.expression/src/main/java/org/springframework/expression/TypeConverter.java
...in/java/org/springframework/expression/TypeConverter.java
+3
-3
org.springframework.expression/src/main/java/org/springframework/expression/TypedValue.java
.../main/java/org/springframework/expression/TypedValue.java
+6
-6
org.springframework.expression/src/main/java/org/springframework/expression/spel/ExpressionState.java
.../org/springframework/expression/spel/ExpressionState.java
+5
-5
org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/CommonTypeDescriptors.java
...gframework/expression/spel/ast/CommonTypeDescriptors.java
+12
-12
org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/FunctionReference.java
...pringframework/expression/spel/ast/FunctionReference.java
+2
-2
org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java
...java/org/springframework/expression/spel/ast/Indexer.java
+11
-11
org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/OperatorDivide.java
...g/springframework/expression/spel/ast/OperatorDivide.java
+2
-2
org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Projection.java
...a/org/springframework/expression/spel/ast/Projection.java
+4
-4
org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Selection.java
...va/org/springframework/expression/spel/ast/Selection.java
+7
-7
org.springframework.expression/src/main/java/org/springframework/expression/spel/support/ReflectiveConstructorExecutor.java
...xpression/spel/support/ReflectiveConstructorExecutor.java
+2
-2
org.springframework.expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodExecutor.java
...ork/expression/spel/support/ReflectiveMethodExecutor.java
+2
-2
org.springframework.expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyResolver.java
...k/expression/spel/support/ReflectivePropertyResolver.java
+13
-13
org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java
...rk/expression/spel/support/StandardEvaluationContext.java
+3
-3
org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java
...mework/expression/spel/support/StandardTypeConverter.java
+5
-5
org.springframework.expression/src/test/java/org/springframework/expression/spel/ExpressionLanguageScenarioTests.java
...work/expression/spel/ExpressionLanguageScenarioTests.java
+3
-3
org.springframework.expression/src/test/java/org/springframework/expression/spel/ExpressionStateTests.java
...springframework/expression/spel/ExpressionStateTests.java
+4
-4
org.springframework.expression/src/test/java/org/springframework/expression/spel/ExpressionTestsUsingCoreConversionService.java
...ssion/spel/ExpressionTestsUsingCoreConversionService.java
+9
-9
org.springframework.expression/src/test/java/org/springframework/expression/spel/ScenariosForSpringSecurity.java
...framework/expression/spel/ScenariosForSpringSecurity.java
+4
-4
未找到文件。
org.springframework.context/src/main/java/org/springframework/context/expression/BeanExpressionContextAccessor.java
浏览文件 @
46c9a003
...
...
@@ -17,7 +17,7 @@
package
org.springframework.context.expression
;
import
org.springframework.beans.factory.config.BeanExpressionContext
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
import
org.springframework.expression.AccessException
;
import
org.springframework.expression.EvaluationContext
;
import
org.springframework.expression.PropertyAccessor
;
...
...
org.springframework.context/src/main/java/org/springframework/context/expression/BeanFactoryAccessor.java
浏览文件 @
46c9a003
...
...
@@ -17,7 +17,7 @@
package
org.springframework.context.expression
;
import
org.springframework.beans.factory.BeanFactory
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
import
org.springframework.expression.AccessException
;
import
org.springframework.expression.EvaluationContext
;
import
org.springframework.expression.PropertyAccessor
;
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/
Binding
Point.java
→
org.springframework.core/src/main/java/org/springframework/core/convert/
Conversion
Point.java
浏览文件 @
46c9a003
...
...
@@ -27,17 +27,19 @@ import org.springframework.util.Assert;
// TODO doesn't support more than depth of one (eg. Map<String,List<Foo>> or List<String>[])
/**
* Type metadata about a bindable target value.
* A point where conversion needs to be performed. Provides additional context about the point such
* as field or method parameter information.
*
* @author Keith Donald
* @author Andy Clement
*/
public
class
Binding
Point
<
T
>
{
public
class
Conversion
Point
<
T
>
{
/**
* Constant value typeDescriptor for the type of a null value
*/
public
final
static
BindingPoint
NULL_TYPE_DESCRIPTOR
=
new
BindingPoint
((
Class
<?>)
null
);
@SuppressWarnings
(
"unchecked"
)
public
final
static
ConversionPoint
NULL
=
new
ConversionPoint
((
Class
<?>)
null
);
private
MethodParameter
methodParameter
;
...
...
@@ -52,7 +54,7 @@ public class BindingPoint<T> {
* a Map or collection, where no additional binding metadata is available.
* @param type the actual type
*/
public
Binding
Point
(
Class
<?>
type
)
{
public
Conversion
Point
(
Class
<?>
type
)
{
this
.
type
=
type
;
}
...
...
@@ -61,7 +63,7 @@ public class BindingPoint<T> {
* from a method parameter, such as a setter method argument.
* @param methodParameter the MethodParameter to wrap
*/
public
Binding
Point
(
MethodParameter
methodParameter
)
{
public
Conversion
Point
(
MethodParameter
methodParameter
)
{
Assert
.
notNull
(
methodParameter
,
"MethodParameter must not be null"
);
this
.
methodParameter
=
methodParameter
;
}
...
...
@@ -70,7 +72,7 @@ public class BindingPoint<T> {
* Create a new descriptor for a field. Use this constructor when a bound value originates from a field.
* @param field the field to wrap
*/
public
Binding
Point
(
Field
field
)
{
public
Conversion
Point
(
Field
field
)
{
Assert
.
notNull
(
field
,
"Field must not be null"
);
this
.
field
=
field
;
}
...
...
@@ -153,7 +155,6 @@ public class BindingPoint<T> {
/**
* Determine the generic key type of the wrapped Map parameter/field, if any.
*
* @return the generic type, or <code>null</code> if none
*/
public
Class
<?>
getMapKeyType
()
{
...
...
@@ -168,7 +169,6 @@ public class BindingPoint<T> {
/**
* Determine the generic value type of the wrapped Map parameter/field, if any.
*
* @return the generic type, or <code>null</code> if none
*/
public
Class
<?>
getMapValueType
()
{
...
...
@@ -201,7 +201,6 @@ public class BindingPoint<T> {
* Return the wrapped MethodParameter, if any.
* <p>
* Note: Either MethodParameter or Field is available.
*
* @return the MethodParameter, or <code>null</code> if none
*/
public
MethodParameter
getMethodParameter
()
{
...
...
@@ -212,7 +211,6 @@ public class BindingPoint<T> {
* Return the wrapped Field, if any.
* <p>
* Note: Either MethodParameter or Field is available.
*
* @return the Field, or <code>null</code> if none
*/
public
Field
getField
()
{
...
...
@@ -248,7 +246,8 @@ public class BindingPoint<T> {
* @param targetType the target type
* @return true if this type is assignable to the target
*/
public
boolean
isAssignableTo
(
BindingPoint
targetType
)
{
@SuppressWarnings
(
"unchecked"
)
public
boolean
isAssignableTo
(
ConversionPoint
targetType
)
{
return
targetType
.
getType
().
isAssignableFrom
(
getType
());
}
...
...
@@ -257,9 +256,9 @@ public class BindingPoint<T> {
* @param type the class
* @return the type descriptor
*/
public
static
<
T
>
Binding
Point
<
T
>
valueOf
(
Class
<
T
>
type
)
{
public
static
<
T
>
Conversion
Point
<
T
>
valueOf
(
Class
<
T
>
type
)
{
// TODO needs a cache for common type descriptors
return
new
Binding
Point
<
T
>(
type
);
return
new
Conversion
Point
<
T
>(
type
);
}
/**
...
...
@@ -267,9 +266,10 @@ public class BindingPoint<T> {
* @param object the object
* @return the type descriptor
*/
public
static
BindingPoint
forObject
(
Object
object
)
{
@SuppressWarnings
(
"unchecked"
)
public
static
ConversionPoint
forObject
(
Object
object
)
{
if
(
object
==
null
)
{
return
NULL
_TYPE_DESCRIPTOR
;
return
NULL
;
}
else
{
return
valueOf
(
object
.
getClass
());
}
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/TypeConverter.java
浏览文件 @
46c9a003
...
...
@@ -18,8 +18,9 @@ package org.springframework.core.convert;
/**
* A service interface for type conversion. This is the entry point into the convert system.
* <p>
* Call {@link #convert(Object, Class)} to perform a thread-safe type conversion using
* this system.
* Call {@link #convert(Object, Class)} to perform a thread-safe type conversion using this system.<br>
* Call {@link #convert(Object, ConversionPoint)} to perform a conversion with additional context about the point
* where conversion needs to occur.
*
* @author Keith Donald
*/
...
...
@@ -34,12 +35,12 @@ public interface TypeConverter {
boolean
canConvert
(
Class
<?>
sourceType
,
Class
<?>
targetType
);
/**
* Returns true if objects of sourceType can be converted to the type of the
binding
point.
* Returns true if objects of sourceType can be converted to the type of the
conversion
point.
* @param source the source to convert from (may be null)
* @param point context about the target type to convert to
* @return true if a conversion can be performed, false if not
*/
boolean
canConvert
(
Class
<?>
sourceType
,
Binding
Point
<?>
point
);
boolean
canConvert
(
Class
<?>
sourceType
,
Conversion
Point
<?>
point
);
/**
* Convert the source to targetType.
...
...
@@ -51,12 +52,12 @@ public interface TypeConverter {
<
S
,
T
>
T
convert
(
S
source
,
Class
<
T
>
targetType
);
/**
* Convert the source to type T needed by the
binding
point.
* Convert the source to type T needed by the
conversion
point.
* @param source the source to convert from (may be null)
* @param point a binding point where a conversion is required
* @return the converted object, an instance of {@link
Binding
Point#getType()}</code>, or <code>null</code> if a null source was provided
* @return the converted object, an instance of {@link
Conversion
Point#getType()}</code>, or <code>null</code> if a null source was provided
* @throws ConvertException if an exception occurred
*/
<
S
,
T
>
T
convert
(
S
source
,
Binding
Point
<
T
>
point
);
<
S
,
T
>
T
convert
(
S
source
,
Conversion
Point
<
T
>
point
);
}
\ No newline at end of file
org.springframework.core/src/main/java/org/springframework/core/convert/converter/Converter.java
浏览文件 @
46c9a003
...
...
@@ -19,10 +19,10 @@ import org.springframework.core.convert.ConvertException;
import
org.springframework.core.convert.TypeConverter
;
/**
* A converter converts a source object of type S to a target of type T
and back
.
* A converter converts a source object of type S to a target of type T.
* <p>
* Implementations of this interface are thread-safe and can be shared. Converters are typically registered with and
*
accessed through a {@link TypeConverter}
.
*
invoked behind a {@link TypeConverter}. They typically should not be called directly
.
* </p>
* @author Keith Donald
*/
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/converter/ConverterFactory.java
浏览文件 @
46c9a003
...
...
@@ -15,6 +15,20 @@
*/
package
org.springframework.core.convert.converter
;
/**
* A factory for a "ranged" converters that can convert objects from S to subtypes of R.
* @author kdonald
* @param <S> The source type converters created by this factory can convert from
* @param <R> The target range (or base) type converters created by this factory can convert to;
* for example {@link Number} for a set of number subtypes.
*/
public
interface
ConverterFactory
<
S
,
R
>
{
/**
* Get the converter to convert from S to target type T, where T is also an instance of R.
* @param <T> the target type
* @param targetType the target type to convert to
* @return A converter from S to T
*/
<
T
extends
R
>
Converter
<
S
,
T
>
getConverter
(
Class
<
T
>
targetType
);
}
\ No newline at end of file
org.springframework.core/src/main/java/org/springframework/core/convert/converter/ConverterRegistry.java
浏览文件 @
46c9a003
package
org.springframework.core.convert.converter
;
/**
* A interface for registering converters with a type conversion system.
* @author Keith Donald
*/
public
interface
ConverterRegistry
{
/**
* Add a converter to this registry.
*/
void
addConverter
(
Converter
<?,
?>
converter
);
/**
* Add a converter factory to this registry.
*/
void
addConverterFactory
(
ConverterFactory
<?,
?>
converter
);
/**
* Remove a converter from this registry.
*/
void
removeConverter
(
Converter
<?,
?>
converter
);
/**
* Remove a converter factory from this registry.
*/
void
removeConverterFactory
(
Converter
<?,
?>
converter
);
}
\ No newline at end of file
org.springframework.core/src/main/java/org/springframework/core/convert/support/AbstractCollectionConverter.java
浏览文件 @
46c9a003
...
...
@@ -16,7 +16,7 @@
package
org.springframework.core.convert.support
;
import
org.springframework.core.convert.ConversionFailedException
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
/**
* Base class for converters that convert to and from collection types (arrays and java.util.Collection types)
...
...
@@ -28,18 +28,18 @@ abstract class AbstractCollectionConverter implements ConversionExecutor {
private
ConversionExecutor
elementConverter
;
private
Binding
Point
sourceCollectionType
;
private
Conversion
Point
sourceCollectionType
;
private
Binding
Point
targetCollectionType
;
private
Conversion
Point
targetCollectionType
;
public
AbstractCollectionConverter
(
BindingPoint
sourceCollectionType
,
Binding
Point
targetCollectionType
,
GenericTypeConverter
conversionService
)
{
public
AbstractCollectionConverter
(
ConversionPoint
sourceCollectionType
,
Conversion
Point
targetCollectionType
,
GenericTypeConverter
conversionService
)
{
this
.
conversionService
=
conversionService
;
this
.
sourceCollectionType
=
sourceCollectionType
;
this
.
targetCollectionType
=
targetCollectionType
;
Class
<?>
sourceElementType
=
sourceCollectionType
.
getElementType
();
Class
<?>
targetElementType
=
targetCollectionType
.
getElementType
();
if
(
sourceElementType
!=
null
&&
targetElementType
!=
null
)
{
elementConverter
=
conversionService
.
getConversionExecutor
(
sourceElementType
,
Binding
Point
.
valueOf
(
targetElementType
));
elementConverter
=
conversionService
.
getConversionExecutor
(
sourceElementType
,
Conversion
Point
.
valueOf
(
targetElementType
));
}
else
{
elementConverter
=
NoOpConversionExecutor
.
INSTANCE
;
}
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToArray.java
浏览文件 @
46c9a003
...
...
@@ -18,7 +18,7 @@ package org.springframework.core.convert.support;
import
java.lang.reflect.Array
;
import
org.springframework.core.convert.TypeConverter
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
/**
* Special one-way converter that converts from a source array to a target array. Supports type conversion of the
...
...
@@ -29,7 +29,7 @@ import org.springframework.core.convert.BindingPoint;
*/
class
ArrayToArray
extends
AbstractCollectionConverter
{
public
ArrayToArray
(
BindingPoint
sourceArrayType
,
Binding
Point
targetArrayType
,
GenericTypeConverter
conversionService
)
{
public
ArrayToArray
(
ConversionPoint
sourceArrayType
,
Conversion
Point
targetArrayType
,
GenericTypeConverter
conversionService
)
{
super
(
sourceArrayType
,
targetArrayType
,
conversionService
);
}
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToCollection.java
浏览文件 @
46c9a003
...
...
@@ -18,7 +18,7 @@ package org.springframework.core.convert.support;
import
java.lang.reflect.Array
;
import
java.util.Collection
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
/**
* Special converter that converts from a source array to a target collection. Supports the selection of an
...
...
@@ -29,7 +29,7 @@ import org.springframework.core.convert.BindingPoint;
*/
class
ArrayToCollection
extends
AbstractCollectionConverter
{
public
ArrayToCollection
(
BindingPoint
sourceArrayType
,
Binding
Point
targetCollectionType
,
public
ArrayToCollection
(
ConversionPoint
sourceArrayType
,
Conversion
Point
targetCollectionType
,
GenericTypeConverter
conversionService
)
{
super
(
sourceArrayType
,
targetCollectionType
,
conversionService
);
}
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToArray.java
浏览文件 @
46c9a003
...
...
@@ -19,7 +19,7 @@ import java.lang.reflect.Array;
import
java.util.Collection
;
import
java.util.Iterator
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
/**
* Special converter that converts from target collection to a source array.
...
...
@@ -28,7 +28,7 @@ import org.springframework.core.convert.BindingPoint;
*/
class
CollectionToArray
extends
AbstractCollectionConverter
{
public
CollectionToArray
(
BindingPoint
sourceArrayType
,
Binding
Point
targetCollectionType
,
public
CollectionToArray
(
ConversionPoint
sourceArrayType
,
Conversion
Point
targetCollectionType
,
GenericTypeConverter
conversionService
)
{
super
(
sourceArrayType
,
targetCollectionType
,
conversionService
);
}
...
...
@@ -52,7 +52,7 @@ class CollectionToArray extends AbstractCollectionConverter {
while
(
it
.
hasNext
())
{
Object
value
=
it
.
next
();
if
(
value
!=
null
)
{
elementConverter
=
getConversionService
().
getConversionExecutor
(
value
.
getClass
(),
Binding
Point
.
valueOf
(
getTargetElementType
()));
elementConverter
=
getConversionService
().
getConversionExecutor
(
value
.
getClass
(),
Conversion
Point
.
valueOf
(
getTargetElementType
()));
break
;
}
}
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToCollection.java
浏览文件 @
46c9a003
...
...
@@ -18,7 +18,7 @@ package org.springframework.core.convert.support;
import
java.util.Collection
;
import
java.util.Iterator
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
/**
* A converter that can convert from one collection type to another.
...
...
@@ -27,7 +27,7 @@ import org.springframework.core.convert.BindingPoint;
*/
class
CollectionToCollection
extends
AbstractCollectionConverter
{
public
CollectionToCollection
(
BindingPoint
sourceCollectionType
,
Binding
Point
targetCollectionType
,
public
CollectionToCollection
(
ConversionPoint
sourceCollectionType
,
Conversion
Point
targetCollectionType
,
GenericTypeConverter
conversionService
)
{
super
(
sourceCollectionType
,
targetCollectionType
,
conversionService
);
}
...
...
@@ -53,7 +53,7 @@ class CollectionToCollection extends AbstractCollectionConverter {
while
(
it
.
hasNext
())
{
Object
value
=
it
.
next
();
if
(
value
!=
null
)
{
elementConverter
=
getConversionService
().
getConversionExecutor
(
value
.
getClass
(),
Binding
Point
.
valueOf
(
getTargetElementType
()));
elementConverter
=
getConversionService
().
getConversionExecutor
(
value
.
getClass
(),
Conversion
Point
.
valueOf
(
getTargetElementType
()));
break
;
}
}
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericTypeConverter.java
浏览文件 @
46c9a003
...
...
@@ -28,7 +28,7 @@ import java.util.Map;
import
org.springframework.core.GenericTypeResolver
;
import
org.springframework.core.convert.ConverterNotFoundException
;
import
org.springframework.core.convert.TypeConverter
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
import
org.springframework.core.convert.converter.Converter
;
import
org.springframework.core.convert.converter.ConverterFactory
;
import
org.springframework.core.convert.converter.ConverterInfo
;
...
...
@@ -98,10 +98,10 @@ public class GenericTypeConverter implements TypeConverter, ConverterRegistry {
public
boolean
canConvert
(
Class
<?>
sourceType
,
Class
<?>
targetType
)
{
return
canConvert
(
sourceType
,
Binding
Point
.
valueOf
(
targetType
));
return
canConvert
(
sourceType
,
Conversion
Point
.
valueOf
(
targetType
));
}
public
boolean
canConvert
(
Class
<?>
sourceType
,
Binding
Point
<?>
targetType
)
{
public
boolean
canConvert
(
Class
<?>
sourceType
,
Conversion
Point
<?>
targetType
)
{
ConversionExecutor
executor
=
getConversionExecutor
(
sourceType
,
targetType
);
if
(
executor
!=
null
)
{
return
true
;
...
...
@@ -115,10 +115,10 @@ public class GenericTypeConverter implements TypeConverter, ConverterRegistry {
}
public
<
S
,
T
>
T
convert
(
S
source
,
Class
<
T
>
targetType
)
{
return
convert
(
source
,
Binding
Point
.
valueOf
(
targetType
));
return
convert
(
source
,
Conversion
Point
.
valueOf
(
targetType
));
}
public
<
S
,
T
>
T
convert
(
S
source
,
Binding
Point
<
T
>
targetType
)
{
public
<
S
,
T
>
T
convert
(
S
source
,
Conversion
Point
<
T
>
targetType
)
{
if
(
source
==
null
)
{
return
null
;
}
...
...
@@ -139,11 +139,11 @@ public class GenericTypeConverter implements TypeConverter, ConverterRegistry {
}
}
ConversionExecutor
getConversionExecutor
(
Class
sourceClass
,
Binding
Point
targetType
)
ConversionExecutor
getConversionExecutor
(
Class
sourceClass
,
Conversion
Point
targetType
)
throws
ConverterNotFoundException
{
Assert
.
notNull
(
sourceClass
,
"The sourceType to convert from is required"
);
Assert
.
notNull
(
targetType
,
"The targetType to convert to is required"
);
BindingPoint
sourceType
=
Binding
Point
.
valueOf
(
sourceClass
);
ConversionPoint
sourceType
=
Conversion
Point
.
valueOf
(
sourceClass
);
if
(
sourceType
.
isArray
())
{
if
(
targetType
.
isArray
())
{
return
new
ArrayToArray
(
sourceType
,
targetType
,
this
);
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToMap.java
浏览文件 @
46c9a003
...
...
@@ -22,7 +22,7 @@ import java.util.SortedMap;
import
java.util.TreeMap
;
import
org.springframework.core.convert.ConversionFailedException
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
/**
* Converts from one map to another map, with support for converting individual map elements based on generic type information.
...
...
@@ -31,9 +31,9 @@ import org.springframework.core.convert.BindingPoint;
@SuppressWarnings
(
"unchecked"
)
class
MapToMap
implements
ConversionExecutor
{
private
Binding
Point
sourceType
;
private
Conversion
Point
sourceType
;
private
Binding
Point
targetType
;
private
Conversion
Point
targetType
;
private
GenericTypeConverter
conversionService
;
...
...
@@ -45,7 +45,7 @@ class MapToMap implements ConversionExecutor {
* @param targetType the target map type
* @param conversionService the conversion service
*/
public
MapToMap
(
BindingPoint
sourceType
,
Binding
Point
targetType
,
GenericTypeConverter
conversionService
)
{
public
MapToMap
(
ConversionPoint
sourceType
,
Conversion
Point
targetType
,
GenericTypeConverter
conversionService
)
{
this
.
sourceType
=
sourceType
;
this
.
targetType
=
targetType
;
this
.
conversionService
=
conversionService
;
...
...
@@ -55,9 +55,9 @@ class MapToMap implements ConversionExecutor {
private
EntryConverter
createEntryConverter
()
{
if
(
sourceType
.
isMapEntryTypeKnown
()
&&
targetType
.
isMapEntryTypeKnown
())
{
ConversionExecutor
keyConverter
=
conversionService
.
getConversionExecutor
(
sourceType
.
getMapKeyType
(),
Binding
Point
.
valueOf
(
targetType
.
getMapKeyType
()));
Conversion
Point
.
valueOf
(
targetType
.
getMapKeyType
()));
ConversionExecutor
valueConverter
=
conversionService
.
getConversionExecutor
(
sourceType
.
getMapValueType
(),
Binding
Point
.
valueOf
(
targetType
.
getMapValueType
()));
Conversion
Point
.
valueOf
(
targetType
.
getMapValueType
()));
return
new
EntryConverter
(
keyConverter
,
valueConverter
);
}
else
{
return
EntryConverter
.
NO_OP_INSTANCE
;
...
...
@@ -94,11 +94,11 @@ class MapToMap implements ConversionExecutor {
Object
key
=
entry
.
getKey
();
Object
value
=
entry
.
getValue
();
if
(
keyConverter
==
null
&&
key
!=
null
)
{
keyConverter
=
conversionService
.
getConversionExecutor
(
key
.
getClass
(),
Binding
Point
keyConverter
=
conversionService
.
getConversionExecutor
(
key
.
getClass
(),
Conversion
Point
.
valueOf
(
targetKeyType
));
}
if
(
valueConverter
==
null
&&
value
!=
null
)
{
valueConverter
=
conversionService
.
getConversionExecutor
(
value
.
getClass
(),
Binding
Point
valueConverter
=
conversionService
.
getConversionExecutor
(
value
.
getClass
(),
Conversion
Point
.
valueOf
(
targetValueType
));
}
if
(
keyConverter
!=
null
&&
valueConverter
!=
null
)
{
...
...
org.springframework.core/src/main/java/org/springframework/core/convert/support/StaticConversionExecutor.java
浏览文件 @
46c9a003
...
...
@@ -16,7 +16,7 @@
package
org.springframework.core.convert.support
;
import
org.springframework.core.convert.ConversionFailedException
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
import
org.springframework.core.convert.converter.Converter
;
import
org.springframework.core.style.ToStringCreator
;
...
...
@@ -27,13 +27,13 @@ import org.springframework.core.style.ToStringCreator;
@SuppressWarnings
(
"unchecked"
)
class
StaticConversionExecutor
implements
ConversionExecutor
{
private
final
Binding
Point
sourceType
;
private
final
Conversion
Point
sourceType
;
private
final
Binding
Point
targetType
;
private
final
Conversion
Point
targetType
;
private
final
Converter
converter
;
public
StaticConversionExecutor
(
BindingPoint
sourceType
,
Binding
Point
targetType
,
Converter
converter
)
{
public
StaticConversionExecutor
(
ConversionPoint
sourceType
,
Conversion
Point
targetType
,
Converter
converter
)
{
this
.
sourceType
=
sourceType
;
this
.
targetType
=
targetType
;
this
.
converter
=
converter
;
...
...
org.springframework.core/src/test/java/org/springframework/core/convert/
TypeDescriptor
Tests.java
→
org.springframework.core/src/test/java/org/springframework/core/convert/
ConversionPoint
Tests.java
浏览文件 @
46c9a003
...
...
@@ -26,7 +26,7 @@ import org.junit.Test;
/**
* @author Andy Clement
*/
public
class
TypeDescriptor
Tests
{
public
class
ConversionPoint
Tests
{
List
<
String
>
listOfString
;
int
[]
intArray
;
...
...
@@ -34,13 +34,13 @@ public class TypeDescriptorTests {
@Test
public
void
testWrapperType
()
{
BindingPoint
desc
=
Binding
Point
.
valueOf
(
int
.
class
);
ConversionPoint
desc
=
Conversion
Point
.
valueOf
(
int
.
class
);
assertEquals
(
Integer
.
class
,
desc
.
getType
());
}
@Test
public
void
listDescriptors
()
throws
Exception
{
BindingPoint
typeDescriptor
=
new
BindingPoint
(
TypeDescriptor
Tests
.
class
.
getDeclaredField
(
"listOfString"
));
ConversionPoint
typeDescriptor
=
new
ConversionPoint
(
ConversionPoint
Tests
.
class
.
getDeclaredField
(
"listOfString"
));
assertFalse
(
typeDescriptor
.
isArray
());
assertEquals
(
List
.
class
,
typeDescriptor
.
getType
());
assertEquals
(
String
.
class
,
typeDescriptor
.
getElementType
());
...
...
@@ -50,7 +50,7 @@ public class TypeDescriptorTests {
@Test
public
void
arrayTypeDescriptors
()
throws
Exception
{
BindingPoint
typeDescriptor
=
new
BindingPoint
(
TypeDescriptor
Tests
.
class
.
getDeclaredField
(
"intArray"
));
ConversionPoint
typeDescriptor
=
new
ConversionPoint
(
ConversionPoint
Tests
.
class
.
getDeclaredField
(
"intArray"
));
assertTrue
(
typeDescriptor
.
isArray
());
assertEquals
(
Integer
.
TYPE
,
typeDescriptor
.
getElementType
());
assertEquals
(
"int[]"
,
typeDescriptor
.
asString
());
...
...
@@ -58,14 +58,14 @@ public class TypeDescriptorTests {
@Test
public
void
buildingArrayTypeDescriptors
()
throws
Exception
{
BindingPoint
typeDescriptor
=
new
Binding
Point
(
new
int
[
0
].
getClass
());
ConversionPoint
typeDescriptor
=
new
Conversion
Point
(
new
int
[
0
].
getClass
());
assertTrue
(
typeDescriptor
.
isArray
());
assertEquals
(
Integer
.
TYPE
,
typeDescriptor
.
getElementType
());
}
@Test
public
void
complexTypeDescriptors
()
throws
Exception
{
BindingPoint
typeDescriptor
=
new
BindingPoint
(
TypeDescriptor
Tests
.
class
.
getDeclaredField
(
"arrayOfListOfString"
));
ConversionPoint
typeDescriptor
=
new
ConversionPoint
(
ConversionPoint
Tests
.
class
.
getDeclaredField
(
"arrayOfListOfString"
));
assertTrue
(
typeDescriptor
.
isArray
());
assertEquals
(
List
.
class
,
typeDescriptor
.
getElementType
());
// TODO asc notice that the type of the list elements is lost: typeDescriptor.getElementType() should return a TypeDescriptor
...
...
org.springframework.core/src/test/java/org/springframework/core/convert/support/ArrayToArrayTests.java
浏览文件 @
46c9a003
...
...
@@ -3,7 +3,7 @@ package org.springframework.core.convert.support;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
org.junit.Test
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
import
org.springframework.core.convert.support.ArrayToArray
;
import
org.springframework.core.convert.support.DefaultTypeConverter
;
...
...
@@ -12,7 +12,7 @@ public class ArrayToArrayTests {
@Test
public
void
testArrayToArrayConversion
()
{
DefaultTypeConverter
service
=
new
DefaultTypeConverter
();
ArrayToArray
c
=
new
ArrayToArray
(
BindingPoint
.
valueOf
(
String
[].
class
),
Binding
Point
.
valueOf
(
Integer
[].
class
),
service
);
ArrayToArray
c
=
new
ArrayToArray
(
ConversionPoint
.
valueOf
(
String
[].
class
),
Conversion
Point
.
valueOf
(
Integer
[].
class
),
service
);
Integer
[]
result
=
(
Integer
[])
c
.
execute
(
new
String
[]
{
"1"
,
"2"
,
"3"
});
assertEquals
(
new
Integer
(
1
),
result
[
0
]);
assertEquals
(
new
Integer
(
2
),
result
[
1
]);
...
...
org.springframework.core/src/test/java/org/springframework/core/convert/support/ArrayToCollectionTests.java
浏览文件 @
46c9a003
...
...
@@ -9,7 +9,7 @@ import java.util.Set;
import
java.util.SortedSet
;
import
org.junit.Test
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
import
org.springframework.core.convert.support.ArrayToCollection
;
import
org.springframework.core.convert.support.DefaultTypeConverter
;
...
...
@@ -18,7 +18,7 @@ public class ArrayToCollectionTests {
@Test
public
void
testArrayToCollectionConversion
()
throws
Exception
{
DefaultTypeConverter
service
=
new
DefaultTypeConverter
();
ArrayToCollection
c
=
new
ArrayToCollection
(
BindingPoint
.
valueOf
(
String
[].
class
),
new
Binding
Point
(
getClass
().
getField
(
"bindTarget"
)),
service
);
ArrayToCollection
c
=
new
ArrayToCollection
(
ConversionPoint
.
valueOf
(
String
[].
class
),
new
Conversion
Point
(
getClass
().
getField
(
"bindTarget"
)),
service
);
List
result
=
(
List
)
c
.
execute
(
new
String
[]
{
"1"
,
"2"
,
"3"
});
assertEquals
(
new
Integer
(
1
),
result
.
get
(
0
));
assertEquals
(
new
Integer
(
2
),
result
.
get
(
1
));
...
...
@@ -28,7 +28,7 @@ public class ArrayToCollectionTests {
@Test
public
void
testArrayToSetConversion
()
throws
Exception
{
DefaultTypeConverter
service
=
new
DefaultTypeConverter
();
ArrayToCollection
c
=
new
ArrayToCollection
(
BindingPoint
.
valueOf
(
String
[].
class
),
new
Binding
Point
(
getClass
().
getField
(
"setTarget"
)),
service
);
ArrayToCollection
c
=
new
ArrayToCollection
(
ConversionPoint
.
valueOf
(
String
[].
class
),
new
Conversion
Point
(
getClass
().
getField
(
"setTarget"
)),
service
);
Set
result
=
(
Set
)
c
.
execute
(
new
String
[]
{
"1"
});
assertEquals
(
"1"
,
result
.
iterator
().
next
());
}
...
...
@@ -36,7 +36,7 @@ public class ArrayToCollectionTests {
@Test
public
void
testArrayToSortedSetConversion
()
throws
Exception
{
DefaultTypeConverter
service
=
new
DefaultTypeConverter
();
ArrayToCollection
c
=
new
ArrayToCollection
(
BindingPoint
.
valueOf
(
String
[].
class
),
new
Binding
Point
(
getClass
().
getField
(
"sortedSetTarget"
)),
service
);
ArrayToCollection
c
=
new
ArrayToCollection
(
ConversionPoint
.
valueOf
(
String
[].
class
),
new
Conversion
Point
(
getClass
().
getField
(
"sortedSetTarget"
)),
service
);
SortedSet
result
=
(
SortedSet
)
c
.
execute
(
new
String
[]
{
"1"
});
assertEquals
(
new
Integer
(
1
),
result
.
iterator
().
next
());
}
...
...
@@ -44,7 +44,7 @@ public class ArrayToCollectionTests {
@Test
public
void
testArrayToCollectionImplConversion
()
throws
Exception
{
DefaultTypeConverter
service
=
new
DefaultTypeConverter
();
ArrayToCollection
c
=
new
ArrayToCollection
(
BindingPoint
.
valueOf
(
String
[].
class
),
new
Binding
Point
(
getClass
().
getField
(
"implTarget"
)),
service
);
ArrayToCollection
c
=
new
ArrayToCollection
(
ConversionPoint
.
valueOf
(
String
[].
class
),
new
Conversion
Point
(
getClass
().
getField
(
"implTarget"
)),
service
);
LinkedList
result
=
(
LinkedList
)
c
.
execute
(
new
String
[]
{
"1"
});
assertEquals
(
"1"
,
result
.
iterator
().
next
());
}
...
...
@@ -52,7 +52,7 @@ public class ArrayToCollectionTests {
@Test
public
void
testArrayToNonGenericCollectionConversionNullElement
()
throws
Exception
{
DefaultTypeConverter
service
=
new
DefaultTypeConverter
();
ArrayToCollection
c
=
new
ArrayToCollection
(
BindingPoint
.
valueOf
(
String
[].
class
),
new
Binding
Point
(
getClass
().
getField
(
"listTarget"
)),
service
);
ArrayToCollection
c
=
new
ArrayToCollection
(
ConversionPoint
.
valueOf
(
String
[].
class
),
new
Conversion
Point
(
getClass
().
getField
(
"listTarget"
)),
service
);
List
result
=
(
List
)
c
.
execute
(
new
Integer
[]
{
null
,
new
Integer
(
1
)
});
assertEquals
(
null
,
result
.
get
(
0
));
assertEquals
(
new
Integer
(
1
),
result
.
get
(
1
));
...
...
org.springframework.core/src/test/java/org/springframework/core/convert/support/CollectionToArrayTests.java
浏览文件 @
46c9a003
...
...
@@ -6,7 +6,7 @@ import java.util.ArrayList;
import
java.util.Collection
;
import
org.junit.Test
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
import
org.springframework.core.convert.support.CollectionToArray
;
import
org.springframework.core.convert.support.DefaultTypeConverter
;
...
...
@@ -15,8 +15,8 @@ public class CollectionToArrayTests {
@Test
public
void
testCollectionToArrayConversion
()
throws
Exception
{
DefaultTypeConverter
service
=
new
DefaultTypeConverter
();
CollectionToArray
c
=
new
CollectionToArray
(
new
Binding
Point
(
getClass
().
getField
(
"bindTarget"
)),
Binding
Point
.
valueOf
(
Integer
[].
class
),
service
);
CollectionToArray
c
=
new
CollectionToArray
(
new
Conversion
Point
(
getClass
().
getField
(
"bindTarget"
)),
Conversion
Point
.
valueOf
(
Integer
[].
class
),
service
);
bindTarget
.
add
(
"1"
);
bindTarget
.
add
(
"2"
);
bindTarget
.
add
(
"3"
);
...
...
@@ -29,7 +29,7 @@ public class CollectionToArrayTests {
@Test
public
void
testCollectionToArrayConversionNoGenericInfo
()
throws
Exception
{
DefaultTypeConverter
service
=
new
DefaultTypeConverter
();
CollectionToArray
c
=
new
CollectionToArray
(
BindingPoint
.
valueOf
(
Collection
.
class
),
Binding
Point
CollectionToArray
c
=
new
CollectionToArray
(
ConversionPoint
.
valueOf
(
Collection
.
class
),
Conversion
Point
.
valueOf
(
Integer
[].
class
),
service
);
bindTarget
.
add
(
"1"
);
bindTarget
.
add
(
"2"
);
...
...
@@ -43,7 +43,7 @@ public class CollectionToArrayTests {
@Test
public
void
testCollectionToArrayConversionNoGenericInfoNullElement
()
throws
Exception
{
DefaultTypeConverter
service
=
new
DefaultTypeConverter
();
CollectionToArray
c
=
new
CollectionToArray
(
BindingPoint
.
valueOf
(
Collection
.
class
),
Binding
Point
CollectionToArray
c
=
new
CollectionToArray
(
ConversionPoint
.
valueOf
(
Collection
.
class
),
Conversion
Point
.
valueOf
(
Integer
[].
class
),
service
);
bindTarget
.
add
(
null
);
bindTarget
.
add
(
"1"
);
...
...
org.springframework.core/src/test/java/org/springframework/core/convert/support/CollectionToCollectionTests.java
浏览文件 @
46c9a003
...
...
@@ -8,7 +8,7 @@ import java.util.Collection;
import
java.util.List
;
import
org.junit.Test
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
import
org.springframework.core.convert.support.CollectionToCollection
;
import
org.springframework.core.convert.support.DefaultTypeConverter
;
...
...
@@ -17,8 +17,8 @@ public class CollectionToCollectionTests {
@Test
public
void
testCollectionToCollectionConversion
()
throws
Exception
{
DefaultTypeConverter
service
=
new
DefaultTypeConverter
();
CollectionToCollection
c
=
new
CollectionToCollection
(
new
Binding
Point
(
getClass
().
getField
(
"bindTarget"
)),
new
Binding
Point
(
getClass
().
getField
(
"integerTarget"
)),
service
);
CollectionToCollection
c
=
new
CollectionToCollection
(
new
Conversion
Point
(
getClass
().
getField
(
"bindTarget"
)),
new
Conversion
Point
(
getClass
().
getField
(
"integerTarget"
)),
service
);
bindTarget
.
add
(
"1"
);
bindTarget
.
add
(
"2"
);
bindTarget
.
add
(
"3"
);
...
...
@@ -31,8 +31,8 @@ public class CollectionToCollectionTests {
@Test
public
void
testCollectionToCollectionConversionNoGenericInfo
()
throws
Exception
{
DefaultTypeConverter
service
=
new
DefaultTypeConverter
();
CollectionToCollection
c
=
new
CollectionToCollection
(
Binding
Point
.
valueOf
(
Collection
.
class
),
Binding
Point
.
valueOf
(
List
.
class
),
service
);
CollectionToCollection
c
=
new
CollectionToCollection
(
Conversion
Point
.
valueOf
(
Collection
.
class
),
Conversion
Point
.
valueOf
(
List
.
class
),
service
);
bindTarget
.
add
(
"1"
);
bindTarget
.
add
(
"2"
);
bindTarget
.
add
(
"3"
);
...
...
@@ -45,8 +45,8 @@ public class CollectionToCollectionTests {
@Test
public
void
testCollectionToCollectionConversionNoGenericInfoSource
()
throws
Exception
{
DefaultTypeConverter
service
=
new
DefaultTypeConverter
();
CollectionToCollection
c
=
new
CollectionToCollection
(
Binding
Point
.
valueOf
(
Collection
.
class
),
new
Binding
Point
(
getClass
().
getField
(
"integerTarget"
)),
service
);
CollectionToCollection
c
=
new
CollectionToCollection
(
Conversion
Point
.
valueOf
(
Collection
.
class
),
new
Conversion
Point
(
getClass
().
getField
(
"integerTarget"
)),
service
);
bindTarget
.
add
(
"1"
);
bindTarget
.
add
(
"2"
);
bindTarget
.
add
(
"3"
);
...
...
@@ -59,8 +59,8 @@ public class CollectionToCollectionTests {
@Test
public
void
testCollectionToCollectionConversionNoGenericInfoSourceNullValues
()
throws
Exception
{
DefaultTypeConverter
service
=
new
DefaultTypeConverter
();
CollectionToCollection
c
=
new
CollectionToCollection
(
Binding
Point
.
valueOf
(
Collection
.
class
),
new
Binding
Point
(
getClass
().
getField
(
"integerTarget"
)),
service
);
CollectionToCollection
c
=
new
CollectionToCollection
(
Conversion
Point
.
valueOf
(
Collection
.
class
),
new
Conversion
Point
(
getClass
().
getField
(
"integerTarget"
)),
service
);
bindTarget
.
add
(
null
);
bindTarget
.
add
(
"1"
);
bindTarget
.
add
(
"2"
);
...
...
@@ -77,8 +77,8 @@ public class CollectionToCollectionTests {
@Test
public
void
testCollectionToCollectionConversionNoGenericInfoSourceEmpty
()
throws
Exception
{
DefaultTypeConverter
service
=
new
DefaultTypeConverter
();
CollectionToCollection
c
=
new
CollectionToCollection
(
Binding
Point
.
valueOf
(
Collection
.
class
),
new
Binding
Point
(
getClass
().
getField
(
"integerTarget"
)),
service
);
CollectionToCollection
c
=
new
CollectionToCollection
(
Conversion
Point
.
valueOf
(
Collection
.
class
),
new
Conversion
Point
(
getClass
().
getField
(
"integerTarget"
)),
service
);
List
result
=
(
List
)
c
.
execute
(
bindTarget
);
assertTrue
(
result
.
isEmpty
());
}
...
...
org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericTypeConverterTests.java
浏览文件 @
46c9a003
...
...
@@ -28,7 +28,7 @@ import java.util.Map;
import
org.junit.Ignore
;
import
org.junit.Test
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
import
org.springframework.core.convert.ConversionFailedException
;
import
org.springframework.core.convert.ConverterNotFoundException
;
import
org.springframework.core.convert.converter.Converter
;
...
...
@@ -156,7 +156,7 @@ public class GenericTypeConverterTests {
@Test
public
void
convertArrayToListGenericTypeConversion
()
throws
Exception
{
converter
.
addConverter
(
new
StringToInteger
());
List
<
Integer
>
result
=
converter
.
convert
(
new
String
[]
{
"1"
,
"2"
,
"3"
},
new
Binding
Point
<
List
<
Integer
>>(
getClass
().
getDeclaredField
(
"genericList"
)));
List
<
Integer
>
result
=
converter
.
convert
(
new
String
[]
{
"1"
,
"2"
,
"3"
},
new
Conversion
Point
<
List
<
Integer
>>(
getClass
().
getDeclaredField
(
"genericList"
)));
assertEquals
(
new
Integer
(
"1"
),
result
.
get
(
0
));
assertEquals
(
new
Integer
(
"2"
),
result
.
get
(
1
));
assertEquals
(
new
Integer
(
"3"
),
result
.
get
(
2
));
...
...
@@ -214,7 +214,7 @@ public class GenericTypeConverterTests {
foo
.
put
(
"2"
,
"BAZ"
);
converter
.
addConverter
(
new
StringToInteger
());
converter
.
addConverter
(
new
StringToEnumFactory
().
getConverter
(
FooEnum
.
class
));
Map
<
String
,
FooEnum
>
map
=
converter
.
convert
(
foo
,
new
Binding
Point
<
Map
<
String
,
FooEnum
>>(
getClass
().
getField
(
"genericMap"
)));
Map
<
String
,
FooEnum
>
map
=
converter
.
convert
(
foo
,
new
Conversion
Point
<
Map
<
String
,
FooEnum
>>(
getClass
().
getField
(
"genericMap"
)));
assertEquals
(
map
.
get
(
1
),
FooEnum
.
BAR
);
assertEquals
(
map
.
get
(
2
),
FooEnum
.
BAZ
);
}
...
...
org.springframework.core/src/test/java/org/springframework/core/convert/support/MapToMapTests.java
浏览文件 @
46c9a003
...
...
@@ -6,7 +6,7 @@ import java.util.HashMap;
import
java.util.Map
;
import
org.junit.Test
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
import
org.springframework.core.convert.support.DefaultTypeConverter
;
import
org.springframework.core.convert.support.MapToMap
;
...
...
@@ -15,8 +15,8 @@ public class MapToMapTests {
@Test
public
void
testMapToMapConversion
()
throws
Exception
{
DefaultTypeConverter
converter
=
new
DefaultTypeConverter
();
MapToMap
c
=
new
MapToMap
(
new
Binding
Point
<
Map
<
String
,
String
>>(
getClass
().
getField
(
"source"
)),
new
Binding
Point
<
Map
<
String
,
FooEnum
>>(
getClass
().
getField
(
"bindTarget"
)),
converter
);
MapToMap
c
=
new
MapToMap
(
new
Conversion
Point
<
Map
<
String
,
String
>>(
getClass
().
getField
(
"source"
)),
new
Conversion
Point
<
Map
<
String
,
FooEnum
>>(
getClass
().
getField
(
"bindTarget"
)),
converter
);
source
.
put
(
"1"
,
"BAR"
);
source
.
put
(
"2"
,
"BAZ"
);
Map
<
String
,
FooEnum
>
result
=
(
Map
<
String
,
FooEnum
>)
c
.
execute
(
source
);
...
...
@@ -27,8 +27,8 @@ public class MapToMapTests {
@Test
public
void
testMapToMapConversionNoGenericInfoOnSource
()
throws
Exception
{
DefaultTypeConverter
service
=
new
DefaultTypeConverter
();
MapToMap
c
=
new
MapToMap
(
Binding
Point
.
valueOf
(
Map
.
class
),
new
Binding
Point
(
getClass
().
getField
(
"bindTarget"
)),
service
);
MapToMap
c
=
new
MapToMap
(
Conversion
Point
.
valueOf
(
Map
.
class
),
new
Conversion
Point
(
getClass
().
getField
(
"bindTarget"
)),
service
);
source
.
put
(
"1"
,
"BAR"
);
source
.
put
(
"2"
,
"BAZ"
);
Map
result
=
(
Map
)
c
.
execute
(
source
);
...
...
@@ -39,8 +39,8 @@ public class MapToMapTests {
@Test
public
void
testMapToMapConversionNoGenericInfo
()
throws
Exception
{
DefaultTypeConverter
service
=
new
DefaultTypeConverter
();
MapToMap
c
=
new
MapToMap
(
Binding
Point
.
valueOf
(
Map
.
class
),
Binding
Point
.
valueOf
(
Map
.
class
),
service
);
MapToMap
c
=
new
MapToMap
(
Conversion
Point
.
valueOf
(
Map
.
class
),
Conversion
Point
.
valueOf
(
Map
.
class
),
service
);
source
.
put
(
"1"
,
"BAR"
);
source
.
put
(
"2"
,
"BAZ"
);
Map
result
=
(
Map
)
c
.
execute
(
source
);
...
...
org.springframework.expression/src/main/java/org/springframework/expression/TypeConverter.java
浏览文件 @
46c9a003
...
...
@@ -16,7 +16,7 @@
package
org.springframework.expression
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
/**
* A type converter can convert values between different types encountered
...
...
@@ -48,7 +48,7 @@ public interface TypeConverter {
* @return the converted value
* @throws EvaluationException if conversion is not possible
*/
Object
convertValue
(
Object
value
,
Binding
Point
typeDescriptor
)
throws
EvaluationException
;
Object
convertValue
(
Object
value
,
Conversion
Point
typeDescriptor
)
throws
EvaluationException
;
/**
* Return true if the type converter can convert the specified type to the desired target type.
...
...
@@ -64,6 +64,6 @@ public interface TypeConverter {
* @param typeDescriptor a type descriptor that supplies extra information about the requested result type
* @return true if that conversion can be performed
*/
boolean
canConvert
(
Class
<?>
sourceType
,
Binding
Point
typeDescriptor
);
boolean
canConvert
(
Class
<?>
sourceType
,
Conversion
Point
typeDescriptor
);
}
org.springframework.expression/src/main/java/org/springframework/expression/TypedValue.java
浏览文件 @
46c9a003
...
...
@@ -15,7 +15,7 @@
*/
package
org.springframework.expression
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
/**
* Encapsulates an object and a type descriptor that describes it.
...
...
@@ -28,9 +28,9 @@ import org.springframework.core.convert.BindingPoint;
public
class
TypedValue
{
private
Object
value
;
private
Binding
Point
typeDescriptor
;
private
Conversion
Point
typeDescriptor
;
public
static
final
TypedValue
NULL_TYPED_VALUE
=
new
TypedValue
(
null
,
BindingPoint
.
NULL_TYPE_DESCRIPTOR
);
public
static
final
TypedValue
NULL_TYPED_VALUE
=
new
TypedValue
(
null
,
ConversionPoint
.
NULL
);
/**
* Create a TypedValue for a simple object. The type descriptor is inferred
...
...
@@ -39,7 +39,7 @@ public class TypedValue {
*/
public
TypedValue
(
Object
value
)
{
this
.
value
=
value
;
this
.
typeDescriptor
=
Binding
Point
.
forObject
(
value
);
this
.
typeDescriptor
=
Conversion
Point
.
forObject
(
value
);
}
/**
...
...
@@ -47,7 +47,7 @@ public class TypedValue {
* @param value the object value
* @param typeDescriptor a type descriptor describing the type of the value
*/
public
TypedValue
(
Object
value
,
Binding
Point
typeDescriptor
)
{
public
TypedValue
(
Object
value
,
Conversion
Point
typeDescriptor
)
{
this
.
value
=
value
;
this
.
typeDescriptor
=
typeDescriptor
;
}
...
...
@@ -56,7 +56,7 @@ public class TypedValue {
return
this
.
value
;
}
public
Binding
Point
getTypeDescriptor
()
{
public
Conversion
Point
getTypeDescriptor
()
{
return
this
.
typeDescriptor
;
}
...
...
org.springframework.expression/src/main/java/org/springframework/expression/spel/ExpressionState.java
浏览文件 @
46c9a003
...
...
@@ -20,7 +20,7 @@ import java.util.List;
import
java.util.Map
;
import
java.util.Stack
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
import
org.springframework.expression.EvaluationContext
;
import
org.springframework.expression.EvaluationException
;
import
org.springframework.expression.Operation
;
...
...
@@ -99,7 +99,7 @@ public class ExpressionState {
if
(
value
==
null
)
{
return
TypedValue
.
NULL_TYPED_VALUE
;
}
else
{
return
new
TypedValue
(
value
,
Binding
Point
.
forObject
(
value
));
return
new
TypedValue
(
value
,
Conversion
Point
.
forObject
(
value
));
}
}
...
...
@@ -111,11 +111,11 @@ public class ExpressionState {
return
this
.
relatedContext
.
getTypeLocator
().
findType
(
type
);
}
public
Object
convertValue
(
Object
value
,
Binding
Point
targetTypeDescriptor
)
throws
EvaluationException
{
public
Object
convertValue
(
Object
value
,
Conversion
Point
targetTypeDescriptor
)
throws
EvaluationException
{
return
this
.
relatedContext
.
getTypeConverter
().
convertValue
(
value
,
targetTypeDescriptor
);
}
public
Object
convertValue
(
TypedValue
value
,
Binding
Point
targetTypeDescriptor
)
throws
EvaluationException
{
public
Object
convertValue
(
TypedValue
value
,
Conversion
Point
targetTypeDescriptor
)
throws
EvaluationException
{
return
this
.
relatedContext
.
getTypeConverter
().
convertValue
(
value
.
getValue
(),
targetTypeDescriptor
);
}
...
...
@@ -153,7 +153,7 @@ public class ExpressionState {
OperatorOverloader
overloader
=
this
.
relatedContext
.
getOperatorOverloader
();
if
(
overloader
.
overridesOperation
(
op
,
left
,
right
))
{
Object
returnValue
=
overloader
.
operate
(
op
,
left
,
right
);
return
new
TypedValue
(
returnValue
,
Binding
Point
.
forObject
(
returnValue
));
return
new
TypedValue
(
returnValue
,
Conversion
Point
.
forObject
(
returnValue
));
}
else
{
String
leftType
=
(
left
==
null
?
"null"
:
left
.
getClass
().
getName
());
...
...
org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/CommonTypeDescriptors.java
浏览文件 @
46c9a003
...
...
@@ -15,7 +15,7 @@
*/
package
org.springframework.expression.spel.ast
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
/**
* @author Andy Clement
...
...
@@ -23,16 +23,16 @@ import org.springframework.core.convert.BindingPoint;
*/
public
interface
CommonTypeDescriptors
{
// TODO push into TypeDescriptor?
static
BindingPoint
BOOLEAN_TYPE_DESCRIPTOR
=
Binding
Point
.
valueOf
(
Boolean
.
class
);
static
BindingPoint
INTEGER_TYPE_DESCRIPTOR
=
Binding
Point
.
valueOf
(
Integer
.
class
);
static
BindingPoint
CHARACTER_TYPE_DESCRIPTOR
=
Binding
Point
.
valueOf
(
Character
.
class
);
static
BindingPoint
LONG_TYPE_DESCRIPTOR
=
Binding
Point
.
valueOf
(
Long
.
class
);
static
BindingPoint
SHORT_TYPE_DESCRIPTOR
=
Binding
Point
.
valueOf
(
Short
.
class
);
static
BindingPoint
BYTE_TYPE_DESCRIPTOR
=
Binding
Point
.
valueOf
(
Byte
.
class
);
static
BindingPoint
FLOAT_TYPE_DESCRIPTOR
=
Binding
Point
.
valueOf
(
Float
.
class
);
static
BindingPoint
DOUBLE_TYPE_DESCRIPTOR
=
Binding
Point
.
valueOf
(
Double
.
class
);
static
BindingPoint
STRING_TYPE_DESCRIPTOR
=
Binding
Point
.
valueOf
(
String
.
class
);
static
BindingPoint
CLASS_TYPE_DESCRIPTOR
=
Binding
Point
.
valueOf
(
Class
.
class
);
static
BindingPoint
OBJECT_TYPE_DESCRIPTOR
=
Binding
Point
.
valueOf
(
Object
.
class
);
static
ConversionPoint
BOOLEAN_TYPE_DESCRIPTOR
=
Conversion
Point
.
valueOf
(
Boolean
.
class
);
static
ConversionPoint
INTEGER_TYPE_DESCRIPTOR
=
Conversion
Point
.
valueOf
(
Integer
.
class
);
static
ConversionPoint
CHARACTER_TYPE_DESCRIPTOR
=
Conversion
Point
.
valueOf
(
Character
.
class
);
static
ConversionPoint
LONG_TYPE_DESCRIPTOR
=
Conversion
Point
.
valueOf
(
Long
.
class
);
static
ConversionPoint
SHORT_TYPE_DESCRIPTOR
=
Conversion
Point
.
valueOf
(
Short
.
class
);
static
ConversionPoint
BYTE_TYPE_DESCRIPTOR
=
Conversion
Point
.
valueOf
(
Byte
.
class
);
static
ConversionPoint
FLOAT_TYPE_DESCRIPTOR
=
Conversion
Point
.
valueOf
(
Float
.
class
);
static
ConversionPoint
DOUBLE_TYPE_DESCRIPTOR
=
Conversion
Point
.
valueOf
(
Double
.
class
);
static
ConversionPoint
STRING_TYPE_DESCRIPTOR
=
Conversion
Point
.
valueOf
(
String
.
class
);
static
ConversionPoint
CLASS_TYPE_DESCRIPTOR
=
Conversion
Point
.
valueOf
(
Class
.
class
);
static
ConversionPoint
OBJECT_TYPE_DESCRIPTOR
=
Conversion
Point
.
valueOf
(
Object
.
class
);
}
org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/FunctionReference.java
浏览文件 @
46c9a003
...
...
@@ -22,7 +22,7 @@ import java.lang.reflect.Modifier;
import
org.antlr.runtime.Token
;
import
org.springframework.core.MethodParameter
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
import
org.springframework.expression.EvaluationException
;
import
org.springframework.expression.TypeConverter
;
import
org.springframework.expression.TypedValue
;
...
...
@@ -104,7 +104,7 @@ public class FunctionReference extends SpelNodeImpl {
try
{
ReflectionUtils
.
makeAccessible
(
m
);
Object
result
=
m
.
invoke
(
m
.
getClass
(),
functionArgs
);
return
new
TypedValue
(
result
,
new
Binding
Point
(
new
MethodParameter
(
m
,-
1
)));
return
new
TypedValue
(
result
,
new
Conversion
Point
(
new
MethodParameter
(
m
,-
1
)));
}
catch
(
IllegalArgumentException
e
)
{
throw
new
SpelException
(
getCharPositionInLine
(),
e
,
SpelMessages
.
EXCEPTION_DURING_FUNCTION_CALL
,
name
,
e
.
getMessage
());
...
...
org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java
浏览文件 @
46c9a003
...
...
@@ -21,7 +21,7 @@ import java.util.List;
import
java.util.Map
;
import
org.antlr.runtime.Token
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
import
org.springframework.expression.EvaluationException
;
import
org.springframework.expression.TypedValue
;
import
org.springframework.expression.spel.ExpressionState
;
...
...
@@ -47,15 +47,15 @@ public class Indexer extends SpelNodeImpl {
public
TypedValue
getValueInternal
(
ExpressionState
state
)
throws
EvaluationException
{
TypedValue
context
=
state
.
getActiveContextObject
();
Object
targetObject
=
context
.
getValue
();
Binding
Point
targetObjectTypeDescriptor
=
context
.
getTypeDescriptor
();
Conversion
Point
targetObjectTypeDescriptor
=
context
.
getTypeDescriptor
();
TypedValue
indexValue
=
getChild
(
0
).
getValueInternal
(
state
);
Object
index
=
indexValue
.
getValue
();
// Indexing into a Map
if
(
targetObject
instanceof
Map
)
{
Object
possiblyConvertedKey
=
state
.
convertValue
(
indexValue
,
Binding
Point
.
valueOf
(
targetObjectTypeDescriptor
.
getMapKeyType
()));
Object
possiblyConvertedKey
=
state
.
convertValue
(
indexValue
,
Conversion
Point
.
valueOf
(
targetObjectTypeDescriptor
.
getMapKeyType
()));
Object
o
=
((
Map
<?,
?>)
targetObject
).
get
(
possiblyConvertedKey
);
return
new
TypedValue
(
o
,
Binding
Point
.
valueOf
(
targetObjectTypeDescriptor
.
getMapValueType
()));
return
new
TypedValue
(
o
,
Conversion
Point
.
valueOf
(
targetObjectTypeDescriptor
.
getMapValueType
()));
}
int
idx
=
(
Integer
)
state
.
convertValue
(
index
,
INTEGER_TYPE_DESCRIPTOR
);
...
...
@@ -65,7 +65,7 @@ public class Indexer extends SpelNodeImpl {
}
if
(
targetObject
.
getClass
().
isArray
())
{
return
new
TypedValue
(
accessArrayElement
(
targetObject
,
idx
),
Binding
Point
.
valueOf
(
targetObjectTypeDescriptor
.
getElementType
()));
return
new
TypedValue
(
accessArrayElement
(
targetObject
,
idx
),
Conversion
Point
.
valueOf
(
targetObjectTypeDescriptor
.
getElementType
()));
}
else
if
(
targetObject
instanceof
Collection
)
{
Collection
<?>
c
=
(
Collection
<?>)
targetObject
;
if
(
idx
>=
c
.
size
())
{
...
...
@@ -74,7 +74,7 @@ public class Indexer extends SpelNodeImpl {
int
pos
=
0
;
for
(
Object
o
:
c
)
{
if
(
pos
==
idx
)
{
return
new
TypedValue
(
o
,
Binding
Point
.
valueOf
(
targetObjectTypeDescriptor
.
getElementType
()));
return
new
TypedValue
(
o
,
Conversion
Point
.
valueOf
(
targetObjectTypeDescriptor
.
getElementType
()));
}
pos
++;
}
...
...
@@ -99,7 +99,7 @@ public class Indexer extends SpelNodeImpl {
public
void
setValue
(
ExpressionState
state
,
Object
newValue
)
throws
EvaluationException
{
TypedValue
contextObject
=
state
.
getActiveContextObject
();
Object
targetObject
=
contextObject
.
getValue
();
Binding
Point
targetObjectTypeDescriptor
=
contextObject
.
getTypeDescriptor
();
Conversion
Point
targetObjectTypeDescriptor
=
contextObject
.
getTypeDescriptor
();
TypedValue
index
=
getChild
(
0
).
getValueInternal
(
state
);
if
(
targetObject
==
null
)
{
...
...
@@ -108,8 +108,8 @@ public class Indexer extends SpelNodeImpl {
// Indexing into a Map
if
(
targetObjectTypeDescriptor
.
isMap
())
{
Map
map
=
(
Map
)
targetObject
;
Object
possiblyConvertedKey
=
state
.
convertValue
(
index
.
getValue
(),
Binding
Point
.
valueOf
(
targetObjectTypeDescriptor
.
getMapKeyType
()));
Object
possiblyConvertedValue
=
state
.
convertValue
(
newValue
,
Binding
Point
.
valueOf
(
targetObjectTypeDescriptor
.
getMapValueType
()));
Object
possiblyConvertedKey
=
state
.
convertValue
(
index
.
getValue
(),
Conversion
Point
.
valueOf
(
targetObjectTypeDescriptor
.
getMapKeyType
()));
Object
possiblyConvertedValue
=
state
.
convertValue
(
newValue
,
Conversion
Point
.
valueOf
(
targetObjectTypeDescriptor
.
getMapValueType
()));
map
.
put
(
possiblyConvertedKey
,
possiblyConvertedValue
);
return
;
}
...
...
@@ -125,7 +125,7 @@ public class Indexer extends SpelNodeImpl {
}
if
(
targetObject
instanceof
List
)
{
List
list
=
(
List
)
targetObject
;
Object
possiblyConvertedValue
=
state
.
convertValue
(
newValue
,
Binding
Point
.
valueOf
(
targetObjectTypeDescriptor
.
getElementType
()));
Object
possiblyConvertedValue
=
state
.
convertValue
(
newValue
,
Conversion
Point
.
valueOf
(
targetObjectTypeDescriptor
.
getElementType
()));
list
.
set
(
idx
,
possiblyConvertedValue
);
}
else
{
throw
new
SpelException
(
SpelMessages
.
INDEXING_NOT_SUPPORTED_FOR_TYPE
,
contextObject
.
getClass
().
getName
());
...
...
@@ -185,7 +185,7 @@ public class Indexer extends SpelNodeImpl {
}
else
{
Object
[]
array
=
(
Object
[])
ctx
;
checkAccess
(
array
.
length
,
idx
);
array
[
idx
]
=
state
.
convertValue
(
newValue
,
Binding
Point
.
valueOf
(
clazz
));
array
[
idx
]
=
state
.
convertValue
(
newValue
,
Conversion
Point
.
valueOf
(
clazz
));
}
}
...
...
org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/OperatorDivide.java
浏览文件 @
46c9a003
...
...
@@ -17,7 +17,7 @@
package
org.springframework.expression.spel.ast
;
import
org.antlr.runtime.Token
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
import
org.springframework.expression.EvaluationException
;
import
org.springframework.expression.Operation
;
import
org.springframework.expression.TypedValue
;
...
...
@@ -56,7 +56,7 @@ public class OperatorDivide extends Operator {
}
}
Object
result
=
state
.
operate
(
Operation
.
DIVIDE
,
operandOne
,
operandTwo
);
return
new
TypedValue
(
result
,
Binding
Point
.
forObject
(
result
));
return
new
TypedValue
(
result
,
Conversion
Point
.
forObject
(
result
));
}
}
org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Projection.java
浏览文件 @
46c9a003
...
...
@@ -22,7 +22,7 @@ import java.util.List;
import
java.util.Map
;
import
org.antlr.runtime.Token
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
import
org.springframework.expression.EvaluationException
;
import
org.springframework.expression.TypedValue
;
import
org.springframework.expression.spel.ExpressionState
;
...
...
@@ -60,13 +60,13 @@ public class Projection extends SpelNodeImpl {
List
<
Object
>
result
=
new
ArrayList
<
Object
>();
for
(
Map
.
Entry
entry
:
mapdata
.
entrySet
())
{
try
{
state
.
pushActiveContextObject
(
new
TypedValue
(
entry
,
Binding
Point
.
valueOf
(
Map
.
Entry
.
class
)));
state
.
pushActiveContextObject
(
new
TypedValue
(
entry
,
Conversion
Point
.
valueOf
(
Map
.
Entry
.
class
)));
result
.
add
(
getChild
(
0
).
getValueInternal
(
state
).
getValue
());
}
finally
{
state
.
popActiveContextObject
();
}
}
return
new
TypedValue
(
result
,
Binding
Point
.
valueOf
(
List
.
class
));
// TODO unable to build correct type descriptor
return
new
TypedValue
(
result
,
Conversion
Point
.
valueOf
(
List
.
class
));
// TODO unable to build correct type descriptor
}
else
if
(
operand
instanceof
List
)
{
List
<
Object
>
data
=
new
ArrayList
<
Object
>();
data
.
addAll
((
Collection
<?>)
operand
);
...
...
@@ -74,7 +74,7 @@ public class Projection extends SpelNodeImpl {
int
idx
=
0
;
for
(
Object
element
:
data
)
{
try
{
state
.
pushActiveContextObject
(
new
TypedValue
(
element
,
Binding
Point
.
valueOf
(
op
.
getTypeDescriptor
().
getType
())));
state
.
pushActiveContextObject
(
new
TypedValue
(
element
,
Conversion
Point
.
valueOf
(
op
.
getTypeDescriptor
().
getType
())));
state
.
enterScope
(
"index"
,
idx
);
result
.
add
(
getChild
(
0
).
getValueInternal
(
state
).
getValue
());
}
finally
{
...
...
org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Selection.java
浏览文件 @
46c9a003
...
...
@@ -23,7 +23,7 @@ import java.util.List;
import
java.util.Map
;
import
org.antlr.runtime.Token
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
import
org.springframework.expression.EvaluationException
;
import
org.springframework.expression.TypedValue
;
import
org.springframework.expression.spel.ExpressionState
;
...
...
@@ -66,7 +66,7 @@ public class Selection extends SpelNodeImpl {
for
(
Map
.
Entry
entry
:
mapdata
.
entrySet
())
{
try
{
lastKey
=
entry
.
getKey
();
TypedValue
kvpair
=
new
TypedValue
(
entry
,
Binding
Point
.
valueOf
(
Map
.
Entry
.
class
));
TypedValue
kvpair
=
new
TypedValue
(
entry
,
Conversion
Point
.
valueOf
(
Map
.
Entry
.
class
));
state
.
pushActiveContextObject
(
kvpair
);
Object
o
=
selectionCriteria
.
getValueInternal
(
state
).
getValue
();
if
(
o
instanceof
Boolean
)
{
...
...
@@ -86,13 +86,13 @@ public class Selection extends SpelNodeImpl {
}
}
if
((
variant
==
FIRST
||
variant
==
LAST
)
&&
result
.
size
()
==
0
)
{
return
new
TypedValue
(
null
,
BindingPoint
.
NULL_TYPE_DESCRIPTOR
);
return
new
TypedValue
(
null
,
ConversionPoint
.
NULL
);
}
if
(
variant
==
LAST
)
{
Map
resultMap
=
new
HashMap
();
Object
lastValue
=
result
.
get
(
lastKey
);
resultMap
.
put
(
lastKey
,
lastValue
);
return
new
TypedValue
(
resultMap
,
Binding
Point
.
valueOf
(
Map
.
class
));
return
new
TypedValue
(
resultMap
,
Conversion
Point
.
valueOf
(
Map
.
class
));
}
return
new
TypedValue
(
result
,
op
.
getTypeDescriptor
());
}
else
if
(
operand
instanceof
Collection
)
{
...
...
@@ -102,13 +102,13 @@ public class Selection extends SpelNodeImpl {
int
idx
=
0
;
for
(
Object
element
:
data
)
{
try
{
state
.
pushActiveContextObject
(
new
TypedValue
(
element
,
Binding
Point
.
valueOf
(
op
.
getTypeDescriptor
().
getElementType
())));
state
.
pushActiveContextObject
(
new
TypedValue
(
element
,
Conversion
Point
.
valueOf
(
op
.
getTypeDescriptor
().
getElementType
())));
state
.
enterScope
(
"index"
,
idx
);
Object
o
=
selectionCriteria
.
getValueInternal
(
state
).
getValue
();
if
(
o
instanceof
Boolean
)
{
if
(((
Boolean
)
o
).
booleanValue
()
==
true
)
{
if
(
variant
==
FIRST
)
{
return
new
TypedValue
(
element
,
Binding
Point
.
valueOf
(
op
.
getTypeDescriptor
().
getElementType
()));
return
new
TypedValue
(
element
,
Conversion
Point
.
valueOf
(
op
.
getTypeDescriptor
().
getElementType
()));
}
result
.
add
(
element
);
}
...
...
@@ -126,7 +126,7 @@ public class Selection extends SpelNodeImpl {
return
TypedValue
.
NULL_TYPED_VALUE
;
}
if
(
variant
==
LAST
)
{
return
new
TypedValue
(
result
.
get
(
result
.
size
()
-
1
),
Binding
Point
.
valueOf
(
op
.
getTypeDescriptor
().
getElementType
()));
return
new
TypedValue
(
result
.
get
(
result
.
size
()
-
1
),
Conversion
Point
.
valueOf
(
op
.
getTypeDescriptor
().
getElementType
()));
}
return
new
TypedValue
(
result
,
op
.
getTypeDescriptor
());
}
else
{
...
...
org.springframework.expression/src/main/java/org/springframework/expression/spel/support/ReflectiveConstructorExecutor.java
浏览文件 @
46c9a003
...
...
@@ -18,7 +18,7 @@ package org.springframework.expression.spel.support;
import
java.lang.reflect.Constructor
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
import
org.springframework.expression.AccessException
;
import
org.springframework.expression.ConstructorExecutor
;
import
org.springframework.expression.EvaluationContext
;
...
...
@@ -56,7 +56,7 @@ class ReflectiveConstructorExecutor implements ConstructorExecutor {
if
(!
c
.
isAccessible
())
{
c
.
setAccessible
(
true
);
}
return
new
TypedValue
(
c
.
newInstance
(
arguments
),
Binding
Point
.
valueOf
(
c
.
getClass
()));
return
new
TypedValue
(
c
.
newInstance
(
arguments
),
Conversion
Point
.
valueOf
(
c
.
getClass
()));
}
catch
(
Exception
ex
)
{
throw
new
AccessException
(
"Problem invoking constructor: "
+
c
,
ex
);
}
...
...
org.springframework.expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodExecutor.java
浏览文件 @
46c9a003
...
...
@@ -19,7 +19,7 @@ package org.springframework.expression.spel.support;
import
java.lang.reflect.Method
;
import
org.springframework.core.MethodParameter
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
import
org.springframework.expression.AccessException
;
import
org.springframework.expression.EvaluationContext
;
import
org.springframework.expression.MethodExecutor
;
...
...
@@ -55,7 +55,7 @@ class ReflectiveMethodExecutor implements MethodExecutor {
arguments
=
ReflectionHelper
.
setupArgumentsForVarargsInvocation
(
this
.
method
.
getParameterTypes
(),
arguments
);
}
ReflectionUtils
.
makeAccessible
(
this
.
method
);
return
new
TypedValue
(
this
.
method
.
invoke
(
target
,
arguments
),
new
Binding
Point
(
new
MethodParameter
(
method
,-
1
)));
return
new
TypedValue
(
this
.
method
.
invoke
(
target
,
arguments
),
new
Conversion
Point
(
new
MethodParameter
(
method
,-
1
)));
}
catch
(
Exception
ex
)
{
throw
new
AccessException
(
"Problem invoking method: "
+
this
.
method
,
ex
);
}
...
...
org.springframework.expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyResolver.java
浏览文件 @
46c9a003
...
...
@@ -25,7 +25,7 @@ import java.util.Map;
import
java.util.concurrent.ConcurrentHashMap
;
import
org.springframework.core.MethodParameter
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
import
org.springframework.expression.AccessException
;
import
org.springframework.expression.EvaluationContext
;
import
org.springframework.expression.EvaluationException
;
...
...
@@ -48,7 +48,7 @@ public class ReflectivePropertyResolver implements PropertyAccessor {
protected
final
Map
<
CacheKey
,
Member
>
writerCache
=
new
ConcurrentHashMap
<
CacheKey
,
Member
>();
protected
final
Map
<
CacheKey
,
BindingPoint
>
typeDescriptorCache
=
new
ConcurrentHashMap
<
CacheKey
,
Binding
Point
>();
protected
final
Map
<
CacheKey
,
ConversionPoint
>
typeDescriptorCache
=
new
ConcurrentHashMap
<
CacheKey
,
Conversion
Point
>();
/**
* @return null which means this is a general purpose accessor
...
...
@@ -72,14 +72,14 @@ public class ReflectivePropertyResolver implements PropertyAccessor {
Method
method
=
findGetterForProperty
(
name
,
type
,
target
instanceof
Class
);
if
(
method
!=
null
)
{
this
.
readerCache
.
put
(
cacheKey
,
method
);
this
.
typeDescriptorCache
.
put
(
cacheKey
,
new
Binding
Point
(
new
MethodParameter
(
method
,-
1
)));
this
.
typeDescriptorCache
.
put
(
cacheKey
,
new
Conversion
Point
(
new
MethodParameter
(
method
,-
1
)));
return
true
;
}
else
{
Field
field
=
findField
(
name
,
type
,
target
instanceof
Class
);
if
(
field
!=
null
)
{
this
.
readerCache
.
put
(
cacheKey
,
field
);
this
.
typeDescriptorCache
.
put
(
cacheKey
,
new
Binding
Point
(
field
));
this
.
typeDescriptorCache
.
put
(
cacheKey
,
new
Conversion
Point
(
field
));
return
true
;
}
}
...
...
@@ -96,7 +96,7 @@ public class ReflectivePropertyResolver implements PropertyAccessor {
if
(
target
instanceof
Class
)
{
throw
new
AccessException
(
"Cannot access length on array class itself"
);
}
return
new
TypedValue
(
Array
.
getLength
(
target
),
Binding
Point
.
valueOf
(
Integer
.
TYPE
));
return
new
TypedValue
(
Array
.
getLength
(
target
),
Conversion
Point
.
valueOf
(
Integer
.
TYPE
));
}
CacheKey
cacheKey
=
new
CacheKey
(
type
,
name
);
...
...
@@ -114,7 +114,7 @@ public class ReflectivePropertyResolver implements PropertyAccessor {
if
(
method
!=
null
)
{
try
{
ReflectionUtils
.
makeAccessible
(
method
);
BindingPoint
resultTypeDescriptor
=
new
Binding
Point
(
new
MethodParameter
(
method
,-
1
));
ConversionPoint
resultTypeDescriptor
=
new
Conversion
Point
(
new
MethodParameter
(
method
,-
1
));
return
new
TypedValue
(
method
.
invoke
(
target
),
resultTypeDescriptor
);
}
catch
(
Exception
ex
)
{
...
...
@@ -135,7 +135,7 @@ public class ReflectivePropertyResolver implements PropertyAccessor {
if
(
field
!=
null
)
{
try
{
ReflectionUtils
.
makeAccessible
(
field
);
return
new
TypedValue
(
field
.
get
(
target
),
new
Binding
Point
(
field
));
return
new
TypedValue
(
field
.
get
(
target
),
new
Conversion
Point
(
field
));
}
catch
(
Exception
ex
)
{
throw
new
AccessException
(
"Unable to access field: "
+
name
,
ex
);
...
...
@@ -158,14 +158,14 @@ public class ReflectivePropertyResolver implements PropertyAccessor {
Method
method
=
findSetterForProperty
(
name
,
type
,
target
instanceof
Class
);
if
(
method
!=
null
)
{
this
.
writerCache
.
put
(
cacheKey
,
method
);
this
.
typeDescriptorCache
.
put
(
cacheKey
,
new
Binding
Point
(
new
MethodParameter
(
method
,
0
)));
this
.
typeDescriptorCache
.
put
(
cacheKey
,
new
Conversion
Point
(
new
MethodParameter
(
method
,
0
)));
return
true
;
}
else
{
Field
field
=
findField
(
name
,
type
,
target
instanceof
Class
);
if
(
field
!=
null
)
{
this
.
writerCache
.
put
(
cacheKey
,
field
);
this
.
typeDescriptorCache
.
put
(
cacheKey
,
new
Binding
Point
(
field
));
this
.
typeDescriptorCache
.
put
(
cacheKey
,
new
Conversion
Point
(
field
));
return
true
;
}
}
...
...
@@ -179,7 +179,7 @@ public class ReflectivePropertyResolver implements PropertyAccessor {
Class
<?>
type
=
(
target
instanceof
Class
?
(
Class
<?>)
target
:
target
.
getClass
());
Object
possiblyConvertedNewValue
=
newValue
;
Binding
Point
typeDescriptor
=
getTypeDescriptor
(
context
,
target
,
name
);
Conversion
Point
typeDescriptor
=
getTypeDescriptor
(
context
,
target
,
name
);
if
(
typeDescriptor
!=
null
)
{
try
{
possiblyConvertedNewValue
=
context
.
getTypeConverter
().
convertValue
(
newValue
,
typeDescriptor
);
...
...
@@ -236,17 +236,17 @@ public class ReflectivePropertyResolver implements PropertyAccessor {
throw
new
AccessException
(
"Neither setter nor field found for property '"
+
name
+
"'"
);
}
private
Binding
Point
getTypeDescriptor
(
EvaluationContext
context
,
Object
target
,
String
name
)
{
private
Conversion
Point
getTypeDescriptor
(
EvaluationContext
context
,
Object
target
,
String
name
)
{
if
(
target
==
null
)
{
return
null
;
}
Class
<?>
type
=
(
target
instanceof
Class
?
(
Class
<?>)
target
:
target
.
getClass
());
if
(
type
.
isArray
()
&&
name
.
equals
(
"length"
))
{
return
Binding
Point
.
valueOf
(
Integer
.
TYPE
);
return
Conversion
Point
.
valueOf
(
Integer
.
TYPE
);
}
CacheKey
cacheKey
=
new
CacheKey
(
type
,
name
);
Binding
Point
typeDescriptor
=
this
.
typeDescriptorCache
.
get
(
cacheKey
);
Conversion
Point
typeDescriptor
=
this
.
typeDescriptorCache
.
get
(
cacheKey
);
if
(
typeDescriptor
==
null
)
{
// attempt to populate the cache entry
try
{
...
...
org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java
浏览文件 @
46c9a003
...
...
@@ -22,7 +22,7 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.Map
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
import
org.springframework.expression.ConstructorResolver
;
import
org.springframework.expression.EvaluationContext
;
import
org.springframework.expression.MethodResolver
;
...
...
@@ -75,10 +75,10 @@ public class StandardEvaluationContext implements EvaluationContext {
}
public
void
setRootObject
(
Object
rootObject
)
{
this
.
rootObject
=
new
TypedValue
(
rootObject
,
Binding
Point
.
forObject
(
rootObject
));
this
.
rootObject
=
new
TypedValue
(
rootObject
,
Conversion
Point
.
forObject
(
rootObject
));
}
public
void
setRootObject
(
Object
rootObject
,
Binding
Point
typeDescriptor
)
{
public
void
setRootObject
(
Object
rootObject
,
Conversion
Point
typeDescriptor
)
{
this
.
rootObject
=
new
TypedValue
(
rootObject
,
typeDescriptor
);
}
...
...
org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java
浏览文件 @
46c9a003
...
...
@@ -18,7 +18,7 @@ package org.springframework.expression.spel.support;
import
org.springframework.core.convert.ConvertException
;
import
org.springframework.core.convert.ConverterNotFoundException
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
import
org.springframework.core.convert.support.DefaultTypeConverter
;
import
org.springframework.expression.EvaluationException
;
import
org.springframework.expression.TypeConverter
;
...
...
@@ -46,11 +46,11 @@ public class StandardTypeConverter implements TypeConverter {
@SuppressWarnings
(
"unchecked"
)
public
<
T
>
T
convertValue
(
Object
value
,
Class
<
T
>
targetType
)
throws
EvaluationException
{
return
(
T
)
convertValue
(
value
,
Binding
Point
.
valueOf
(
targetType
));
return
(
T
)
convertValue
(
value
,
Conversion
Point
.
valueOf
(
targetType
));
}
@SuppressWarnings
(
"unchecked"
)
public
Object
convertValue
(
Object
value
,
Binding
Point
typeDescriptor
)
throws
EvaluationException
{
public
Object
convertValue
(
Object
value
,
Conversion
Point
typeDescriptor
)
throws
EvaluationException
{
try
{
return
this
.
typeConverter
.
convert
(
value
,
typeDescriptor
);
}
...
...
@@ -63,10 +63,10 @@ public class StandardTypeConverter implements TypeConverter {
}
public
boolean
canConvert
(
Class
<?>
sourceType
,
Class
<?>
targetType
)
{
return
canConvert
(
sourceType
,
Binding
Point
.
valueOf
(
targetType
));
return
canConvert
(
sourceType
,
Conversion
Point
.
valueOf
(
targetType
));
}
public
boolean
canConvert
(
Class
<?>
sourceType
,
Binding
Point
targetType
)
{
public
boolean
canConvert
(
Class
<?>
sourceType
,
Conversion
Point
targetType
)
{
return
this
.
typeConverter
.
canConvert
(
sourceType
,
targetType
);
}
...
...
org.springframework.expression/src/test/java/org/springframework/expression/spel/ExpressionLanguageScenarioTests.java
浏览文件 @
46c9a003
...
...
@@ -23,7 +23,7 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.Map
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
import
org.springframework.expression.AccessException
;
import
org.springframework.expression.EvaluationContext
;
import
org.springframework.expression.EvaluationException
;
...
...
@@ -236,7 +236,7 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
private
static
class
FruitColourAccessor
implements
PropertyAccessor
{
private
static
Map
<
String
,
Color
>
propertyMap
=
new
HashMap
<
String
,
Color
>();
private
static
BindingPoint
mapElementTypeDescriptor
=
Binding
Point
.
valueOf
(
Color
.
class
);
private
static
ConversionPoint
mapElementTypeDescriptor
=
Conversion
Point
.
valueOf
(
Color
.
class
);
static
{
propertyMap
.
put
(
"banana"
,
Color
.
yellow
);
...
...
@@ -295,7 +295,7 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
}
public
TypedValue
read
(
EvaluationContext
context
,
Object
target
,
String
name
)
throws
AccessException
{
return
new
TypedValue
(
propertyMap
.
get
(
name
),
Binding
Point
.
valueOf
(
Color
.
class
));
return
new
TypedValue
(
propertyMap
.
get
(
name
),
Conversion
Point
.
valueOf
(
Color
.
class
));
}
public
boolean
canWrite
(
EvaluationContext
context
,
Object
target
,
String
name
)
throws
AccessException
{
...
...
org.springframework.expression/src/test/java/org/springframework/expression/spel/ExpressionStateTests.java
浏览文件 @
46c9a003
...
...
@@ -18,7 +18,7 @@ package org.springframework.expression.spel;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
import
org.springframework.expression.EvaluationContext
;
import
org.springframework.expression.EvaluationException
;
import
org.springframework.expression.Operation
;
...
...
@@ -117,7 +117,7 @@ public class ExpressionStateTests extends ExpressionTestCase {
assertEquals
(
TypedValue
.
NULL_TYPED_VALUE
,
state
.
getRootContextObject
());
((
StandardEvaluationContext
)
state
.
getEvaluationContext
()).
setRootObject
(
null
,
BindingPoint
.
NULL_TYPE_DESCRIPTOR
);
((
StandardEvaluationContext
)
state
.
getEvaluationContext
()).
setRootObject
(
null
,
ConversionPoint
.
NULL
);
assertEquals
(
null
,
state
.
getRootContextObject
().
getValue
());
}
...
...
@@ -222,10 +222,10 @@ public class ExpressionStateTests extends ExpressionTestCase {
public
void
testTypeConversion
()
throws
EvaluationException
{
ExpressionState
state
=
getState
();
String
s
=
(
String
)
state
.
convertValue
(
34
,
Binding
Point
.
valueOf
(
String
.
class
));
String
s
=
(
String
)
state
.
convertValue
(
34
,
Conversion
Point
.
valueOf
(
String
.
class
));
assertEquals
(
"34"
,
s
);
s
=
(
String
)
state
.
convertValue
(
new
TypedValue
(
34
),
Binding
Point
.
valueOf
(
String
.
class
));
s
=
(
String
)
state
.
convertValue
(
new
TypedValue
(
34
),
Conversion
Point
.
valueOf
(
String
.
class
));
assertEquals
(
"34"
,
s
);
}
...
...
org.springframework.expression/src/test/java/org/springframework/expression/spel/ExpressionTestsUsingCoreConversionService.java
浏览文件 @
46c9a003
...
...
@@ -19,7 +19,7 @@ package org.springframework.expression.spel;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
import
org.springframework.core.convert.support.DefaultTypeConverter
;
import
org.springframework.core.convert.support.GenericTypeConverter
;
import
org.springframework.expression.EvaluationException
;
...
...
@@ -35,9 +35,9 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
public
class
ExpressionTestsUsingCoreConversionService
extends
ExpressionTestCase
{
private
static
List
<
String
>
listOfString
=
new
ArrayList
<
String
>();
private
static
Binding
Point
typeDescriptorForListOfString
=
null
;
private
static
Conversion
Point
typeDescriptorForListOfString
=
null
;
private
static
List
<
Integer
>
listOfInteger
=
new
ArrayList
<
Integer
>();
private
static
Binding
Point
typeDescriptorForListOfInteger
=
null
;
private
static
Conversion
Point
typeDescriptorForListOfInteger
=
null
;
static
{
listOfString
.
add
(
"1"
);
...
...
@@ -50,8 +50,8 @@ public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCas
public
void
setUp
()
throws
Exception
{
super
.
setUp
();
typeDescriptorForListOfString
=
new
Binding
Point
(
ExpressionTestsUsingCoreConversionService
.
class
.
getDeclaredField
(
"listOfString"
));
typeDescriptorForListOfInteger
=
new
Binding
Point
(
ExpressionTestsUsingCoreConversionService
.
class
.
getDeclaredField
(
"listOfInteger"
));
typeDescriptorForListOfString
=
new
Conversion
Point
(
ExpressionTestsUsingCoreConversionService
.
class
.
getDeclaredField
(
"listOfString"
));
typeDescriptorForListOfInteger
=
new
Conversion
Point
(
ExpressionTestsUsingCoreConversionService
.
class
.
getDeclaredField
(
"listOfInteger"
));
}
...
...
@@ -96,20 +96,20 @@ public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCas
private
final
DefaultTypeConverter
service
=
new
DefaultTypeConverter
();
public
boolean
canConvert
(
Class
<?>
sourceType
,
Class
<?>
targetType
)
{
return
this
.
service
.
canConvert
(
sourceType
,
Binding
Point
.
valueOf
(
targetType
));
return
this
.
service
.
canConvert
(
sourceType
,
Conversion
Point
.
valueOf
(
targetType
));
}
public
boolean
canConvert
(
Class
<?>
sourceType
,
Binding
Point
typeDescriptor
)
{
public
boolean
canConvert
(
Class
<?>
sourceType
,
Conversion
Point
typeDescriptor
)
{
return
this
.
service
.
canConvert
(
sourceType
,
typeDescriptor
);
}
@SuppressWarnings
(
"unchecked"
)
public
<
T
>
T
convertValue
(
Object
value
,
Class
<
T
>
targetType
)
throws
EvaluationException
{
return
(
T
)
this
.
service
.
convert
(
value
,
Binding
Point
.
valueOf
(
targetType
));
return
(
T
)
this
.
service
.
convert
(
value
,
Conversion
Point
.
valueOf
(
targetType
));
}
@SuppressWarnings
(
"unchecked"
)
public
Object
convertValue
(
Object
value
,
Binding
Point
typeDescriptor
)
throws
EvaluationException
{
public
Object
convertValue
(
Object
value
,
Conversion
Point
typeDescriptor
)
throws
EvaluationException
{
return
this
.
service
.
convert
(
value
,
typeDescriptor
);
}
}
...
...
org.springframework.expression/src/test/java/org/springframework/expression/spel/ScenariosForSpringSecurity.java
浏览文件 @
46c9a003
...
...
@@ -19,7 +19,7 @@ package org.springframework.expression.spel;
import
java.lang.reflect.Method
;
import
org.springframework.core.MethodParameter
;
import
org.springframework.core.convert.
Binding
Point
;
import
org.springframework.core.convert.
Conversion
Point
;
import
org.springframework.expression.AccessException
;
import
org.springframework.expression.EvaluationContext
;
import
org.springframework.expression.EvaluationException
;
...
...
@@ -214,7 +214,7 @@ public class ScenariosForSpringSecurity extends ExpressionTestCase {
}
public
TypedValue
read
(
EvaluationContext
context
,
Object
target
,
String
name
)
throws
AccessException
{
return
new
TypedValue
(
new
Principal
(),
Binding
Point
.
valueOf
(
Principal
.
class
));
return
new
TypedValue
(
new
Principal
(),
Conversion
Point
.
valueOf
(
Principal
.
class
));
}
public
boolean
canWrite
(
EvaluationContext
context
,
Object
target
,
String
name
)
throws
AccessException
{
...
...
@@ -244,7 +244,7 @@ public class ScenariosForSpringSecurity extends ExpressionTestCase {
}
public
TypedValue
read
(
EvaluationContext
context
,
Object
target
,
String
name
)
throws
AccessException
{
return
new
TypedValue
(
activePerson
,
Binding
Point
.
valueOf
(
Person
.
class
));
return
new
TypedValue
(
activePerson
,
Conversion
Point
.
valueOf
(
Person
.
class
));
}
public
boolean
canWrite
(
EvaluationContext
context
,
Object
target
,
String
name
)
throws
AccessException
{
...
...
@@ -283,7 +283,7 @@ public class ScenariosForSpringSecurity extends ExpressionTestCase {
if
(
m
.
isVarArgs
())
{
args
=
ReflectionHelper
.
setupArgumentsForVarargsInvocation
(
m
.
getParameterTypes
(),
args
);
}
return
new
TypedValue
(
m
.
invoke
(
null
,
args
),
new
Binding
Point
(
new
MethodParameter
(
m
,-
1
)));
return
new
TypedValue
(
m
.
invoke
(
null
,
args
),
new
Conversion
Point
(
new
MethodParameter
(
m
,-
1
)));
}
catch
(
Exception
ex
)
{
throw
new
AccessException
(
"Problem invoking hasRole"
,
ex
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录