com/scalagent/kjoram/jms/QBrowseReply.java

00001 /*
00002  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
00003  * Copyright (C) 2001 - ScalAgent Distributed Technologies
00004  * Copyright (C) 1996 - Dyade
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or any later version.
00010  * 
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00019  * USA.
00020  *
00021  * Initial developer(s): Frederic Maistre (INRIA)
00022  * Contributor(s): Nicolas Tachker (ScalAgent)
00023  */
00024 package com.scalagent.kjoram.jms;
00025 
00026 import com.scalagent.kjoram.messages.Message;
00027 import java.util.Hashtable;
00028 import java.util.Enumeration;
00029 import java.util.Vector;
00030 
00036 public class QBrowseReply extends AbstractJmsReply
00037 {
00039   private Message message = null;
00041   private Vector messages = null;
00042 
00043 
00049   public QBrowseReply(com.scalagent.kjoram.comm.BrowseReply destReply)
00050   {
00051     super(destReply.getCorrelationId());
00052     Vector vec = destReply.getMessages();
00053     if (vec != null && vec.size() == 1)
00054       message = (Message) vec.elementAt(0);
00055     else
00056       messages = vec;
00057   }
00058 
00062   private QBrowseReply(int correlationId)
00063   {
00064     super(correlationId);
00065   }
00066 
00070   private QBrowseReply(int correlationId, Message message)
00071   {
00072     super(correlationId);
00073     this.message = message;
00074   }
00075 
00079   private QBrowseReply(int correlationId, Vector messages)
00080   {
00081     super(correlationId);
00082     this.messages = messages;
00083   }
00084 
00085   public QBrowseReply() {
00086     messages = new Vector();
00087   }
00088 
00090   public Vector getMessages()
00091   {
00092     if (message != null) {
00093       Vector vec = new Vector();
00094       vec.addElement(message);
00095       return vec;
00096     }
00097     return messages;
00098   }
00099 
00100   public void addMessage(Message msg) {
00101     messages.addElement(msg);
00102   }
00103 
00104   public void setMessage(Message msg) {
00105     message = msg;
00106   }
00107 
00108   public Hashtable soapCode() {
00109     Hashtable h = super.soapCode();
00110     // Coding and adding the messages into a array:
00111     int size = messages.size();
00112     if (size > 0) {
00113       Vector arrayMsg = new Vector();
00114       for (int i = 0; i<size; i++) {
00115         Message msg = (Message) messages.elementAt(0);
00116         messages.removeElementAt(0);
00117         arrayMsg.insertElementAt(msg.soapCode(),i);
00118       }
00119       if (arrayMsg != null)
00120         h.put("arrayMsg",arrayMsg);
00121     } else {
00122       if (message != null) {
00123         h.put("singleMsg",message.soapCode());
00124       }
00125     }
00126     return h;
00127   }
00128 
00133   public static Object soapDecode(Hashtable h) {
00134     QBrowseReply req = new QBrowseReply();
00135     req.setCorrelationId(((Integer) h.get("correlationId")).intValue());
00136     Vector arrayMsg = (Vector) h.get("arrayMsg");
00137     if (arrayMsg != null) {
00138       for (int i = 0; i<arrayMsg.size(); i++)
00139         req.addMessage(Message.soapDecode((Hashtable) arrayMsg.elementAt(i)));
00140     } else
00141       req.setMessage(Message.soapDecode((Hashtable)h.get("singleMsg")));
00142     return req;
00143   }
00144 }

Generated on Tue Sep 16 16:14:24 2008 for joram by  doxygen 1.5.0