/src/main/java/com/google/gwt/user/client/rpc/core/java/sql/Date_CustomFieldSerializer.java

https://bitbucket.org/chii/gwt-syncproxy · Java · 71 lines · 40 code · 10 blank · 21 comment · 0 complexity · c1042f4d3b03f844089f910ea3373612 MD5 · raw file

  1. /*
  2. * Copyright 2008 Google Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.google.gwt.user.client.rpc.core.java.sql;
  17. import com.google.gwt.user.client.rpc.CustomFieldSerializer;
  18. import com.google.gwt.user.client.rpc.SerializationException;
  19. import com.google.gwt.user.client.rpc.SerializationStreamReader;
  20. import com.google.gwt.user.client.rpc.SerializationStreamWriter;
  21. import java.sql.Date;
  22. /**
  23. * Custom field serializer for {@link java.sql.Date}. Similar to Time, we use
  24. * the three-arg constructor to account for variances in implementations of
  25. * Date.
  26. */
  27. public final class Date_CustomFieldSerializer extends
  28. CustomFieldSerializer<Date> {
  29. @SuppressWarnings("unused")
  30. public static void deserialize(SerializationStreamReader streamReader,
  31. Date instance) {
  32. // No fields
  33. }
  34. public static Date instantiate(SerializationStreamReader streamReader)
  35. throws SerializationException {
  36. return new Date(streamReader.readLong());
  37. }
  38. public static void serialize(SerializationStreamWriter streamWriter,
  39. Date instance) throws SerializationException {
  40. streamWriter.writeLong(instance.getTime());
  41. }
  42. @Override
  43. public void deserializeInstance(SerializationStreamReader streamReader,
  44. Date instance) throws SerializationException {
  45. deserialize(streamReader, instance);
  46. }
  47. @Override
  48. public boolean hasCustomInstantiateInstance() {
  49. return true;
  50. }
  51. @Override
  52. public Date instantiateInstance(SerializationStreamReader streamReader)
  53. throws SerializationException {
  54. return instantiate(streamReader);
  55. }
  56. @Override
  57. public void serializeInstance(SerializationStreamWriter streamWriter,
  58. Date instance) throws SerializationException {
  59. serialize(streamWriter, instance);
  60. }
  61. }