001: /*
002: * @(#)MapMessage.java 1.35 02/04/09
003: *
004: * Copyright 1997-2002 Sun Microsystems, Inc. All Rights Reserved.
005: *
006: * SUN PROPRIETARY/CONFIDENTIAL.
007: * This software is the proprietary information of Sun Microsystems, Inc.
008: * Use is subject to license terms.
009: *
010: */
011:
012: package javax.jms;
013:
014: import java.util.Enumeration;
015:
016: /** A <CODE>MapMessage</CODE> object is used to send a set of name-value pairs.
017: * The names are <CODE>String</CODE> objects, and the values are primitive
018: * data types in the Java programming language. The names must have a value that
019: * is not null, and not an empty string. The entries can be accessed
020: * sequentially or randomly by name. The order of the entries is undefined.
021: * <CODE>MapMessage</CODE> inherits from the <CODE>Message</CODE> interface
022: * and adds a message body that contains a Map.
023: *
024: * <P>The primitive types can be read or written explicitly using methods
025: * for each type. They may also be read or written generically as objects.
026: * For instance, a call to <CODE>MapMessage.setInt("foo", 6)</CODE> is
027: * equivalent to <CODE>MapMessage.setObject("foo", new Integer(6))</CODE>.
028: * Both forms are provided, because the explicit form is convenient for
029: * static programming, and the object form is needed when types are not known
030: * at compile time.
031: *
032: * <P>When a client receives a <CODE>MapMessage</CODE>, it is in read-only
033: * mode. If a client attempts to write to the message at this point, a
034: * <CODE>MessageNotWriteableException</CODE> is thrown. If
035: * <CODE>clearBody</CODE> is called, the message can now be both read from and
036: * written to.
037: *
038: * <P><CODE>MapMessage</CODE> objects support the following conversion table.
039: * The marked cases must be supported. The unmarked cases must throw a
040: * <CODE>JMSException</CODE>. The <CODE>String</CODE>-to-primitive conversions
041: * may throw a runtime exception if the primitive's <CODE>valueOf()</CODE>
042: * method does not accept it as a valid <CODE>String</CODE> representation of
043: * the primitive.
044: *
045: * <P>A value written as the row type can be read as the column type.
046: *
047: * <PRE>
048: * | | boolean byte short char int long float double String byte[]
049: * |----------------------------------------------------------------------
050: * |boolean | X X
051: * |byte | X X X X X
052: * |short | X X X X
053: * |char | X X
054: * |int | X X X
055: * |long | X X
056: * |float | X X X
057: * |double | X X
058: * |String | X X X X X X X X
059: * |byte[] | X
060: * |----------------------------------------------------------------------
061: * </PRE>
062: *
063: * <P>Attempting to read a null value as a primitive type must be treated
064: * as calling the primitive's corresponding <code>valueOf(String)</code>
065: * conversion method with a null value. Since <code>char</code> does not
066: * support a <code>String</code> conversion, attempting to read a null value
067: * as a <code>char</code> must throw a <code>NullPointerException</code>.
068: *
069: * @version 1.1 February 2, 002
070: * @author Mark Hapner
071: * @author Rich Burridge
072: *
073: * @see javax.jms.Session#createMapMessage()
074: * @see javax.jms.BytesMessage
075: * @see javax.jms.Message
076: * @see javax.jms.ObjectMessage
077: * @see javax.jms.StreamMessage
078: * @see javax.jms.TextMessage
079: */
080:
081: public interface MapMessage extends Message {
082:
083: /** Returns the <CODE>boolean</CODE> value with the specified name.
084: *
085: * @param name the name of the <CODE>boolean</CODE>
086: *
087: * @return the <CODE>boolean</CODE> value with the specified name
088: *
089: * @exception JMSException if the JMS provider fails to read the message
090: * due to some internal error.
091: * @exception MessageFormatException if this type conversion is invalid.
092: */
093:
094: boolean getBoolean(String name) throws JMSException;
095:
096: /** Returns the <CODE>byte</CODE> value with the specified name.
097: *
098: * @param name the name of the <CODE>byte</CODE>
099: *
100: * @return the <CODE>byte</CODE> value with the specified name
101: *
102: * @exception JMSException if the JMS provider fails to read the message
103: * due to some internal error.
104: * @exception MessageFormatException if this type conversion is invalid.
105: */
106:
107: byte getByte(String name) throws JMSException;
108:
109: /** Returns the <CODE>short</CODE> value with the specified name.
110: *
111: * @param name the name of the <CODE>short</CODE>
112: *
113: * @return the <CODE>short</CODE> value with the specified name
114: *
115: * @exception JMSException if the JMS provider fails to read the message
116: * due to some internal error.
117: * @exception MessageFormatException if this type conversion is invalid.
118: */
119:
120: short getShort(String name) throws JMSException;
121:
122: /** Returns the Unicode character value with the specified name.
123: *
124: * @param name the name of the Unicode character
125: *
126: * @return the Unicode character value with the specified name
127: *
128: * @exception JMSException if the JMS provider fails to read the message
129: * due to some internal error.
130: * @exception MessageFormatException if this type conversion is invalid.
131: */
132:
133: char getChar(String name) throws JMSException;
134:
135: /** Returns the <CODE>int</CODE> value with the specified name.
136: *
137: * @param name the name of the <CODE>int</CODE>
138: *
139: * @return the <CODE>int</CODE> value with the specified name
140: *
141: * @exception JMSException if the JMS provider fails to read the message
142: * due to some internal error.
143: * @exception MessageFormatException if this type conversion is invalid.
144: */
145:
146: int getInt(String name) throws JMSException;
147:
148: /** Returns the <CODE>long</CODE> value with the specified name.
149: *
150: * @param name the name of the <CODE>long</CODE>
151: *
152: * @return the <CODE>long</CODE> value with the specified name
153: *
154: * @exception JMSException if the JMS provider fails to read the message
155: * due to some internal error.
156: * @exception MessageFormatException if this type conversion is invalid.
157: */
158:
159: long getLong(String name) throws JMSException;
160:
161: /** Returns the <CODE>float</CODE> value with the specified name.
162: *
163: * @param name the name of the <CODE>float</CODE>
164: *
165: * @return the <CODE>float</CODE> value with the specified name
166: *
167: * @exception JMSException if the JMS provider fails to read the message
168: * due to some internal error.
169: * @exception MessageFormatException if this type conversion is invalid.
170: */
171:
172: float getFloat(String name) throws JMSException;
173:
174: /** Returns the <CODE>double</CODE> value with the specified name.
175: *
176: * @param name the name of the <CODE>double</CODE>
177: *
178: * @return the <CODE>double</CODE> value with the specified name
179: *
180: * @exception JMSException if the JMS provider fails to read the message
181: * due to some internal error.
182: * @exception MessageFormatException if this type conversion is invalid.
183: */
184:
185: double getDouble(String name) throws JMSException;
186:
187: /** Returns the <CODE>String</CODE> value with the specified name.
188: *
189: * @param name the name of the <CODE>String</CODE>
190: *
191: * @return the <CODE>String</CODE> value with the specified name; if there
192: * is no item by this name, a null value is returned
193: *
194: * @exception JMSException if the JMS provider fails to read the message
195: * due to some internal error.
196: * @exception MessageFormatException if this type conversion is invalid.
197: */
198:
199: String getString(String name) throws JMSException;
200:
201: /** Returns the byte array value with the specified name.
202: *
203: * @param name the name of the byte array
204: *
205: * @return a copy of the byte array value with the specified name; if there
206: * is no
207: * item by this name, a null value is returned.
208: *
209: * @exception JMSException if the JMS provider fails to read the message
210: * due to some internal error.
211: * @exception MessageFormatException if this type conversion is invalid.
212: */
213:
214: byte[] getBytes(String name) throws JMSException;
215:
216: /** Returns the value of the object with the specified name.
217: *
218: * <P>This method can be used to return, in objectified format,
219: * an object in the Java programming language ("Java object") that had
220: * been stored in the Map with the equivalent
221: * <CODE>setObject</CODE> method call, or its equivalent primitive
222: * <CODE>set<I>type</I></CODE> method.
223: *
224: * <P>Note that byte values are returned as <CODE>byte[]</CODE>, not
225: * <CODE>Byte[]</CODE>.
226: *
227: * @param name the name of the Java object
228: *
229: * @return a copy of the Java object value with the specified name, in
230: * objectified format (for example, if the object was set as an
231: * <CODE>int</CODE>, an <CODE>Integer</CODE> is returned); if there is no
232: * item by this name, a null value is returned
233: *
234: * @exception JMSException if the JMS provider fails to read the message
235: * due to some internal error.
236: */
237:
238: Object getObject(String name) throws JMSException;
239:
240: /** Returns an <CODE>Enumeration</CODE> of all the names in the
241: * <CODE>MapMessage</CODE> object.
242: *
243: * @return an enumeration of all the names in this <CODE>MapMessage</CODE>
244: *
245: * @exception JMSException if the JMS provider fails to read the message
246: * due to some internal error.
247: */
248:
249: Enumeration getMapNames() throws JMSException;
250:
251: /** Sets a <CODE>boolean</CODE> value with the specified name into the Map.
252: *
253: * @param name the name of the <CODE>boolean</CODE>
254: * @param value the <CODE>boolean</CODE> value to set in the Map
255: *
256: * @exception JMSException if the JMS provider fails to write the message
257: * due to some internal error.
258: * @exception IllegalArgumentException if the name is null or if the name is
259: * an empty string.
260: * @exception MessageNotWriteableException if the message is in read-only
261: * mode.
262: */
263:
264: void setBoolean(String name, boolean value) throws JMSException;
265:
266: /** Sets a <CODE>byte</CODE> value with the specified name into the Map.
267: *
268: * @param name the name of the <CODE>byte</CODE>
269: * @param value the <CODE>byte</CODE> value to set in the Map
270: *
271: * @exception JMSException if the JMS provider fails to write the message
272: * due to some internal error.
273: * @exception IllegalArgumentException if the name is null or if the name is
274: * an empty string.
275: * @exception MessageNotWriteableException if the message is in read-only
276: * mode.
277: */
278:
279: void setByte(String name, byte value) throws JMSException;
280:
281: /** Sets a <CODE>short</CODE> value with the specified name into the Map.
282: *
283: * @param name the name of the <CODE>short</CODE>
284: * @param value the <CODE>short</CODE> value to set in the Map
285: *
286: * @exception JMSException if the JMS provider fails to write the message
287: * due to some internal error.
288: * @exception IllegalArgumentException if the name is null or if the name is
289: * an empty string.
290: * @exception MessageNotWriteableException if the message is in read-only
291: * mode.
292: */
293:
294: void setShort(String name, short value) throws JMSException;
295:
296: /** Sets a Unicode character value with the specified name into the Map.
297: *
298: * @param name the name of the Unicode character
299: * @param value the Unicode character value to set in the Map
300: *
301: * @exception JMSException if the JMS provider fails to write the message
302: * due to some internal error.
303: * @exception IllegalArgumentException if the name is null or if the name is
304: * an empty string.
305: * @exception MessageNotWriteableException if the message is in read-only
306: * mode.
307: */
308:
309: void setChar(String name, char value) throws JMSException;
310:
311: /** Sets an <CODE>int</CODE> value with the specified name into the Map.
312: *
313: * @param name the name of the <CODE>int</CODE>
314: * @param value the <CODE>int</CODE> value to set in the Map
315: *
316: * @exception JMSException if the JMS provider fails to write the message
317: * due to some internal error.
318: * @exception IllegalArgumentException if the name is null or if the name is
319: * an empty string.
320: * @exception MessageNotWriteableException if the message is in read-only
321: * mode.
322: */
323:
324: void setInt(String name, int value) throws JMSException;
325:
326: /** Sets a <CODE>long</CODE> value with the specified name into the Map.
327: *
328: * @param name the name of the <CODE>long</CODE>
329: * @param value the <CODE>long</CODE> value to set in the Map
330: *
331: * @exception JMSException if the JMS provider fails to write the message
332: * due to some internal error.
333: * @exception IllegalArgumentException if the name is null or if the name is
334: * an empty string.
335: * @exception MessageNotWriteableException if the message is in read-only
336: * mode.
337: */
338:
339: void setLong(String name, long value) throws JMSException;
340:
341: /** Sets a <CODE>float</CODE> value with the specified name into the Map.
342: *
343: * @param name the name of the <CODE>float</CODE>
344: * @param value the <CODE>float</CODE> value to set in the Map
345: *
346: * @exception JMSException if the JMS provider fails to write the message
347: * due to some internal error.
348: * @exception IllegalArgumentException if the name is null or if the name is
349: * an empty string.
350: * @exception MessageNotWriteableException if the message is in read-only
351: * mode.
352: */
353:
354: void setFloat(String name, float value) throws JMSException;
355:
356: /** Sets a <CODE>double</CODE> value with the specified name into the Map.
357: *
358: * @param name the name of the <CODE>double</CODE>
359: * @param value the <CODE>double</CODE> value to set in the Map
360: *
361: * @exception JMSException if the JMS provider fails to write the message
362: * due to some internal error.
363: * @exception IllegalArgumentException if the name is null or if the name is
364: * an empty string.
365: * @exception MessageNotWriteableException if the message is in read-only
366: * mode.
367: */
368:
369: void setDouble(String name, double value) throws JMSException;
370:
371: /** Sets a <CODE>String</CODE> value with the specified name into the Map.
372: *
373: * @param name the name of the <CODE>String</CODE>
374: * @param value the <CODE>String</CODE> value to set in the Map
375: *
376: * @exception JMSException if the JMS provider fails to write the message
377: * due to some internal error.
378: * @exception IllegalArgumentException if the name is null or if the name is
379: * an empty string.
380: * @exception MessageNotWriteableException if the message is in read-only
381: * mode.
382: */
383:
384: void setString(String name, String value) throws JMSException;
385:
386: /** Sets a byte array value with the specified name into the Map.
387: *
388: * @param name the name of the byte array
389: * @param value the byte array value to set in the Map; the array
390: * is copied so that the value for <CODE>name</CODE> will
391: * not be altered by future modifications
392: *
393: * @exception JMSException if the JMS provider fails to write the message
394: * due to some internal error.
395: * @exception NullPointerException if the name is null, or if the name is
396: * an empty string.
397: * @exception MessageNotWriteableException if the message is in read-only
398: * mode.
399: */
400:
401: void setBytes(String name, byte[] value) throws JMSException;
402:
403: /** Sets a portion of the byte array value with the specified name into the
404: * Map.
405: *
406: * @param name the name of the byte array
407: * @param value the byte array value to set in the Map
408: * @param offset the initial offset within the byte array
409: * @param length the number of bytes to use
410: *
411: * @exception JMSException if the JMS provider fails to write the message
412: * due to some internal error.
413: * @exception IllegalArgumentException if the name is null or if the name is
414: * an empty string.
415: * @exception MessageNotWriteableException if the message is in read-only
416: * mode.
417: */
418:
419: void setBytes(String name, byte[] value, int offset, int length)
420: throws JMSException;
421:
422: /** Sets an object value with the specified name into the Map.
423: *
424: * <P>This method works only for the objectified primitive
425: * object types (<code>Integer</code>, <code>Double</code>,
426: * <code>Long</code> ...), <code>String</code> objects, and byte
427: * arrays.
428: *
429: * @param name the name of the Java object
430: * @param value the Java object value to set in the Map
431: *
432: * @exception JMSException if the JMS provider fails to write the message
433: * due to some internal error.
434: * @exception IllegalArgumentException if the name is null or if the name is
435: * an empty string.
436: * @exception MessageFormatException if the object is invalid.
437: * @exception MessageNotWriteableException if the message is in read-only
438: * mode.
439: */
440:
441: void setObject(String name, Object value) throws JMSException;
442:
443: /** Indicates whether an item exists in this <CODE>MapMessage</CODE> object.
444: *
445: * @param name the name of the item to test
446: *
447: * @return true if the item exists
448: *
449: * @exception JMSException if the JMS provider fails to determine if the
450: * item exists due to some internal error.
451: */
452:
453: boolean itemExists(String name) throws JMSException;
454: }
|