1. /*
  2. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  3. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  4. */
  5. package javax.jms;
  6. import java.util.Enumeration;
  7. /** A <CODE>MapMessage</CODE> object is used to send a set of name-value pairs.
  8. * The names are <CODE>String</CODE> objects, and the values are primitive
  9. * data types in the Java programming language. The entries can be accessed
  10. * sequentially or randomly by name. The order of the entries is undefined.
  11. * <CODE>MapMessage</CODE> inherits from the <CODE>Message</CODE> interface
  12. * and adds a message body that contains a Map.
  13. *
  14. * <P>The primitive types can be read or written explicitly using methods
  15. * for each type. They may also be read or written generically as objects.
  16. * For instance, a call to <CODE>MapMessage.setInt("foo", 6)</CODE> is
  17. * equivalent to <CODE>MapMessage.setObject("foo", new Integer(6))</CODE>.
  18. * Both forms are provided, because the explicit form is convenient for
  19. * static programming, and the object form is needed when types are not known
  20. * at compile time.
  21. *
  22. * <P>When a client receives a <CODE>MapMessage</CODE>, it is in read-only
  23. * mode. If a client attempts to write to the message at this point, a
  24. * <CODE>MessageNotWriteableException</CODE> is thrown. If
  25. * <CODE>clearBody</CODE> is called, the message can now be both read from and
  26. * written to.
  27. *
  28. * <P><CODE>MapMessage</CODE> objects support the following conversion table.
  29. * The marked cases must be supported. The unmarked cases must throw a
  30. * <CODE>JMSException</CODE>. The <CODE>String</CODE>-to-primitive conversions
  31. * may throw a runtime exception if the primitive's <CODE>valueOf()</CODE>
  32. * method does not accept it as a valid <CODE>String</CODE> representation of
  33. * the primitive.
  34. *
  35. * <P>A value written as the row type can be read as the column type.
  36. *
  37. * <PRE>
  38. * | | boolean byte short char int long float double String byte[]
  39. * |----------------------------------------------------------------------
  40. * |boolean | X X
  41. * |byte | X X X X X
  42. * |short | X X X X
  43. * |char | X X
  44. * |int | X X X
  45. * |long | X X
  46. * |float | X X X
  47. * |double | X X
  48. * |String | X X X X X X X X
  49. * |byte[] | X
  50. * |----------------------------------------------------------------------
  51. * </PRE>
  52. *
  53. * <P>Attempting to read a null value as a primitive type must be treated
  54. * as calling the primitive's corresponding <code>valueOf(String)</code>
  55. * conversion method with a null value. Since <code>char</code> does not
  56. * support a <code>String</code> conversion, attempting to read a null value
  57. * as a <code>char</code> must throw a <code>NullPointerException</code>.
  58. *
  59. * @version 1.0 - 6 August 1998
  60. * @author Mark Hapner
  61. * @author Rich Burridge
  62. *
  63. * @see javax.jms.Session#createMapMessage()
  64. * @see javax.jms.BytesMessage
  65. * @see javax.jms.Message
  66. * @see javax.jms.ObjectMessage
  67. * @see javax.jms.StreamMessage
  68. * @see javax.jms.TextMessage
  69. */
  70. public interface MapMessage extends Message {
  71. /** Returns the <CODE>boolean</CODE> value with the specified name.
  72. *
  73. * @param name the name of the <CODE>boolean</CODE>
  74. *
  75. * @return the <CODE>boolean</CODE> value with the specified name
  76. *
  77. * @exception JMSException if the JMS provider fails to read the message
  78. * due to some internal error.
  79. * @exception MessageFormatException if this type conversion is invalid.
  80. */
  81. boolean
  82. getBoolean(String name) throws JMSException;
  83. /** Returns the <CODE>byte</CODE> value with the specified name.
  84. *
  85. * @param name the name of the <CODE>byte</CODE>
  86. *
  87. * @return the <CODE>byte</CODE> value with the specified name
  88. *
  89. * @exception JMSException if the JMS provider fails to read the message
  90. * due to some internal error.
  91. * @exception MessageFormatException if this type conversion is invalid.
  92. */
  93. byte
  94. getByte(String name) throws JMSException;
  95. /** Returns the <CODE>short</CODE> value with the specified name.
  96. *
  97. * @param name the name of the <CODE>short</CODE>
  98. *
  99. * @return the <CODE>short</CODE> value with the specified name
  100. *
  101. * @exception JMSException if the JMS provider fails to read the message
  102. * due to some internal error.
  103. * @exception MessageFormatException if this type conversion is invalid.
  104. */
  105. short
  106. getShort(String name) throws JMSException;
  107. /** Returns the Unicode character value with the specified name.
  108. *
  109. * @param name the name of the Unicode character
  110. *
  111. * @return the Unicode character value with the specified name
  112. *
  113. * @exception JMSException if the JMS provider fails to read the message
  114. * due to some internal error.
  115. * @exception MessageFormatException if this type conversion is invalid.
  116. */
  117. char
  118. getChar(String name) throws JMSException;
  119. /** Returns the <CODE>int</CODE> value with the specified name.
  120. *
  121. * @param name the name of the <CODE>int</CODE>
  122. *
  123. * @return the <CODE>int</CODE> value with the specified name
  124. *
  125. * @exception JMSException if the JMS provider fails to read the message
  126. * due to some internal error.
  127. * @exception MessageFormatException if this type conversion is invalid.
  128. */
  129. int
  130. getInt(String name) throws JMSException;
  131. /** Returns the <CODE>long</CODE> value with the specified name.
  132. *
  133. * @param name the name of the <CODE>long</CODE>
  134. *
  135. * @return the <CODE>long</CODE> value with the specified name
  136. *
  137. * @exception JMSException if the JMS provider fails to read the message
  138. * due to some internal error.
  139. * @exception MessageFormatException if this type conversion is invalid.
  140. */
  141. long
  142. getLong(String name) throws JMSException;
  143. /** Returns the <CODE>float</CODE> value with the specified name.
  144. *
  145. * @param name the name of the <CODE>float</CODE>
  146. *
  147. * @return the <CODE>float</CODE> value with the specified name
  148. *
  149. * @exception JMSException if the JMS provider fails to read the message
  150. * due to some internal error.
  151. * @exception MessageFormatException if this type conversion is invalid.
  152. */
  153. float
  154. getFloat(String name) throws JMSException;
  155. /** Returns the <CODE>double</CODE> value with the specified name.
  156. *
  157. * @param name the name of the <CODE>double</CODE>
  158. *
  159. * @return the <CODE>double</CODE> value with the specified name
  160. *
  161. * @exception JMSException if the JMS provider fails to read the message
  162. * due to some internal error.
  163. * @exception MessageFormatException if this type conversion is invalid.
  164. */
  165. double
  166. getDouble(String name) throws JMSException;
  167. /** Returns the <CODE>String</CODE> value with the specified name.
  168. *
  169. * @param name the name of the <CODE>String</CODE>
  170. *
  171. * @return the <CODE>String</CODE> value with the specified name; if there
  172. * is no item by this name, a null value is returned
  173. *
  174. * @exception JMSException if the JMS provider fails to read the message
  175. * due to some internal error.
  176. * @exception MessageFormatException if this type conversion is invalid.
  177. */
  178. String
  179. getString(String name) throws JMSException;
  180. /** Returns the byte array value with the specified name.
  181. *
  182. * @param name the name of the byte array
  183. *
  184. * @return a copy of the byte array value with the specified name; if there
  185. * is no
  186. * item by this name, a null value is returned.
  187. *
  188. * @exception JMSException if the JMS provider fails to read the message
  189. * due to some internal error.
  190. * @exception MessageFormatException if this type conversion is invalid.
  191. */
  192. byte[]
  193. getBytes(String name) throws JMSException;
  194. /** Returns the value of the object with the specified name.
  195. *
  196. * <P>This method can be used to return, in objectified format,
  197. * an object in the Java programming language ("Java object") that had
  198. * been stored in the Map with the equivalent
  199. * <CODE>setObject</CODE> method call, or its equivalent primitive
  200. * <CODE>set<I>type</I></CODE> method.
  201. *
  202. * <P>Note that byte values are returned as <CODE>byte[]</CODE>, not
  203. * <CODE>Byte[]</CODE>.
  204. *
  205. * @param name the name of the Java object
  206. *
  207. * @return a copy of the Java object value with the specified name, in
  208. * objectified format (for example, if the object was set as an
  209. * <CODE>int</CODE>, an <CODE>Integer</CODE> is returned); if there is no
  210. * item by this name, a null value is returned
  211. *
  212. * @exception JMSException if the JMS provider fails to read the message
  213. * due to some internal error.
  214. */
  215. Object
  216. getObject(String name) throws JMSException;
  217. /** Returns an <CODE>Enumeration</CODE> of all the names in the
  218. * <CODE>MapMessage</CODE> object.
  219. *
  220. * @return an enumeration of all the names in this <CODE>MapMessage</CODE>
  221. *
  222. * @exception JMSException if the JMS provider fails to read the message
  223. * due to some internal error.
  224. */
  225. Enumeration
  226. getMapNames() throws JMSException;
  227. /** Sets a <CODE>boolean</CODE> value with the specified name into the Map.
  228. *
  229. * @param name the name of the <CODE>boolean</CODE>
  230. * @param value the <CODE>boolean</CODE> value to set in the Map
  231. *
  232. * @exception JMSException if the JMS provider fails to write the message
  233. * due to some internal error.
  234. * @exception MessageNotWriteableException if the message is in read-only
  235. * mode.
  236. */
  237. void
  238. setBoolean(String name, boolean value) throws JMSException;
  239. /** Sets a <CODE>byte</CODE> value with the specified name into the Map.
  240. *
  241. * @param name the name of the <CODE>byte</CODE>
  242. * @param value the <CODE>byte</CODE> value to set in the Map
  243. *
  244. * @exception JMSException if the JMS provider fails to write the message
  245. * due to some internal error.
  246. * @exception MessageNotWriteableException if the message is in read-only
  247. * mode.
  248. */
  249. void
  250. setByte(String name, byte value)
  251. throws JMSException;
  252. /** Sets a <CODE>short</CODE> value with the specified name into the Map.
  253. *
  254. * @param name the name of the <CODE>short</CODE>
  255. * @param value the <CODE>short</CODE> value to set in the Map
  256. *
  257. * @exception JMSException if the JMS provider fails to write the message
  258. * due to some internal error.
  259. * @exception MessageNotWriteableException if the message is in read-only
  260. * mode.
  261. */
  262. void
  263. setShort(String name, short value)
  264. throws JMSException;
  265. /** Sets a Unicode character value with the specified name into the Map.
  266. *
  267. * @param name the name of the Unicode character
  268. * @param value the Unicode character value to set in the Map
  269. *
  270. * @exception JMSException if the JMS provider fails to write the message
  271. * due to some internal error.
  272. * @exception MessageNotWriteableException if the message is in read-only
  273. * mode.
  274. */
  275. void
  276. setChar(String name, char value)
  277. throws JMSException;
  278. /** Sets an <CODE>int</CODE> value with the specified name into the Map.
  279. *
  280. * @param name the name of the <CODE>int</CODE>
  281. * @param value the <CODE>int</CODE> value to set in the Map
  282. *
  283. * @exception JMSException if the JMS provider fails to write the message
  284. * due to some internal error.
  285. * @exception MessageNotWriteableException if the message is in read-only
  286. * mode.
  287. */
  288. void
  289. setInt(String name, int value)
  290. throws JMSException;
  291. /** Sets a <CODE>long</CODE> value with the specified name into the Map.
  292. *
  293. * @param name the name of the <CODE>long</CODE>
  294. * @param value the <CODE>long</CODE> value to set in the Map
  295. *
  296. * @exception JMSException if the JMS provider fails to write the message
  297. * due to some internal error.
  298. * @exception MessageNotWriteableException if the message is in read-only
  299. * mode.
  300. */
  301. void
  302. setLong(String name, long value)
  303. throws JMSException;
  304. /** Sets a <CODE>float</CODE> value with the specified name into the Map.
  305. *
  306. * @param name the name of the <CODE>float</CODE>
  307. * @param value the <CODE>float</CODE> value to set in the Map
  308. *
  309. * @exception JMSException if the JMS provider fails to write the message
  310. * due to some internal error.
  311. * @exception MessageNotWriteableException if the message is in read-only
  312. * mode.
  313. */
  314. void
  315. setFloat(String name, float value)
  316. throws JMSException;
  317. /** Sets a <CODE>double</CODE> value with the specified name into the Map.
  318. *
  319. * @param name the name of the <CODE>double</CODE>
  320. * @param value the <CODE>double</CODE> value to set in the Map
  321. *
  322. * @exception JMSException if the JMS provider fails to write the message
  323. * due to some internal error.
  324. * @exception MessageNotWriteableException if the message is in read-only
  325. * mode.
  326. */
  327. void
  328. setDouble(String name, double value)
  329. throws JMSException;
  330. /** Sets a <CODE>String</CODE> value with the specified name into the Map.
  331. *
  332. * @param name the name of the <CODE>String</CODE>
  333. * @param value the <CODE>String</CODE> value to set in the Map
  334. *
  335. * @exception JMSException if the JMS provider fails to write the message
  336. * due to some internal error.
  337. * @exception MessageNotWriteableException if the message is in read-only
  338. * mode.
  339. */
  340. void
  341. setString(String name, String value)
  342. throws JMSException;
  343. /** Sets a byte array value with the specified name into the Map.
  344. *
  345. * @param name the name of the byte array
  346. * @param value the byte array value to set in the Map; the array
  347. * is copied so that the value for <CODE>name</CODE> will
  348. * not be altered by future modifications
  349. *
  350. * @exception JMSException if the JMS provider fails to write the message
  351. * due to some internal error.
  352. * @exception MessageNotWriteableException if the message is in read-only
  353. * mode.
  354. */
  355. void
  356. setBytes(String name, byte[] value)
  357. throws JMSException;
  358. /** Sets a portion of the byte array value with the specified name into the
  359. * Map.
  360. *
  361. * @param name the name of the byte array
  362. * @param value the byte array value to set in the Map
  363. * @param offset the initial offset within the byte array
  364. * @param length the number of bytes to use
  365. *
  366. * @exception JMSException if the JMS provider fails to write the message
  367. * due to some internal error.
  368. * @exception MessageNotWriteableException if the message is in read-only
  369. * mode.
  370. */
  371. void
  372. setBytes(String name, byte[] value,
  373. int offset, int length)
  374. throws JMSException;
  375. /** Sets an object value with the specified name into the Map.
  376. *
  377. * <P>This method works only for the objectified primitive
  378. * object types (<code>Integer</code>, <code>Double</code>,
  379. * <code>Long</code> ...), <code>String</code> objects, and byte
  380. * arrays.
  381. *
  382. * @param name the name of the Java object
  383. * @param value the Java object value to set in the Map
  384. *
  385. * @exception JMSException if the JMS provider fails to write the message
  386. * due to some internal error.
  387. * @exception MessageFormatException if the object is invalid.
  388. * @exception MessageNotWriteableException if the message is in read-only
  389. * mode.
  390. */
  391. void
  392. setObject(String name, Object value)
  393. throws JMSException;
  394. /** Indicates whether an item exists in this <CODE>MapMessage</CODE> object.
  395. *
  396. * @param name the name of the item to test
  397. *
  398. * @return true if the item exists
  399. *
  400. * @exception JMSException if the JMS provider fails to determine if the
  401. * item exists due to some internal error.
  402. */
  403. boolean
  404. itemExists(String name) throws JMSException;
  405. }