From 5eafdb49702f59539efcdf216023ef3682975be6 Mon Sep 17 00:00:00 2001 From: Gunnar Morling Date: Wed, 29 May 2013 23:58:54 +0200 Subject: [PATCH] #28 Updating JavaDocs for API classes --- core/src/main/java/org/mapstruct/Mapper.java | 6 ++++ core/src/main/java/org/mapstruct/Mappers.java | 33 +++++++++++++------ core/src/main/java/org/mapstruct/Mapping.java | 15 +++++++++ .../src/main/java/org/mapstruct/Mappings.java | 11 ++++++- integrationtest/pom.xml | 4 +-- 5 files changed, 56 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/org/mapstruct/Mapper.java b/core/src/main/java/org/mapstruct/Mapper.java index 1a4a6b44a..19c3fd867 100644 --- a/core/src/main/java/org/mapstruct/Mapper.java +++ b/core/src/main/java/org/mapstruct/Mapper.java @@ -32,5 +32,11 @@ import java.lang.annotation.Target; @Target(ElementType.TYPE) @Retention(RetentionPolicy.SOURCE) public @interface Mapper { + + /** + * The mapper types used by this mapper. + * + * @return The mapper types used by this mapper. + */ Class[] uses() default { }; } diff --git a/core/src/main/java/org/mapstruct/Mappers.java b/core/src/main/java/org/mapstruct/Mappers.java index 0cc65c320..9dac57563 100644 --- a/core/src/main/java/org/mapstruct/Mappers.java +++ b/core/src/main/java/org/mapstruct/Mappers.java @@ -18,30 +18,43 @@ */ package org.mapstruct; - +/** + * Factory for getting mapper instances. + * + * @author Gunnar Morling + */ public class Mappers { private final static String IMPLEMENTATION_SUFFIX = "Impl"; /** - * TODO: Check that - * - clazz is an interface - * - the implementation type implements clazz - * - clazz is annotated with @Mapper + * Returns an instance of the given mapper type. * - * TODO: Use privileged action + * @param clazz The type of the mapper to return. + * + * @return An instance of the given mapper type. */ - @SuppressWarnings("unchecked") public static T getMapper(Class clazz) { try { -// ClassLoader classLoader = clazz.getClassLoader(); + // Check that + // - clazz is an interface + // - the implementation type implements clazz + // - clazz is annotated with @Mapper + // + // Use privileged action ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - return (T) classLoader.loadClass( clazz.getName() + IMPLEMENTATION_SUFFIX ).newInstance(); + if ( classLoader == null ) { + classLoader = Mappers.class.getClassLoader(); + } + + @SuppressWarnings("unchecked") + T mapper = (T) classLoader.loadClass( clazz.getName() + IMPLEMENTATION_SUFFIX ).newInstance(); + + return mapper; } catch ( Exception e ) { - e.printStackTrace(); throw new RuntimeException( e ); } } diff --git a/core/src/main/java/org/mapstruct/Mapping.java b/core/src/main/java/org/mapstruct/Mapping.java index 82fd6b98b..c0c31859b 100644 --- a/core/src/main/java/org/mapstruct/Mapping.java +++ b/core/src/main/java/org/mapstruct/Mapping.java @@ -18,9 +18,24 @@ */ package org.mapstruct; +/** + * Configures the mapping of one bean attribute. + * + * @author Gunnar Morling + */ public @interface Mapping { + /** + * The source name of the configured property as defined by the JavaBeans specification. + * + * @return The source name of the configured property. + */ String source(); + /** + * The target name of the configured property as defined by the JavaBeans specification. + * + * @return The target name of the configured property. + */ String target(); } diff --git a/core/src/main/java/org/mapstruct/Mappings.java b/core/src/main/java/org/mapstruct/Mappings.java index 9ff51fcf9..d418e7126 100644 --- a/core/src/main/java/org/mapstruct/Mappings.java +++ b/core/src/main/java/org/mapstruct/Mappings.java @@ -18,8 +18,17 @@ */ package org.mapstruct; - +/** + * Configures the mappings of several bean attributes. + * + * @author Gunnar Morling + */ public @interface Mappings { + /** + * The onfiguration of the bean attributes. + * + * @return The configuration of the bean attributes. + */ Mapping[] value(); } diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index ae1af64ad..d8f773257 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -64,8 +64,8 @@ org.mapstruct.ap.MappingProcessor - - false + + false