KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exolab > jms > tranlog > DataTransactionLogEntry


1 /**
2  * Redistribution and use of this software and associated documentation
3  * ("Software"), with or without modification, are permitted provided
4  * that the following conditions are met:
5  *
6  * 1. Redistributions of source code must retain copyright
7  * statements and notices. Redistributions must also contain a
8  * copy of this document.
9  *
10  * 2. Redistributions in binary form must reproduce the
11  * above copyright notice, this list of conditions and the
12  * following disclaimer in the documentation and/or other
13  * materials provided with the distribution.
14  *
15  * 3. The name "Exolab" must not be used to endorse or promote
16  * products derived from this Software without prior written
17  * permission of Exoffice Technologies. For written permission,
18  * please contact info@exolab.org.
19  *
20  * 4. Products derived from this Software may not be called "Exolab"
21  * nor may "Exolab" appear in their names without prior written
22  * permission of Exoffice Technologies. Exolab is a registered
23  * trademark of Exoffice Technologies.
24  *
25  * 5. Due credit should be given to the Exolab Project
26  * (http://www.exolab.org/).
27  *
28  * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32  * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39  * OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Copyright 2002-2003 (C) Exoffice Technologies Inc. All Rights Reserved.
42  *
43  *
44  * $Id: DataTransactionLogEntry.java,v 1.1 2004/11/26 01:51:01 tanderson Exp $
45  *
46  * Date Author Changes
47  * 20/11/2001 jima Created
48  */

49 package org.exolab.jms.tranlog;
50
51
52 import java.io.Externalizable JavaDoc;
53 import java.io.IOException JavaDoc;
54 import java.io.ObjectInput JavaDoc;
55 import java.io.ObjectOutput JavaDoc;
56 import java.io.Serializable JavaDoc;
57
58
59 /**
60  * This entry associates resource specific data to an XID. The data is
61  * any serializable object
62  */

63 public class DataTransactionLogEntry
64     extends BaseTransactionLogEntry
65     implements Externalizable JavaDoc {
66
67     /**
68      * This is the unique id used to identify the version of the class
69      * for the purpose of Serialization
70      */

71     static final long serialVersionUID = 2;
72
73     /**
74      * opaque data for this transaction
75      */

76     private Object JavaDoc _data;
77
78
79     /**
80      * Default constuctor for serialization
81      */

82     public DataTransactionLogEntry() {
83     }
84
85     /**
86      * Create an instance of this object for the specified transaction
87      * identifier and resource identifier.
88      * <p>
89      * Mark as the transaction being created now
90      *
91      * @param txid - transaction identifier
92      * @param rid - resource identifier
93      */

94     DataTransactionLogEntry(ExternalXid txid, String JavaDoc rid) {
95         this(txid, rid, System.currentTimeMillis());
96     }
97
98     /**
99      * Create an instance of this object for the specified transaction
100      * identifier and resource identifier
101      * <p>
102      * Mark the transaction as being created at the specified time
103      *
104      * @param long txid - the transaction identifier
105      * @param long rid - the resource identifier
106      * @param long created - a timestamp for this transaction
107      */

108     DataTransactionLogEntry(ExternalXid txid, String JavaDoc rid, long created) {
109         super(txid, rid, created);
110     }
111
112     /**
113      * Set the data for the transaction. If the specified object is
114      * not Serializable then throw an IllegalArgumentException
115      *
116      * @param object - object data to set
117      * @throws IOException - if it cannot serialize the data
118      * @throws IllegalArgumentException - if it is not serializable
119      */

120     public void setData(Object JavaDoc data)
121         throws IllegalArgumentException JavaDoc, IOException JavaDoc {
122         if ((Serializable JavaDoc.class.isAssignableFrom(data.getClass())) ||
123             (Externalizable JavaDoc.class.isAssignableFrom(data.getClass()))) {
124             _data = new String JavaDoc(SerializationHelper.serialize(data));
125         } else {
126             throw new IllegalArgumentException JavaDoc(
127                 "The object to setObject must be serializable");
128         }
129     }
130
131     /**
132      * Return the object for this transaction entry
133      *
134      * @return Object
135      */

136     public Object JavaDoc getData() {
137         return _data;
138     }
139
140     // implementation of Externalizable.writeExternal
141
public void writeExternal(ObjectOutput JavaDoc stream)
142         throws IOException JavaDoc {
143         stream.writeLong(serialVersionUID);
144         stream.writeObject(_data);
145         super.writeExternal(stream);
146     }
147
148     // implementation of Externalizable.writeExternal
149
public void readExternal(ObjectInput JavaDoc stream)
150         throws IOException JavaDoc, ClassNotFoundException JavaDoc {
151         long version = stream.readLong();
152         if (version == serialVersionUID) {
153             _data = stream.readObject();
154             super.readExternal(stream);
155         } else {
156             throw new IOException JavaDoc("No support for DataTransactionLogEntry " +
157                 "with version " + version);
158         }
159     }
160 }
161
Popular Tags