001: package org.mockejb.jms;
002:
003: import java.util.*;
004: import javax.jms.*;
005:
006: /**
007: * <code>MapMessage</code> implementation.
008: * @author Dimitar Gospodinov
009: * @see javax.jms.MapMessage
010: */
011: public class MapMessageImpl extends MessageImpl implements MapMessage {
012:
013: private final PrimitiveMap map = new PrimitiveMap();
014:
015: /**
016: * Creates empty <code>MapMessageImpl<code>
017: */
018: public MapMessageImpl() {
019: super ();
020: }
021:
022: /**
023: * Creates <code>MapMessageImpl</code> and copies its header, properties and
024: * body from <code>msg<code>
025: * @param msg
026: * @throws JMSException
027: */
028: public MapMessageImpl(MapMessage msg) throws JMSException {
029: super (msg);
030:
031: Enumeration e = msg.getMapNames();
032: while (e.hasMoreElements()) {
033: String name = (String) e.nextElement();
034: setObject(name, msg.getObject(name));
035: }
036: }
037:
038: /**
039: * @see javax.jms.MapMessage#getBoolean(java.lang.String)
040: */
041: public boolean getBoolean(String name) throws JMSException {
042: return map.getBoolean(name);
043: }
044:
045: /**
046: * @see javax.jms.MapMessage#getByte(java.lang.String)
047: */
048: public byte getByte(String name) throws JMSException {
049: return map.getByte(name);
050: }
051:
052: /**
053: * @see javax.jms.MapMessage#getShort(java.lang.String)
054: */
055: public short getShort(String name) throws JMSException {
056: return map.getShort(name);
057: }
058:
059: /**
060: * @see javax.jms.MapMessage#getChar(java.lang.String)
061: */
062: public char getChar(String name) throws JMSException {
063: return map.getChar(name);
064: }
065:
066: /**
067: * @see javax.jms.MapMessage#getInt(java.lang.String)
068: */
069: public int getInt(String name) throws JMSException {
070: return map.getInt(name);
071: }
072:
073: /**
074: * @see javax.jms.MapMessage#getLong(java.lang.String)
075: */
076: public long getLong(String name) throws JMSException {
077: return map.getLong(name);
078: }
079:
080: /**
081: * @see javax.jms.MapMessage#getFloat(java.lang.String)
082: */
083: public float getFloat(String name) throws JMSException {
084: return map.getFloat(name);
085: }
086:
087: /**
088: * @see javax.jms.MapMessage#getDouble(java.lang.String)
089: */
090: public double getDouble(String name) throws JMSException {
091: return map.getDouble(name);
092: }
093:
094: /**
095: * @see javax.jms.MapMessage#getString(java.lang.String)
096: */
097: public String getString(String name) throws JMSException {
098: return map.getString(name);
099: }
100:
101: /**
102: * @see javax.jms.MapMessage#getBytes(java.lang.String)
103: */
104: public byte[] getBytes(String name) throws JMSException {
105: return map.getBytes(name);
106: }
107:
108: /**
109: * @see javax.jms.MapMessage#getObject(java.lang.String)
110: */
111: public Object getObject(String name) throws JMSException {
112: return map.getObject(name);
113: }
114:
115: /**
116: * @see javax.jms.MapMessage#getMapNames()
117: */
118: public Enumeration getMapNames() throws JMSException {
119: return map.getNames();
120: }
121:
122: /**
123: * @see javax.jms.MapMessage#setBoolean(java.lang.String, boolean)
124: */
125: public void setBoolean(String name, boolean value)
126: throws JMSException {
127: checkBodyWriteable();
128: map.setBoolean(name, value);
129: }
130:
131: /**
132: * @see javax.jms.MapMessage#setByte(java.lang.String, byte)
133: */
134: public void setByte(String name, byte value) throws JMSException {
135: checkBodyWriteable();
136: map.setByte(name, value);
137: }
138:
139: /**
140: * @see javax.jms.MapMessage#setShort(java.lang.String, short)
141: */
142: public void setShort(String name, short value) throws JMSException {
143: checkBodyWriteable();
144: map.setShort(name, value);
145: }
146:
147: /**
148: * @see javax.jms.MapMessage#setChar(java.lang.String, char)
149: */
150: public void setChar(String name, char value) throws JMSException {
151: checkBodyWriteable();
152: map.setChar(name, value);
153: }
154:
155: /**
156: * @see javax.jms.MapMessage#setInt(java.lang.String, int)
157: */
158: public void setInt(String name, int value) throws JMSException {
159: checkBodyWriteable();
160: map.setInt(name, value);
161: }
162:
163: /**
164: * @see javax.jms.MapMessage#setLong(java.lang.String, long)
165: */
166: public void setLong(String name, long value) throws JMSException {
167: checkBodyWriteable();
168: map.setLong(name, value);
169: }
170:
171: /**
172: * @see javax.jms.MapMessage#setFloat(java.lang.String, float)
173: */
174: public void setFloat(String name, float value) throws JMSException {
175: checkBodyWriteable();
176: map.setFloat(name, value);
177: }
178:
179: /**
180: * @see javax.jms.MapMessage#setDouble(java.lang.String, double)
181: */
182: public void setDouble(String name, double value)
183: throws JMSException {
184: checkBodyWriteable();
185: map.setDouble(name, value);
186: }
187:
188: /**
189: * @see javax.jms.MapMessage#setString(java.lang.String, java.lang.String)
190: */
191: public void setString(String name, String value)
192: throws JMSException {
193: checkBodyWriteable();
194: map.setString(name, value);
195: }
196:
197: /**
198: * @see javax.jms.MapMessage#setBytes(java.lang.String, byte[])
199: */
200: public void setBytes(String name, byte[] value) throws JMSException {
201: checkBodyWriteable();
202: map.setBytes(name, value);
203: }
204:
205: /**
206: * @see javax.jms.MapMessage#setBytes(java.lang.String, byte[], int, int)
207: */
208: public void setBytes(String name, byte[] value, int offset,
209: int length) throws JMSException {
210:
211: checkBodyWriteable();
212:
213: if (value == null || length < 0 || offset < 0
214: || (offset + length) > value.length) {
215: throw new IllegalArgumentException();
216: }
217: byte[] valueToSet = new byte[length];
218: int i = 0;
219: while (length > 0) {
220: valueToSet[i++] = value[offset++];
221: length--;
222: }
223: map.setBytes(name, valueToSet);
224: }
225:
226: /**
227: * @see javax.jms.MapMessage#setObject(java.lang.String, java.lang.Object)
228: */
229: public void setObject(String name, Object value)
230: throws JMSException {
231: checkBodyWriteable();
232: map.setObject(name, value);
233: }
234:
235: /**
236: * @see javax.jms.MapMessage#itemExists(java.lang.String)
237: */
238: public boolean itemExists(String name) throws JMSException {
239: return map.containsKey(name);
240: }
241:
242: // Non-standard methods
243:
244: /**
245: * Sets message body in read-only mode.
246: * @throws JMSException
247: */
248: void resetBody() throws JMSException {
249: setBodyReadOnly();
250: }
251:
252: }
|