Class Mappers


  • public class Mappers
    extends java.lang.Object
    Factory for obtaining mapper instances if no explicit component model such as CDI is configured via Mapper.componentModel().

    Mapper implementation types are expected to have the same fully qualified name as their interface type, with the suffix Impl appended. When using this factory, mapper types - and any mappers they use - are instantiated by invoking their public no-args constructor.

    By convention, a single instance of each mapper is retrieved from the factory and exposed on the mapper interface type by declaring a member named INSTANCE like this:

     @Mapper
     public interface CustomerMapper {
    
         CustomerMapper INSTANCE = Mappers.getMapper( CustomerMapper.class );
    
         // mapping methods...
     }
     
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String IMPLEMENTATION_SUFFIX  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Mappers()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.util.List<java.lang.ClassLoader> collectClassLoaders​(java.lang.ClassLoader classLoader)  
      private static <T> T doGetMapper​(java.lang.Class<T> clazz, java.lang.ClassLoader classLoader)  
      private static <T> java.lang.Class<? extends T> doGetMapperClass​(java.lang.Class<T> clazz, java.lang.ClassLoader classLoader)  
      static <T> T getMapper​(java.lang.Class<T> clazz)
      Returns an instance of the given mapper type.
      private static <T> T getMapper​(java.lang.Class<T> mapperType, java.lang.Iterable<java.lang.ClassLoader> classLoaders)  
      static <T> java.lang.Class<? extends T> getMapperClass​(java.lang.Class<T> clazz)
      Returns the class of the implementation for the given mapper type.
      private static <T> java.lang.Class<? extends T> getMapperClass​(java.lang.Class<T> mapperType, java.lang.Iterable<java.lang.ClassLoader> classLoaders)  
      private static <T> T getMapperFromServiceLoader​(java.lang.Class<T> clazz, java.lang.ClassLoader classLoader)  
      • Methods inherited from class java.lang.Object

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

      • IMPLEMENTATION_SUFFIX

        private static final java.lang.String IMPLEMENTATION_SUFFIX
        See Also:
        Constant Field Values
    • Constructor Detail

      • Mappers

        private Mappers()
    • Method Detail

      • getMapper

        public static <T> T getMapper​(java.lang.Class<T> clazz)
        Returns an instance of the given mapper type.
        Type Parameters:
        T - The type of the mapper to create.
        Parameters:
        clazz - The type of the mapper to return.
        Returns:
        An instance of the given mapper type.
      • getMapper

        private static <T> T getMapper​(java.lang.Class<T> mapperType,
                                       java.lang.Iterable<java.lang.ClassLoader> classLoaders)
                                throws java.lang.ClassNotFoundException,
                                       java.lang.NoSuchMethodException
        Throws:
        java.lang.ClassNotFoundException
        java.lang.NoSuchMethodException
      • doGetMapper

        private static <T> T doGetMapper​(java.lang.Class<T> clazz,
                                         java.lang.ClassLoader classLoader)
                                  throws java.lang.NoSuchMethodException
        Throws:
        java.lang.NoSuchMethodException
      • getMapperClass

        public static <T> java.lang.Class<? extends T> getMapperClass​(java.lang.Class<T> clazz)
        Returns the class of the implementation for the given mapper type.
        Type Parameters:
        T - The type of the mapper to create.
        Parameters:
        clazz - The type of the mapper to return.
        Returns:
        A class of the implementation for the given mapper type.
        Since:
        1.3
      • getMapperClass

        private static <T> java.lang.Class<? extends T> getMapperClass​(java.lang.Class<T> mapperType,
                                                                       java.lang.Iterable<java.lang.ClassLoader> classLoaders)
                                                                throws java.lang.ClassNotFoundException
        Throws:
        java.lang.ClassNotFoundException
      • doGetMapperClass

        private static <T> java.lang.Class<? extends T> doGetMapperClass​(java.lang.Class<T> clazz,
                                                                         java.lang.ClassLoader classLoader)
      • getMapperFromServiceLoader

        private static <T> T getMapperFromServiceLoader​(java.lang.Class<T> clazz,
                                                        java.lang.ClassLoader classLoader)
      • collectClassLoaders

        private static java.util.List<java.lang.ClassLoader> collectClassLoaders​(java.lang.ClassLoader classLoader)