1 16 package net.sf.dozer.util.mapping.fieldmap; 17 18 import java.lang.reflect.InvocationTargetException ; 19 import java.lang.reflect.Method ; 20 21 import net.sf.dozer.util.mapping.util.MappingUtils; 22 23 import org.apache.commons.lang.StringUtils; 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 27 33 public class MapFieldMap extends FieldMap { 34 private static final Log log = LogFactory.getLog(MapFieldMap.class); 35 36 private final MappingUtils mappingUtils = new MappingUtils(); 37 38 public void writeDestinationValue(Object destObj, Object destFieldValue, ClassMap classMap) 39 throws IllegalAccessException , InvocationTargetException , InstantiationException , ClassNotFoundException , 40 NoSuchMethodException , NoSuchFieldException { 41 Method destFieldWriteMethod = getDestFieldWriteMethod(destObj.getClass()); 42 if (destFieldWriteMethod.getParameterTypes().length == 2) { String key = null; 44 if (StringUtils.isEmpty(getSourceField().getKey())) { 45 key = getSourceField().getName(); 46 } else { 47 key = getSourceField().getKey(); 48 } 49 50 if (log.isDebugEnabled()) { 51 log.debug("Getting ready to invoke write method on the destination object: " 52 + mappingUtils.getClassNameWithoutPackage(destObj.getClass()) + ", Write Method: " 53 + destFieldWriteMethod.getName() + ", Dest value: " + destFieldValue); 54 } 55 destFieldWriteMethod.invoke(destObj, new Object [] { key, destFieldValue }); 56 } else { super.writeDestinationValue(destObj, destFieldValue, classMap); 58 } 59 } 60 61 } 62 | Popular Tags |