1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 2000-2007 Sun Microsystems, Inc. All rights reserved.
5 *
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common Development
8 * and Distribution License ("CDDL") (collectively, the "License"). You may
9 * not use this file except in compliance with the License. You can obtain
10 * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
11 * or mq/legal/LICENSE.txt. See the License for the specific language
12 * governing permissions and limitations under the License.
13 *
14 * When distributing the software, include this License Header Notice in each
15 * file and include the License file at mq/legal/LICENSE.txt. Sun designates
16 * this particular file as subject to the "Classpath" exception as provided by
17 * Sun in the GPL Version 2 section of the License file that accompanied this
18 * code. If applicable, add the following below the License Header, with the
19 * fields enclosed by brackets [] replaced by your own identifying information:
20 * "Portions Copyrighted [year] [name of copyright owner]"
21 *
22 * Contributor(s):
23 *
24 * If you wish your version of this file to be governed by only the CDDL or
25 * only the GPL Version 2, indicate your decision by adding "[Contributor]
26 * elects to include this software in this distribution under the [CDDL or GPL
27 * Version 2] license." If you don't indicate a single choice of license, a
28 * recipient has the option to distribute your version of this file under
29 * either the CDDL, the GPL Version 2 or to extend the choice of license to
30 * its licensees as provided above. However, if you add GPL Version 2 code
31 * and therefore, elected the GPL Version 2 license, then the option applies
32 * only if the new code is made subject to such option by the copyright holder.
33 */
34
35 /*
36 * @(#)ObjectMessage.java 1.21 07/02/07
37 */
38
39 package javax.jms;
40
41 import java.io.Serializable;
42
43 /** An <CODE>ObjectMessage</CODE> object is used to send a message that contains
44 * a serializable object in the Java programming language ("Java object").
45 * It inherits from the <CODE>Message</CODE> interface and adds a body
46 * containing a single reference to an object. Only <CODE>Serializable</CODE>
47 * Java objects can be used.
48 *
49 * <P>If a collection of Java objects must be sent, one of the
50 * <CODE>Collection</CODE> classes provided since JDK 1.2 can be used.
51 *
52 * <P>When a client receives an <CODE>ObjectMessage</CODE>, it is in read-only
53 * mode. If a client attempts to write to the message at this point, a
54 * <CODE>MessageNotWriteableException</CODE> is thrown. If
55 * <CODE>clearBody</CODE> is called, the message can now be both read from and
56 * written to.
57 *
58 * @see javax.jms.Session#createObjectMessage()
59 * @see javax.jms.Session#createObjectMessage(Serializable)
60 * @see javax.jms.BytesMessage
61 * @see javax.jms.MapMessage
62 * @see javax.jms.Message
63 * @see javax.jms.StreamMessage
64 * @see javax.jms.TextMessage
65 */
66
67 public interface ObjectMessage extends Message {
68
69 /** Sets the serializable object containing this message's data.
70 * It is important to note that an <CODE>ObjectMessage</CODE>
71 * contains a snapshot of the object at the time <CODE>setObject()</CODE>
72 * is called; subsequent modifications of the object will have no
73 * effect on the <CODE>ObjectMessage</CODE> body.
74 *
75 * @param object the message's data
76 *
77 * @exception JMSException if the JMS provider fails to set the object
78 * due to some internal error.
79 * @exception MessageFormatException if object serialization fails.
80 * @exception MessageNotWriteableException if the message is in read-only
81 * mode.
82 */
83
84 void
85 setObject(Serializable object) throws JMSException;
86
87
88 /** Gets the serializable object containing this message's data. The
89 * default value is null.
90 *
91 * @return the serializable object containing this message's data
92 *
93 * @exception JMSException if the JMS provider fails to get the object
94 * due to some internal error.
95 * @exception MessageFormatException if object deserialization fails.
96 */
97
98 Serializable
99 getObject() throws JMSException;
100 }