View Javadoc

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