1 3 package jodd.datetime; 4 5 import jodd.datetime.converter.*; 6 7 import java.util.Map ; 8 import java.util.HashMap ; 9 import java.util.Iterator ; 10 import java.util.Calendar ; 11 12 16 public class JdtConverterManager { 17 18 20 private static Map converters = new HashMap (); 21 22 static { 23 registerDefaults(); 24 } 25 26 29 public static void unregisterAll() { 30 converters.clear(); 31 } 32 33 34 38 public static void registerDefaults() { 39 register(DateTimeStamp.class, new DateTimeStampConverter()); 40 register(Calendar .class, new CalendarConverter()); 41 register(java.util.GregorianCalendar .class, new GregorianCalendarConverter()); 42 register(java.util.Date .class, new DateConverter()); 43 register(java.sql.Date .class, new SqlDateConverter()); 44 register(java.sql.Timestamp .class, new SqlTimestampConverter()); 45 } 46 47 52 public static void register(Class type, JdtConverter converter) { 53 converters.put(type, converter); 54 } 55 56 public static void unregister(Class type) { 57 converters.remove(type); 58 } 59 60 61 63 64 68 public static JdtConverter lookup(Class type) { 69 return (JdtConverter) converters.get(type); 70 } 71 72 76 public static JdtConverter lookup(Object source) { 77 JdtConverter converter = lookup(source.getClass()); 78 if (converter == null) { Iterator it = converters.keySet().iterator(); 80 while (it.hasNext()) { 81 Class key = (Class ) it.next(); 82 if (key.isInstance(source)) { 83 converter = lookup(key); 84 break; 85 } 86 } 87 } 88 return converter; 89 } 90 91 } 92 | Popular Tags |