KickJava   Java API By Example, From Geeks To Geeks.

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


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>SessDenyRequest</code> instance is used by a <code>Session</code>
32  * for denying the messages it consumed.
33  */

34 public class SessDenyRequest 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   /** <code>true</code> if the request must not be acked by the server. */
41   private boolean doNotAck = false;
42
43
44   /**
45    * Constructs a <code>SessDenyRequest</code> instance.
46    *
47    * @param targetName Name of the target queue or subscription.
48    * @param ids Vector of denied message identifiers.
49    * @param queueMode <code>true</code> if this request is destinated to a
50    * queue.
51    */

52   public SessDenyRequest(String JavaDoc targetName, Vector JavaDoc ids, boolean queueMode)
53   {
54     super(targetName);
55     this.ids = ids;
56     this.queueMode = queueMode;
57   }
58
59   /**
60    * Constructs a <code>SessDenyRequest</code> instance.
61    *
62    * @param targetName Name of the target queue or subscription.
63    * @param ids Vector of denied message identifiers.
64    * @param queueMode <code>true</code> if this request is destinated to a
65    * queue.
66    * @param doNotAck <code>true</code> if this request must not be acked by
67    * the server.
68    */

69   public SessDenyRequest(String JavaDoc targetName, Vector JavaDoc ids, boolean queueMode,
70                          boolean doNotAck)
71   {
72     super(targetName);
73     this.ids = ids;
74     this.queueMode = queueMode;
75     this.doNotAck = doNotAck;
76   }
77
78   /**
79    * Constructs a <code>SessDenyRequest</code> instance.
80    */

81   public SessDenyRequest()
82   {}
83
84
85   /** Sets the vector of identifiers. */
86   public void setIds(Vector JavaDoc ids)
87   {
88     this.ids = ids;
89   }
90
91   public void addId(String JavaDoc id) {
92     if (ids == null)
93       ids = new Vector JavaDoc();
94     ids.addElement(id);
95   }
96
97   /** Sets the target destination type. */
98   public void setQueueMode(boolean queueMode)
99   {
100     this.queueMode = queueMode;
101   }
102
103   /** Sets the server ack policy. */
104   public void setDoNotAck(boolean doNotAck)
105   {
106     this.doNotAck = doNotAck;
107   }
108
109   /** Returns the vector of denyed messages identifiers. */
110   public Vector JavaDoc getIds()
111   {
112     return ids;
113   }
114
115   /** Returns <code>true</code> if the request is destinated to a queue. */
116   public boolean getQueueMode()
117   {
118     return queueMode;
119   }
120
121   /**
122    * Returns <code>true</code> if the request must not be acked by the
123    * server.
124    */

125   public boolean getDoNotAck()
126   {
127     return doNotAck;
128   }
129
130   public Hashtable JavaDoc soapCode() {
131     Hashtable JavaDoc h = super.soapCode();
132     h.put("queueMode",new Boolean JavaDoc(queueMode));
133     h.put("doNotAck",new Boolean JavaDoc(doNotAck));
134     // Coding and adding the messages into a array:
135
int size = ids.size();
136     if (size > 0) {
137       Vector JavaDoc arrayId = new Vector JavaDoc();
138       for (int i = 0; i<size; i++) {
139         arrayId.insertElementAt((String JavaDoc) ids.elementAt(0),i);
140         ids.removeElementAt(0);
141       }
142       if (arrayId != null)
143         h.put("arrayId",arrayId);
144     }
145     return h;
146   }
147
148   public static Object JavaDoc soapDecode(Hashtable JavaDoc h) {
149     SessDenyRequest req = new SessDenyRequest();
150     req.setRequestId(((Integer JavaDoc) h.get("requestId")).intValue());
151     req.setTarget((String JavaDoc) h.get("target"));
152     req.setQueueMode(((Boolean JavaDoc) h.get("queueMode")).booleanValue());
153     req.setDoNotAck(((Boolean JavaDoc) h.get("doNotAck")).booleanValue());
154     Vector JavaDoc arrayId = (Vector JavaDoc) h.get("arrayId");
155     if (arrayId != null) {
156       for (int i = 0; i<arrayId.size(); i++)
157         req.addId((String JavaDoc) arrayId.elementAt(i));
158     }
159     return req;
160   }
161 }
162
Popular Tags