Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
c278e1e9
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,发现更多精彩内容 >>
提交
c278e1e9
编写于
3月 06, 2009
作者:
K
Keith Donald
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
convert system spi and api
上级
f83019af
变更
22
隐藏空白更改
内联
并排
Showing
22 changed file
with
947 addition
and
0 deletion
+947
-0
org.springframework.core/src/main/java/org/springframework/core/convert/ConversionException.java
...org/springframework/core/convert/ConversionException.java
+41
-0
org.springframework.core/src/main/java/org/springframework/core/convert/ConversionExecutionException.java
...gframework/core/convert/ConversionExecutionException.java
+96
-0
org.springframework.core/src/main/java/org/springframework/core/convert/ConversionExecutor.java
.../org/springframework/core/convert/ConversionExecutor.java
+45
-0
org.springframework.core/src/main/java/org/springframework/core/convert/ConversionExecutorNotFoundException.java
...ork/core/convert/ConversionExecutorNotFoundException.java
+55
-0
org.springframework.core/src/main/java/org/springframework/core/convert/ConversionService.java
...a/org/springframework/core/convert/ConversionService.java
+88
-0
org.springframework.core/src/main/java/org/springframework/core/convert/converter/Converter.java
...org/springframework/core/convert/converter/Converter.java
+51
-0
org.springframework.core/src/main/java/org/springframework/core/convert/converter/NumberToNumber.java
...pringframework/core/convert/converter/NumberToNumber.java
+47
-0
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToBigDecimal.java
...gframework/core/convert/converter/StringToBigDecimal.java
+35
-0
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToBigInteger.java
...gframework/core/convert/converter/StringToBigInteger.java
+35
-0
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToBoolean.java
...ringframework/core/convert/converter/StringToBoolean.java
+81
-0
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToByte.java
.../springframework/core/convert/converter/StringToByte.java
+33
-0
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToCharacter.java
...ngframework/core/convert/converter/StringToCharacter.java
+36
-0
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToDouble.java
...pringframework/core/convert/converter/StringToDouble.java
+33
-0
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToEnum.java
.../springframework/core/convert/converter/StringToEnum.java
+34
-0
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToFloat.java
...springframework/core/convert/converter/StringToFloat.java
+33
-0
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToInteger.java
...ringframework/core/convert/converter/StringToInteger.java
+33
-0
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToLocale.java
...pringframework/core/convert/converter/StringToLocale.java
+37
-0
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToLong.java
.../springframework/core/convert/converter/StringToLong.java
+33
-0
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToShort.java
...springframework/core/convert/converter/StringToShort.java
+33
-0
org.springframework.core/src/main/java/org/springframework/core/convert/converter/SuperConverter.java
...pringframework/core/convert/converter/SuperConverter.java
+54
-0
org.springframework.core/src/main/java/org/springframework/core/convert/converter/package.html
...a/org/springframework/core/convert/converter/package.html
+7
-0
org.springframework.core/src/main/java/org/springframework/core/convert/package.html
...c/main/java/org/springframework/core/convert/package.html
+7
-0
未找到文件。
org.springframework.core/src/main/java/org/springframework/core/convert/ConversionException.java
0 → 100644
浏览文件 @
c278e1e9
/*
* Copyright 2004-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert
;
/**
* Base class for exceptions thrown by the convert system.
*
* @author Keith Donald
*/
public
abstract
class
ConversionException
extends
RuntimeException
{
/**
* Creates a new conversion exception.
* @param message the exception message
* @param cause the cause
*/
public
ConversionException
(
String
message
,
Throwable
cause
)
{
super
(
message
,
cause
);
}
/**
* Creates a new conversion exception.
* @param message the exception message
*/
public
ConversionException
(
String
message
)
{
super
(
message
);
}
}
org.springframework.core/src/main/java/org/springframework/core/convert/ConversionExecutionException.java
0 → 100644
浏览文件 @
c278e1e9
/*
* Copyright 2004-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert
;
import
org.springframework.core.style.StylerUtils
;
/**
* Thrown when an attempt to execute a type conversion fails.
*
* @author Keith Donald
*/
public
class
ConversionExecutionException
extends
ConversionException
{
/**
* The value we tried to convert. Transient because we cannot guarantee that the value is Serializable.
*/
private
transient
Object
value
;
/**
* The source type we tried to convert the value from.
*/
private
Class
<?>
sourceClass
;
/**
* The target type we tried to convert the value to.
*/
private
Class
<?>
targetClass
;
/**
* Creates a new conversion exception.
* @param value the value we tried to convert
* @param sourceClass the value's original type
* @param targetClass the value's target type
* @param cause the cause of the conversion failure
*/
public
ConversionExecutionException
(
Object
value
,
Class
<?>
sourceClass
,
Class
<?>
targetClass
,
Throwable
cause
)
{
super
(
defaultMessage
(
value
,
sourceClass
,
targetClass
,
cause
),
cause
);
this
.
value
=
value
;
this
.
sourceClass
=
sourceClass
;
this
.
targetClass
=
targetClass
;
}
/**
* Creates a new conversion exception.
* @param value the value we tried to convert
* @param sourceClass the value's original type
* @param targetClass the value's target type
* @param message a descriptive message of what went wrong.
*/
public
ConversionExecutionException
(
Object
value
,
Class
<?>
sourceClass
,
Class
<?>
targetClass
,
String
message
)
{
super
(
message
);
this
.
value
=
value
;
this
.
sourceClass
=
sourceClass
;
this
.
targetClass
=
targetClass
;
}
/**
* Returns the actual value we tried to convert, an instance of {@link #getSourceClass()}.
*/
public
Object
getValue
()
{
return
value
;
}
/**
* Returns the source type we tried to convert the value from.
*/
public
Class
<?>
getSourceClass
()
{
return
sourceClass
;
}
/**
* Returns the target type we tried to convert the value to.
*/
public
Class
<?>
getTargetClass
()
{
return
targetClass
;
}
private
static
String
defaultMessage
(
Object
value
,
Class
<?>
sourceClass
,
Class
<?>
targetClass
,
Throwable
cause
)
{
return
"Unable to convert value "
+
StylerUtils
.
style
(
value
)
+
" from type '"
+
sourceClass
.
getName
()
+
"' to type '"
+
targetClass
.
getName
()
+
"'; reason = '"
+
cause
.
getMessage
()
+
"'"
;
}
}
\ No newline at end of file
org.springframework.core/src/main/java/org/springframework/core/convert/ConversionExecutor.java
0 → 100644
浏览文件 @
c278e1e9
/*
* Copyright 2004-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert
;
/**
* A command object that is parameterized with the information necessary to perform a conversion of a source input to a
* target output. Encapsulates knowledge about how to convert source objects to a specific target type using a specific
* converter.
*
* @author Keith Donald
*/
public
interface
ConversionExecutor
<
S
,
T
>
{
/**
* Returns the source class of conversions performed by this executor.
* @return the source class
*/
public
Class
<
S
>
getSourceClass
();
/**
* Returns the target class of conversions performed by this executor.
* @return the target class
*/
public
Class
<
T
>
getTargetClass
();
/**
* Execute the conversion for the provided source object.
* @param source the source object to convert
*/
public
T
execute
(
S
source
)
throws
ConversionExecutionException
;
}
\ No newline at end of file
org.springframework.core/src/main/java/org/springframework/core/convert/ConversionExecutorNotFoundException.java
0 → 100644
浏览文件 @
c278e1e9
/*
* Copyright 2004-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert
;
/**
* Thrown when a conversion executor could not be found in a conversion service.
*
* @see ConversionService#getConversionExecutor(Class, Class)
* @author Keith Donald
*/
public
class
ConversionExecutorNotFoundException
extends
ConversionException
{
private
Class
<?>
sourceClass
;
private
Class
<?>
targetClass
;
/**
* Creates a new conversion executor not found exception.
* @param sourceClass the source type requested to convert from
* @param targetClass the target type requested to convert to
* @param message a descriptive message
*/
public
ConversionExecutorNotFoundException
(
Class
<?>
sourceClass
,
Class
<?>
targetClass
,
String
message
)
{
super
(
message
);
this
.
sourceClass
=
sourceClass
;
this
.
targetClass
=
targetClass
;
}
/**
* Returns the source type requested to convert from.
*/
public
Class
<?>
getSourceClass
()
{
return
sourceClass
;
}
/**
* Returns the target type requested to convert to.
*/
public
Class
<?>
getTargetClass
()
{
return
targetClass
;
}
}
org.springframework.core/src/main/java/org/springframework/core/convert/ConversionService.java
0 → 100644
浏览文件 @
c278e1e9
/*
* Copyright 2004-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert
;
/**
* A service interface for type conversion. This is the entry point into the convert system. Call one of the
* {@link #executeConversion(Object, Class) executeConversion} operations to perform a thread-safe type conversion using
* this system. Call one of the {@link #getConversionExecutor(Class, Class) getConversionExecutor} operations to obtain
* a thread-safe {@link ConversionExecutor} command for later use.
*
* @author Keith Donald
*/
public
interface
ConversionService
{
/**
* Convert the source object to <code>targetClass</code>
* @param source the source to convert from (may be null)
* @param targetClass the target class to convert to
* @return the converted object, an instance of the <code>targetClass</code>, or <code>null</code> if a null source
* was provided
* @throws ConversionExecutorNotFoundException if no suitable conversion executor could be found to convert the
* source to an instance of targetClass
* @throws ConversionException if an exception occurred during the conversion process
*/
public
<
T
>
T
executeConversion
(
Object
source
,
Class
<
T
>
targetClass
)
throws
ConversionExecutorNotFoundException
,
ConversionException
;
/**
* Convert the source object to <code>targetClass</code> using a custom converter.
* @param converterId the id of the custom converter, which must be registered with this conversion service and
* capable of converting to the targetClass
* @param source the source to convert from (may be null)
* @param targetClass the target class to convert to
* @return the converted object, an instance of the <code>targetClass</code>, or <code>null</code> if a null source
* was provided
* @throws ConversionExecutorNotFoundException if no suitable conversion executor could be found to convert the
* source to an instance of targetClass
* @throws ConversionException if an exception occurred during the conversion process
*/
public
<
T
>
T
executeConversion
(
String
converterId
,
Object
source
,
Class
<
T
>
targetClass
)
throws
ConversionExecutorNotFoundException
,
ConversionException
;
/**
* Get a ConversionExecutor capable of converting objects from <code>sourceClass</code> to <code>targetClass</code>.
* The returned ConversionExecutor is thread-safe and may safely be cached for later use by client code.
* @param sourceClass the source class to convert from (required)
* @param targetClass the target class to convert to (required)
* @return the executor that can execute instance type conversion, never null
* @throws ConversionExecutorNotFoundException when no suitable conversion executor could be found
*/
public
<
S
,
T
>
ConversionExecutor
<
S
,
T
>
getConversionExecutor
(
Class
<
S
>
sourceClass
,
Class
<
T
>
targetClass
)
throws
ConversionExecutorNotFoundException
;
/**
* Get a ConversionExecutor that uses a custom converter to capable convert objects from <code>sourceClass</code> to
* <code>targetClass</code>. The returned ConversionExecutor is thread-safe and may safely be cached for use in
* client code.
* @param converterId the id of the custom converter, which must be registered with this conversion service and
* capable of converting from sourceClass to targetClass (required)
* @param sourceClass the source class to convert from (required)
* @param targetClass the target class to convert to (required)
* @return the executor that can execute instance type conversion, never null
* @throws ConversionExecutorNotFoundException when no suitable conversion executor could be found
*/
public
<
S
,
T
>
ConversionExecutor
<
S
,
T
>
getConversionExecutor
(
String
converterId
,
Class
<
S
>
sourceClass
,
Class
<
T
>
targetClass
)
throws
ConversionExecutorNotFoundException
;
/**
* Lookup a class by its well-known alias. For example, <code>long</code> for <code>java.lang.Long</code>
* @param alias the class alias
* @return the class, or <code>null</code> if no alias exists
*/
public
Class
<?>
getClassForAlias
(
String
alias
);
}
\ No newline at end of file
org.springframework.core/src/main/java/org/springframework/core/convert/converter/Converter.java
0 → 100644
浏览文件 @
c278e1e9
/*
* Copyright 2004-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert.converter
;
import
org.springframework.core.convert.ConversionException
;
import
org.springframework.core.convert.ConversionService
;
/**
* A converter converts a source object of type S to a target type of type T and back.
* <p>
* Implementations of this interface are thread-safe and can be shared. Converters are typically registered with and
* accessed through a {@link ConversionService}.
* </p>
* @author Keith Donald
*/
public
interface
Converter
<
S
,
T
>
{
/**
* Convert the source S to target type T.
* @param source the source object to convert, which must be an instance of S
* @return the converted object, which must be an instance of T
* @throws Exception an exception occurred performing the conversion; may be any checked exception, the conversion
* system will handle wrapping the failure in a {@link ConversionException} that provides a consistent type
* conversion error context
*/
public
T
convert
(
S
source
)
throws
Exception
;
/**
* Convert the target T back to source type S.
* @param target the target object to convert, which must be an instance of T
* @return the converted object, which must be an instance of S
* @throws Exception an exception occurred performing the conversion; may be any checked exception, the conversion
* system will handle wrapping the failure in a {@link ConversionException} that provides a consistent type
* conversion error context
*/
public
S
convertBack
(
T
target
)
throws
Exception
;
}
\ No newline at end of file
org.springframework.core/src/main/java/org/springframework/core/convert/converter/NumberToNumber.java
0 → 100644
浏览文件 @
c278e1e9
/*
* Copyright 2004-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert.converter
;
import
org.springframework.util.NumberUtils
;
/**
*Converts from any JDK-standard Number implementation to any other JDK-standard Number implementation.
*
* Support Number classes include byte, short, integer, float, double, long, big integer, big decimal. This class
* delegates to {@link NumberUtils#convertNumberToTargetClass(Number, Class)} to perform the conversion.
*
* @see java.lang.Byte
* @see java.lang.Short
* @see java.lang.Integer
* @see java.lang.Long
* @see java.math.BigInteger
* @see java.lang.Float
* @see java.lang.Double
* @see java.math.BigDecimal
*
* @author Keith Donald
*/
public
class
NumberToNumber
implements
SuperConverter
<
Number
,
Number
>
{
public
<
N
extends
Number
>
N
convert
(
Number
source
,
Class
<
N
>
targetClass
)
throws
Exception
{
return
NumberUtils
.
convertNumberToTargetClass
(
source
,
targetClass
);
}
public
Number
convertBack
(
Number
target
)
throws
Exception
{
return
target
;
}
}
\ No newline at end of file
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToBigDecimal.java
0 → 100644
浏览文件 @
c278e1e9
/*
* Copyright 2004-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert.converter
;
import
java.math.BigDecimal
;
/**
* Converts a String to a BigDecimal and back.
*
* @author Keith Donald
*/
public
class
StringToBigDecimal
implements
Converter
<
String
,
BigDecimal
>
{
public
BigDecimal
convert
(
String
source
)
throws
Exception
{
return
new
BigDecimal
(
source
);
}
public
String
convertBack
(
BigDecimal
target
)
throws
Exception
{
return
target
.
toString
();
}
}
\ No newline at end of file
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToBigInteger.java
0 → 100644
浏览文件 @
c278e1e9
/*
* Copyright 2004-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert.converter
;
import
java.math.BigInteger
;
/**
* Converts a String to a BigInteger and back.
*
* @author Keith Donald
*/
public
class
StringToBigInteger
implements
Converter
<
String
,
BigInteger
>
{
public
BigInteger
convert
(
String
source
)
throws
Exception
{
return
new
BigInteger
(
source
);
}
public
String
convertBack
(
BigInteger
target
)
throws
Exception
{
return
target
.
toString
();
}
}
\ No newline at end of file
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToBoolean.java
0 → 100644
浏览文件 @
c278e1e9
/*
* Copyright 2004-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert.converter
;
/**
* Converts String to a Boolean and back.
*
* @author Keith Donald
*/
public
class
StringToBoolean
implements
Converter
<
String
,
Boolean
>
{
private
static
final
String
VALUE_TRUE
=
"true"
;
private
static
final
String
VALUE_FALSE
=
"false"
;
private
String
trueString
;
private
String
falseString
;
/**
* Create a StringToBoolean converter.
*/
public
StringToBoolean
()
{
}
/**
* Create a StringToBoolean converter configured with specific values for true and false strings.
* @param trueString special true string to use
* @param falseString special false string to use
*/
public
StringToBoolean
(
String
trueString
,
String
falseString
)
{
this
.
trueString
=
trueString
;
this
.
falseString
=
falseString
;
}
public
Boolean
convert
(
String
source
)
throws
Exception
{
if
(
trueString
!=
null
&&
source
.
equals
(
trueString
))
{
return
Boolean
.
TRUE
;
}
else
if
(
falseString
!=
null
&&
source
.
equals
(
falseString
))
{
return
Boolean
.
FALSE
;
}
else
if
(
trueString
==
null
&&
source
.
equals
(
VALUE_TRUE
))
{
return
Boolean
.
TRUE
;
}
else
if
(
falseString
==
null
&&
source
.
equals
(
VALUE_FALSE
))
{
return
Boolean
.
FALSE
;
}
else
{
throw
new
IllegalArgumentException
(
"Invalid boolean value ["
+
source
+
"]"
);
}
}
public
String
convertBack
(
Boolean
target
)
throws
Exception
{
if
(
Boolean
.
TRUE
.
equals
(
target
))
{
if
(
trueString
!=
null
)
{
return
trueString
;
}
else
{
return
VALUE_TRUE
;
}
}
else
if
(
Boolean
.
FALSE
.
equals
(
target
))
{
if
(
falseString
!=
null
)
{
return
falseString
;
}
else
{
return
VALUE_FALSE
;
}
}
else
{
throw
new
IllegalArgumentException
(
"Invalid boolean value ["
+
target
+
"]"
);
}
}
}
\ No newline at end of file
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToByte.java
0 → 100644
浏览文件 @
c278e1e9
/*
* Copyright 2004-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert.converter
;
/**
* Converts a String to a Byte and back.
*
* @author Keith Donald
*/
public
class
StringToByte
implements
Converter
<
String
,
Byte
>
{
public
Byte
convert
(
String
source
)
throws
Exception
{
return
new
Byte
(
source
);
}
public
String
convertBack
(
Byte
target
)
throws
Exception
{
return
target
.
toString
();
}
}
\ No newline at end of file
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToCharacter.java
0 → 100644
浏览文件 @
c278e1e9
/*
* Copyright 2004-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert.converter
;
/**
* Converts a String to a Character and back.
*
* @author Keith Donald
*/
public
class
StringToCharacter
implements
Converter
<
String
,
Character
>
{
public
Character
convert
(
String
source
)
throws
Exception
{
if
(
source
.
length
()
>
1
)
{
throw
new
IllegalArgumentException
(
"To be a Character the String '"
+
source
+
"' must have a length of 1"
);
}
return
new
Character
(
source
.
charAt
(
0
));
}
public
String
convertBack
(
Character
target
)
throws
Exception
{
return
target
.
toString
();
}
}
\ No newline at end of file
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToDouble.java
0 → 100644
浏览文件 @
c278e1e9
/*
* Copyright 2004-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert.converter
;
/**
* Converts a String to a Double and back.
*
* @author Keith Donald
*/
public
class
StringToDouble
implements
Converter
<
String
,
Double
>
{
public
Double
convert
(
String
source
)
throws
Exception
{
return
Double
.
valueOf
(
source
);
}
public
String
convertBack
(
Double
target
)
throws
Exception
{
return
target
.
toString
();
}
}
\ No newline at end of file
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToEnum.java
0 → 100644
浏览文件 @
c278e1e9
/*
* Copyright 2004-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert.converter
;
/**
* Converts from a String to Enum and back.
*
* @author Scott Andrews
*/
@SuppressWarnings
(
"unchecked"
)
public
class
StringToEnum
implements
SuperConverter
<
String
,
Enum
>
{
public
<
E
extends
Enum
>
E
convert
(
String
source
,
Class
<
E
>
targetClass
)
throws
Exception
{
return
Enum
.
valueOf
(
targetClass
,
source
);
}
public
String
convertBack
(
Enum
target
)
throws
Exception
{
return
target
.
name
();
}
}
\ No newline at end of file
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToFloat.java
0 → 100644
浏览文件 @
c278e1e9
/*
* Copyright 2004-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert.converter
;
/**
* Converts a String to an Short using {@link Short#valueOf(String)}.
*
* @author Keith Donald
*/
public
class
StringToFloat
implements
Converter
<
String
,
Float
>
{
public
Float
convert
(
String
source
)
throws
Exception
{
return
Float
.
valueOf
(
source
);
}
public
String
convertBack
(
Float
target
)
throws
Exception
{
return
target
.
toString
();
}
}
\ No newline at end of file
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToInteger.java
0 → 100644
浏览文件 @
c278e1e9
/*
* Copyright 2004-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert.converter
;
/**
* Converts a String to an Integer using {@link Integer#valueOf(String)}.
*
* @author Keith Donald
*/
public
class
StringToInteger
implements
Converter
<
String
,
Integer
>
{
public
Integer
convert
(
String
source
)
throws
Exception
{
return
Integer
.
valueOf
(
source
);
}
public
String
convertBack
(
Integer
target
)
throws
Exception
{
return
target
.
toString
();
}
}
\ No newline at end of file
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToLocale.java
0 → 100644
浏览文件 @
c278e1e9
/*
* Copyright 2004-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert.converter
;
import
java.util.Locale
;
import
org.springframework.util.StringUtils
;
/**
* Converts a String to a Locale using {@link StringUtils#parseLocaleString(String)}.
*
* @author Keith Donald
*/
public
class
StringToLocale
implements
Converter
<
String
,
Locale
>
{
public
Locale
convert
(
String
source
)
throws
Exception
{
return
StringUtils
.
parseLocaleString
(
source
);
}
public
String
convertBack
(
Locale
target
)
throws
Exception
{
return
target
.
toString
();
}
}
\ No newline at end of file
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToLong.java
0 → 100644
浏览文件 @
c278e1e9
/*
* Copyright 2004-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert.converter
;
/**
* Converts a String to an Long using {@link Long#valueOf(String)}.
*
* @author Keith Donald
*/
public
class
StringToLong
implements
Converter
<
String
,
Long
>
{
public
Long
convert
(
String
source
)
throws
Exception
{
return
Long
.
valueOf
(
source
);
}
public
String
convertBack
(
Long
target
)
throws
Exception
{
return
target
.
toString
();
}
}
\ No newline at end of file
org.springframework.core/src/main/java/org/springframework/core/convert/converter/StringToShort.java
0 → 100644
浏览文件 @
c278e1e9
/*
* Copyright 2004-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert.converter
;
/**
* Converts a String to an Short using {@link Short#valueOf(String)}.
*
* @author Keith Donald
*/
public
class
StringToShort
implements
Converter
<
String
,
Short
>
{
public
Short
convert
(
String
source
)
throws
Exception
{
return
Short
.
valueOf
(
source
);
}
public
String
convertBack
(
Short
target
)
throws
Exception
{
return
target
.
toString
();
}
}
\ No newline at end of file
org.springframework.core/src/main/java/org/springframework/core/convert/converter/SuperConverter.java
0 → 100644
浏览文件 @
c278e1e9
/*
* Copyright 2004-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.convert.converter
;
import
org.springframework.core.convert.ConversionException
;
import
org.springframework.core.convert.ConversionService
;
/**
* A super converter converts a source object of type S to a target type of type AT and back, where AT is equal to or a
* subclass of T.
* <p>
* Implementations of this interface are thread-safe and can be shared. Converters are typically registered with and
* accessed through a {@link ConversionService}.
* </p>
* @author Keith Donald
*/
public
interface
SuperConverter
<
S
,
T
>
{
/**
* Convert the source S to an instance of AT.
* @param source the source object to convert, which must be an instance of S
* @param actualTargetClass the actual target class to convert to (AT), which must be equal to or a specialization
* of T.
* @return the converted object, which must be an instance of AT
* @throws Exception an exception occurred performing the conversion; may be any checked exception, the conversion
* system will handle wrapping the failure in a {@link ConversionException} that provides a consistent type
* conversion error context
*/
public
<
AT
extends
T
>
AT
convert
(
S
source
,
Class
<
AT
>
actualTargetClass
)
throws
Exception
;
/**
* Convert the target T to an instance of S.
* @param target the target object to convert, which must be an instance of T.
* @return the converted object, which must be an instance of S.
* @throws Exception an exception occurred performing the conversion; may be any checked exception, the conversion
* system will handle wrapping the failure in a {@link ConversionException} that provides a consistent type
* conversion error context
*/
public
S
convertBack
(
T
target
)
throws
Exception
;
}
\ No newline at end of file
org.springframework.core/src/main/java/org/springframework/core/convert/converter/package.html
0 → 100644
浏览文件 @
c278e1e9
<html>
<body>
<p>
User Converter API and default Converter implementations.
</p>
</body>
</html>
\ No newline at end of file
org.springframework.core/src/main/java/org/springframework/core/convert/package.html
0 → 100644
浏览文件 @
c278e1e9
<html>
<body>
<p>
Type conversion system SPI.
</p>
</body>
</html>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录