01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.objectserver.managedobject;
05:
06: import com.tc.exception.TCRuntimeException;
07: import com.tc.io.serializer.api.Serializer;
08: import com.tc.objectserver.core.api.ManagedObjectState;
09:
10: import java.io.IOException;
11: import java.io.ObjectInput;
12: import java.io.ObjectOutput;
13:
14: public class ManagedObjectStateSerializer implements Serializer {
15:
16: public void serializeTo(Object o, ObjectOutput out) {
17: if (!(o instanceof ManagedObjectState))
18: throw new AssertionError(
19: "Attempt to serialize an unknown type: " + o);
20: try {
21: ManagedObjectState mo = (ManagedObjectState) o;
22: out.writeByte(mo.getType());
23: mo.writeTo(out);
24: } catch (IOException e) {
25: throw new TCRuntimeException(e);
26: }
27: }
28:
29: public Object deserializeFrom(ObjectInput in) {
30: try {
31: byte type = in.readByte();
32: return getStateFactory().readManagedObjectStateFrom(in,
33: type);
34: } catch (IOException e) {
35: throw new AssertionError(e);
36: }
37: }
38:
39: public byte getSerializerID() {
40: return MANAGED_OBJECT_STATE;
41: }
42:
43: public static ManagedObjectStateFactory getStateFactory() {
44: return ManagedObjectStateFactory.getInstance();
45: }
46:
47: }
|