View Javadoc

    1   package org.codehaus.xfire.aegis.type.basic;
    2
    3   import java.sql.Time;
    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.XsTimeFormat;
    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 TimeType
    20      extends Type
    21  {
    22      private static XsTimeFormat format = new XsTimeFormat();
    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 Time(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((Time) object);
    45          writer.writeValue(format.format(c));
    46      }
    47  }