public interface ConversionHandler
An interface defining the possible data type conversions supported by the configuration framework.
This interface defines a couple of methods related to different kinds of data type conversion:
Data type conversion is related to variable substitution (aka interpolation).
Before a value can be converted to a target type substitution has to be
performed first, and the conversion is done on the resulting value. In order
to support this, the conversion methods expect a
ConfigurationInterpolator
object; Configuration
implementations here pass in their associated instance.
A Configuration
object is associated with a concrete
ConversionHandler
implementation. Whenever a data type conversion is
required it delegates to this handler. By providing a custom
ConversionHandler
object, the type conversion performed by the
configuration object can be adapted.
Modifier and Type | Method and Description |
---|---|
<T> T |
to(Object src,
Class<T> targetCls,
ConfigurationInterpolator ci)
Converts a single object to the specified target type.
|
Object |
toArray(Object src,
Class<?> elemClass,
ConfigurationInterpolator ci)
Converts the given object to an array of the specified element type.
|
<T> void |
toCollection(Object src,
Class<T> elemClass,
ConfigurationInterpolator ci,
Collection<T> dest)
Converts the given object to a collection of the specified type.
|
<T> T to(Object src, Class<T> targetCls, ConfigurationInterpolator ci)
ConversionException
is thrown. It is up to a concrete
implementation how null values are handled; a default strategy
would be to return null if the source object is null.T
- the type of the desired resultsrc
- the object to be convertedtargetCls
- the target class of the conversionci
- an object for performing variable substitutionConversionException
- if the requested conversion is not possibleObject toArray(Object src, Class<?> elemClass, ConfigurationInterpolator ci)
ConversionException
is thrown. Note
that the result type of this method is Object
; because this
method can also produce arrays of a primitive type the return type
Object[]
cannot be used.src
- the object to be convertedelemClass
- the element class of the resulting arrayci
- an object for performing variable substitutionConversionException
- if the conversion of an element is not
possible<T> void toCollection(Object src, Class<T> elemClass, ConfigurationInterpolator ci, Collection<T> dest)
ConversionException
is thrown.T
- the type of the elements of the destination collectionsrc
- the object to be convertedelemClass
- the element class of the destination collectionci
- an object for performing variable substitutiondest
- the destination collectionCopyright © 2001–2020 The Apache Software Foundation. All rights reserved.