KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > typeconverter > SqlTimeConverter


1 // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
2

3 package jodd.typeconverter;
4
5 import java.sql.Time JavaDoc;
6
7 /**
8  * Converts given object to java.sql.Time.
9  */

10 public class SqlTimeConverter implements TypeConverter {
11
12     public static Time JavaDoc valueOf(Object JavaDoc value) {
13
14         if (value == null) {
15             return null;
16         }
17         if (value instanceof Time JavaDoc) {
18             return (Time JavaDoc) value;
19         }
20         if (value instanceof Number JavaDoc) {
21             return new Time JavaDoc(((Number JavaDoc) value).longValue());
22         }
23
24         try {
25             return (Time.valueOf(value.toString()));
26         } catch (IllegalArgumentException JavaDoc iaex) {
27             throw new TypeConversionException(iaex);
28         }
29     }
30
31     public Object JavaDoc convert(Object JavaDoc value) {
32         return valueOf(value);
33     }
34 }
35
Popular Tags