1 16 package net.sf.dozer.util.mapping.converters; 17 18 import net.sf.dozer.util.mapping.MappingException; 19 import net.sf.dozer.util.mapping.vo.CustomDoubleObject; 20 import net.sf.dozer.util.mapping.vo.CustomDoubleObjectIF; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 25 28 public class TestCustomConverter implements CustomConverter { 29 30 private static final Log log = LogFactory.getLog(TestCustomConverter.class); 31 32 public Object convert(Object destination, Object source, Class destClass, Class sourceClass) { 33 log.debug("Source Class is:" + sourceClass.getName()); 35 log.debug("Dest Class is:" + destClass.getName()); 36 37 if (source == null) { 38 return null; 39 } 40 41 CustomDoubleObjectIF dest = null; 42 if (source instanceof Double ) { 43 if (destination == null) { 45 dest = new CustomDoubleObject(); 46 } else { 47 dest = (CustomDoubleObjectIF) destination; 48 } 49 dest.setTheDouble(((Double ) source).doubleValue()); 50 return dest; 51 } else if (source instanceof CustomDoubleObject) { 52 double sourceObj = ((CustomDoubleObjectIF) source).getTheDouble(); 53 return new Double (sourceObj); 54 } else { 55 throw new MappingException("Converter TestCustomConverter used incorrectly. Arguments passed in were:" 56 + destination + " and " + source); 57 } 58 } 59 } | Popular Tags |