1 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 ; 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)) throw new AssertionError ("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 e) { 23 throw new TCRuntimeException(e); 24 } 25 } 26 27 public Object deserializeFrom(ObjectInput in) { 28 try { 29 byte type = in.readByte(); 30 return getStateFactory().readManagedObjectStateFrom(in, type); 31 } catch (IOException e) { 32 throw new AssertionError (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 |