1 package org.sapia.soto.config.types; 2 3 import java.text.DateFormat ; 4 import java.text.ParseException ; 5 import java.text.SimpleDateFormat ; 6 7 import org.sapia.util.xml.confix.ConfigurationException; 8 import org.sapia.util.xml.confix.ObjectCreationCallback; 9 10 19 public class DateType implements ObjectCreationCallback{ 20 21 private String _value, _pattern; 22 23 public void setValue(String value){ 24 _value = value; 25 } 26 27 36 public void setPattern(String pattern){ 37 _pattern = pattern; 38 } 39 40 43 public Object onCreate() throws ConfigurationException { 44 if(_value == null){ 45 throw new ConfigurationException("Date value not specified"); 46 } 47 try{ 48 if(_pattern == null){ 49 return DateFormat.getDateInstance().parse(_value); 50 } 51 else{ 52 SimpleDateFormat fm = new SimpleDateFormat (_pattern); 53 return fm.parseObject(_value); 54 } 55 }catch(ParseException e){ 56 throw new ConfigurationException("Could not parse date: " + _value + "; " + 57 "have you specified an appropriate pattern?", e); 58 } 59 } 60 } 61 | Popular Tags |