1 package org.codehaus.xfire.aegis.type.basic;
2
3 import java.text.ParseException;
4 import java.util.Calendar;
5 import java.util.Date;
6
7 import org.codehaus.xfire.MessageContext;
8 import org.codehaus.xfire.aegis.MessageReader;
9 import org.codehaus.xfire.aegis.MessageWriter;
10 import org.codehaus.xfire.aegis.type.Type;
11 import org.codehaus.xfire.fault.XFireFault;
12 import org.codehaus.xfire.util.date.XsDateFormat;
13
14 /***
15 * Type for the Date class which serializes as an xsd:date (no time information).
16 *
17 * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
18 */
19 public class DateType
20 extends Type
21 {
22 private static XsDateFormat format = new XsDateFormat();
23
24 public Object readObject(MessageReader reader, MessageContext context) throws XFireFault
25 {
26 String value = reader.getValue();
27
28 if (value == null) return null;
29
30 try
31 {
32 Calendar c = (Calendar) format.parseObject(value);
33 return c.getTime();
34 }
35 catch (ParseException e)
36 {
37 throw new XFireFault("Could not parse xs:dat: " + e.getMessage(), e, XFireFault.SENDER);
38 }
39 }
40
41 public void writeObject(Object object, MessageWriter writer, MessageContext context)
42 {
43 Calendar c = Calendar.getInstance();
44 c.setTime((Date) object);
45 writer.writeValue(format.format(c));
46 }
47 }