Package org.apache.ofbiz.base.conversion
Class AbstractConverter<S,T>
- java.lang.Object
-
- org.apache.ofbiz.base.conversion.AbstractConverter<S,T>
-
- All Implemented Interfaces:
Converter<S,T>
,ConverterLoader
- Direct Known Subclasses:
AbstractLocalizedConverter
,BooleanConverters.BooleanToInteger
,BooleanConverters.BooleanToString
,BooleanConverters.IntegerToBoolean
,BooleanConverters.StringToBoolean
,CollectionConverters.ArrayToList
,CollectionConverters.ListToString
,CollectionConverters.MapToList
,CollectionConverters.MapToSet
,CollectionConverters.MapToString
,CollectionConverters.StringToMap
,Converters.GenericValueToJSON
,Converters.GenericValueToList
,Converters.GenericValueToSet
,Converters.GenericValueToString
,Converters.JSONToGenericValue
,Converters.NullFieldToObject
,Converters.ObjectToNullField
,DateTimeConverters.CalendarToDate
,DateTimeConverters.CalendarToLong
,DateTimeConverters.CalendarToString
,DateTimeConverters.CalendarToTimestamp
,DateTimeConverters.DateToLong
,DateTimeConverters.DateToSqlDate
,DateTimeConverters.DateToSqlTime
,DateTimeConverters.DateToTimestamp
,DateTimeConverters.DurationToBigDecimal
,DateTimeConverters.DurationToDouble
,DateTimeConverters.DurationToFloat
,DateTimeConverters.DurationToLong
,DateTimeConverters.DurationToString
,DateTimeConverters.NumberToDate
,DateTimeConverters.NumberToDuration
,DateTimeConverters.NumberToSqlDate
,DateTimeConverters.NumberToSqlTime
,DateTimeConverters.NumberToTimestamp
,DateTimeConverters.SqlDateToDate
,DateTimeConverters.SqlDateToTime
,DateTimeConverters.SqlDateToTimestamp
,DateTimeConverters.SqlTimeToSqlDate
,DateTimeConverters.StringToTimeZone
,DateTimeConverters.TimestampToDate
,DateTimeConverters.TimestampToSqlDate
,DateTimeConverters.TimestampToSqlTime
,DateTimeConverters.TimeZoneToString
,FlexibleStringExpanderTests.SpecialNumberToString
,GenericSingletonToList
,GenericSingletonToSet
,JSONConverters.JSONToList
,JSONConverters.JSONToMap
,JSONConverters.ListToJSON
,JSONConverters.MapToJSON
,MiscConverters.BlobToBlob
,MiscConverters.BlobToByteArray
,MiscConverters.ByteArrayToBlob
,MiscConverters.ByteArrayToByteBuffer
,MiscConverters.ByteBufferToByteArray
,MiscConverters.CharsetToString
,MiscConverters.ClobToString
,MiscConverters.DecimalFormatToString
,MiscConverters.EnumToString
,MiscConverters.LocaleToString
,MiscConverters.RegexPatternToString
,MiscConverters.SimpleDateFormatToString
,MiscConverters.StringToCharset
,MiscConverters.StringToClob
,MiscConverters.StringToDecimalFormat
,MiscConverters.StringToLocale
,MiscConverters.StringToRegexPattern
,MiscConverters.StringToSimpleDateFormat
,MiscConverters.StringToUUID
,MiscConverters.UUIDToString
,NetConverters.InetAddressToString
,NetConverters.StringToInetAddress
,NetConverters.StringToURI
,NetConverters.StringToURL
,NetConverters.URIToString
,NetConverters.URIToURL
,NetConverters.URLToString
,NetConverters.URLToURI
,NumberConverters.DoubleToBigDecimal
,NumberConverters.FloatToBigDecimal
,NumberConverters.GenericNumberToDouble
,NumberConverters.GenericNumberToFloat
,NumberConverters.GenericNumberToInteger
,NumberConverters.GenericNumberToLong
,NumberConverters.GenericNumberToShort
,NumberConverters.IntegerToBigDecimal
,NumberConverters.IntegerToByte
,NumberConverters.LongToBigDecimal
,NumberConverters.LongToByte
,NumberConverters.StringToByte
,NumberConverters.StringToShort
public abstract class AbstractConverter<S,T> extends java.lang.Object implements Converter<S,T>, ConverterLoader
Abstract Converter class. This class handles converter registration and it implements thecanConvert
,getSourceClass
, andgetTargetClass
methods.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractConverter(java.lang.Class<? super S> sourceClass, java.lang.Class<? super T> targetClass)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canConvert(java.lang.Class<?> sourceClass, java.lang.Class<?> targetClass)
Returnstrue
if this object can convertsourceClass
totargetClass
.T
convert(java.lang.Class<? extends T> targetClass, S obj)
Convertsobj
toT
.java.lang.Class<? super S>
getSourceClass()
Returns the sourceClass
for this converter.java.lang.Class<? super T>
getTargetClass()
Returns the targetClass
for this converter.void
loadConverters()
Create and register converters with the Java object type conversion framework.
-
-
-
Method Detail
-
loadConverters
public void loadConverters()
Description copied from interface:ConverterLoader
Create and register converters with the Java object type conversion framework. If the converter extends one of the converter abstract classes, then the converter will register itself when an instance is created. Otherwise, callConverters.registerConverter(Converter)
with theConverter
instance.- Specified by:
loadConverters
in interfaceConverterLoader
-
convert
public T convert(java.lang.Class<? extends T> targetClass, S obj) throws ConversionException
Description copied from interface:Converter
Convertsobj
toT
.- Specified by:
convert
in interfaceConverter<S,T>
- Parameters:
targetClass
- TheClass
to convert toobj
- The sourceObject
to convert- Returns:
- The converted
Object
- Throws:
ConversionException
-
canConvert
public boolean canConvert(java.lang.Class<?> sourceClass, java.lang.Class<?> targetClass)
Description copied from interface:Converter
Returnstrue
if this object can convertsourceClass
totargetClass
.Implementations can accomodate class hierarchy ranges by converting super classes or interfaces.
- Specified by:
canConvert
in interfaceConverter<S,T>
- Parameters:
sourceClass
- The sourceClass
targetClass
- The targetClass
- Returns:
true
if this object can convertsourceClass
totargetClass
.
-
getSourceClass
public java.lang.Class<? super S> getSourceClass()
Description copied from interface:Converter
Returns the sourceClass
for this converter.- Specified by:
getSourceClass
in interfaceConverter<S,T>
- Returns:
- The source
Class
for this converter
-
-