Class Converters


  • public class Converters
    extends java.lang.Object
    A Converter factory and repository.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static java.util.concurrent.ConcurrentHashMap<java.lang.String,​Converter<?,​?>> converterMap  
      protected static java.lang.String DELIMITER  
      protected static java.lang.String module  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <S,​T>
      Converter<S,​T>
      getConverter​(java.lang.Class<S> sourceClass, java.lang.Class<T> targetClass)
      Returns an appropriate Converter instance for sourceClass and targetClass.
      static void loadContainedConverters​(java.lang.Class<?> containerClass)
      Load all classes that implement Converter and are contained in containerClass.
      static <S,​T>
      void
      registerConverter​(Converter<S,​T> converter)
      Registers a Converter instance to be used by the getConverter(Class, Class) method.
      static <S,​T>
      void
      registerConverter​(Converter<S,​T> converter, java.lang.Class<?> sourceClass, java.lang.Class<?> targetClass)  
      static <S,​T>
      void
      registerCreator​(ConverterCreator creator)
      Registers a ConverterCreater instance to be used by the getConverter(Class, Class) method, when a converter can't be found.
      • Methods inherited from class java.lang.Object

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

      • module

        protected static final java.lang.String module
      • converterMap

        protected static final java.util.concurrent.ConcurrentHashMap<java.lang.String,​Converter<?,​?>> converterMap
    • Method Detail

      • getConverter

        public static <S,​T> Converter<S,​T> getConverter​(java.lang.Class<S> sourceClass,
                                                                    java.lang.Class<T> targetClass)
                                                             throws java.lang.ClassNotFoundException
        Returns an appropriate Converter instance for sourceClass and targetClass. If no matching Converter is found, the method throws ClassNotFoundException.

        This method is intended to be used when the source or target Object types are unknown at compile time. If the source and target Object types are known at compile time, then one of the "ready made" converters should be used.

        Parameters:
        sourceClass - The object class to convert from
        targetClass - The object class to convert to
        Returns:
        A matching Converter instance
        Throws:
        java.lang.ClassNotFoundException
      • loadContainedConverters

        public static void loadContainedConverters​(java.lang.Class<?> containerClass)
        Load all classes that implement Converter and are contained in containerClass.
        Parameters:
        containerClass -
      • registerCreator

        public static <S,​T> void registerCreator​(ConverterCreator creator)
        Registers a ConverterCreater instance to be used by the getConverter(Class, Class) method, when a converter can't be found.
        Type Parameters:
        S - The source object type
        T - The target object type
        Parameters:
        creator - The ConverterCreater instance to register
      • registerConverter

        public static <S,​T> void registerConverter​(Converter<S,​T> converter)
        Registers a Converter instance to be used by the getConverter(Class, Class) method.
        Type Parameters:
        S - The source object type
        T - The target object type
        Parameters:
        converter - The Converter instance to register
      • registerConverter

        public static <S,​T> void registerConverter​(Converter<S,​T> converter,
                                                         java.lang.Class<?> sourceClass,
                                                         java.lang.Class<?> targetClass)