Coverage Report - org.dozer.classmap.generator.GeneratorUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
GeneratorUtils
91%
11/12
90%
9/10
3.333
 
 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.classmap.generator;
 17  
 
 18  
 import org.dozer.classmap.ClassMap;
 19  
 import org.dozer.classmap.Configuration;
 20  
 import org.dozer.fieldmap.DozerField;
 21  
 import org.dozer.fieldmap.FieldMap;
 22  
 import org.dozer.fieldmap.GenericFieldMap;
 23  
 import org.dozer.util.MappingUtils;
 24  
 
 25  
 /**
 26  
  * @author Dmitry Spikhalskiy
 27  
  */
 28  
 public final class GeneratorUtils {
 29  
   private static final String CLASS = "class";
 30  
   private static final String CALLBACK = "callback";
 31  
   private static final String CALLBACKS = "callbacks";
 32  
 
 33  0
   private GeneratorUtils() {}
 34  
 
 35  
   public static boolean shouldIgnoreField(String fieldName, Class<?> srcType, Class<?> destType) {
 36  28153
     if (CLASS.equals(fieldName)) {
 37  1024
       return true;
 38  
     }
 39  27129
     if ((CALLBACK.equals(fieldName) || CALLBACKS.equals(fieldName))
 40  
             && (MappingUtils.isProxy(srcType) || MappingUtils.isProxy(destType))) {
 41  14
       return true;
 42  
     }
 43  27115
     return false;
 44  
   }
 45  
 
 46  
   public static void addGenericMapping(ClassMap classMap, Configuration configuration, String srcName, String destName) {
 47  13427
     FieldMap fieldMap = new GenericFieldMap(classMap);
 48  
 
 49  13427
     fieldMap.setSrcField(new DozerField(srcName, null));
 50  13427
     fieldMap.setDestField(new DozerField(destName, null));
 51  
 
 52  
     // add CopyByReferences per defect #1728159
 53  13427
     MappingUtils.applyGlobalCopyByReference(configuration, fieldMap, classMap);
 54  13427
     classMap.addFieldMapping(fieldMap);
 55  13427
   }
 56  
 }