|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectAnyConverter
@NotThreadSafe public class AnyConverter
An utility for converting arbitrary objects to arbitrary target types without
the need to handle ObjectConverter and ConverterRegistry explicitly. This
is a convenience class for converting a few instances of unknown type.
Note:
If a large amount of objects of the same type need to be converted to the same target
type, or if the source type is known at compile-time, then it is often more advisable
to use ObjectConverter directly.
Thread safety
This class is not thread safe. If conversions need to be performed by
concurrent threads, then each thread shall use its own AnyConverter instance.
| utility/geotk-utility (download) | View source code for this class |
| Constructor Summary | |
|---|---|
AnyConverter()
Creates a new AnyConverter which will use the
system converter registry. |
|
AnyConverter(ConverterRegistry registry)
Creates a new AnyConverter which will use the given converter registry. |
|
| Method Summary | ||
|---|---|---|
protected void |
conversionFailed(NonconvertibleObjectException exception)
Invoked by tryConvert when an object can not be converted. |
|
|
convert(Object value,
Class<T> targetType)
Converts the given value to the given type. |
|
Object |
tryConvert(Object value,
Class<?> targetType)
Tries to convert the given value to the given type. |
|
| Methods inherited from class Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public AnyConverter()
AnyConverter which will use the
system converter registry.
public AnyConverter(ConverterRegistry registry)
AnyConverter which will use the given converter registry.
registry - The converter registry to use, or null for the
system one.| Method Detail |
|---|
public <T> T convert(Object value,
Class<T> targetType)
throws NonconvertibleObjectException
T - The parameterized type of targetType.value - The value to convert (can be null).targetType - The desired type.
NonconvertibleObjectException - If the conversion can not be performed.
public Object tryConvert(Object value,
Class<?> targetType)
conversionFailed and returns the value unchanged.
value - The value to convert (can be null).targetType - The desired type.
protected void conversionFailed(NonconvertibleObjectException exception)
tryConvert when an object can not be converted. The default
implementation logs the exception at the FINE level.
Subclasses can override this method if they want to logs the message in a different way.
exception - The exception that occurred while trying to convert an object.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||