Class ConverterManagerImpl

  • All Implemented Interfaces:
    ConverterManager

    public final class ConverterManagerImpl
    extends java.lang.Object
    implements ConverterManager
    An implementation of ConverterManager.

    The algorithm used is to:

    1. Try to find and use a Converter registered for the fromClass, syntax and toClass and use it.
    2. If this fails, then if the toClass isAssignableFrom the fromClass then just assign it.
    3. If this fails try to find and use a Converter registered for the fromClass and the toClass ignoring the syntax.
    4. If this fails then throw a ConverterException.
    • Constructor Summary

      Constructors 
      Constructor Description
      ConverterManagerImpl()
      Create an empty ConverterManagerImpl
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addConverter​(java.lang.Class<?> fromClass, java.lang.String syntax, java.lang.Class<?> toClass, Converter converter)
      Add a Converter to this ConverterManager.
      boolean canConvert​(java.lang.Class<?> fromClass, java.lang.String syntax, java.lang.Class<?> toClass)
      Determine whether this converter manager is able to carry out a specified conversion.
      <T> T convert​(java.lang.Object source, java.lang.String syntax, java.lang.Class<T> toClass)
      Convert a given source object with an optional LDAP syntax to an instance of a given class.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ConverterManagerImpl

        public ConverterManagerImpl()
        Create an empty ConverterManagerImpl
    • Method Detail

      • canConvert

        public boolean canConvert​(java.lang.Class<?> fromClass,
                                  java.lang.String syntax,
                                  java.lang.Class<?> toClass)
        Description copied from interface: ConverterManager
        Determine whether this converter manager is able to carry out a specified conversion.
        Specified by:
        canConvert in interface ConverterManager
        Parameters:
        fromClass - Convert from the fromClass.
        syntax - Using the LDAP syntax (may be null).
        toClass - To the toClass.
        Returns:
        True if the conversion is supported, false otherwise.
      • convert

        public <T> T convert​(java.lang.Object source,
                             java.lang.String syntax,
                             java.lang.Class<T> toClass)
        Description copied from interface: ConverterManager
        Convert a given source object with an optional LDAP syntax to an instance of a given class.
        Specified by:
        convert in interface ConverterManager
        Type Parameters:
        T - The class to convert to.
        Parameters:
        source - The object to convert.
        syntax - The LDAP syntax to use (may be null).
        toClass - The class to convert to.
        Returns:
        The converted object.
      • addConverter

        public void addConverter​(java.lang.Class<?> fromClass,
                                 java.lang.String syntax,
                                 java.lang.Class<?> toClass,
                                 Converter converter)
        Add a Converter to this ConverterManager.
        Parameters:
        fromClass - The class the Converter should be used to convert from.
        syntax - The LDAP syntax that the Converter should be used for.
        toClass - The class the Converter should be used to convert to.
        converter - The Converter to add.