1 24 25 package org.objectweb.dream.message.codec; 26 27 import java.io.DataInput ; 28 import java.io.DataOutput ; 29 import java.io.Externalizable ; 30 import java.io.IOException ; 31 import java.io.ObjectInput ; 32 import java.io.ObjectOutput ; 33 34 import org.objectweb.dream.message.Message; 35 import org.objectweb.dream.message.MessageNC; 36 import org.objectweb.dream.message.MessageTypeImpl; 37 import org.objectweb.dream.message.MessageTypeNCImpl; 38 39 42 public class MessageCodecStreamImpl extends AbstractMessageCodecObjectStream 43 { 44 45 49 52 protected Message doDecodeSingleMessage(DataInput input) throws IOException 53 { 54 Message m; 55 boolean messageNC = input.readBoolean(); 56 if (messageNC) 57 { 58 m = messageManagerItf 59 .createMessage(MessageTypeNCImpl.EMPTY_MESSAGE_TYPE_NC); 60 } 61 else 62 { 63 m = messageManagerItf.createMessage(MessageTypeImpl.EMPTY_MESSAGE_TYPE); 64 } 65 try 66 { 67 ((Externalizable ) m).readExternal((ObjectInput ) input); 68 } 69 catch (ClassNotFoundException e) 70 { 71 throw new IOException ("Unable to decode message : " + e.getMessage()); 72 } 73 m.setMessageManagerId(messageManagerItf.getMessageManagerId()); 74 return m; 75 } 76 77 81 protected void doEncodeSingleMessage(Message message, DataOutput output) 82 throws IOException 83 { 84 if (message instanceof MessageNC) 85 { 86 output.writeBoolean(true); 87 } 88 else 89 { 90 output.writeBoolean(false); 91 } 92 ((Externalizable ) message).writeExternal((ObjectOutput ) output); 93 } 94 } | Popular Tags |