KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > shared > client > XACnxRecoverReply


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2001 - 2006 ScalAgent Distributed Technologies
4  * Copyright (C) 1996 - 2000 Dyade
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA.
20  *
21  * Initial developer(s): Frederic Maistre (INRIA)
22  * Contributor(s): ScalAgent Distributed Technologies
23  */

24 package org.objectweb.joram.shared.client;
25
26 import java.io.Externalizable JavaDoc;
27 import java.io.InputStream JavaDoc;
28 import java.io.OutputStream JavaDoc;
29 import java.io.IOException JavaDoc;
30 import java.util.Vector JavaDoc;
31
32 import org.objectweb.joram.shared.stream.Streamable;
33 import org.objectweb.joram.shared.stream.StreamUtil;
34
35 /**
36  * A <code>XACnxRecoverReply</code> replies to a
37  * <code>XACnxRecoverRequest</code> and carries transaction identifiers.
38  */

39 public final class XACnxRecoverReply extends AbstractJmsReply {
40   /** Branch qualifiers. */
41   private Vector JavaDoc bqs;
42
43   public void setBQS(Vector JavaDoc bqs) {
44     this.bqs = bqs;
45   }
46
47   /** Format identifiers. */
48   private Vector JavaDoc fis;
49
50   public void setFIS(Vector JavaDoc fis) {
51     this.fis = fis;
52   }
53
54   /** Global transaction identifiers. */
55   private Vector JavaDoc gtis;
56
57   public void setGTIS(Vector JavaDoc gtis) {
58     this.gtis = gtis;
59   }
60
61   protected int getClassId() {
62     return XA_CNX_RECOVER_REPLY;
63   }
64
65   /**
66    * Constructs a <code>XACnxRecoverReply</code> instance.
67    *
68    * @param req The replied request.
69    * @param bqs Branch qualifiers.
70    * @param fis Format identifiers.
71    * @param gtis Global transaction identifiers.
72    */

73   public XACnxRecoverReply(XACnxRecoverRequest req,
74                            Vector JavaDoc bqs,
75                            Vector JavaDoc fis,
76                            Vector JavaDoc gtis) {
77     super(req.getRequestId());
78     this.bqs = bqs;
79     this.fis = fis;
80     this.gtis = gtis;
81   }
82
83   /**
84    * Constructs a <code>XACnxRecoverReply</code> instance.
85    */

86   public XACnxRecoverReply() {}
87
88   /** Returns the number of transaction identifiers. */
89   public int getSize() {
90     return bqs.size();
91   }
92
93   /** Returns a branch qualifier. */
94   public byte[] getBranchQualifier(int index) {
95     return (byte[]) bqs.get(index);
96   }
97
98   /** Returns a format identifier. */
99   public int getFormatId(int index) {
100     return ((Integer JavaDoc) fis.get(index)).intValue();
101   }
102
103   /** Returns a global transaction identifier. */
104   public byte[] getGlobalTransactionId(int index) {
105     return (byte[]) gtis.get(index);
106   }
107
108   /* ***** ***** ***** ***** *****
109    * Streamable interface
110    * ***** ***** ***** ***** ***** */

111
112   private static void writeVectorOfByteArrayTo(Vector JavaDoc v, OutputStream JavaDoc os) throws IOException JavaDoc {
113     if (v == null) {
114       StreamUtil.writeTo(-1, os);
115     } else {
116       int size = v.size();
117       StreamUtil.writeTo(size, os);
118       for (int i=0; i<size; i++) {
119         StreamUtil.writeTo((byte []) v.elementAt(i), os);
120       }
121     }
122   }
123
124   private static Vector JavaDoc readVectorOfByteArrayFrom(InputStream JavaDoc is) throws IOException JavaDoc {
125     int size = StreamUtil.readIntFrom(is);
126     if (size == -1) {
127       return null;
128     } else {
129       Vector JavaDoc v = new Vector JavaDoc(size);
130       for (int i=0; i<size; i++) {
131         v.addElement(StreamUtil.readByteArrayFrom(is));
132       }
133       return v;
134     }
135   }
136
137   /**
138    * The object implements the writeTo method to write its contents to
139    * the output stream.
140    *
141    * @param os the stream to write the object to
142    */

143   public void writeTo(OutputStream JavaDoc os) throws IOException JavaDoc {
144     super.writeTo(os);
145     writeVectorOfByteArrayTo(bqs, os);
146     if (fis == null) {
147       StreamUtil.writeTo(-1, os);
148     } else {
149       int size = fis.size();
150       StreamUtil.writeTo(size, os);
151       for (int i=0; i<size; i++) {
152         StreamUtil.writeTo(((Integer JavaDoc) fis.elementAt(i)).intValue(), os);
153       }
154     }
155     writeVectorOfByteArrayTo(fis, os);
156     writeVectorOfByteArrayTo(gtis, os);
157   }
158
159   /**
160    * The object implements the readFrom method to restore its contents from
161    * the input stream.
162    *
163    * @param is the stream to read data from in order to restore the object
164    */

165   public void readFrom(InputStream JavaDoc is) throws IOException JavaDoc {
166     super.readFrom(is);
167     bqs = readVectorOfByteArrayFrom(is);
168     int size = StreamUtil.readIntFrom(is);
169     if (size == -1) {
170       fis = null;
171     } else {
172       fis = new Vector JavaDoc(size);
173       for (int i=0; i<size; i++) {
174         fis.addElement(new Integer JavaDoc(StreamUtil.readIntFrom(is)));
175       }
176     }
177     gtis = readVectorOfByteArrayFrom(is);
178   }
179 }
180
Popular Tags