1 21 package com.presumo.jms.message; 22 23 import java.io.Serializable ; 24 import java.io.IOException ; 25 26 import java.io.DataInput ; 27 import java.io.DataOutput ; 28 29 import java.io.ByteArrayOutputStream ; 30 import java.io.ByteArrayInputStream ; 31 import java.io.ObjectOutputStream ; 32 import java.io.ObjectInputStream ; 33 34 import javax.jms.TextMessage ; 35 import javax.jms.JMSException ; 36 import javax.jms.MessageFormatException ; 37 import javax.jms.MessageNotWriteableException ; 38 39 45 public final class JmsTextMessage extends JmsMessage 46 implements TextMessage , java.io.Externalizable 47 { 48 private static final byte TEXT = 0; 49 private static final byte NO_TEXT = 1; 50 51 private String textMessage; 52 53 57 public JmsTextMessage() 58 { 59 super(); 60 } 61 62 public JmsTextMessage(String name) 63 { 64 super(name); 65 } 66 67 public JmsTextMessage(byte [] buf, int offset, int length) 68 { 69 super(buf, offset, length); 70 } 71 72 76 79 public String getText() throws JMSException 80 { 81 return this.textMessage; 82 } 83 84 87 public void setText(String payload) throws JMSException 88 { 89 checkWrite(); 90 this.textMessage = payload; 91 } 92 93 public void clearBody() throws JMSException 94 { 95 checkWrite(); 96 super.clearBody(); 97 this.textMessage = null; 98 } 99 100 107 public void unmarshal(DataInput in) throws IOException 108 { 109 super.unmarshal(in); 113 114 byte sanityByte = in.readByte(); 115 if (sanityByte == TEXT) { 116 this.textMessage = in.readUTF(); 117 } 118 this.setReadOnly(); 119 } 120 121 128 public void marshal(DataOutput out) throws IOException 129 { 130 super.marshal(out); 134 135 if (this.textMessage == null || this.textMessage.length() == 0) 136 out.writeByte(NO_TEXT); 137 else { 138 out.writeByte(TEXT); 139 out.writeUTF(this.textMessage); 140 } 141 } 142 143 144 148 152 final byte getMarshalingID() 153 { 154 return MessageEncoder.TEXT_MESSAGE; 155 } 156 157 } 158 159 | Popular Tags |