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, 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.StringBufferToString, MiscConverters.StringToCharset, MiscConverters.StringToClob, MiscConverters.StringToDecimalFormat, MiscConverters.StringToLocale, MiscConverters.StringToRegexPattern, MiscConverters.StringToSimpleDateFormat, MiscConverters.StringToUUID, MiscConverters.StringWrapperToString, 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.IntegerToBigInteger, NumberConverters.IntegerToByte, NumberConverters.LongToBigDecimal, NumberConverters.LongToByte, NumberConverters.StringToByte, NumberConverters.StringToShort

public abstract class AbstractConverter<S,T> extends Object implements Converter<S,T>, ConverterLoader
Abstract Converter class. This class handles converter registration and it implements the canConvert, getSourceClass, and getTargetClass methods.
  • Constructor Details

    • AbstractConverter

      protected AbstractConverter(Class<? super S> sourceClass, Class<? super T> targetClass)
  • Method Details

    • 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, call Converters.registerConverter(Converter) with the Converter instance.
      Specified by:
      loadConverters in interface ConverterLoader
    • convert

      public T convert(Class<? extends T> targetClass, S obj) throws ConversionException
      Description copied from interface: Converter
      Converts obj to T.
      Specified by:
      convert in interface Converter<S,T>
      Parameters:
      targetClass - The Class to convert to
      obj - The source Object to convert
      Returns:
      The converted Object
      Throws:
      ConversionException
    • canConvert

      public boolean canConvert(Class<?> sourceClass, Class<?> targetClass)
      Description copied from interface: Converter
      Returns true if this object can convert sourceClass to targetClass.

      Implementations can accomodate class hierarchy ranges by converting super classes or interfaces.

      Specified by:
      canConvert in interface Converter<S,T>
      Parameters:
      sourceClass - The source Class
      targetClass - The target Class
      Returns:
      true if this object can convert sourceClass to targetClass.
    • getSourceClass

      public Class<? super S> getSourceClass()
      Description copied from interface: Converter
      Returns the source Class for this converter.
      Specified by:
      getSourceClass in interface Converter<S,T>
      Returns:
      The source Class for this converter
    • getTargetClass

      public Class<? super T> getTargetClass()
      Description copied from interface: Converter
      Returns the target Class for this converter.
      Specified by:
      getTargetClass in interface Converter<S,T>
      Returns:
      The target Class for this converter