| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.dozer.loader.api; |
| 17 | |
|
| 18 | |
import org.dozer.classmap.MappingFileData; |
| 19 | |
import org.dozer.loader.DozerBuilder; |
| 20 | |
import org.dozer.util.DozerConstants; |
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
public abstract class BeanMappingBuilder { |
| 29 | |
|
| 30 | |
private DozerBuilder dozerBuilder; |
| 31 | |
|
| 32 | 27 | public BeanMappingBuilder() { |
| 33 | 27 | } |
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
public MappingFileData build() { |
| 40 | 27 | dozerBuilder = new DozerBuilder(); |
| 41 | 27 | configure(); |
| 42 | 27 | return dozerBuilder.build(); |
| 43 | |
} |
| 44 | |
|
| 45 | |
public TypeMappingBuilder mapping(String typeA, String typeB, TypeMappingOption ... typeMappingOption) { |
| 46 | 0 | return mapping(new TypeDefinition(typeA), new TypeDefinition(typeB), typeMappingOption); |
| 47 | |
} |
| 48 | |
|
| 49 | |
public TypeMappingBuilder mapping(TypeDefinition typeA, String typeB, TypeMappingOption ... typeMappingOption) { |
| 50 | 0 | return mapping(typeA, new TypeDefinition(typeB), typeMappingOption); |
| 51 | |
} |
| 52 | |
|
| 53 | |
public TypeMappingBuilder mapping(String typeA, TypeDefinition typeB, TypeMappingOption ... typeMappingOption) { |
| 54 | 0 | return mapping(new TypeDefinition(typeA), typeB, typeMappingOption); |
| 55 | |
} |
| 56 | |
|
| 57 | |
public TypeMappingBuilder mapping(Class<?> typeA, Class<?> typeB, TypeMappingOption ... typeMappingOption) { |
| 58 | 24 | return mapping(new TypeDefinition(typeA), new TypeDefinition(typeB), typeMappingOption); |
| 59 | |
} |
| 60 | |
|
| 61 | |
public TypeMappingBuilder mapping(TypeDefinition typeA, Class<?> typeB, TypeMappingOption ... typeMappingOption) { |
| 62 | 0 | return mapping(typeA, new TypeDefinition(typeB), typeMappingOption); |
| 63 | |
} |
| 64 | |
|
| 65 | |
public TypeMappingBuilder mapping(Class<?> typeA, TypeDefinition typeB, TypeMappingOption ... typeMappingOption) { |
| 66 | 0 | return mapping(new TypeDefinition(typeA), typeB, typeMappingOption); |
| 67 | |
} |
| 68 | |
|
| 69 | |
public TypeMappingBuilder mapping(TypeDefinition typeA, TypeDefinition typeB, TypeMappingOption ... typeMappingOption) { |
| 70 | 29 | DozerBuilder.MappingBuilder mappingBuilder = dozerBuilder.mapping(); |
| 71 | 29 | DozerBuilder.ClassDefinitionBuilder typeBuilderA = mappingBuilder.classA(typeA.getName()); |
| 72 | 29 | DozerBuilder.ClassDefinitionBuilder typeBuilderB = mappingBuilder.classB(typeB.getName()); |
| 73 | |
|
| 74 | 29 | typeA.build(typeBuilderA); |
| 75 | 29 | typeB.build(typeBuilderB); |
| 76 | |
|
| 77 | 53 | for (TypeMappingOption option : typeMappingOption) { |
| 78 | 24 | option.apply(mappingBuilder); |
| 79 | |
} |
| 80 | |
|
| 81 | 29 | return new TypeMappingBuilder(mappingBuilder); |
| 82 | |
} |
| 83 | |
|
| 84 | |
public TypeDefinition type(String name) { |
| 85 | 1 | return new TypeDefinition(name); |
| 86 | |
} |
| 87 | |
|
| 88 | |
public TypeDefinition type(Class<?> type) { |
| 89 | 9 | return new TypeDefinition(type); |
| 90 | |
} |
| 91 | |
|
| 92 | |
public FieldDefinition field(String name) { |
| 93 | 7 | return new FieldDefinition(name); |
| 94 | |
} |
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
public FieldDefinition this_() { |
| 101 | 3 | return new FieldDefinition(DozerConstants.SELF_KEYWORD); |
| 102 | |
} |
| 103 | |
|
| 104 | |
protected abstract void configure(); |
| 105 | |
|
| 106 | |
} |