|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.mmm.util.component.base.AbstractComponent
net.sf.mmm.util.component.base.AbstractLoggableComponent
net.sf.mmm.util.value.base.AbstractGenericValueConverter<String>
net.sf.mmm.util.value.base.StringValueConverterImpl
@Singleton @Named public class StringValueConverterImpl
This is a utility class providing support for dealing with values (e.g. when reading configurations).
Field Summary | |
---|---|
private static StringValueConverterImpl |
instance
|
private Iso8601Util |
iso8601Util
|
private StringUtil |
stringUtil
|
Constructor Summary | |
---|---|
StringValueConverterImpl()
The constructor. |
Method Summary | ||
---|---|---|
protected
|
convertUnknownValue(String value,
Class<V> type,
Object valueSource)
This method converts the given String -value to the
given type . |
|
|
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 . |
|
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 static Number |
parseNumber(String numberValue,
Object valueSource)
This method parses a numeric value. |
|
void |
setIso8601Util(Iso8601Util iso8601Util)
This method sets the Iso8601Util . |
|
void |
setStringUtil(StringUtil stringUtil)
|
Methods inherited from class net.sf.mmm.util.value.base.AbstractGenericValueConverter |
---|
convertValue, convertValue, convertValue, convertValue, convertValue |
Methods inherited from class net.sf.mmm.util.component.base.AbstractLoggableComponent |
---|
getLogger, setLogger |
Methods inherited from class net.sf.mmm.util.component.base.AbstractComponent |
---|
doInitialized, getInitializationState, initialize |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface net.sf.mmm.util.value.api.GenericValueConverter |
---|
convertValue, convertValue, convertValue, convertValue, convertValue |
Field Detail |
---|
private static StringValueConverterImpl instance
getInstance()
private Iso8601Util iso8601Util
getIso8601Util()
private StringUtil stringUtil
getStringUtil()
Constructor Detail |
---|
public StringValueConverterImpl()
Method Detail |
---|
public static StringValueConverterImpl getInstance()
StringValueConverterImpl
.getInstance()
methods and
construct new instances via the container-framework of your choice (like
plexus, pico, springframework, etc.). To wire up the dependent components
everything is properly annotated using common-annotations (JSR-250). If
your container does NOT support this, you should consider using a better
one.
protected void doInitialize()
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 setprivate static 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
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
).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
).
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |