1 46 package org.mr.api.jms; 47 48 import java.io.IOException ; 49 50 import javax.jms.JMSException ; 51 import javax.jms.MessageNotWriteableException ; 52 import javax.jms.TextMessage ; 53 import org.mr.core.util.byteable.Byteable; 54 import org.mr.core.util.byteable.ByteableInputStream; 55 import org.mr.core.util.byteable.ByteableOutputStream; 56 import org.mr.core.util.byteable.ByteableRegistry; 57 58 59 68 public class MantaTextMessage extends MantaMessage implements TextMessage { 69 70 71 72 76 public MantaTextMessage(){ 77 78 } 79 85 MantaTextMessage(MantaSession sess) throws JMSException { 86 this(sess,null); 87 88 } 90 97 MantaTextMessage(MantaSession sess, String msg) throws JMSException { 98 flags = (flags & ONLY_MSG_TYPES) | TEXT_MESSAGE; 99 message = msg; 100 creatingSession = sess; 101 } 103 104 107 public void setText(String message) throws JMSException { 108 if (isWriteable()) 109 this.message = message; 110 else 111 throw new MessageNotWriteableException ("MNJMS00025 : THE MESSAGE IS NOT IN A WRITEABLE STATE. FAILED ON METHOD setText()."); 112 113 114 } 116 119 public String getText() throws JMSException { 120 return message; 121 } 123 126 public final void clearBody() throws JMSException { 127 super.clearBody(); 128 message = null; 133 } 135 public void toBytes(ByteableOutputStream out) throws IOException { 136 super.toBytes(out); 137 out.writeUTF(message); 138 out.flush(); 139 } 140 141 public Byteable createInstance(ByteableInputStream in) throws IOException { 142 143 MantaTextMessage ctm; 144 try { 145 146 ctm = new MantaTextMessage(null); 147 createHeadersAndProperties(ctm,in); 148 ctm.message=in.readUTF(); 149 } 150 catch (JMSException ee) { 151 throw new IOException ("MNJMS00FFA : METHOD createInstance() FAILED ON MantaTextMessage. EXCEPTION TEXT : "+ee.getMessage()); 152 } 153 154 return ctm; 155 } 156 157 public void registerToByteableRegistry() { 158 ByteableRegistry.registerByteableFactory(getByteableName() , this); 159 } 160 161 public final static String BYTEABLENAME = "MantaTextMsg"; 162 public String getByteableName() { 163 164 return BYTEABLENAME; 165 } 166 167 public static void register() throws JMSException { 168 MantaTextMessage instance = new MantaTextMessage(null); 169 instance.registerToByteableRegistry(); 170 } 171 172 public String toString(){ 173 return message; 174 } 175 176 189 public MantaMessage makeCopy() throws JMSException { 190 MantaTextMessage copy = new MantaTextMessage(); 191 initCopy(copy); 192 copy.message = message; 193 return copy; 194 } 195 196 197 private String message = null; 198 } | Popular Tags |