Coverage Report - org.dozer.propertydescriptor.JavaBeanPropertyDescriptor
 
Classes in this File Line Coverage Branch Coverage Complexity
JavaBeanPropertyDescriptor
94%
17/18
100%
10/10
2.167
 
 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.propertydescriptor;
 17  
 
 18  
 import org.dozer.fieldmap.HintContainer;
 19  
 import org.dozer.util.MappingUtils;
 20  
 import org.dozer.util.ReflectionUtils;
 21  
 
 22  
 import java.beans.PropertyDescriptor;
 23  
 import java.lang.reflect.Method;
 24  
 
 25  
 /**
 26  
  * 
 27  
  * Internal class used to read and write values for fields that follow the java bean spec and have corresponding
 28  
  * getter/setter methods for the field that are name accordingly. If the field does not have the necessary
 29  
  * getter/setter, an exception will be thrown. Only intended for internal use.
 30  
  * 
 31  
  * @author garsombke.franz
 32  
  * @author tierney.matt
 33  
  */
 34  
 public class JavaBeanPropertyDescriptor extends GetterSetterPropertyDescriptor {
 35  
   private PropertyDescriptor pd;
 36  
 
 37  
   public JavaBeanPropertyDescriptor(Class<?> clazz, String fieldName, boolean isIndexed, int index,
 38  
       HintContainer srcDeepIndexHintContainer, HintContainer destDeepIndexHintContainer) {
 39  58018
     super(clazz, fieldName, isIndexed, index, srcDeepIndexHintContainer, destDeepIndexHintContainer);
 40  58018
   }
 41  
 
 42  
   @Override
 43  
   public Method getWriteMethod() throws NoSuchMethodException {
 44  97817
     Method result = getPropertyDescriptor(destDeepIndexHintContainer).getWriteMethod();
 45  97813
     result = result == null ? ReflectionUtils.getNonVoidSetter(clazz, fieldName) : result;
 46  97813
     if (result == null) {
 47  378
       throw new NoSuchMethodException("Unable to determine write method for Field: '" + fieldName + "' in Class: " + clazz);
 48  
     }
 49  97435
     return result;
 50  
   }
 51  
 
 52  
   @Override
 53  
   protected String getSetMethodName() throws NoSuchMethodException {
 54  0
     return getWriteMethod().getName();
 55  
   }
 56  
 
 57  
   @Override
 58  
   protected Method getReadMethod() throws NoSuchMethodException {
 59  323965
     Method result = getPropertyDescriptor(srcDeepIndexHintContainer).getReadMethod();
 60  323870
     if (result == null) {
 61  112
       throw new NoSuchMethodException("Unable to determine read method for Field: '" + fieldName + "' in Class: " + clazz);
 62  
     }
 63  323758
     return result;
 64  
   }
 65  
 
 66  
   @Override
 67  
   protected boolean isCustomSetMethod() {
 68  131336
     return false;
 69  
   }
 70  
 
 71  
   private PropertyDescriptor getPropertyDescriptor(HintContainer deepIndexHintContainer) {
 72  421782
     if (pd == null) {
 73  57370
       pd = ReflectionUtils.findPropertyDescriptor(clazz, fieldName, deepIndexHintContainer);
 74  57287
       if (pd == null) {
 75  16
         MappingUtils.throwMappingException("Property: '" + fieldName + "' not found in Class: " + clazz);
 76  
       }
 77  
     }
 78  421683
     return pd;
 79  
   }
 80  
 
 81  
 }