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="16.1", sinceVersion="4.0") public abstract class AbstractConverter extends java.lang.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: 26156 $ $Date: 2024-01-13 10:26:46 -0300 (Sat, 13 Jan 2024) $
-
-
Constructor Summary
Constructors Constructor Description AbstractConverter()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <T> T
convert(java.lang.Class<T> type, java.lang.Object value)
Converts the specified input object into an output object of the specified type.<T> T
convert(java.lang.Class<T> type, java.lang.Object value, java.util.Locale locale)
Converts the specified input object into an output object of the specified type.<T> T
convert(java.lang.Class<T> type, java.lang.Object value, java.util.Locale locale, java.lang.String pattern)
Converts the specified input object into an output object of the specified type.protected abstract <T> T
doConversion(java.lang.Class<T> type, java.lang.Object value, java.util.Locale locale, java.lang.String pattern)
Converts the specified input object into an output object of the specified type.protected boolean
doesNullValueReturnNull()
protected boolean
doesValueInstanceOfTypeReturnValue()
java.util.Locale
getDefaultLocale()
java.lang.String
getDefaultPattern()
void
setDefaultLocale(java.util.Locale defaultLocale)
void
setDefaultPattern(java.lang.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 java.util.Locale getDefaultLocale()
-
setDefaultLocale
public void setDefaultLocale(java.util.Locale defaultLocale)
-
getDefaultPattern
public java.lang.String getDefaultPattern()
-
setDefaultPattern
public void setDefaultPattern(java.lang.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(java.lang.Class<T> type, java.lang.Object value, java.util.Locale locale, java.lang.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(java.lang.Class<T> type, java.lang.Object value, java.util.Locale locale, java.lang.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(java.lang.Class<T> type, java.lang.Object value, java.util.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(java.lang.Class<T> type, java.lang.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.
-
-