Package org.mapstruct.factory
Class Mappers
- java.lang.Object
-
- org.mapstruct.factory.Mappers
-
public class Mappers extends java.lang.ObjectFactory for obtaining mapper instances if no explicit component model such as CDI is configured viaMapper.componentModel().Mapper implementation types are expected to have the same fully qualified name as their interface type, with the suffix
Implappended. 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
INSTANCElike 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.StringIMPLEMENTATION_SUFFIX
-
Constructor Summary
Constructors Modifier Constructor Description privateMappers()
-
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> TdoGetMapper(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> TgetMapper(java.lang.Class<T> clazz)Returns an instance of the given mapper type.private static <T> TgetMapper(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> TgetMapperFromServiceLoader(java.lang.Class<T> clazz, java.lang.ClassLoader classLoader)
-
-
-
Field Detail
-
IMPLEMENTATION_SUFFIX
private static final java.lang.String IMPLEMENTATION_SUFFIX
- See Also:
- Constant Field Values
-
-
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.ClassNotFoundExceptionjava.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)
-
-