KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > sandesha > ws > rm > SequenceAcknowledgement


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 package org.apache.sandesha.ws.rm;
19
20 import org.apache.axis.message.MessageElement;
21 import org.apache.axis.message.SOAPEnvelope;
22 import org.apache.axis.message.SOAPHeaderElement;
23 import org.apache.sandesha.Constants;
24
25 import javax.xml.soap.Name JavaDoc;
26 import javax.xml.soap.SOAPException JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.LinkedList JavaDoc;
29 import java.util.List JavaDoc;
30
31 /**
32  * class SequenceAcknowledgement
33  *
34  * @author Amila Navarathna
35  * @author Jaliya Ekanayaka
36  * @author Sudar Nimalan
37  */

38 public class SequenceAcknowledgement extends MessageElement implements IRmElement {
39
40     /**
41      * Field seqAck
42      */

43     private MessageElement seqAck; // this element
44

45     /**
46      * Field ackRanges
47      */

48     private List JavaDoc ackRanges;
49
50     /**
51      * Field nackList
52      */

53     private List JavaDoc nackList;
54
55     /**
56      * Field identifier
57      */

58     private Identifier identifier;
59
60     /**
61      * Constructor SequenceAcknowledgement
62      */

63     public SequenceAcknowledgement() {
64
65         ackRanges = new LinkedList JavaDoc();
66         nackList = new LinkedList JavaDoc();
67         seqAck = new MessageElement();
68
69         seqAck.setName(Constants.WSRM.NS_PREFIX_RM + Constants.COLON + Constants.WSRM.SEQUENCE_ACK);
70     }
71
72     /**
73      * Method getSoapElement
74      *
75      * @return MessageElement
76      * @throws SOAPException
77      */

78     public MessageElement getSoapElement() throws SOAPException JavaDoc {
79
80         Iterator JavaDoc ite = ackRanges.iterator();
81
82         while (ite.hasNext()) {
83             MessageElement element = (MessageElement) ite.next();
84
85             seqAck.addChildElement(element);
86         }
87
88         ite = nackList.iterator();
89
90         while (ite.hasNext()) {
91             MessageElement element = (MessageElement) ite.next();
92
93             seqAck.addChildElement(element);
94         }
95
96         seqAck.addChildElement(identifier.getSoapElement());
97
98         return seqAck;
99     }
100
101     /**
102      * Method toSoapEnvelop
103      *
104      * @param envelope
105      * @return SOAPEnvelope
106      * @throws SOAPException
107      */

108     public SOAPEnvelope toSoapEnvelop(SOAPEnvelope envelope) throws SOAPException JavaDoc {
109
110         SOAPEnvelope env = envelope;
111
112         if (env.getHeader() == null) {
113             env.addHeader();
114         }
115
116         Name JavaDoc name = env.createName("", Constants.WSRM.NS_PREFIX_RM, Constants.WSRM.NS_URI_RM);
117         SOAPHeaderElement headerElement = (SOAPHeaderElement) env.getHeader().addHeaderElement(name);
118
119         headerElement.setActor(null);
120         headerElement.setName(Constants.WSRM.SEQUENCE_ACK);
121         headerElement.setMustUnderstand(true);
122
123         Iterator JavaDoc iterator = ackRanges.iterator();
124
125         while (iterator.hasNext()) {
126
127             AcknowledgementRange ackRange = (AcknowledgementRange) iterator.next();
128             ackRange.toSOAPEnvelope(headerElement);
129         }
130
131         iterator = nackList.iterator();
132
133         while (iterator.hasNext()) {
134             Nack nack = (Nack) iterator.next();
135
136             nack.toSOAPEnvelope(headerElement);
137         }
138
139         if (identifier != null) {
140             identifier.toSOAPEnvelope(headerElement);
141         }
142
143         return env;
144     }
145
146     /**
147      * Method fromSOAPEnveploe
148      *
149      * @param headerElement
150      * @return SequenceAcknowledgement
151      */

152     public SequenceAcknowledgement fromSOAPEnveploe(SOAPHeaderElement headerElement) {
153
154         Iterator JavaDoc iterator = headerElement.getChildElements();
155         MessageElement childElement;
156
157         while (iterator.hasNext()) {
158
159             childElement = (MessageElement) iterator.next();
160
161             if (childElement.getName().equals(Constants.WSRM.NS_PREFIX_RM + Constants.COLON + Constants.WSRM.IDENTIFIER)) {
162                 identifier = new Identifier();
163                 identifier.fromSOAPEnvelope(childElement);
164             }
165
166             if (childElement.getName().equals(Constants.WSRM.IDENTIFIER)) {
167                 identifier = new Identifier();
168                 identifier.fromSOAPEnvelope(childElement);
169             }
170
171             if (childElement.getName().equals(Constants.WSRM.NS_PREFIX_RM + Constants.COLON + Constants.WSRM.ACK_RANGE)) {
172                 AcknowledgementRange ackRange = new AcknowledgementRange();
173
174                 ackRange.fromSOAPEnvelope(childElement);
175                 ackRanges.add(ackRange);
176             }
177
178             if (childElement.getName().equals(Constants.WSRM.ACK_RANGE)) {
179                 AcknowledgementRange ackRange = new AcknowledgementRange();
180                 ackRange.fromSOAPEnvelope(childElement);
181                 ackRanges.add(ackRange);
182             }
183
184             if (childElement.getName().equals(Constants.WSRM.NS_PREFIX_RM + Constants.COLON + Constants.WSRM.NACK)) {
185                 Nack nack = new Nack();
186                 nack.fromSOAPEnvelope(childElement);
187             }
188
189             if (childElement.getName().equals(Constants.WSRM.NACK)) {
190                 Nack nack = new Nack();
191                 nack.fromSOAPEnvelope(childElement);
192             }
193         }
194
195         return this;
196     }
197
198     /**
199      * Method addChildElement
200      *
201      * @param element
202      * @throws SOAPException
203      */

204     public void addChildElement(MessageElement element) throws SOAPException JavaDoc {
205         seqAck.addChildElement(element);
206     }
207
208     /**
209      * Method getAckRanges
210      *
211      * @return List
212      */

213     public List JavaDoc getAckRanges() {
214         return ackRanges;
215     }
216
217     /**
218      * Method getIdentifier
219      *
220      * @return Identifier
221      */

222     public Identifier getIdentifier() {
223         return identifier;
224     }
225
226     /**
227      * Method getNackList
228      *
229      * @return List
230      */

231     public List JavaDoc getNackList() {
232         return nackList;
233     }
234
235     /**
236      * method addAckRanges
237      *
238      * @param ackRange
239      * @return AcknowledgementRange
240      */

241     public AcknowledgementRange addAckRanges(AcknowledgementRange ackRange) {
242
243         ackRanges.add(ackRange);
244
245         return ackRange;
246     }
247
248     /**
249      * Method addNackRanges
250      *
251      * @param nack
252      * @return Nack
253      */

254     public Nack addNackRanges(Nack nack) {
255
256         nackList.add(nack);
257
258         return nack;
259     }
260
261     /**
262      * Method setIdentifier
263      *
264      * @param identifier
265      */

266     public void setIdentifier(Identifier identifier) {
267         this.identifier = identifier;
268     }
269
270     /**
271      * Method setAckRanges
272      *
273      * @param list
274      */

275     public void setAckRanges(List JavaDoc list) {
276         ackRanges = list;
277     }
278 }
Popular Tags