1 /***
2 * Redistribution and use of this software and associated documentation
3 * ("Software"), with or without modification, are permitted provided
4 * that the following conditions are met:
5 *
6 * 1. Redistributions of source code must retain copyright
7 * statements and notices. Redistributions must also contain a
8 * copy of this document.
9 *
10 * 2. Redistributions in binary form must reproduce the
11 * above copyright notice, this list of conditions and the
12 * following disclaimer in the documentation and/or other
13 * materials provided with the distribution.
14 *
15 * 3. The name "Exolab" must not be used to endorse or promote
16 * products derived from this Software without prior written
17 * permission of Exoffice Technologies. For written permission,
18 * please contact info@exolab.org.
19 *
20 * 4. Products derived from this Software may not be called "Exolab"
21 * nor may "Exolab" appear in their names without prior written
22 * permission of Exoffice Technologies. Exolab is a registered
23 * trademark of Exoffice Technologies.
24 *
25 * 5. Due credit should be given to the Exolab Project
26 * (http://www.exolab.org/).
27 *
28 * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32 * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39 * OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Copyright 2000-2003 (C) Exoffice Technologies Inc. All Rights Reserved.
42 *
43 * $Id: TextMessageImpl.java,v 1.1 2004/11/26 01:50:43 tanderson Exp $
44 *
45 * Date Author Changes
46 * 02/26/2000 jimm Created
47 */
48
49 package org.exolab.jms.message;
50
51 import java.io.IOException;
52 import java.io.ObjectInput;
53 import java.io.ObjectOutput;
54
55 import javax.jms.JMSException;
56 import javax.jms.MessageNotWriteableException;
57 import javax.jms.TextMessage;
58
59
60 /***
61 * This class implements the <code>javax.jms.TextMessage</code> interface
62 *
63 * @version $Revision: 1.1 $ $Date: 2004/11/26 01:50:43 $
64 * @author <a href="mailto:mourikis@exolab.org">Jim Mourikis</a>
65 * @see javax.jms.TextMessage
66 */
67 public final class TextMessageImpl extends MessageImpl implements TextMessage {
68
69 /***
70 * Object version no. for serialization
71 */
72 static final long serialVersionUID = 1;
73
74 /***
75 * The message body
76 */
77 private String _text = null;
78
79 /***
80 * Construct a new TextMessage
81 *
82 * @throws JMSException if the message type can't be set
83 */
84 public TextMessageImpl() throws JMSException {
85 setJMSType("TextMessage");
86 }
87
88 /***
89 * Clone an instance of this object
90 *
91 * @return a copy of this object
92 * @throws CloneNotSupportedException if object or attributes aren't
93 * cloneable
94 */
95 public final Object clone() throws CloneNotSupportedException {
96 return super.clone();
97 }
98
99 /***
100 * Serialize out this message's data
101 *
102 * @param out the stream to serialize out to
103 * @throws IOException if any I/O exceptions occurr
104 */
105 public final void writeExternal(ObjectOutput out) throws IOException {
106 super.writeExternal(out);
107 out.writeLong(serialVersionUID);
108 out.writeObject(_text);
109 }
110
111 /***
112 * Serialize in this message's data
113 *
114 * @param in the stream to serialize in from
115 * @throws ClassNotFoundException if the class for an object being
116 * restored cannot be found.
117 * @throws IOException if any I/O exceptions occur
118 */
119 public final void readExternal(ObjectInput in)
120 throws ClassNotFoundException, IOException {
121 super.readExternal(in);
122 long version = in.readLong();
123 if (version == serialVersionUID) {
124 _text = (String) in.readObject();
125 } else {
126 throw new IOException("Incorrect version enountered: " + version +
127 ". This version = " + serialVersionUID);
128 }
129 }
130
131 /***
132 * Set the string containing this message's data.
133 *
134 * @param string the String containing the message's data
135 * @throws MessageNotWriteableException if message in read-only mode.
136 */
137 public final void setText(String string)
138 throws MessageNotWriteableException {
139 checkWrite();
140 _text = string;
141 }
142
143 /***
144 * Get the string containing this message's data. The default value is
145 * null.
146 *
147 * @return the String containing the message's data
148 */
149 public final String getText() {
150 return _text;
151 }
152
153 /***
154 * Clear out the message body. Clearing a message's body does not clear
155 * its header values or property entries.
156 * If this message body was read-only, calling this method leaves the
157 * message body is in the same state as an empty body in a newly created
158 * message
159 */
160 public final void clearBody() throws JMSException {
161 super.clearBody();
162 _text = null;
163 }
164
165 /***
166 * Returns the message text
167 */
168 public final String toString() {
169 return getText();
170 }
171
172 }