KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > scalagent > kjoram > jms > QBrowseReply


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2001 - ScalAgent Distributed Technologies
4  * Copyright (C) 1996 - 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): Nicolas Tachker (ScalAgent)
23  */

24 package com.scalagent.kjoram.jms;
25
26 import com.scalagent.kjoram.messages.Message;
27 import java.util.Hashtable JavaDoc;
28 import java.util.Enumeration JavaDoc;
29 import java.util.Vector JavaDoc;
30
31 /**
32  * A <code>QBrowseReply</code> instance is used by a JMS client proxy for
33  * forwarding a <code>BrowseReply</code> destination notification,
34  * actually replying to a client <code>QBrowseRequest</code>.
35  */

36 public class QBrowseReply extends AbstractJmsReply
37 {
38   /** The message carried by this reply. */
39   private Message message = null;
40   /** The vector of messages carried by this reply. */
41   private Vector JavaDoc messages = null;
42
43
44   /**
45    * Constructs a <code>QBrowseReply</code> instance.
46    *
47    * @param destReply The queue reply actually forwarded.
48    */

49   public QBrowseReply(com.scalagent.kjoram.comm.BrowseReply destReply)
50   {
51     super(destReply.getCorrelationId());
52     Vector JavaDoc vec = destReply.getMessages();
53     if (vec != null && vec.size() == 1)
54       message = (Message) vec.elementAt(0);
55     else
56       messages = vec;
57   }
58
59   /**
60    * Constructs an empty <code>QBrowseReply</code>.
61    */

62   private QBrowseReply(int correlationId)
63   {
64     super(correlationId);
65   }
66
67   /**
68    * Constructs a <code>QBrowseReply</code>.
69    */

70   private QBrowseReply(int correlationId, Message message)
71   {
72     super(correlationId);
73     this.message = message;
74   }
75
76   /**
77    * Constructs a <code>QBrowseReply</code>.
78    */

79   private QBrowseReply(int correlationId, Vector JavaDoc messages)
80   {
81     super(correlationId);
82     this.messages = messages;
83   }
84
85   public QBrowseReply() {
86     messages = new Vector JavaDoc();
87   }
88
89   /** Returns the vector of messages carried by this reply. */
90   public Vector JavaDoc getMessages()
91   {
92     if (message != null) {
93       Vector JavaDoc vec = new Vector JavaDoc();
94       vec.addElement(message);
95       return vec;
96     }
97     return messages;
98   }
99
100   public void addMessage(Message msg) {
101     messages.addElement(msg);
102   }
103
104   public void setMessage(Message msg) {
105     message = msg;
106   }
107
108   public Hashtable JavaDoc soapCode() {
109     Hashtable JavaDoc h = super.soapCode();
110     // Coding and adding the messages into a array:
111
int size = messages.size();
112     if (size > 0) {
113       Vector JavaDoc arrayMsg = new Vector JavaDoc();
114       for (int i = 0; i<size; i++) {
115         Message msg = (Message) messages.elementAt(0);
116         messages.removeElementAt(0);
117         arrayMsg.insertElementAt(msg.soapCode(),i);
118       }
119       if (arrayMsg != null)
120         h.put("arrayMsg",arrayMsg);
121     } else {
122       if (message != null) {
123         h.put("singleMsg",message.soapCode());
124       }
125     }
126     return h;
127   }
128
129   /**
130    * Transforms a hashtable of primitive values into a
131    * <code>QBrowseReply</code> reply.
132    */

133   public static Object JavaDoc soapDecode(Hashtable JavaDoc h) {
134     QBrowseReply req = new QBrowseReply();
135     req.setCorrelationId(((Integer JavaDoc) h.get("correlationId")).intValue());
136     Vector JavaDoc arrayMsg = (Vector JavaDoc) h.get("arrayMsg");
137     if (arrayMsg != null) {
138       for (int i = 0; i<arrayMsg.size(); i++)
139         req.addMessage(Message.soapDecode((Hashtable JavaDoc) arrayMsg.elementAt(i)));
140     } else
141       req.setMessage(Message.soapDecode((Hashtable JavaDoc)h.get("singleMsg")));
142     return req;
143   }
144 }
145
Popular Tags