1 16 package net.sf.dozer.util.mapping.util; 17 18 import java.text.DateFormat ; 19 import java.text.SimpleDateFormat ; 20 import java.util.Locale ; 21 22 import net.sf.dozer.util.mapping.fieldmap.ClassMap; 23 import net.sf.dozer.util.mapping.fieldmap.FieldMap; 24 25 26 29 public class DateFormatContainer { 30 private final ClassMap classMap; 31 private final FieldMap fieldMap; 32 private DateFormat dateFormat; 33 34 public DateFormatContainer(ClassMap classMap, FieldMap fieldMap) { 35 this.classMap = classMap; 36 this.fieldMap = fieldMap; 37 } 38 39 public DateFormat getDateFormat() { 40 if (dateFormat == null) { 41 dateFormat = determineDateFormat(); 42 } 43 return dateFormat; 44 } 45 46 public void setDateFormat(DateFormat dateFormat) { 47 this.dateFormat = dateFormat; 48 } 49 50 private DateFormat determineDateFormat() { 51 if (classMap == null || fieldMap == null) { 52 return null; 53 } 54 String dfStr = fieldMap.getSourceField().getDateFormat() == null ? fieldMap.getDestField().getDateFormat() 56 : fieldMap.getSourceField().getDateFormat(); 57 58 MappingUtils mappingUtils = new MappingUtils(); 61 if (mappingUtils.isBlankOrNull(dfStr)) { 62 dfStr = classMap.getDateFormat(); 63 } 64 65 return dfStr == null ? null : new SimpleDateFormat (dfStr, Locale.getDefault()); 66 } 67 } 68 | Popular Tags |