Coverage Report - org.dozer.loader.api.BeanMappingBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
BeanMappingBuilder
78%
18/23
100%
2/2
1.071
 
 1  
 /**
 2  
  * Copyright 2005-2013 Dozer Project
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 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  
  * Programmatic Builder of Dozer mappings.
 25  
  *
 26  
  * @author Dmitry Buzdin
 27  
  */
 28  
 public abstract class BeanMappingBuilder {
 29  
 
 30  
   private DozerBuilder dozerBuilder;
 31  
 
 32  27
   public BeanMappingBuilder() {
 33  27
   }
 34  
 
 35  
   /**
 36  
    * For internal use
 37  
    * @return mappings created with given builder
 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  
    * References current object in mapping process.
 98  
    * @return field definition
 99  
    */
 100  
   public FieldDefinition this_() {
 101  3
     return new FieldDefinition(DozerConstants.SELF_KEYWORD);
 102  
   }
 103  
 
 104  
   protected abstract void configure();
 105  
 
 106  
 }