Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
b9ebdd28
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,发现更多精彩内容 >>
提交
b9ebdd28
编写于
8月 12, 2011
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
polishing
上级
c97257b1
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
66 addition
and
66 deletion
+66
-66
org.springframework.context/src/main/java/org/springframework/format/FormatterRegistry.java
...in/java/org/springframework/format/FormatterRegistry.java
+1
-0
org.springframework.context/src/main/java/org/springframework/format/support/FormattingConversionService.java
...framework/format/support/FormattingConversionService.java
+13
-8
org.springframework.context/src/main/java/org/springframework/format/support/FormattingConversionServiceFactoryBean.java
...ormat/support/FormattingConversionServiceFactoryBean.java
+42
-49
org.springframework.context/src/test/java/org/springframework/format/support/FormattingConversionServiceFactoryBeanTests.java
.../support/FormattingConversionServiceFactoryBeanTests.java
+8
-8
org.springframework.transaction/src/main/java/org/springframework/transaction/support/DefaultTransactionStatus.java
...amework/transaction/support/DefaultTransactionStatus.java
+2
-1
未找到文件。
org.springframework.context/src/main/java/org/springframework/format/FormatterRegistry.java
浏览文件 @
b9ebdd28
...
@@ -34,6 +34,7 @@ public interface FormatterRegistry extends ConverterRegistry {
...
@@ -34,6 +34,7 @@ public interface FormatterRegistry extends ConverterRegistry {
* The field type is implied by the parameterized Formatter instance.
* The field type is implied by the parameterized Formatter instance.
* @param formatter the formatter to add
* @param formatter the formatter to add
* @see #addFormatterForFieldType(Class, Formatter)
* @see #addFormatterForFieldType(Class, Formatter)
* @since 3.1
*/
*/
void
addFormatter
(
Formatter
<?>
formatter
);
void
addFormatter
(
Formatter
<?>
formatter
);
...
...
org.springframework.context/src/main/java/org/springframework/format/support/FormattingConversionService.java
浏览文件 @
b9ebdd28
...
@@ -65,10 +65,10 @@ public class FormattingConversionService extends GenericConversionService
...
@@ -65,10 +65,10 @@ public class FormattingConversionService extends GenericConversionService
public
void
addFormatter
(
Formatter
<?>
formatter
)
{
public
void
addFormatter
(
Formatter
<?>
formatter
)
{
final
Class
<?>
fieldType
=
GenericTypeResolver
.
resolveTypeArgument
(
formatter
.
getClass
(),
Formatter
.
class
);
Class
<?>
fieldType
=
GenericTypeResolver
.
resolveTypeArgument
(
formatter
.
getClass
(),
Formatter
.
class
);
if
(
fieldType
==
null
)
{
if
(
fieldType
==
null
)
{
throw
new
IllegalArgumentException
(
"Unable to extract parameterized field type argument from Formatter ["
throw
new
IllegalArgumentException
(
"Unable to extract parameterized field type argument from Formatter ["
+
+
formatter
.
getClass
().
getName
()
+
"]; does the formatter parameterize the <T> generic type?"
);
formatter
.
getClass
().
getName
()
+
"]; does the formatter parameterize the <T> generic type?"
);
}
}
addFormatterForFieldType
(
fieldType
,
formatter
);
addFormatterForFieldType
(
fieldType
,
formatter
);
}
}
...
@@ -84,7 +84,7 @@ public class FormattingConversionService extends GenericConversionService
...
@@ -84,7 +84,7 @@ public class FormattingConversionService extends GenericConversionService
}
}
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
public
void
addFormatterForFieldAnnotation
(
final
AnnotationFormatterFactory
annotationFormatterFactory
)
{
public
void
addFormatterForFieldAnnotation
(
AnnotationFormatterFactory
annotationFormatterFactory
)
{
final
Class
<?
extends
Annotation
>
annotationType
=
(
Class
<?
extends
Annotation
>)
final
Class
<?
extends
Annotation
>
annotationType
=
(
Class
<?
extends
Annotation
>)
GenericTypeResolver
.
resolveTypeArgument
(
annotationFormatterFactory
.
getClass
(),
AnnotationFormatterFactory
.
class
);
GenericTypeResolver
.
resolveTypeArgument
(
annotationFormatterFactory
.
getClass
(),
AnnotationFormatterFactory
.
class
);
if
(
annotationType
==
null
)
{
if
(
annotationType
==
null
)
{
...
@@ -101,6 +101,7 @@ public class FormattingConversionService extends GenericConversionService
...
@@ -101,6 +101,7 @@ public class FormattingConversionService extends GenericConversionService
}
}
}
}
private
static
class
PrinterConverter
implements
GenericConverter
{
private
static
class
PrinterConverter
implements
GenericConverter
{
private
Class
<?>
fieldType
;
private
Class
<?>
fieldType
;
...
@@ -143,6 +144,7 @@ public class FormattingConversionService extends GenericConversionService
...
@@ -143,6 +144,7 @@ public class FormattingConversionService extends GenericConversionService
}
}
}
}
private
static
class
ParserConverter
implements
GenericConverter
{
private
static
class
ParserConverter
implements
GenericConverter
{
private
Class
<?>
fieldType
;
private
Class
<?>
fieldType
;
...
@@ -188,7 +190,8 @@ public class FormattingConversionService extends GenericConversionService
...
@@ -188,7 +190,8 @@ public class FormattingConversionService extends GenericConversionService
}
}
}
}
private
final
class
AnnotationPrinterConverter
implements
ConditionalGenericConverter
{
private
class
AnnotationPrinterConverter
implements
ConditionalGenericConverter
{
private
Class
<?
extends
Annotation
>
annotationType
;
private
Class
<?
extends
Annotation
>
annotationType
;
...
@@ -227,7 +230,8 @@ public class FormattingConversionService extends GenericConversionService
...
@@ -227,7 +230,8 @@ public class FormattingConversionService extends GenericConversionService
}
}
}
}
private
final
class
AnnotationParserConverter
implements
ConditionalGenericConverter
{
private
class
AnnotationParserConverter
implements
ConditionalGenericConverter
{
private
Class
<?
extends
Annotation
>
annotationType
;
private
Class
<?
extends
Annotation
>
annotationType
;
...
@@ -265,8 +269,9 @@ public class FormattingConversionService extends GenericConversionService
...
@@ -265,8 +269,9 @@ public class FormattingConversionService extends GenericConversionService
return
String
.
class
.
getName
()
+
" -> @"
+
annotationType
.
getName
()
+
" "
+
fieldType
.
getName
()
+
": "
+
annotationFormatterFactory
;
return
String
.
class
.
getName
()
+
" -> @"
+
annotationType
.
getName
()
+
" "
+
fieldType
.
getName
()
+
": "
+
annotationFormatterFactory
;
}
}
}
}
private
static
final
class
AnnotationConverterKey
{
private
static
class
AnnotationConverterKey
{
private
final
Annotation
annotation
;
private
final
Annotation
annotation
;
...
...
org.springframework.context/src/main/java/org/springframework/format/support/FormattingConversionServiceFactoryBean.java
浏览文件 @
b9ebdd28
...
@@ -69,18 +69,19 @@ public class FormattingConversionServiceFactoryBean
...
@@ -69,18 +69,19 @@ public class FormattingConversionServiceFactoryBean
private
Set
<
FormatterRegistrar
>
formatterRegistrars
;
private
Set
<
FormatterRegistrar
>
formatterRegistrars
;
private
FormattingConversionService
conversionServic
e
;
private
boolean
registerDefaultFormatters
=
tru
e
;
private
StringValueResolver
embeddedValueResolver
;
private
StringValueResolver
embeddedValueResolver
;
private
boolean
registerDefaultFormatters
=
true
;
private
FormattingConversionService
conversionService
;
/**
/**
* Configure the set of custom converter objects that should be added.
* Configure the set of custom converter objects that should be added.
* @param converters instances of any of the following:
* @param converters instances of any of the following:
*
{@link org.springframework.core.convert.converter.Converter},
* {@link org.springframework.core.convert.converter.Converter},
*
{@link org.springframework.core.convert.converter.ConverterFactory},
* {@link org.springframework.core.convert.converter.ConverterFactory},
*
{@link org.springframework.core.convert.converter.GenericConverter}.
*
{@link org.springframework.core.convert.converter.GenericConverter}
*/
*/
public
void
setConverters
(
Set
<?>
converters
)
{
public
void
setConverters
(
Set
<?>
converters
)
{
this
.
converters
=
converters
;
this
.
converters
=
converters
;
...
@@ -88,8 +89,7 @@ public class FormattingConversionServiceFactoryBean
...
@@ -88,8 +89,7 @@ public class FormattingConversionServiceFactoryBean
/**
/**
* Configure the set of custom formatter objects that should be added.
* Configure the set of custom formatter objects that should be added.
* @param formatters instances of {@link Formatter} or
* @param formatters instances of {@link Formatter} or {@link AnnotationFormatterFactory}
* {@link AnnotationFormatterFactory}.
*/
*/
public
void
setFormatters
(
Set
<?>
formatters
)
{
public
void
setFormatters
(
Set
<?>
formatters
)
{
this
.
formatters
=
formatters
;
this
.
formatters
=
formatters
;
...
@@ -113,14 +113,10 @@ public class FormattingConversionServiceFactoryBean
...
@@ -113,14 +113,10 @@ public class FormattingConversionServiceFactoryBean
this
.
formatterRegistrars
=
formatterRegistrars
;
this
.
formatterRegistrars
=
formatterRegistrars
;
}
}
public
void
setEmbeddedValueResolver
(
StringValueResolver
embeddedValueResolver
)
{
this
.
embeddedValueResolver
=
embeddedValueResolver
;
}
/**
/**
* Indicate
s whether default formatters should be registered or not. By
* Indicate
whether default formatters should be registered or not.
*
default built-in formatters are registered. This flag can be used to
*
<p>By default, built-in formatters are registered. This flag can be used
* turn that off and rely on explicitly registered formatters only.
* t
o t
urn that off and rely on explicitly registered formatters only.
* @see #setFormatters(Set)
* @see #setFormatters(Set)
* @see #setFormatterRegistrars(Set)
* @see #setFormatterRegistrars(Set)
*/
*/
...
@@ -128,8 +124,10 @@ public class FormattingConversionServiceFactoryBean
...
@@ -128,8 +124,10 @@ public class FormattingConversionServiceFactoryBean
this
.
registerDefaultFormatters
=
registerDefaultFormatters
;
this
.
registerDefaultFormatters
=
registerDefaultFormatters
;
}
}
public
void
setEmbeddedValueResolver
(
StringValueResolver
embeddedValueResolver
)
{
this
.
embeddedValueResolver
=
embeddedValueResolver
;
}
// implementing InitializingBean
public
void
afterPropertiesSet
()
{
public
void
afterPropertiesSet
()
{
this
.
conversionService
=
new
DefaultFormattingConversionService
(
this
.
embeddedValueResolver
,
this
.
registerDefaultFormatters
);
this
.
conversionService
=
new
DefaultFormattingConversionService
(
this
.
embeddedValueResolver
,
this
.
registerDefaultFormatters
);
...
@@ -137,46 +135,16 @@ public class FormattingConversionServiceFactoryBean
...
@@ -137,46 +135,16 @@ public class FormattingConversionServiceFactoryBean
registerFormatters
();
registerFormatters
();
}
}
// implementing FactoryBean
public
FormattingConversionService
getObject
()
{
return
this
.
conversionService
;
}
public
Class
<?
extends
FormattingConversionService
>
getObjectType
()
{
return
FormattingConversionService
.
class
;
}
public
boolean
isSingleton
()
{
return
true
;
}
// subclassing hooks
/**
* Subclasses may override this method to register formatters and/or converters.
* Starting with Spring 3.1 however the recommended way of doing that is to
* through FormatterRegistrars.
* @see #setFormatters(Set)
* @see #setFormatterRegistrars(Set)
* @deprecated since Spring 3.1 in favor of {@link #setFormatterRegistrars(Set)}
*/
@Deprecated
protected
void
installFormatters
(
FormatterRegistry
registry
)
{
}
// private helper methods
private
void
registerFormatters
()
{
private
void
registerFormatters
()
{
if
(
this
.
formatters
!=
null
)
{
if
(
this
.
formatters
!=
null
)
{
for
(
Object
formatter
:
this
.
formatters
)
{
for
(
Object
formatter
:
this
.
formatters
)
{
if
(
formatter
instanceof
Formatter
<?>)
{
if
(
formatter
instanceof
Formatter
<?>)
{
this
.
conversionService
.
addFormatter
((
Formatter
<?>)
formatter
);
this
.
conversionService
.
addFormatter
((
Formatter
<?>)
formatter
);
}
else
if
(
formatter
instanceof
AnnotationFormatterFactory
<?>)
{
}
else
if
(
formatter
instanceof
AnnotationFormatterFactory
<?>)
{
this
.
conversionService
.
addFormatterForFieldAnnotation
((
AnnotationFormatterFactory
<?>)
formatter
);
this
.
conversionService
.
addFormatterForFieldAnnotation
((
AnnotationFormatterFactory
<?>)
formatter
);
}
else
{
}
else
{
throw
new
IllegalArgumentException
(
throw
new
IllegalArgumentException
(
"Custom formatters must be implementations of Formatter or AnnotationFormatterFactory"
);
"Custom formatters must be implementations of Formatter or AnnotationFormatterFactory"
);
}
}
...
@@ -190,4 +158,29 @@ public class FormattingConversionServiceFactoryBean
...
@@ -190,4 +158,29 @@ public class FormattingConversionServiceFactoryBean
installFormatters
(
this
.
conversionService
);
installFormatters
(
this
.
conversionService
);
}
}
/**
* Subclasses may override this method to register formatters and/or converters.
* Starting with Spring 3.1 however the recommended way of doing that is to
* through FormatterRegistrars.
* @see #setFormatters(Set)
* @see #setFormatterRegistrars(Set)
* @deprecated since Spring 3.1 in favor of {@link #setFormatterRegistrars(Set)}
*/
@Deprecated
protected
void
installFormatters
(
FormatterRegistry
registry
)
{
}
public
FormattingConversionService
getObject
()
{
return
this
.
conversionService
;
}
public
Class
<?
extends
FormattingConversionService
>
getObjectType
()
{
return
FormattingConversionService
.
class
;
}
public
boolean
isSingleton
()
{
return
true
;
}
}
}
org.springframework.context/src/test/java/org/springframework/format/support/FormattingConversionServiceFactoryBeanTests.java
浏览文件 @
b9ebdd28
...
@@ -15,10 +15,6 @@
...
@@ -15,10 +15,6 @@
*/
*/
package
org.springframework.format.support
;
package
org.springframework.format.support
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
fail
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.RetentionPolicy
;
...
@@ -29,6 +25,7 @@ import java.util.Locale;
...
@@ -29,6 +25,7 @@ import java.util.Locale;
import
java.util.Set
;
import
java.util.Set
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.springframework.core.convert.ConversionFailedException
;
import
org.springframework.core.convert.ConversionFailedException
;
import
org.springframework.core.convert.TypeDescriptor
;
import
org.springframework.core.convert.TypeDescriptor
;
import
org.springframework.format.AnnotationFormatterFactory
;
import
org.springframework.format.AnnotationFormatterFactory
;
...
@@ -40,8 +37,9 @@ import org.springframework.format.Printer;
...
@@ -40,8 +37,9 @@ import org.springframework.format.Printer;
import
org.springframework.format.annotation.NumberFormat
;
import
org.springframework.format.annotation.NumberFormat
;
import
org.springframework.format.annotation.NumberFormat.Style
;
import
org.springframework.format.annotation.NumberFormat.Style
;
import
static
org
.
junit
.
Assert
.*;
/**
/**
* Test fixture for FormattingConversionServiceFactoryBean.
* @author Rossen Stoyanchev
* @author Rossen Stoyanchev
*/
*/
public
class
FormattingConversionServiceFactoryBeanTests
{
public
class
FormattingConversionServiceFactoryBeanTests
{
...
@@ -68,8 +66,9 @@ public class FormattingConversionServiceFactoryBeanTests {
...
@@ -68,8 +66,9 @@ public class FormattingConversionServiceFactoryBeanTests {
try
{
try
{
fcs
.
convert
(
"5%"
,
TypeDescriptor
.
valueOf
(
String
.
class
),
descriptor
);
fcs
.
convert
(
"5%"
,
TypeDescriptor
.
valueOf
(
String
.
class
),
descriptor
);
fail
(
"This format should not be parseable"
);
fail
(
"This format should not be parseable"
);
}
catch
(
ConversionFailedException
e
)
{
}
assertTrue
(
e
.
getCause
()
instanceof
NumberFormatException
);
catch
(
ConversionFailedException
ex
)
{
assertTrue
(
ex
.
getCause
()
instanceof
NumberFormatException
);
}
}
}
}
...
@@ -117,7 +116,8 @@ public class FormattingConversionServiceFactoryBeanTests {
...
@@ -117,7 +116,8 @@ public class FormattingConversionServiceFactoryBeanTests {
try
{
try
{
factory
.
afterPropertiesSet
();
factory
.
afterPropertiesSet
();
fail
(
"Expected formatter to be rejected"
);
fail
(
"Expected formatter to be rejected"
);
}
catch
(
IllegalArgumentException
e
)
{
}
catch
(
IllegalArgumentException
ex
)
{
// expected
// expected
}
}
}
}
...
...
org.springframework.transaction/src/main/java/org/springframework/transaction/support/DefaultTransactionStatus.java
浏览文件 @
b9ebdd28
/*
/*
* Copyright 2002-20
09
the original author or authors.
* Copyright 2002-20
11
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -161,6 +161,7 @@ public class DefaultTransactionStatus extends AbstractTransactionStatus {
...
@@ -161,6 +161,7 @@ public class DefaultTransactionStatus extends AbstractTransactionStatus {
* Delegate the flushing to the transaction object,
* Delegate the flushing to the transaction object,
* provided that the latter implements the {@link SmartTransactionObject} interface.
* provided that the latter implements the {@link SmartTransactionObject} interface.
*/
*/
@Override
public
void
flush
()
{
public
void
flush
()
{
if
(
this
.
transaction
instanceof
SmartTransactionObject
)
{
if
(
this
.
transaction
instanceof
SmartTransactionObject
)
{
((
SmartTransactionObject
)
this
.
transaction
).
flush
();
((
SmartTransactionObject
)
this
.
transaction
).
flush
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录