1 17 18 package org.sape.carbon.core.config.type.handlers; 19 20 21 import java.text.DateFormat ; 22 import java.text.ParseException ; 23 import java.text.SimpleDateFormat ; 24 import java.util.Date ; 25 26 import org.sape.carbon.core.config.type.ConfigurationTypeHandler; 27 import org.sape.carbon.core.config.type.TypeConversionException; 28 29 38 public class DateTypeHandler implements ConfigurationTypeHandler { 39 40 41 42 private static DateFormat dateFormat; 43 44 static { 45 DateTypeHandler.dateFormat = new SimpleDateFormat ("MM/dd/yyyy H:m:s"); 46 } 47 48 57 public Object toObject(Class type, String stringValue) 58 throws TypeConversionException { 59 60 Date object = null; 61 try { 62 object = DateTypeHandler.dateFormat.parse(stringValue); 63 } catch (ParseException pe) { 64 throw new TypeConversionException( 65 this.getClass(), 66 "Couldn't parse date", pe); 67 } 68 return object; 69 } 70 71 78 public String toString(Object objectValue) { 79 return DateTypeHandler.dateFormat.format((Date ) objectValue); 80 } 81 82 } 83 | Popular Tags |