mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#28 Updating JavaDocs for API classes
This commit is contained in:
parent
2694b6e8f9
commit
5eafdb4970
@ -32,5 +32,11 @@ import java.lang.annotation.Target;
|
|||||||
@Target(ElementType.TYPE)
|
@Target(ElementType.TYPE)
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
public @interface Mapper {
|
public @interface Mapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The mapper types used by this mapper.
|
||||||
|
*
|
||||||
|
* @return The mapper types used by this mapper.
|
||||||
|
*/
|
||||||
Class<?>[] uses() default { };
|
Class<?>[] uses() default { };
|
||||||
}
|
}
|
||||||
|
@ -18,30 +18,43 @@
|
|||||||
*/
|
*/
|
||||||
package org.mapstruct;
|
package org.mapstruct;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory for getting mapper instances.
|
||||||
|
*
|
||||||
|
* @author Gunnar Morling
|
||||||
|
*/
|
||||||
public class Mappers {
|
public class Mappers {
|
||||||
|
|
||||||
private final static String IMPLEMENTATION_SUFFIX = "Impl";
|
private final static String IMPLEMENTATION_SUFFIX = "Impl";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: Check that
|
* Returns an instance of the given mapper type.
|
||||||
* - clazz is an interface
|
|
||||||
* - the implementation type implements clazz
|
|
||||||
* - clazz is annotated with @Mapper
|
|
||||||
*
|
*
|
||||||
* 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> T getMapper(Class<T> clazz) {
|
public static <T> T getMapper(Class<T> clazz) {
|
||||||
try {
|
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();
|
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 ) {
|
catch ( Exception e ) {
|
||||||
e.printStackTrace();
|
|
||||||
throw new RuntimeException( e );
|
throw new RuntimeException( e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,9 +18,24 @@
|
|||||||
*/
|
*/
|
||||||
package org.mapstruct;
|
package org.mapstruct;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures the mapping of one bean attribute.
|
||||||
|
*
|
||||||
|
* @author Gunnar Morling
|
||||||
|
*/
|
||||||
public @interface Mapping {
|
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();
|
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();
|
String target();
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,17 @@
|
|||||||
*/
|
*/
|
||||||
package org.mapstruct;
|
package org.mapstruct;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures the mappings of several bean attributes.
|
||||||
|
*
|
||||||
|
* @author Gunnar Morling
|
||||||
|
*/
|
||||||
public @interface Mappings {
|
public @interface Mappings {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The onfiguration of the bean attributes.
|
||||||
|
*
|
||||||
|
* @return The configuration of the bean attributes.
|
||||||
|
*/
|
||||||
Mapping[] value();
|
Mapping[] value();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user