KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > objectserver > managedobject > ManagedObjectStateSerializer


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.objectserver.managedobject;
5
6 import com.tc.exception.TCRuntimeException;
7 import com.tc.io.serializer.api.Serializer;
8 import com.tc.objectserver.core.api.ManagedObjectState;
9
10 import java.io.IOException JavaDoc;
11 import java.io.ObjectInput JavaDoc;
12 import java.io.ObjectOutput JavaDoc;
13
14 public class ManagedObjectStateSerializer implements Serializer {
15
16   public void serializeTo(Object JavaDoc o, ObjectOutput JavaDoc out) {
17     if (!(o instanceof ManagedObjectState)) throw new AssertionError JavaDoc("Attempt to serialize an unknown type: " + o);
18     try {
19       ManagedObjectState mo = (ManagedObjectState) o;
20       out.writeByte(mo.getType());
21       mo.writeTo(out);
22     } catch (IOException JavaDoc e) {
23       throw new TCRuntimeException(e);
24     }
25   }
26
27   public Object JavaDoc deserializeFrom(ObjectInput JavaDoc in) {
28     try {
29       byte type = in.readByte();
30       return getStateFactory().readManagedObjectStateFrom(in, type);
31     } catch (IOException JavaDoc e) {
32       throw new AssertionError JavaDoc(e);
33     }
34   }
35
36   public byte getSerializerID() {
37     return MANAGED_OBJECT_STATE;
38   }
39
40   public static ManagedObjectStateFactory getStateFactory() {
41     return ManagedObjectStateFactory.getInstance();
42   }
43
44 }
45
Popular Tags