KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > scalagent > kjoram > TextMessage


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2001 - ScalAgent Distributed Technologies
4  * Copyright (C) 1996 - Dyade
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA.
20  *
21  * Initial developer(s): Frederic Maistre (INRIA)
22  * Contributor(s): Nicolas Tachker (ScalAgent)
23  */

24 package com.scalagent.kjoram;
25
26 import com.scalagent.kjoram.excepts.*;
27
28
29 public class TextMessage extends Message
30 {
31   /** The wrapped text. */
32   private String JavaDoc text = null;
33   /** <code>true</code> if the message body is read-only. */
34   private boolean RObody = false;
35
36   /**
37    * Instanciates a bright new <code>TextMessage</code>.
38    */

39   TextMessage()
40   {
41     super();
42   }
43   
44   /**
45    * Instanciates a <code>TextMessage</code> wrapping a consumed
46    * MOM message containing a text.
47    *
48    * @param sess The consuming session.
49    * @param momMsg The MOM message to wrap.
50    */

51   TextMessage(Session sess, com.scalagent.kjoram.messages.Message momMsg)
52   {
53     super(sess, momMsg);
54     text = momMsg.getText();
55     RObody = true;
56   }
57
58
59   /**
60    * API method.
61    *
62    * @exception JMSException Actually never thrown.
63    */

64   public void clearBody() throws JMSException
65   {
66     super.clearBody();
67     text = null;
68     RObody = false;
69   }
70
71   /**
72    * API method.
73    *
74    * @exception MessageNotWriteableException When trying to set the text
75    * if the message body is read-only.
76    */

77   public void setText(String JavaDoc text) throws MessageNotWriteableException
78   {
79     if (RObody)
80       throw new MessageNotWriteableException("Can't set a text as the"
81                                              + " message body is read-only.");
82     this.text = text;
83   }
84
85   /**
86    * API method.
87    *
88    * @exception JMSException Actually never thrown.
89    */

90   public String JavaDoc getText() throws JMSException
91   {
92     return text;
93   }
94
95   /**
96    * Method actually preparing the message for sending by transfering the
97    * local body into the wrapped MOM message.
98    *
99    * @exception Exception If an error occurs while serializing.
100    */

101   protected void prepare() throws Exception JavaDoc
102   {
103     super.prepare();
104     momMsg.clearBody();
105     momMsg.setText(text);
106   }
107 }
108
Popular Tags