KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > presumo > jms > message > JmsMapMessage


1 /**
2  * This file is part of Presumo.
3  *
4  * Presumo is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * Presumo is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Presumo; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  *
19  * Copyright 2001 Dan Greff
20  */

21 package com.presumo.jms.message;
22
23 import java.io.Serializable JavaDoc;
24 import java.io.IOException JavaDoc;
25
26 import java.io.DataInput JavaDoc;
27 import java.io.DataOutput JavaDoc;
28
29 import java.io.ByteArrayOutputStream JavaDoc;
30 import java.io.ByteArrayInputStream JavaDoc;
31 import java.io.ObjectOutputStream JavaDoc;
32 import java.io.ObjectInputStream JavaDoc;
33
34 import javax.jms.MapMessage JavaDoc;
35 import javax.jms.JMSException JavaDoc;
36 import javax.jms.MessageFormatException JavaDoc;
37 import javax.jms.MessageNotWriteableException JavaDoc;
38
39 /**
40  * Implementation of the JMS interface MapMessage
41  *
42  * @see javax.jms.MapMessage
43  * @author Dan Greff
44  */

45 public final class JmsMapMessage extends JmsMessage
46   implements MapMessage JavaDoc, java.io.Externalizable JavaDoc
47 {
48
49   private PrimitiveMap messageBody;
50   
51     /////////////////////////////////////////////////////////////////////////
52
// Constructors //
53
/////////////////////////////////////////////////////////////////////////
54

55   public JmsMapMessage()
56   {
57     super();
58     messageBody = new PrimitiveMap();
59   }
60   
61   public JmsMapMessage(String JavaDoc name)
62   {
63     super(name);
64     messageBody = new PrimitiveMap();
65   }
66
67   public JmsMapMessage(byte [] msg, int offset, int length)
68     throws IOException JavaDoc
69   {
70     super(msg, offset, length);
71   }
72   
73     /////////////////////////////////////////////////////////////////////////
74
// Public Methods //
75
/////////////////////////////////////////////////////////////////////////
76

77   public void clearBody() throws JMSException JavaDoc
78   {
79     checkWrite();
80     messageBody.clear();
81   }
82
83   public boolean getBoolean(String JavaDoc name) throws JMSException JavaDoc
84   {
85     return messageBody.getBoolean(name);
86   }
87
88   public byte getByte(String JavaDoc name) throws JMSException JavaDoc
89   {
90     return messageBody.getByte(name);
91   }
92
93   public byte[] getBytes(String JavaDoc name) throws JMSException JavaDoc
94   {
95     return messageBody.getBytes(name);
96   }
97
98   public short getShort(String JavaDoc name) throws JMSException JavaDoc
99   {
100     return messageBody.getShort(name);
101   }
102
103   public char getChar(String JavaDoc name) throws JMSException JavaDoc
104   {
105     return messageBody.getChar(name);
106   }
107
108   public int getInt(String JavaDoc name) throws JMSException JavaDoc
109   {
110     return messageBody.getInt(name);
111   }
112
113   public long getLong(String JavaDoc name) throws JMSException JavaDoc
114   {
115     return messageBody.getLong(name);
116   }
117
118   public float getFloat(String JavaDoc name) throws JMSException JavaDoc
119   {
120     return messageBody.getFloat(name);
121   }
122  
123   public double getDouble(String JavaDoc name) throws JMSException JavaDoc
124   {
125     return messageBody.getDouble(name);
126   }
127
128   public String JavaDoc getString(String JavaDoc name) throws JMSException JavaDoc
129   {
130     return messageBody.getString(name);
131   }
132
133   public Object JavaDoc getObject(String JavaDoc name) throws JMSException JavaDoc
134   {
135     return messageBody.getObject(name);
136   }
137
138   public void setBoolean(String JavaDoc name, boolean value) throws JMSException JavaDoc
139   {
140     checkWrite();
141     messageBody.setBoolean(name, value);
142   }
143
144   public void setByte(String JavaDoc name, byte value) throws JMSException JavaDoc
145   {
146     checkWrite();
147     messageBody.setByte(name, value);
148   }
149
150   public void setBytes(String JavaDoc name, byte[] value) throws JMSException JavaDoc
151   {
152     checkWrite();
153     messageBody.setBytes(name, value);
154   }
155
156   public void setBytes(String JavaDoc name, byte[] value, int offset, int length)
157     throws JMSException JavaDoc
158   {
159     checkWrite();
160     messageBody.setBytes(name, value, offset, length);
161   }
162
163   public void setShort(String JavaDoc name, short value) throws JMSException JavaDoc
164   {
165     checkWrite();
166     messageBody.setShort(name, value);
167   }
168
169   public void setChar(String JavaDoc name, char value) throws JMSException JavaDoc
170   {
171     checkWrite();
172     messageBody.setChar(name, value);
173   }
174
175   public void setInt(String JavaDoc name, int value) throws JMSException JavaDoc
176   {
177     checkWrite();
178     messageBody.setInt(name, value);
179   }
180
181   public void setLong(String JavaDoc name, long value) throws JMSException JavaDoc
182   {
183     checkWrite();
184     messageBody.setLong(name, value);
185   }
186
187   public void setFloat(String JavaDoc name, float value) throws JMSException JavaDoc
188   {
189     checkWrite();
190     messageBody.setFloat(name, value);
191   }
192
193   public void setDouble(String JavaDoc name, double value) throws JMSException JavaDoc
194   {
195     checkWrite();
196     messageBody.setDouble(name, value);
197   }
198
199   public void setString(String JavaDoc name, String JavaDoc value) throws JMSException JavaDoc
200   {
201     checkWrite();
202     messageBody.setString(name, value);
203   }
204
205   public void setObject(String JavaDoc name, Object JavaDoc value) throws JMSException JavaDoc
206   {
207     checkWrite();
208     messageBody.setObject(name, value);
209   }
210
211   public java.util.Enumeration JavaDoc getMapNames() throws JMSException JavaDoc
212   {
213     return messageBody.getPrimitiveNames();
214   }
215
216   public boolean itemExists(String JavaDoc name) throws JMSException JavaDoc
217   {
218     return messageBody.primitiveExists(name);
219   }
220   
221
222   /**
223    *
224    */

225   public final void unmarshal(DataInput JavaDoc in) throws IOException JavaDoc
226   {
227     //
228
// Read in the message header and properties
229
//
230
super.unmarshal(in);
231     if (messageBody == null)
232       messageBody = new PrimitiveMap();
233     messageBody.unmarshal(in);
234     
235   }
236   
237   /**
238    *
239    */

240   public final void marshal(DataOutput JavaDoc out) throws IOException JavaDoc
241   {
242     super.marshal(out);
243     messageBody.marshal(out);
244   }
245
246
247     /////////////////////////////////////////////////////////////////////////
248
// Package Methods //
249
/////////////////////////////////////////////////////////////////////////
250

251   /*
252    * @return byte identifier for this message type. Specifically
253    * MessageConverter#OBJECT_MESSAGE
254    */

255   byte getMarshalingID()
256   {
257     return MessageEncoder.MAP_MESSAGE;
258   }
259   
260 }
261
262
Popular Tags