Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
chenpeng_fei
spring-framework
提交
d9f8ee88
S
spring-framework
项目概览
chenpeng_fei
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
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,发现更多精彩内容 >>
提交
d9f8ee88
编写于
5月 27, 2014
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Introduced EmbeddedValueResolutionSupport base class for AnnotationFormatterFactory implementations
上级
8f2ed66b
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
75 addition
and
94 deletion
+75
-94
spring-context/src/main/java/org/springframework/context/support/EmbeddedValueResolutionSupport.java
...ework/context/support/EmbeddedValueResolutionSupport.java
+50
-0
spring-context/src/main/java/org/springframework/format/datetime/DateTimeFormatAnnotationFormatterFactory.java
...at/datetime/DateTimeFormatAnnotationFormatterFactory.java
+5
-17
spring-context/src/main/java/org/springframework/format/datetime/joda/JodaDateTimeFormatAnnotationFormatterFactory.java
...me/joda/JodaDateTimeFormatAnnotationFormatterFactory.java
+5
-18
spring-context/src/main/java/org/springframework/format/datetime/standard/Jsr310DateTimeFormatAnnotationFormatterFactory.java
...ndard/Jsr310DateTimeFormatAnnotationFormatterFactory.java
+7
-20
spring-context/src/main/java/org/springframework/format/number/NumberFormatAnnotationFormatterFactory.java
...format/number/NumberFormatAnnotationFormatterFactory.java
+8
-39
未找到文件。
spring-context/src/main/java/org/springframework/context/support/EmbeddedValueResolutionSupport.java
0 → 100644
浏览文件 @
d9f8ee88
/*
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.context.support
;
import
org.springframework.context.EmbeddedValueResolverAware
;
import
org.springframework.util.StringValueResolver
;
/**
* Convenient base class for components with a need for embedded value resolution
* (i.e. {@link org.springframework.context.EmbeddedValueResolverAware} consumers).
*
* @author Juergen Hoeller
* @since 4.1
*/
public
class
EmbeddedValueResolutionSupport
implements
EmbeddedValueResolverAware
{
private
StringValueResolver
embeddedValueResolver
;
@Override
public
void
setEmbeddedValueResolver
(
StringValueResolver
resolver
)
{
this
.
embeddedValueResolver
=
resolver
;
}
/**
* Resolve the given embedded value through this instance's {@link StringValueResolver}.
* @param value the value to resolve
* @return the resolved value, or always the original value if no resolver is available
* @see #setEmbeddedValueResolver
*/
protected
String
resolveEmbeddedValue
(
String
value
)
{
return
(
this
.
embeddedValueResolver
!=
null
?
this
.
embeddedValueResolver
.
resolveStringValue
(
value
)
:
value
);
}
}
spring-context/src/main/java/org/springframework/format/datetime/DateTimeFormatAnnotationFormatterFactory.java
浏览文件 @
d9f8ee88
/*
* Copyright 2002-201
3
the original author or authors.
* Copyright 2002-201
4
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -22,13 +22,12 @@ import java.util.Date;
import
java.util.HashSet
;
import
java.util.Set
;
import
org.springframework.context.
EmbeddedValueResolverAware
;
import
org.springframework.context.
support.EmbeddedValueResolutionSupport
;
import
org.springframework.format.AnnotationFormatterFactory
;
import
org.springframework.format.Formatter
;
import
org.springframework.format.Parser
;
import
org.springframework.format.Printer
;
import
org.springframework.format.annotation.DateTimeFormat
;
import
org.springframework.util.StringValueResolver
;
/**
* Formats fields annotated with the {@link DateTimeFormat} annotation using
...
...
@@ -38,11 +37,12 @@ import org.springframework.util.StringValueResolver;
* @since 3.2
* @see org.springframework.format.datetime.joda.JodaDateTimeFormatAnnotationFormatterFactory
*/
public
class
DateTimeFormatAnnotationFormatterFactory
implements
AnnotationFormatterFactory
<
DateTimeFormat
>,
EmbeddedValueResolverAware
{
public
class
DateTimeFormatAnnotationFormatterFactory
extends
EmbeddedValueResolutionSupport
implements
AnnotationFormatterFactory
<
DateTimeFormat
>
{
private
static
final
Set
<
Class
<?>>
FIELD_TYPES
;
static
{
Set
<
Class
<?>>
fieldTypes
=
new
HashSet
<
Class
<?>>(
4
);
fieldTypes
.
add
(
Date
.
class
);
...
...
@@ -52,14 +52,6 @@ public class DateTimeFormatAnnotationFormatterFactory implements
}
private
StringValueResolver
embeddedValueResolver
;
@Override
public
void
setEmbeddedValueResolver
(
StringValueResolver
resolver
)
{
this
.
embeddedValueResolver
=
resolver
;
}
@Override
public
Set
<
Class
<?>>
getFieldTypes
()
{
return
FIELD_TYPES
;
...
...
@@ -83,8 +75,4 @@ public class DateTimeFormatAnnotationFormatterFactory implements
return
formatter
;
}
protected
String
resolveEmbeddedValue
(
String
value
)
{
return
(
this
.
embeddedValueResolver
!=
null
?
this
.
embeddedValueResolver
.
resolveStringValue
(
value
)
:
value
);
}
}
spring-context/src/main/java/org/springframework/format/datetime/joda/JodaDateTimeFormatAnnotationFormatterFactory.java
浏览文件 @
d9f8ee88
/*
* Copyright 2002-201
3
the original author or authors.
* Copyright 2002-201
4
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -29,12 +29,11 @@ import org.joda.time.ReadableInstant;
import
org.joda.time.ReadablePartial
;
import
org.joda.time.format.DateTimeFormatter
;
import
org.springframework.context.
EmbeddedValueResolverAware
;
import
org.springframework.context.
support.EmbeddedValueResolutionSupport
;
import
org.springframework.format.AnnotationFormatterFactory
;
import
org.springframework.format.Parser
;
import
org.springframework.format.Printer
;
import
org.springframework.format.annotation.DateTimeFormat
;
import
org.springframework.util.StringValueResolver
;
/**
* Formats fields annotated with the {@link DateTimeFormat} annotation using Joda-Time.
...
...
@@ -46,10 +45,11 @@ import org.springframework.util.StringValueResolver;
* @since 3.0
* @see DateTimeFormat
*/
public
class
JodaDateTimeFormatAnnotationFormatterFactory
implements
AnnotationFormatterFactory
<
DateTimeFormat
>
,
EmbeddedValueResolverAware
{
public
class
JodaDateTimeFormatAnnotationFormatterFactory
extends
EmbeddedValueResolutionSupport
implements
AnnotationFormatterFactory
<
DateTimeFormat
>
{
private
static
final
Set
<
Class
<?>>
FIELD_TYPES
;
static
{
// Create the set of field types that may be annotated with @DateTimeFormat.
// Note: the 3 ReadablePartial concrete types are registered explicitly since
...
...
@@ -69,19 +69,6 @@ public class JodaDateTimeFormatAnnotationFormatterFactory
}
private
StringValueResolver
embeddedValueResolver
;
@Override
public
void
setEmbeddedValueResolver
(
StringValueResolver
resolver
)
{
this
.
embeddedValueResolver
=
resolver
;
}
protected
String
resolveEmbeddedValue
(
String
value
)
{
return
(
this
.
embeddedValueResolver
!=
null
?
this
.
embeddedValueResolver
.
resolveStringValue
(
value
)
:
value
);
}
@Override
public
final
Set
<
Class
<?>>
getFieldTypes
()
{
return
FIELD_TYPES
;
...
...
spring-context/src/main/java/org/springframework/format/datetime/standard/Jsr310DateTimeFormatAnnotationFormatterFactory.java
浏览文件 @
d9f8ee88
/*
* Copyright 2002-201
3
the original author or authors.
* Copyright 2002-201
4
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -28,25 +28,25 @@ import java.util.Collections;
import
java.util.HashSet
;
import
java.util.Set
;
import
org.springframework.context.
EmbeddedValueResolverAware
;
import
org.springframework.context.
support.EmbeddedValueResolutionSupport
;
import
org.springframework.format.AnnotationFormatterFactory
;
import
org.springframework.format.Parser
;
import
org.springframework.format.Printer
;
import
org.springframework.format.annotation.DateTimeFormat
;
import
org.springframework.util.StringValueResolver
;
/**
* Formats fields annotated with the {@link DateTimeFormat} annotation using the
JSR-310
* <code>java.time</code> package in JDK 8.
* Formats fields annotated with the {@link DateTimeFormat} annotation using the
*
JSR-310
<code>java.time</code> package in JDK 8.
*
* @author Juergen Hoeller
* @since 4.0
* @see org.springframework.format.annotation.DateTimeFormat
*/
public
class
Jsr310DateTimeFormatAnnotationFormatterFactory
implements
AnnotationFormatterFactory
<
DateTimeFormat
>
,
EmbeddedValueResolverAware
{
public
class
Jsr310DateTimeFormatAnnotationFormatterFactory
extends
EmbeddedValueResolutionSupport
implements
AnnotationFormatterFactory
<
DateTimeFormat
>
{
private
static
final
Set
<
Class
<?>>
FIELD_TYPES
;
static
{
// Create the set of field types that may be annotated with @DateTimeFormat.
Set
<
Class
<?>>
fieldTypes
=
new
HashSet
<
Class
<?>>(
8
);
...
...
@@ -60,19 +60,6 @@ public class Jsr310DateTimeFormatAnnotationFormatterFactory
}
private
StringValueResolver
embeddedValueResolver
;
@Override
public
void
setEmbeddedValueResolver
(
StringValueResolver
resolver
)
{
this
.
embeddedValueResolver
=
resolver
;
}
protected
String
resolveEmbeddedValue
(
String
value
)
{
return
(
this
.
embeddedValueResolver
!=
null
?
this
.
embeddedValueResolver
.
resolveStringValue
(
value
)
:
value
);
}
@Override
public
final
Set
<
Class
<?>>
getFieldTypes
()
{
return
FIELD_TYPES
;
...
...
spring-context/src/main/java/org/springframework/format/number/NumberFormatAnnotationFormatterFactory.java
浏览文件 @
d9f8ee88
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
4
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -16,65 +16,34 @@
package
org.springframework.format.number
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.Set
;
import
org.springframework.context.
EmbeddedValueResolverAware
;
import
org.springframework.context.
support.EmbeddedValueResolutionSupport
;
import
org.springframework.format.AnnotationFormatterFactory
;
import
org.springframework.format.Formatter
;
import
org.springframework.format.Parser
;
import
org.springframework.format.Printer
;
import
org.springframework.format.annotation.NumberFormat
;
import
org.springframework.format.annotation.NumberFormat.Style
;
import
org.springframework.util.NumberUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringValueResolver
;
/**
* Formats fields annotated with the {@link NumberFormat} annotation.
*
* @author Keith Donald
* @author Juergen Hoeller
* @since 3.0
* @see NumberFormat
*/
public
class
NumberFormatAnnotationFormatterFactory
implements
AnnotationFormatterFactory
<
NumberFormat
>,
EmbeddedValueResolverAware
{
private
final
Set
<
Class
<?>>
fieldTypes
;
private
StringValueResolver
embeddedValueResolver
;
public
NumberFormatAnnotationFormatterFactory
()
{
Set
<
Class
<?>>
rawFieldTypes
=
new
HashSet
<
Class
<?>>(
7
);
rawFieldTypes
.
add
(
Short
.
class
);
rawFieldTypes
.
add
(
Integer
.
class
);
rawFieldTypes
.
add
(
Long
.
class
);
rawFieldTypes
.
add
(
Float
.
class
);
rawFieldTypes
.
add
(
Double
.
class
);
rawFieldTypes
.
add
(
BigDecimal
.
class
);
rawFieldTypes
.
add
(
BigInteger
.
class
);
this
.
fieldTypes
=
Collections
.
unmodifiableSet
(
rawFieldTypes
);
}
@Override
public
final
Set
<
Class
<?>>
getFieldTypes
()
{
return
this
.
fieldTypes
;
}
public
class
NumberFormatAnnotationFormatterFactory
extends
EmbeddedValueResolutionSupport
implements
AnnotationFormatterFactory
<
NumberFormat
>
{
@Override
public
void
setEmbeddedValueResolver
(
StringValueResolver
resolver
)
{
this
.
embeddedValueResolver
=
resolver
;
public
Set
<
Class
<?>>
getFieldTypes
(
)
{
return
NumberUtils
.
STANDARD_NUMBER_TYPES
;
}
protected
String
resolveEmbeddedValue
(
String
value
)
{
return
(
this
.
embeddedValueResolver
!=
null
?
this
.
embeddedValueResolver
.
resolveStringValue
(
value
)
:
value
);
}
@Override
public
Printer
<
Number
>
getPrinter
(
NumberFormat
annotation
,
Class
<?>
fieldType
)
{
return
configureFormatterFrom
(
annotation
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录