View Javadoc

    1   package org.codehaus.xfire.aegis.type.basic;
    2
    3   import java.sql.Timestamp;
    4   import java.text.ParseException;
    5   import java.util.Calendar;
    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.XsDateTimeFormat;
    13
    14  /***
    15   * Type for the Time class which serializes to an xs:time.
    16   *
    17   * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
    18   */
    19  public class TimestampType
    20      extends Type
    21  {
    22      private static XsDateTimeFormat format = new XsDateTimeFormat();
    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 new Timestamp(c.getTimeInMillis());
    34          }
    35          catch (ParseException e)
    36          {
    37              throw new XFireFault("Could not parse xs:dateTime: " + 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((Timestamp) object);
    45          writer.writeValue(format.format(c));
    46      }
    47  }