KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Hashtable JavaDoc;
27 import java.util.Enumeration JavaDoc;
28 import java.util.Vector JavaDoc;
29
30 /**
31  * A <code>SessAckRequest</code> instance is used by a <code>Session</code>
32  * for acknowledging the messages it consumed.
33  */

34 public class SessAckRequest extends AbstractJmsRequest
35 {
36   /** Vector of message identifiers. */
37   private Vector JavaDoc ids;
38   /** <code>true</code> if the request is destinated to a queue. */
39   private boolean queueMode;
40
41   /**
42    * Constructs a <code>SessAckRequest</code> instance.
43    *
44    * @param targetName Name of the target queue or subscription.
45    * @param ids Vector of acknowledged message identifiers.
46    * @param queueMode <code>true</code> if this request is destinated to a
47    * queue.
48    */

49   public SessAckRequest(String JavaDoc targetName, Vector JavaDoc ids, boolean queueMode)
50   {
51     super(targetName);
52     this.ids = ids;
53     this.queueMode = queueMode;
54   }
55
56   /**
57    * Constructs a <code>SessAckRequest</code> instance.
58    */

59   public SessAckRequest() {
60     ids = new Vector JavaDoc();
61   }
62
63   /** Sets the vector of identifiers. */
64   public void setIds(Vector JavaDoc ids)
65   {
66     this.ids = ids;
67   }
68
69   public void addId(String JavaDoc id) {
70     ids.addElement(id);
71   }
72
73   /** Sets the target destination type. */
74   public void setQueueMode(boolean queueMode)
75   {
76     this.queueMode = queueMode;
77   }
78
79   /** Returns the vector of acknowledged messages identifiers. */
80   public Vector JavaDoc getIds()
81   {
82     return ids;
83   }
84
85   /** Returns <code>true</code> if the request is destinated to a queue. */
86   public boolean getQueueMode()
87   {
88     return queueMode;
89   }
90
91   public Hashtable JavaDoc soapCode() {
92     Hashtable JavaDoc h = super.soapCode();
93     h.put("queueMode",new Boolean JavaDoc(queueMode));
94     // Coding and adding the messages into a array:
95
int size = ids.size();
96     if (size > 0) {
97       Vector JavaDoc arrayId = new Vector JavaDoc();
98       for (int i = 0; i<size; i++) {
99         arrayId.insertElementAt((String JavaDoc) ids.elementAt(0),i);
100         ids.removeElementAt(0);
101       }
102       if (arrayId != null)
103         h.put("arrayId",arrayId);
104     }
105     return h;
106   }
107
108   public static Object JavaDoc soapDecode(Hashtable JavaDoc h) {
109     SessAckRequest req = new SessAckRequest();
110     req.setRequestId(((Integer JavaDoc) h.get("requestId")).intValue());
111     req.setTarget((String JavaDoc) h.get("target"));
112     req.setQueueMode(((Boolean JavaDoc) h.get("queueMode")).booleanValue());
113     Vector JavaDoc arrayId = (Vector JavaDoc) h.get("arrayId");
114     if (arrayId != null) {
115       for (int i = 0; i<arrayId.size(); i++)
116         req.addId((String JavaDoc) arrayId.elementAt(i));
117     }
118     return req;
119   }
120 }
121
Popular Tags