Package lumis.util.converter
Class AbstractConverter
- java.lang.Object
-
- lumis.util.converter.AbstractConverter
-
- All Implemented Interfaces:
IConverter
- Direct Known Subclasses:
AbstractSourceConverter
,BooleanConverter
,CategorizationDataType.CategorizationConverter
,CollectionConverter
,DateTimeConverter
,FileDataType.FileDataConverter
,FilesDataType.FilesDataConverter
,NumberConverter
,PageDataType.PageDataConverter
,PageOrPageTemplateDataType.PageOrPageTemplateDataConverter
,PageTemplateDataType.PageDataConverter
,ParentContentDataType.ParentContentDataConverter
,ResourcesDataType.ResourcesDataConverter
,RestConverter
,URLConverter
@StableMinor(version="14.0", sinceVersion="4.0") public abstract class AbstractConverter extends Object implements IConverter
This is a abstract converter where a default locale and pattern may be specified and has fallback conversion capability.If the convertion implementation does not support the requested type, this converter falls back to try to convert using
ConvertUtil.convert(Class, Object, Locale, String)
.- Since:
- 4.0.4
- Version:
- $Revision: 24477 $ $Date: 2021-04-28 11:30:36 -0300 (Wed, 28 Apr 2021) $
-
-
Constructor Summary
Constructors Constructor Description AbstractConverter()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <T> T
convert(Class<T> type, Object value)
Converts the specified input object into an output object of the specified type.<T> T
convert(Class<T> type, Object value, Locale locale)
Converts the specified input object into an output object of the specified type.<T> T
convert(Class<T> type, Object value, Locale locale, String pattern)
Converts the specified input object into an output object of the specified type.protected abstract <T> T
doConversion(Class<T> type, Object value, Locale locale, String pattern)
Converts the specified input object into an output object of the specified type.protected boolean
doesNullValueReturnNull()
protected boolean
doesValueInstanceOfTypeReturnValue()
Locale
getDefaultLocale()
String
getDefaultPattern()
void
setDefaultLocale(Locale defaultLocale)
void
setDefaultPattern(String defaultPattern)
protected void
setFallbackToRegisteredConverters(boolean fallbackToRegisteredConverters)
Sets if the registered converters should be tried if this converter does not know how to complete the conversion.protected boolean
shouldFallbackToRegisteredConverters()
Indicates if the registered converters should be tried if this converter does not know how to complete the conversion.
-
-
-
Method Detail
-
getDefaultLocale
public Locale getDefaultLocale()
-
setDefaultLocale
public void setDefaultLocale(Locale defaultLocale)
-
getDefaultPattern
public String getDefaultPattern()
-
setDefaultPattern
public void setDefaultPattern(String defaultPattern)
-
doesNullValueReturnNull
protected boolean doesNullValueReturnNull()
-
doesValueInstanceOfTypeReturnValue
protected boolean doesValueInstanceOfTypeReturnValue()
-
shouldFallbackToRegisteredConverters
protected boolean shouldFallbackToRegisteredConverters()
Indicates if the registered converters should be tried if this converter does not know how to complete the conversion.- Returns:
- true if should fallback to registered converters, false otherwise.
- Since:
- 4.0.11
-
setFallbackToRegisteredConverters
protected void setFallbackToRegisteredConverters(boolean fallbackToRegisteredConverters)
Sets if the registered converters should be tried if this converter does not know how to complete the conversion.Note that if this property is set to
false
, it is important not to fallback to the registered converters, since it may cause an infinite loop.- Parameters:
fallbackToRegisteredConverters
- the value to set.- Since:
- 4.0.11
-
doConversion
protected abstract <T> T doConversion(Class<T> type, Object value, Locale locale, String pattern) throws UnsupportedConversionTypeException
Converts the specified input object into an output object of the specified type.- Type Parameters:
T
- generics support for the data type specified.- Parameters:
type
- data type to which the value should be converted.value
- the input value to be converted.locale
- locale to be used during conversion, if necessary.pattern
- converter specific conversion pattern, to be used during conversion, if necessary.- Throws:
UnsupportedConversionTypeException
- if this converter does not supports converting to the specified type.- Since:
- 4.0.4
-
convert
public <T> T convert(Class<T> type, Object value, Locale locale, String pattern)
Description copied from interface:IConverter
Converts the specified input object into an output object of the specified type.- Specified by:
convert
in interfaceIConverter
- Type Parameters:
T
- generics support for the data type specified.- Parameters:
type
- data type to which the value should be converted.value
- the input value to be converted.locale
- locale to be used during conversion, if necessary.pattern
- converter specific conversion pattern, to be used during conversion, if necessary.
-
convert
public <T> T convert(Class<T> type, Object value, Locale locale)
Description copied from interface:IConverter
Converts the specified input object into an output object of the specified type.- Specified by:
convert
in interfaceIConverter
- Type Parameters:
T
- generics support for the data type specified.- Parameters:
type
- data type to which the value should be converted.value
- the input value to be converted.locale
- locale to be used during conversion
-
convert
public <T> T convert(Class<T> type, Object value)
Description copied from interface:IConverter
Converts the specified input object into an output object of the specified type.- Specified by:
convert
in interfaceIConverter
- Type Parameters:
T
- generics support for the data type specified.- Parameters:
type
- data type to which the value should be converted.value
- the input value to be converted.
-
-