KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > walend > somnifugi > SomniTextMessage


1 package net.walend.somnifugi;
2
3 import java.io.Serializable JavaDoc;
4
5 import javax.jms.TextMessage JavaDoc;
6 import javax.jms.JMSException JavaDoc;
7
8 /**
9 An SomniMessage that contains a text string.
10
11 @author <a HREF="http://walend.net">David Walend</a> <a HREF="mailto:david@walend.net">david@walend.net</a>
12 @since alpha-0-13
13  */

14
15 public class SomniTextMessage
16     extends SomniMessage
17     implements TextMessage JavaDoc
18 {
19     private String JavaDoc gut = null;
20
21     protected SomniTextMessage()
22     {
23         super();
24     }
25
26     /**
27 Copy constructor.
28     */

29     protected SomniTextMessage(SomniTextMessage message,boolean deep)
30         throws JMSException JavaDoc
31     {
32         super(message,deep);
33         if(deep)
34         {
35             gut = (String JavaDoc)serializedCopy(message.getText());
36         }
37         else
38         {
39             gut = message.getText();
40         }
41     }
42
43     /** Sets the serializable Text containing this message's data.
44 It is important to note that an <CODE>TextMessage</CODE>
45 contains a snapshot of the Text at the time <CODE>setText()</CODE>
46 is called; subsequent modifications of the Text will have no
47 effect on the <CODE>TextMessage</CODE> body.
48 <p>
49 @param text the message's data
50  
51 @exception JMSException if the JMS provider fails to set the Text
52                         due to some internal error.
53 @exception MessageFormatException if Text serialization fails.
54 @exception MessageNotWriteableException if the message is in read-only
55                                         mode.
56       */

57     public void setText(String JavaDoc text)
58         throws JMSException JavaDoc
59     {
60         synchronized(guard)
61             {
62                 checkWritable();
63                 gut = text;
64             }
65     }
66
67     /** Gets the serializable Text containing this message's data. The
68 default value is null.
69 <p>
70 @return the serializable Text containing this message's data
71  
72 @exception JMSException if the JMS provider fails to get the Text
73                         due to some internal error.
74 @exception MessageFormatException if Text deserialization fails.
75       */

76     public String JavaDoc getText()
77         throws JMSException JavaDoc
78     {
79         synchronized(guard)
80             {
81                 return gut;
82             }
83     }
84
85     /**
86 Clears out the message body. Clearing a message's body does not clear
87 its header values or property entries.
88 <p>
89 <P>If this message body was read-only, calling this method leaves
90 the message body in the same state as an empty body in a newly
91 created message.
92 <p>
93 @exception JMSException if the JMS provider fails to clear the message
94                         body due to some internal error.
95       */

96     public void clearBody()
97         throws JMSException JavaDoc
98     {
99         synchronized(guard)
100             {
101                 super.clearBody();
102                 gut = null;
103             }
104     }
105
106     /**
107 Create a shallow copy of this message. Override this method if you extend this class to call your own copy constructor.
108     */

109     protected SomniMessage shallowCopy()
110         throws JMSException JavaDoc
111     {
112         synchronized(guard)
113         {
114             return new SomniTextMessage(this,false);
115         }
116     }
117
118     /**
119 Create a deep copy of this message. Override this method if you extend this class to call your own copy constructor.
120     */

121     protected SomniMessage deepCopy()
122         throws JMSException JavaDoc
123     {
124         synchronized(guard)
125         {
126             return new SomniTextMessage(this,true);
127         }
128     }
129
130     public String JavaDoc toString()
131     {
132         StringBuffer JavaDoc buffy = new StringBuffer JavaDoc();
133         buffy.append(super.toString());
134         buffy.append(" contains:");
135
136         if(gut!=null)
137             {
138                 buffy.append(gut.toString());
139             }
140         else
141             {
142                 buffy.append("null");
143             }
144
145         return buffy.toString();
146     }
147 }
148
149 /* Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006 David Walend
150 All rights reserved.
151
152 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
153
154 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
155
156 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
157
158 Neither the name of the SomnifugiJMS Project, walend.net, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission from David Walend.
159
160 Credits in redistributions in source or binary forms must include a link to http://somnifugi.sourceforge.net .
161
162 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
163 The net.walend.somnifugi.sql92 package is modified code from the openmq project, https://mq.dev.java.net/ , Copyright (c) of Sun, and carries the CDDL license, repeated here: You can obtain a copy of the license at https://glassfish.dev.java.net/public/CDDLv1.0.html. See the License for the specific language governing permissions and limitations under the License.
164
165 =================================================================================
166
167 For more information and the latest version of this software, please see http://somnifugi.sourceforge.net and http://walend.net or email <a HREF="mailto:david@walend.net">david@walend.net</a>.
168  */

169
Popular Tags