1 24 package org.objectweb.joram.shared.client; 25 26 import java.io.Externalizable ; 27 import java.io.InputStream ; 28 import java.io.OutputStream ; 29 import java.io.IOException ; 30 import java.util.Vector ; 31 32 import org.objectweb.joram.shared.stream.Streamable; 33 import org.objectweb.joram.shared.stream.StreamUtil; 34 35 39 public final class XACnxRecoverReply extends AbstractJmsReply { 40 41 private Vector bqs; 42 43 public void setBQS(Vector bqs) { 44 this.bqs = bqs; 45 } 46 47 48 private Vector fis; 49 50 public void setFIS(Vector fis) { 51 this.fis = fis; 52 } 53 54 55 private Vector gtis; 56 57 public void setGTIS(Vector gtis) { 58 this.gtis = gtis; 59 } 60 61 protected int getClassId() { 62 return XA_CNX_RECOVER_REPLY; 63 } 64 65 73 public XACnxRecoverReply(XACnxRecoverRequest req, 74 Vector bqs, 75 Vector fis, 76 Vector gtis) { 77 super(req.getRequestId()); 78 this.bqs = bqs; 79 this.fis = fis; 80 this.gtis = gtis; 81 } 82 83 86 public XACnxRecoverReply() {} 87 88 89 public int getSize() { 90 return bqs.size(); 91 } 92 93 94 public byte[] getBranchQualifier(int index) { 95 return (byte[]) bqs.get(index); 96 } 97 98 99 public int getFormatId(int index) { 100 return ((Integer ) fis.get(index)).intValue(); 101 } 102 103 104 public byte[] getGlobalTransactionId(int index) { 105 return (byte[]) gtis.get(index); 106 } 107 108 111 112 private static void writeVectorOfByteArrayTo(Vector v, OutputStream os) throws IOException { 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 readVectorOfByteArrayFrom(InputStream is) throws IOException { 125 int size = StreamUtil.readIntFrom(is); 126 if (size == -1) { 127 return null; 128 } else { 129 Vector v = new Vector (size); 130 for (int i=0; i<size; i++) { 131 v.addElement(StreamUtil.readByteArrayFrom(is)); 132 } 133 return v; 134 } 135 } 136 137 143 public void writeTo(OutputStream os) throws IOException { 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 ) fis.elementAt(i)).intValue(), os); 153 } 154 } 155 writeVectorOfByteArrayTo(fis, os); 156 writeVectorOfByteArrayTo(gtis, os); 157 } 158 159 165 public void readFrom(InputStream is) throws IOException { 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 (size); 173 for (int i=0; i<size; i++) { 174 fis.addElement(new Integer (StreamUtil.readIntFrom(is))); 175 } 176 } 177 gtis = readVectorOfByteArrayFrom(is); 178 } 179 } 180 | Popular Tags |