public class StringValueConverterImpl extends AbstractGenericValueConverter<String> implements StringValueConverter
StringValueConverter
.Modifier and Type | Field and Description |
---|---|
private EnumProvider |
enumProvider |
private static StringValueConverterImpl |
instance |
private Iso8601Util |
iso8601Util |
private MathUtil |
mathUtil |
private StringUtil |
stringUtil |
Constructor and Description |
---|
StringValueConverterImpl()
The constructor.
|
Modifier and Type | Method and Description |
---|---|
protected <V> V |
convertUnknownValue(String value,
Class<V> type,
Object valueSource)
|
<TARGET> TARGET |
convertValue(String value,
Object valueSource,
Class<TARGET> type,
Type targetType)
This method converts the given
value to the given type . |
protected void |
doInitialize()
This method performs the actual
initialization . |
protected EnumProvider |
getEnumProvider() |
static StringValueConverterImpl |
getInstance()
This method gets the singleton instance of this
StringValueConverterImpl . |
protected Iso8601Util |
getIso8601Util()
This method gets the
Iso8601Util used to parse and format date and time according to the standard
ISO-8601 . |
protected StringUtil |
getStringUtil()
This method gets the
StringUtil used to deal with strings. |
private Number |
parseNumber(String numberValue,
Object valueSource)
This method parses a numeric value.
|
void |
setEnumProvider(EnumProvider enumProvider) |
void |
setIso8601Util(Iso8601Util iso8601Util)
This method sets the
Iso8601Util . |
void |
setStringUtil(StringUtil stringUtil) |
convertValue, convertValue, convertValue, convertValue, convertValue
createLogger, getLogger
doInitialized, getInitializationState, initialize
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
convertValue, convertValue, convertValue, convertValue, convertValue
private static StringValueConverterImpl instance
private Iso8601Util iso8601Util
private MathUtil mathUtil
private StringUtil stringUtil
private EnumProvider enumProvider
public static StringValueConverterImpl getInstance()
StringValueConverterImpl
. Cdi.GET_INSTANCE
before using.protected void doInitialize()
AbstractComponent
initialization
. It is called when AbstractComponent.initialize()
is
invoked for the first time. super.
AbstractComponent.doInitialize()
.doInitialize
in class AbstractLoggableComponent
protected Iso8601Util getIso8601Util()
Iso8601Util
used to parse and format date and time according to the standard
ISO-8601
.@Inject public void setIso8601Util(Iso8601Util iso8601Util)
Iso8601Util
.iso8601Util
- the iso8601Util to setprotected StringUtil getStringUtil()
StringUtil
used to deal with strings.@Inject public void setStringUtil(StringUtil stringUtil)
stringUtil
- is the stringUtil to setprotected EnumProvider getEnumProvider()
EnumProvider
used to deal with Enum
s.@Inject public void setEnumProvider(EnumProvider enumProvider)
enumProvider
- is the EnumProvider
to Inject
.private Number parseNumber(String numberValue, Object valueSource) throws WrongValueTypeException
numberValue
- is the number value as string.valueSource
- describes the source of the value. This may be the filename where the value was read
from, an XPath where the value was located in an XML document, etc. It is used in exceptions
thrown if something goes wrong. This will help to find the problem easier.WrongValueTypeException
- if the given string is no number.public final <TARGET> TARGET convertValue(String value, Object valueSource, Class<TARGET> type, Type targetType) throws ValueNotSetException, WrongValueTypeException
GenericValueConverter
value
to the given type
.convertValue
in interface GenericValueConverter<String>
TARGET
- is the type to convert to.value
- is the value to convert. It may be null
.valueSource
- describes the source of the value. This may be the filename where the value was read
from, an XPath where the value was located in an XML document, etc. It is used in exceptions
thrown if something goes wrong. This will help to find the problem easier.type
- is the type the value
should be converted to. It is the raw-type of the given
targetType
.targetType
- is the type to convert the value
to. It is potentially generic and therefore
contains more detailed information than targetClass
. E.g. the targetClass
may be
java.util.List
while this targetType
could be java.util.List<Long>
. This
could help e.g. if the value
is a string like "2, 47, 4252525"
. The caller may
supply the targetClass
again here.value
converted to type
.ValueNotSetException
- if the given value
is null
.WrongValueTypeException
- if the given value
is NOT null
but can NOT be converted
to the given type
(e.g. if value
is "12x" and type
is
Integer.class
).ValueNotSetException
WrongValueTypeException
protected <V> V convertUnknownValue(String value, Class<V> type, Object valueSource) throws ValueNotSetException, WrongValueTypeException
String
-value
to the given type
. It is called from
convertValue(String, Object, Class, Type)
if the given type
is unknown. This default
implementation simply throws a new WrongValueTypeException
. You can extend this class and
override this method in order to support the conversion for additional types. You should first handle the
conversion for all value types you like. Then for all other types you should delegate to the
super
method implementation.V
- is the type the value
should be converted to.value
- is the value to convert.type
- is the type the value
should be converted to.valueSource
- describes the source of the value. This may be the filename where the value was read
from, an XPath where the value was located in an XML document, etc. It is used in exceptions
thrown if something goes wrong. This will help to find the problem easier.value
converted to type
.ValueNotSetException
- if the given value
is null
.WrongValueTypeException
- if the given value
is NOT null
but can NOT be converted
to the given type
(e.g. if value
is "12x" and type
is
Integer.class
).Copyright © 2001–2016 mmm-Team. All rights reserved.