1 26 package org.objectweb.joram.shared.client; 27 28 import java.io.InputStream ; 29 import java.io.OutputStream ; 30 import java.io.IOException ; 31 32 import org.objectweb.joram.shared.stream.Streamable; 33 import org.objectweb.joram.shared.stream.StreamUtil; 34 35 38 public final class JmsRequestGroup extends AbstractJmsRequest { 39 protected int getClassId() { 40 return JMS_REQUEST_GROUP; 41 } 42 43 private AbstractJmsRequest[] requests; 44 45 public JmsRequestGroup(AbstractJmsRequest[] ajr) { 46 requests = ajr; 47 } 48 49 public final AbstractJmsRequest[] getRequests() { 50 return requests; 51 } 52 53 56 public JmsRequestGroup() {} 57 58 public void toString(StringBuffer strbuf) { 59 super.toString(strbuf); 60 strbuf.append(",requests.length=").append(requests.length); 61 strbuf.append(')'); 62 } 63 64 67 68 74 public void writeTo(OutputStream os) throws IOException { 75 super.writeTo(os); 76 if (requests == null) { 77 StreamUtil.writeTo(-1, os); 78 } else { 79 int size = requests.length; 80 StreamUtil.writeTo(size, os); 81 for (int i=0; i<size; i++) { 82 StreamUtil.writeTo(requests[i].getClass().getName(), os); 83 requests[i].writeTo(os); 84 } 85 } 86 } 87 88 94 public void readFrom(InputStream is) throws IOException { 95 super.readFrom(is); 96 int size = StreamUtil.readIntFrom(is); 97 if (size == -1) { 98 requests = null; 99 } else { 100 requests = new AbstractJmsRequest[size]; 101 for (int i=0; i<size; i++) { 102 String cn = StreamUtil.readStringFrom(is); 103 try { 104 requests[i] = (AbstractJmsRequest) Class.forName(cn).newInstance(); 105 } catch (ClassNotFoundException exc) { 106 throw new IOException ("AbstractJmsRequest.readFrom(), Unknown class " + cn); 107 } catch (InstantiationException exc) { 108 throw new IOException ("AbstractJmsRequest.readFrom(), Cannot Instantiate " + cn); 109 } catch (IllegalAccessException exc) { 110 throw new IOException ("AbstractJmsRequest.readFrom(), Cannot IllegalAccessException " + cn); 111 } 112 requests[i].readFrom(is); 113 } 114 } 115 } 116 } 117 | Popular Tags |