KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > typeconverter > JDateTimeConverter


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

3 package jodd.typeconverter;
4
5 import jodd.datetime.JDateTime;
6 import jodd.datetime.DateTimeStamp;
7 import jodd.datetime.JulianDateStamp;
8
9 /**
10  * Converts object to {@link JDateTime}.
11  */

12 public class JDateTimeConverter implements TypeConverter {
13
14     public static JDateTime valueOf(Object JavaDoc value) {
15
16         if (value == null) {
17             return null;
18         }
19
20         if (value instanceof JDateTime) {
21             return (JDateTime) value;
22         }
23         if (value instanceof Number JavaDoc) {
24             return new JDateTime(((Number JavaDoc) value).longValue());
25         }
26         if (value instanceof DateTimeStamp) {
27             return new JDateTime((DateTimeStamp) value);
28         }
29         if (value instanceof JulianDateStamp) {
30             return new JDateTime((JulianDateStamp) value);
31         }
32
33         try {
34             return new JDateTime(value);
35         } catch (IllegalArgumentException JavaDoc iaex) {
36             throw new TypeConversionException(iaex);
37         }
38     }
39
40     public Object JavaDoc convert(Object JavaDoc value) {
41         return valueOf(value);
42     }
43 }
44
Popular Tags