KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > bean > converters > SqlDateConverter


1 package jodd.bean.converters;
2
3 import java.sql.Date;
4
5
6 /**
7  * Converts given object to java.sql.Date.
8  */

9 public final class SqlDateConverter implements jodd.bean.Converter {
10
11     public Object convert(Object value) {
12     
13         if (value == null) {
14             return (Date) null;
15         }
16     
17         if (value instanceof Date) {
18             return value;
19         }
20     
21         try {
22             return (Date.valueOf(value.toString()));
23         } catch (Exception e) {
24             throw new IllegalArgumentException("SqlDate conversion for " + value + " failed.");
25         }
26     }
27 }
28
Popular Tags