Coverage Report - org.dozer.propertydescriptor.CustomGetSetPropertyDescriptor
 
Classes in this File Line Coverage Branch Coverage Complexity
CustomGetSetPropertyDescriptor
100%
20/20
72%
13/18
3
 
 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.lang.ref.SoftReference;
 23  
 import java.lang.reflect.Method;
 24  
 
 25  
 
 26  
 /**
 27  
  * 
 28  
  * Internal class used to read and write values for fields that have an explicitly specified getter or setter method.
 29  
  * Only intended for internal use.
 30  
  * 
 31  
  * @author garsombke.franz
 32  
  * @author tierney.matt
 33  
  */
 34  
 public class CustomGetSetPropertyDescriptor extends JavaBeanPropertyDescriptor {
 35  
 
 36  
   private final String customSetMethod;
 37  
   private final String customGetMethod;
 38  
 
 39  
   private SoftReference<Method> writeMethod;
 40  
   private SoftReference<Method> readMethod;
 41  
 
 42  
   public CustomGetSetPropertyDescriptor(Class<?> clazz, String fieldName, boolean isIndexed, int index, String customSetMethod,
 43  
       String customGetMethod, HintContainer srcDeepIndexHintContainer, HintContainer destDeepIndexHintContainer) {
 44  2449
     super(clazz, fieldName, isIndexed, index, srcDeepIndexHintContainer, destDeepIndexHintContainer);
 45  2449
     this.customSetMethod = customSetMethod;
 46  2449
     this.customGetMethod = customGetMethod;
 47  2449
   }
 48  
 
 49  
   @Override
 50  
   public Method getWriteMethod() throws NoSuchMethodException {
 51  2488
     if (writeMethod == null || writeMethod.get() == null) {
 52  2423
       if (customSetMethod != null && !MappingUtils.isDeepMapping(fieldName)) {
 53  2311
         Method method = ReflectionUtils.findAMethod(clazz, customSetMethod);
 54  2311
         writeMethod = new SoftReference<Method>(method);
 55  2311
       } else {
 56  112
         return super.getWriteMethod();
 57  
       }
 58  
     }
 59  2376
     return writeMethod.get();
 60  
   }
 61  
 
 62  
   @Override
 63  
   protected Method getReadMethod() throws NoSuchMethodException {
 64  2524
     if (readMethod == null || readMethod.get() == null) {
 65  2515
       if (customGetMethod != null) {
 66  547
         Method method = ReflectionUtils.findAMethod(clazz, customGetMethod);
 67  545
         readMethod = new SoftReference<Method>(method);
 68  545
       } else {
 69  1968
         return super.getReadMethod();
 70  
       }
 71  
     }
 72  554
     return readMethod.get();
 73  
   }
 74  
 
 75  
   @Override
 76  
   protected String getSetMethodName() throws NoSuchMethodException {
 77  14
     return customSetMethod != null ? customSetMethod : super.getSetMethodName();
 78  
   }
 79  
   
 80  
   @Override
 81  
   protected boolean isCustomSetMethod() {
 82  14
     return customSetMethod != null;
 83  
   }
 84  
 
 85  
 }