1 16 package net.sf.dozer.util.mapping.converters; 17 18 import org.apache.commons.beanutils.Converter; 19 20 import net.sf.dozer.util.mapping.util.DateFormatContainer; 21 22 23 26 public class StringConverter implements Converter { 27 private DateFormatContainer dateFormat; 28 29 public StringConverter(DateFormatContainer dateFormat) { 30 this.dateFormat = dateFormat; 31 } 32 33 public Object convert(Class destClass, Object sourceObj) { 34 String result = null; 35 36 Class sourceClass = sourceObj.getClass(); 37 if (dateFormat != null && java.util.Date .class.isAssignableFrom(sourceClass)) { 38 result = dateFormat.getDateFormat().format((java.util.Date ) sourceObj); 39 } else if (dateFormat != null && java.util.Calendar .class.isAssignableFrom(sourceClass)) { 40 result = dateFormat.getDateFormat().format(((java.util.Calendar )sourceObj).getTime()); 41 } else { 42 result = sourceObj.toString(); 43 } 44 45 return result; 46 } 47 48 public DateFormatContainer getDateFormat() { 49 return dateFormat; 50 } 51 52 public void setDateFormat(DateFormatContainer dateFormat) { 53 this.dateFormat = dateFormat; 54 } 55 } 56 | Popular Tags |