KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > walend > somnifugi > SomniObjectMessage


1 package net.walend.somnifugi;
2
3 import java.io.Serializable JavaDoc;
4
5 import javax.jms.ObjectMessage JavaDoc;
6 import javax.jms.JMSException JavaDoc;
7
8 /**
9 An SomniMessage that contains an Object.
10
11 @author <a HREF="http://walend.net">David Walend</a> <a HREF="mailto:david@walend.net">david@walend.net</a>
12  */

13
14 public class SomniObjectMessage
15     extends SomniMessage
16     implements ObjectMessage JavaDoc
17 {
18     private Serializable JavaDoc gut = null;
19
20     protected SomniObjectMessage()
21     {
22         super();
23     }
24
25     /**
26 Copy constructor.
27     */

28     protected SomniObjectMessage(SomniObjectMessage message,boolean deep)
29         throws JMSException JavaDoc
30     {
31         super(message,deep);
32         if(deep)
33         {
34             gut = (Serializable JavaDoc)serializedCopy(message.getObject());
35         }
36         else
37         {
38             gut = message.getObject();
39         }
40     }
41
42     /** Sets the serializable object containing this message's data.
43 It is important to note that an <CODE>ObjectMessage</CODE>
44 contains a snapshot of the object at the time <CODE>setObject()</CODE>
45 is called; subsequent modifications of the object will have no
46 effect on the <CODE>ObjectMessage</CODE> body.
47 <p>
48 @param object the message's data
49  
50 @exception JMSException if the JMS provider fails to set the object
51                         due to some internal error.
52 @exception MessageFormatException if object serialization fails.
53 @exception MessageNotWriteableException if the message is in read-only
54                                         mode.
55       */

56     public void setObject(Serializable JavaDoc object)
57         throws JMSException JavaDoc
58     {
59         synchronized(guard)
60             {
61                 checkWritable();
62                 gut = object;
63             }
64     }
65
66     /** Gets the serializable object containing this message's data. The
67 default value is null.
68 <p>
69 @return the serializable object containing this message's data
70  
71 @exception JMSException if the JMS provider fails to get the object
72                         due to some internal error.
73 @exception MessageFormatException if object deserialization fails.
74       */

75     public Serializable JavaDoc getObject()
76         throws JMSException JavaDoc
77     {
78         synchronized(guard)
79             {
80                 return gut;
81             }
82     }
83
84     /**
85 Clears out the message body. Clearing a message's body does not clear
86 its header values or property entries.
87 <p>
88 <P>If this message body was read-only, calling this method leaves
89 the message body in the same state as an empty body in a newly
90 created message.
91 <p>
92 @exception JMSException if the JMS provider fails to clear the message
93                         body due to some internal error.
94       */

95     public void clearBody()
96         throws JMSException JavaDoc
97     {
98         synchronized(guard)
99             {
100                 super.clearBody();
101                 gut = null;
102             }
103     }
104
105     /**
106 Create a shallow copy of this message. Override this method if you extend this class to call your own copy constructor.
107     */

108     protected SomniMessage shallowCopy()
109         throws JMSException JavaDoc
110     {
111         synchronized(guard)
112         {
113             return new SomniObjectMessage(this,false);
114         }
115     }
116
117     /**
118 Create a deep copy of this message. Override this method if you extend this class to call your own copy constructor.
119     */

120     protected SomniMessage deepCopy()
121         throws JMSException JavaDoc
122     {
123         synchronized(guard)
124         {
125             return new SomniObjectMessage(this,true);
126         }
127     }
128
129     public String JavaDoc toString()
130     {
131         StringBuffer JavaDoc buffy = new StringBuffer JavaDoc();
132         buffy.append(super.toString());
133         buffy.append(" contains:");
134
135         if(gut!=null)
136             {
137                 buffy.append(gut.toString());
138             }
139         else
140             {
141                 buffy.append("null");
142             }
143
144         return buffy.toString();
145     }
146 }
147
148 /* Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006 David Walend
149 All rights reserved.
150
151 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
152
153 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
154
155 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
156
157 Neither the name of the SomnifugiJMS Project, walend.net, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission from David Walend.
158
159 Credits in redistributions in source or binary forms must include a link to http://somnifugi.sourceforge.net .
160
161 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
162 The net.walend.somnifugi.sql92 package is modified code from the openmq project, https://mq.dev.java.net/ , Copyright (c) of Sun, and carries the CDDL license, repeated here: You can obtain a copy of the license at https://glassfish.dev.java.net/public/CDDLv1.0.html. See the License for the specific language governing permissions and limitations under the License.
163
164 =================================================================================
165
166 For more information and the latest version of this software, please see http://somnifugi.sourceforge.net and http://walend.net or email <a HREF="mailto:david@walend.net">david@walend.net</a>.
167  */

168
Popular Tags