net.sf.mmm.util.value.impl
Class ValueConverterToClass
java.lang.Object
net.sf.mmm.util.component.base.AbstractComponent
net.sf.mmm.util.component.base.AbstractLoggableComponent
net.sf.mmm.util.value.base.AbstractValueConverter<CharSequence,Class>
net.sf.mmm.util.value.impl.ValueConverterToClass
- All Implemented Interfaces:
- SimpleValueConverter<CharSequence,Class>, ValueConverter<CharSequence,Class>
@Singleton
@Named
public class ValueConverterToClass
- extends AbstractValueConverter<CharSequence,Class>
This is an implementation of the
ValueConverter
interface that converts a
CharSequence
to a Class
.
- Since:
- 1.0.1
- Author:
- Joerg Hohwiller (hohwille at users.sourceforge.net)
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ValueConverterToClass
public ValueConverterToClass()
- The constructor.
getSourceType
public Class<CharSequence> getSourceType()
- This the type of the value accepted by this converter. Use
Object
if you want to accept any value. A very common source-type
is String
.
- Returns:
- the source-type.
getTargetType
public Class<Class> getTargetType()
- Is the guaranteed return-type of the
conversion
. This information
is used externally to choose the most specific ValueConverter
that
is appropriate
for the conversion.
E.g. a generic converter can have Object
as
target-type
while a specific converter may have
Collection
as target-type
. Now
if an object (compliant with the source-type
)
needs to be converted to a Collection
or
List
, the specific converter is used while for other
objects the generic converter is chosen.
Please note that the target-type
is often more
general than the actual returned result
. So a ValueConverter
that converts a
comma-separated String
to an ArrayList
will
typically declare List
as target-type
.
- Returns:
- the target-type.
convert
public Class convert(CharSequence value,
Object valueSource,
GenericType<? extends Class> targetType)
throws ValueException
- This method converts the given
pojo
to the
<TARGET>-type.
- Parameters:
value
- is the value to convert.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.targetType
- is the GenericType
to convert the
value
to. It is potentially generic and therefore
contains more detailed information than a Class
. E.g. the
targetType
could be
java.util.List<Long>
. This could help e.g. if the
value
is a string like "2, 47, 4252525"
.
- Returns:
- the converted
value
or null
if the
conversion is NOT possible. The returned value has to be an
instance
of the given
targetType
.
- Throws:
ValueException
- if the conversion failed (e.g. the given
value
is illegal for the given
targetClass
).
Copyright © 2001-2010 mmm-Team. All Rights Reserved.