| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.dozer.converters; |
| 17 | |
|
| 18 | |
|
| 19 | |
import org.apache.commons.beanutils.Converter; |
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
public class StringConverter implements Converter { |
| 28 | |
private DateFormatContainer dateFormatContainer; |
| 29 | |
|
| 30 | 44494 | public StringConverter(DateFormatContainer dateFormatContainer) { |
| 31 | 44494 | this.dateFormatContainer = dateFormatContainer; |
| 32 | 44494 | } |
| 33 | |
|
| 34 | |
public Object convert(Class destClass, Object srcObj) { |
| 35 | |
String result; |
| 36 | 44493 | Class srcClass = srcObj.getClass(); |
| 37 | 44493 | if (dateFormatContainer != null && java.util.Date.class.isAssignableFrom(srcClass) |
| 38 | |
&& dateFormatContainer.getDateFormat() != null) { |
| 39 | 6 | result = dateFormatContainer.getDateFormat().format((java.util.Date) srcObj); |
| 40 | 44487 | } else if (dateFormatContainer != null && java.util.Calendar.class.isAssignableFrom(srcClass) |
| 41 | |
&& dateFormatContainer.getDateFormat() != null) { |
| 42 | 14 | result = dateFormatContainer.getDateFormat().format(((java.util.Calendar) srcObj).getTime()); |
| 43 | |
} else { |
| 44 | 44473 | result = srcObj.toString(); |
| 45 | |
} |
| 46 | |
|
| 47 | 44493 | return result; |
| 48 | |
} |
| 49 | |
|
| 50 | |
public DateFormatContainer getDateFormatContainer() { |
| 51 | 1 | return dateFormatContainer; |
| 52 | |
} |
| 53 | |
|
| 54 | |
public void setDateFormatContainer(DateFormatContainer dateFormat) { |
| 55 | 1 | this.dateFormatContainer = dateFormat; |
| 56 | 1 | } |
| 57 | |
} |