KickJava   Java API By Example, From Geeks To Geeks.

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


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): ScalAgent Distributed Technologies
22  *
23  * Created on 3 mai 2006
24  *
25  */

26 package org.objectweb.joram.shared.client;
27
28 import java.io.InputStream JavaDoc;
29 import java.io.OutputStream JavaDoc;
30 import java.io.IOException JavaDoc;
31
32 import org.objectweb.joram.shared.stream.Streamable;
33 import org.objectweb.joram.shared.stream.StreamUtil;
34
35 /**
36  *
37  */

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   /**
54    * Constructs a <code>JmsRequestGroup</code> instance.
55    */

56   public JmsRequestGroup() {}
57
58   public void toString(StringBuffer JavaDoc strbuf) {
59     super.toString(strbuf);
60     strbuf.append(",requests.length=").append(requests.length);
61     strbuf.append(')');
62   }
63
64   /* ***** ***** ***** ***** *****
65    * Streamable interface
66    * ***** ***** ***** ***** ***** */

67
68   /**
69    * The object implements the writeTo method to write its contents to
70    * the output stream.
71    *
72    * @param os the stream to write the object to
73    */

74   public void writeTo(OutputStream JavaDoc os) throws IOException JavaDoc {
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   /**
89    * The object implements the readFrom method to restore its contents from
90    * the input stream.
91    *
92    * @param is the stream to read data from in order to restore the object
93    */

94   public void readFrom(InputStream JavaDoc is) throws IOException JavaDoc {
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 JavaDoc cn = StreamUtil.readStringFrom(is);
103         try {
104           requests[i] = (AbstractJmsRequest) Class.forName(cn).newInstance();
105         } catch (ClassNotFoundException JavaDoc exc) {
106           throw new IOException JavaDoc("AbstractJmsRequest.readFrom(), Unknown class " + cn);
107         } catch (InstantiationException JavaDoc exc) {
108           throw new IOException JavaDoc("AbstractJmsRequest.readFrom(), Cannot Instantiate " + cn);
109         } catch (IllegalAccessException JavaDoc exc) {
110           throw new IOException JavaDoc("AbstractJmsRequest.readFrom(), Cannot IllegalAccessException " + cn);
111         }
112         requests[i].readFrom(is);
113       }
114     }
115   }
116 }
117
Popular Tags