KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > jms > message > standard > StandardMessage


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.jms.message.standard;
8
9 import java.util.Enumeration JavaDoc;
10
11 import javax.jms.Destination JavaDoc;
12 import javax.jms.JMSException JavaDoc;
13
14 import org.jboss.jms.client.SessionDelegate;
15 import org.jboss.jms.message.JBossMessage;
16 import org.jboss.jms.util.MessageProperties;
17 import org.jboss.util.id.GUID;
18
19 /**
20  * A standard message
21  *
22  * @author <a HREF="mailto:adrian@jboss.org>Adrian Brock</a>
23  * @version $Revision: 1.3 $
24  */

25 public class StandardMessage
26    implements JBossMessage
27 {
28    // Constants -----------------------------------------------------
29

30    // Attributes ----------------------------------------------------
31

32    /** The session */
33    private transient SessionDelegate session;
34
35    /** The message properties */
36    private MessageProperties properties = new MessageProperties();
37
38    /** The message id */
39    private String JavaDoc messageID;
40
41    /** The destination */
42    private Destination JavaDoc destination;
43
44    /** The delivery mode */
45    private int deliveryMode;
46
47    /** The priority */
48    private int priority;
49
50    /** The send timestamp */
51    private long timestamp;
52
53    /** The expiration timestamp */
54    private long expiration;
55
56    /** The message type */
57    private String JavaDoc type;
58
59    /** The reply to destination */
60    private Destination JavaDoc replyTo;
61
62    /** The correlation id */
63    private String JavaDoc correlationID;
64
65    /** Whether the message has been redelivered */
66    private boolean redelivered;
67
68    /** Whether the message is read only */
69    private boolean readonly = false;
70
71    // Static --------------------------------------------------------
72

73    // Constructors --------------------------------------------------
74

75    // Public --------------------------------------------------------
76

77    public StandardMessage(SessionDelegate session)
78       throws JMSException JavaDoc
79    {
80       this.session = session;
81    }
82
83    // Message implementation ----------------------------------------
84

85    public void acknowledge() throws JMSException JavaDoc
86    {
87       session.acknowledge(this, true);
88    }
89
90    public void clearBody() throws JMSException JavaDoc
91    {
92       readonly = false;
93    }
94
95    public void clearProperties() throws JMSException JavaDoc
96    {
97       properties.clear();
98    }
99
100    public boolean getBooleanProperty(String JavaDoc name) throws JMSException JavaDoc
101    {
102       return properties.getBoolean(name);
103    }
104
105    public byte getByteProperty(String JavaDoc name) throws JMSException JavaDoc
106    {
107       return properties.getByte(name);
108    }
109
110    public double getDoubleProperty(String JavaDoc name) throws JMSException JavaDoc
111    {
112       return properties.getDouble(name);
113    }
114
115    public float getFloatProperty(String JavaDoc name) throws JMSException JavaDoc
116    {
117       return properties.getFloat(name);
118    }
119
120    public int getIntProperty(String JavaDoc name) throws JMSException JavaDoc
121    {
122       return properties.getInt(name);
123    }
124
125    public String JavaDoc getJMSCorrelationID() throws JMSException JavaDoc
126    {
127       return correlationID;
128    }
129
130    public byte[] getJMSCorrelationIDAsBytes() throws JMSException JavaDoc
131    {
132       // TODO getJMSCorrelationIDAsBytes
133
return null;
134    }
135
136    public int getJMSDeliveryMode() throws JMSException JavaDoc
137    {
138       return deliveryMode;
139    }
140
141    public Destination JavaDoc getJMSDestination() throws JMSException JavaDoc
142    {
143       return destination;
144    }
145
146    public long getJMSExpiration() throws JMSException JavaDoc
147    {
148       return expiration;
149    }
150
151    public String JavaDoc getJMSMessageID() throws JMSException JavaDoc
152    {
153       return messageID;
154    }
155
156    public int getJMSPriority() throws JMSException JavaDoc
157    {
158       return priority;
159    }
160
161    public boolean getJMSRedelivered() throws JMSException JavaDoc
162    {
163       return redelivered;
164    }
165
166    public Destination JavaDoc getJMSReplyTo() throws JMSException JavaDoc
167    {
168       return replyTo;
169    }
170
171    public long getJMSTimestamp() throws JMSException JavaDoc
172    {
173       return timestamp;
174    }
175
176    public String JavaDoc getJMSType() throws JMSException JavaDoc
177    {
178       return type;
179    }
180
181    public long getLongProperty(String JavaDoc name) throws JMSException JavaDoc
182    {
183       return properties.getLong(name);
184    }
185
186    public Object JavaDoc getObjectProperty(String JavaDoc name) throws JMSException JavaDoc
187    {
188       return properties.getObject(name);
189    }
190
191    public Enumeration JavaDoc getPropertyNames() throws JMSException JavaDoc
192    {
193       return properties.getMapNames();
194    }
195
196    public short getShortProperty(String JavaDoc name) throws JMSException JavaDoc
197    {
198       return properties.getShort(name);
199    }
200
201    public String JavaDoc getStringProperty(String JavaDoc name) throws JMSException JavaDoc
202    {
203       return properties.getString(name);
204    }
205
206    public boolean propertyExists(String JavaDoc name) throws JMSException JavaDoc
207    {
208       return properties.itemExists(name);
209    }
210
211    public void setBooleanProperty(String JavaDoc name, boolean value) throws JMSException JavaDoc
212    {
213       properties.setBoolean(name, value);
214    }
215
216    public void setByteProperty(String JavaDoc name, byte value) throws JMSException JavaDoc
217    {
218       properties.setByte(name, value);
219    }
220
221    public void setDoubleProperty(String JavaDoc name, double value) throws JMSException JavaDoc
222    {
223       properties.setDouble(name, value);
224    }
225
226    public void setFloatProperty(String JavaDoc name, float value) throws JMSException JavaDoc
227    {
228       properties.setFloat(name, value);
229    }
230
231    public void setIntProperty(String JavaDoc name, int value) throws JMSException JavaDoc
232    {
233       properties.setInt(name, value);
234    }
235
236    public void setJMSCorrelationID(String JavaDoc correlationID) throws JMSException JavaDoc
237    {
238       checkReadOnly();
239       this.correlationID = correlationID;
240    }
241
242    public void setJMSCorrelationIDAsBytes(byte[] correlationID) throws JMSException JavaDoc
243    {
244       checkReadOnly();
245       // TODO setJMSCorrelationIDAsBytes
246
}
247
248    public void setJMSDeliveryMode(int deliveryMode) throws JMSException JavaDoc
249    {
250       checkReadOnly();
251       this.deliveryMode = deliveryMode;
252    }
253
254    public void setJMSDestination(Destination JavaDoc destination) throws JMSException JavaDoc
255    {
256       checkReadOnly();
257       this.destination = destination;
258    }
259
260    public void setJMSExpiration(long expiration) throws JMSException JavaDoc
261    {
262       checkReadOnly();
263       this.expiration = expiration;
264    }
265
266    public void setJMSMessageID(String JavaDoc id) throws JMSException JavaDoc
267    {
268       checkReadOnly();
269       this.messageID = id;
270    }
271
272    public void setJMSPriority(int priority) throws JMSException JavaDoc
273    {
274       checkReadOnly();
275       this.priority = priority;
276    }
277
278    public void setJMSRedelivered(boolean redelivered) throws JMSException JavaDoc
279    {
280       checkReadOnly();
281       this.redelivered = redelivered;
282    }
283
284    public void setJMSReplyTo(Destination JavaDoc replyTo) throws JMSException JavaDoc
285    {
286       checkReadOnly();
287       this.replyTo = replyTo;
288    }
289
290    public void setJMSTimestamp(long timestamp) throws JMSException JavaDoc
291    {
292       checkReadOnly();
293       this.timestamp = timestamp;
294    }
295
296    public void setJMSType(String JavaDoc type) throws JMSException JavaDoc
297    {
298       checkReadOnly();
299       this.type = type;
300    }
301
302    public void setLongProperty(String JavaDoc name, long value) throws JMSException JavaDoc
303    {
304       properties.setLong(name, value);
305    }
306
307    public void setObjectProperty(String JavaDoc name, Object JavaDoc value) throws JMSException JavaDoc
308    {
309       properties.setObject(name, value);
310    }
311
312    public void setShortProperty(String JavaDoc name, short value) throws JMSException JavaDoc
313    {
314       properties.setShort(name, value);
315    }
316
317    public void setStringProperty(String JavaDoc name, String JavaDoc value) throws JMSException JavaDoc
318    {
319       properties.setString(name, value);
320    }
321
322    // JBossMessage implementation -----------------------------------
323

324    public SessionDelegate getSessionDelegate() throws JMSException JavaDoc
325    {
326       return session;
327    }
328    
329    public void generateMessageID() throws JMSException JavaDoc
330    {
331       checkReadOnly();
332       messageID = GUID.asString();
333    }
334
335    public void generateTimestamp() throws JMSException JavaDoc
336    {
337       checkReadOnly();
338       timestamp = System.currentTimeMillis();
339    }
340
341    public void makeReadOnly() throws JMSException JavaDoc
342    {
343       readonly = true;
344       properties.setReadOnly(true);
345    }
346
347    // Object implementation ------------------------------------------
348

349    public Object JavaDoc clone()
350       throws CloneNotSupportedException JavaDoc
351    {
352       return super.clone();
353    }
354
355    // Protected ------------------------------------------------------
356

357    // Package Private ------------------------------------------------
358

359    // Private --------------------------------------------------------
360

361    /**
362     * Checks whether a message is read only
363     *
364     * @throws JMSException for a read only message
365     */

366    private void checkReadOnly()
367       throws JMSException JavaDoc
368    {
369       if (readonly)
370          throw new JMSException JavaDoc("The message is read only");
371    }
372
373    // Inner Classes --------------------------------------------------
374

375 }
376
Popular Tags