KickJava   Java API By Example, From Geeks To Geeks.

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


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.AxisFault;
21 import org.apache.axis.message.SOAPBodyElement;
22 import org.apache.axis.message.SOAPEnvelope;
23 import org.apache.axis.message.SOAPHeaderElement;
24 import org.apache.sandesha.Constants;
25
26 import java.util.Iterator JavaDoc;
27
28 /**
29  * class RMHeaders
30  *
31  * @author Amila Navarathna
32  * @author Jaliya Ekanayaka
33  * @author Sudar Nimalan
34  */

35 public class RMHeaders {
36
37     /**
38      * Field createSequence
39      */

40     private CreateSequence createSequence = null;
41
42     /**
43      * Field createSequenceResponse
44      */

45     private CreateSequenceResponse createSequenceResponse = null;
46
47     /**
48      * Field ackRequest
49      */

50     private AckRequested ackRequest = null;
51
52     /**
53      * Field sequenceAcknowledgement
54      */

55     private SequenceAcknowledgement sequenceAcknowledgement = null;
56
57     /**
58      * Field sequence
59      */

60     private Sequence sequence = null;
61
62     /**
63      * Field terminateSequence
64      */

65     private TerminateSequence terminateSequence = null;
66
67
68     /**
69      * Method toSoapEnvelop
70      *
71      * @param envelope
72      * @return SOAPEnvelope
73      * @throws Exception
74      */

75     public SOAPEnvelope toSoapEnvelop(SOAPEnvelope envelope) throws Exception JavaDoc {
76
77         SOAPEnvelope env = envelope;
78
79         if (createSequence != null) {
80             createSequence.toSoapEnvelop(env);
81         }
82         if (createSequenceResponse != null) {
83             createSequenceResponse.toSoapEnvelop(env);
84         }
85         if (sequenceAcknowledgement != null) {
86             sequenceAcknowledgement.toSoapEnvelop(env);
87         }
88         if (sequence != null) {
89             sequence.toSoapEnvelop(env);
90         }
91         if (ackRequest != null) {
92             ackRequest.toSoapEnvelop(env);
93         }
94         if (terminateSequence != null) {
95             terminateSequence.toSoapEnvelop(env);
96         }
97
98         return env;
99     }
100
101     /**
102      * Method fromSOAPEnvelope
103      *
104      * @param env
105      * @return RMHeaders
106      * @throws AxisFault
107      */

108     public RMHeaders fromSOAPEnvelope(SOAPEnvelope env) throws Exception JavaDoc, AxisFault {
109
110         if (env != null) {
111             Iterator JavaDoc iterator = env.getHeaders().iterator();
112             SOAPHeaderElement headerElement;
113
114             while (iterator.hasNext()) {
115                 headerElement = (SOAPHeaderElement) iterator.next();
116
117                 if (headerElement.getName().equals(Constants.WSRM.SEQUENCE)) {
118                     sequence = new Sequence();
119                     headerElement.setProcessed(true);
120                     headerElement.setMustUnderstand(false);
121                     sequence.fromSOAPEnveploe(headerElement);
122                 }
123
124                 if (headerElement.getName().equals(Constants.WSRM.SEQUENCE_ACK)) {
125                     sequenceAcknowledgement = new SequenceAcknowledgement();
126                     headerElement.setProcessed(true);
127                     headerElement.setMustUnderstand(false);
128                     sequenceAcknowledgement.fromSOAPEnveploe(headerElement);
129                 }
130
131                 if (headerElement.getName().equals(Constants.WSRM.ACK_REQUESTED)) {
132                     ackRequest = new AckRequested();
133                     headerElement.setProcessed(true);
134                     headerElement.setMustUnderstand(false);
135                     ackRequest.fromSOAPEnveploe(headerElement);
136                 }
137             }
138
139             iterator = (Iterator JavaDoc) env.getBody().getChildElements();
140
141             SOAPBodyElement bodyElement;
142
143             while (iterator.hasNext()) {
144                 bodyElement = (SOAPBodyElement) iterator.next();
145
146                 if (bodyElement.getName().equals(Constants.WSRM.CREATE_SEQUENCE)) {
147                     createSequence = new CreateSequence();
148
149                     createSequence.fromSOAPEnveploe(bodyElement);
150                 }
151
152                 if (bodyElement.getName().equals(Constants.WSRM.CREATE_SEQUENCE_RESPONSE)) {
153                     createSequenceResponse = new CreateSequenceResponse();
154
155                     createSequenceResponse.fromSOAPEnveploe(bodyElement);
156                 }
157
158                 if (bodyElement.getName().equals(Constants.WSRM.TERMINATE_DEQUENCE)) {
159                     terminateSequence = new TerminateSequence();
160
161                     terminateSequence.fromSOAPEnveploe(bodyElement);
162                 }
163             }
164         }
165
166         return this;
167     }
168
169     /**
170      * Method getCreateSequenceResponse
171      *
172      * @return CreateSequenceResponse
173      */

174     public CreateSequenceResponse getCreateSequenceResponse() {
175         return createSequenceResponse;
176     }
177
178     /**
179      * Method getSequence
180      *
181      * @return Sequence
182      */

183     public Sequence getSequence() {
184         return sequence;
185     }
186
187     /**
188      * Method getSequenceAcknowledgement
189      *
190      * @return SequenceAcknowledgement
191      */

192     public SequenceAcknowledgement getSequenceAcknowledgement() {
193         return sequenceAcknowledgement;
194     }
195
196     /**
197      * Method getTerminateSequence
198      *
199      * @return TerminateSequence
200      */

201     public TerminateSequence getTerminateSequence() {
202         return terminateSequence;
203     }
204
205     /**
206      * Method setCreateSequence
207      *
208      * @param sequence
209      */

210     public void setCreateSequence(CreateSequence sequence) {
211         createSequence = sequence;
212     }
213
214     /**
215      * Method setCreateSequenceResponse
216      *
217      * @param response
218      */

219     public void setCreateSequenceResponse(CreateSequenceResponse response) {
220         createSequenceResponse = response;
221     }
222
223     /**
224      * Method setSequence
225      *
226      * @param sequence
227      */

228     public void setSequence(Sequence sequence) {
229         this.sequence = sequence;
230     }
231
232     /**
233      * Method setSequenceAcknowledgement
234      *
235      * @param acknowledgement
236      */

237     public void setSequenceAcknowledgement(SequenceAcknowledgement acknowledgement) {
238         sequenceAcknowledgement = acknowledgement;
239     }
240
241     /**
242      * Method setSequenceAcknowledgement
243      *
244      * @param sequence
245      */

246     public void c(TerminateSequence sequence) {
247         terminateSequence = sequence;
248     }
249
250     /**
251      * Method setAckRequest
252      *
253      * @param requested
254      */

255     public void setAckRequest(AckRequested requested) {
256         ackRequest = requested;
257     }
258
259     /**
260      * Method getAckRequest
261      *
262      * @return AckRequested
263      */

264     public AckRequested getAckRequest() {
265         return ackRequest;
266     }
267
268     /**
269      * Method getCreateSequence
270      *
271      * @return CreateSequence
272      */

273     public CreateSequence getCreateSequence() {
274         return createSequence;
275     }
276
277     public static void removeHeaders(SOAPEnvelope env) throws AxisFault {
278         if (env != null) {
279             Iterator JavaDoc iterator = env.getHeaders().iterator();
280             SOAPHeaderElement headerElement;
281
282             while (iterator.hasNext()) {
283                 headerElement = (SOAPHeaderElement) iterator.next();
284
285                 if (headerElement.getName().equals(Constants.WSRM.SEQUENCE)) {
286                     headerElement.detachNode();
287                 }
288                 if (headerElement.getName().equals(Constants.WSRM.SEQUENCE_ACK)) {
289                     headerElement.detachNode();
290                 }
291                 if (headerElement.getName().equals(Constants.WSRM.ACK_REQUESTED)) {
292                     headerElement.detachNode();
293                 }
294             }
295         }
296     }
297 }
Popular Tags