KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > sandesha > RMMessageContext


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 package org.apache.sandesha;
18
19 import org.apache.axis.AxisFault;
20 import org.apache.axis.MessageContext;
21 import org.apache.axis.components.logger.LogFactory;
22 import org.apache.axis.message.addressing.AddressingHeaders;
23 import org.apache.commons.logging.Log;
24 import org.apache.sandesha.util.PolicyLoader;
25 import org.apache.sandesha.ws.rm.RMHeaders;
26
27 import java.util.ArrayList JavaDoc;
28 import java.util.Iterator JavaDoc;
29
30 /**
31  * RMMessageContext is used as the message context for Sandesha. It will carry all the required
32  * paramerters through the processing logics including the MessageContext handed over by the
33  * axis engine.
34  *
35  * @author Jaliya Ekanayake
36  * @author Chamikara Jayalath
37  */

38 public class RMMessageContext {
39     private static final Log log = LogFactory.getLog(RMMessageContext.class.getName());
40
41     private MessageContext msgContext;
42     private String JavaDoc sequenceID;
43     private String JavaDoc messageID;
44     private AddressingHeaders addressingHeaders;
45     private RMHeaders rmHeaders;
46     private String JavaDoc outGoingAddress;
47     private int messageType;
48     private long reTransmissionCount;
49     private long lastPrecessedTime;
50     private long fristProcessedTime;
51     private long retransmissionTime;
52
53     private boolean locked;
54
55     private long lastSentTime;
56     private boolean sync;
57     private boolean hasResponse;
58     private boolean lastMessage;
59     private long msgNumber;
60     private String JavaDoc sourceURL;
61     private String JavaDoc action;
62     private String JavaDoc from;
63     private String JavaDoc replyTo;
64
65     private boolean ackReceived;
66     private String JavaDoc faultTo;
67     private String JavaDoc acksTo;
68     private String JavaDoc to;
69
70     public SandeshaContext getCtx() {
71         return ctx;
72     }
73
74     public void setCtx(SandeshaContext ctx) {
75         this.ctx = ctx;
76     }
77
78     private SandeshaContext ctx;
79
80     public boolean isLocked() {
81         return locked;
82     }
83
84     public void setLocked(boolean locked) {
85         this.locked = locked;
86     }
87
88     public long getFristProcessedTime() {
89         return fristProcessedTime;
90     }
91
92     public void setFristProcessedTime(long fristProcessedTime) {
93         this.fristProcessedTime = fristProcessedTime;
94     }
95
96     public long getRetransmissionTime() {
97         return retransmissionTime;
98     }
99
100     public void setRetransmissionTime(long retransmissionTime) {
101         this.retransmissionTime = retransmissionTime;
102     }
103
104     public RMMessageContext() {
105         retransmissionTime = PolicyLoader.getInstance().getBaseRetransmissionInterval();
106         fristProcessedTime = 0;
107     }
108
109     public boolean isSendOffer() {
110         return sendOffer;
111     }
112
113     public void setSendOffer(boolean sendOffer) {
114         this.sendOffer = sendOffer;
115     }
116
117     private boolean sendOffer;
118
119
120     private ArrayList JavaDoc msgIdList = new ArrayList JavaDoc();
121
122     public void addToMsgIdList(String JavaDoc msgId) {
123         msgIdList.add(msgId);
124     }
125
126     public ArrayList JavaDoc getMessageIdList() {
127         return msgIdList;
128     }
129
130     public String JavaDoc getTo() {
131         return to;
132     }
133
134     public void setTo(String JavaDoc to) {
135         this.to = to;
136     }
137
138     public String JavaDoc getAcksTo() {
139         return acksTo;
140     }
141
142     public void setAcksTo(String JavaDoc acksTo) {
143         this.acksTo = acksTo;
144     }
145
146
147     public String JavaDoc getFrom() {
148         return from;
149     }
150
151     public void setFrom(String JavaDoc from) {
152         this.from = from;
153     }
154
155     public String JavaDoc getReplyTo() {
156         return replyTo;
157     }
158
159     public void setReplyTo(String JavaDoc replyTo) {
160         this.replyTo = replyTo;
161     }
162
163     public String JavaDoc getAction() {
164         return action;
165     }
166
167     public void setAction(String JavaDoc action) {
168         this.action = action;
169     }
170
171     private String JavaDoc oldSequenceID;
172
173
174     public boolean isHasResponse() {
175         return hasResponse;
176     }
177
178     public void setHasResponse(boolean hasResponse) {
179         this.hasResponse = hasResponse;
180     }
181
182     public boolean isLastMessage() {
183         return lastMessage;
184     }
185
186     public void setLastMessage(boolean lastMessage) {
187         this.lastMessage = lastMessage;
188     }
189
190     public String JavaDoc getSourceURL() {
191         return sourceURL;
192     }
193
194     public void setSourceURL(String JavaDoc sourceURL) {
195         this.sourceURL = sourceURL;
196     }
197
198     public long getMsgNumber() {
199         return msgNumber;
200     }
201
202
203     public void setMsgNumber(long msgNumber) {
204         this.msgNumber = msgNumber;
205     }
206
207     public String JavaDoc getOldSequenceID() {
208         return oldSequenceID;
209     }
210
211     public void setOldSequenceID(String JavaDoc oldSequenceID) {
212         this.oldSequenceID = oldSequenceID;
213     }
214
215     public boolean isAckReceived() {
216         return ackReceived;
217     }
218
219     public void setAckReceived(boolean ackReceived) {
220         this.ackReceived = ackReceived;
221     }
222
223     public MessageContext getMsgContext() {
224         return msgContext;
225     }
226
227     public String JavaDoc getSequenceID() {
228         return sequenceID;
229     }
230
231     public void setMsgContext(MessageContext msgContext) {
232         this.msgContext = msgContext;
233     }
234
235     public void setSequenceID(String JavaDoc sequenceID) {
236         this.sequenceID = sequenceID;
237     }
238
239     public String JavaDoc getMessageID() {
240         return messageID;
241     }
242
243     public void setMessageID(String JavaDoc string) {
244         messageID = string;
245     }
246
247     public AddressingHeaders getAddressingHeaders() {
248         return addressingHeaders;
249     }
250
251     public RMHeaders getRMHeaders() {
252         return rmHeaders;
253     }
254
255     public void setAddressingHeaders(AddressingHeaders addressingHeaders) {
256         this.addressingHeaders = addressingHeaders;
257     }
258
259     public void setRMHeaders(RMHeaders rmHeaders) {
260         this.rmHeaders = rmHeaders;
261     }
262
263     public String JavaDoc getOutGoingAddress() {
264         return outGoingAddress;
265     }
266
267     public void setOutGoingAddress(String JavaDoc outGoingAddress) {
268         this.outGoingAddress = outGoingAddress;
269     }
270
271
272     public int getMessageType() {
273         return messageType;
274     }
275
276
277     public void setMessageType(int messageType) {
278         this.messageType = messageType;
279     }
280
281     public void copyContents(RMMessageContext rmMsgContext) {
282         if (addressingHeaders != null)
283             rmMsgContext.setAddressingHeaders(addressingHeaders);
284         if (messageID != null)
285             rmMsgContext.setMessageID(messageID);
286         if (rmHeaders != null)
287             rmMsgContext.setRMHeaders(rmHeaders);
288         if (sequenceID != null)
289             rmMsgContext.setSequenceID(sequenceID);
290         if (outGoingAddress != null)
291             rmMsgContext.setOutGoingAddress(outGoingAddress);
292         if (msgContext != null)
293             rmMsgContext.setMsgContext(msgContext);
294         if (acksTo != null)
295             rmMsgContext.setAcksTo(acksTo);
296         if (to != null)
297             rmMsgContext.setTo(to);
298
299         rmMsgContext.setReTransmissionCount(reTransmissionCount);
300         rmMsgContext.setLastPrecessedTime(lastPrecessedTime);
301         rmMsgContext.setLastMessage(isLastMessage());
302
303     }
304
305     public long getLastPrecessedTime() {
306         return lastPrecessedTime;
307     }
308
309
310     public long getReTransmissionCount() {
311         return reTransmissionCount;
312     }
313
314     public void setLastPrecessedTime(long lastPrecessedTime) {
315         this.lastPrecessedTime = lastPrecessedTime;
316     }
317
318     public void setReTransmissionCount(long reTransmissionCount) {
319         this.reTransmissionCount = reTransmissionCount;
320     }
321
322     /**
323      * This method will copy the contents of one MessageContext to another.
324      *
325      * @param msgContext1
326      * @param msgContext2
327      */

328     public static void copyMessageContext(MessageContext msgContext1, MessageContext msgContext2) {
329
330         try {
331             if (msgContext1.getClassLoader() != null)
332                 msgContext2.setClassLoader(msgContext1.getClassLoader());
333
334             if (msgContext1.getEncodingStyle() != null)
335                 msgContext2.setEncodingStyle(msgContext1.getEncodingStyle());
336
337             if (msgContext1.getPassword() != null)
338                 msgContext2.setPassword(msgContext1.getPassword());
339
340             if (msgContext1.getRoles() != null)
341                 msgContext2.setRoles(msgContext1.getRoles());
342
343             if (msgContext1.getSchemaVersion() != null)
344                 msgContext2.setSchemaVersion(msgContext1.getSchemaVersion());
345
346             if (msgContext1.getSession() != null)
347                 msgContext2.setSession(msgContext1.getSession());
348
349             if (msgContext1.getSession() != null)
350                 msgContext2.setSession(msgContext1.getSession());
351
352             if (msgContext1.getSOAPActionURI() != null)
353                 msgContext2.setSOAPActionURI(msgContext1.getSOAPActionURI());
354
355             if (msgContext1.getSOAPConstants() != null)
356                 msgContext2.setSOAPConstants(msgContext1.getSOAPConstants());
357
358             if (msgContext1.getTargetService() != null)
359                 msgContext2.setTargetService(msgContext1.getTargetService());
360
361             if (msgContext1.getTransportName() != null)
362                 msgContext2.setTransportName(msgContext1.getTransportName());
363
364             if (msgContext1.getTypeMappingRegistry() != null)
365                 msgContext2.setTypeMappingRegistry(msgContext1.getTypeMappingRegistry());
366
367             if (msgContext1.getUsername() != null)
368                 msgContext2.setUsername(msgContext1.getUsername());
369
370             if (msgContext1.getAllPropertyNames() != null) {
371                 Iterator JavaDoc ite = msgContext1.getAllPropertyNames();
372                 while (ite.hasNext()) {
373                     String JavaDoc str = (String JavaDoc) ite.next();
374                     msgContext2.setProperty(str, msgContext1.getProperty(str));
375                 }
376             }
377
378             msgContext2.setTimeout(msgContext1.getTimeout());
379             msgContext2.setUseSOAPAction(msgContext1.useSOAPAction());
380             msgContext2.setPastPivot(msgContext1.getPastPivot());
381             msgContext2.setHighFidelity(msgContext1.isHighFidelity());
382             msgContext2.setMaintainSession(msgContext1.getMaintainSession());
383
384         } catch (AxisFault e) {
385             RMMessageContext.log.error(e);
386         }
387
388     }
389
390     public long getLastSentTime() {
391         return lastSentTime;
392     }
393
394     public void setLastSentTime(long l) {
395         lastSentTime = l;
396     }
397
398
399     public void setSync(boolean sync) {
400         this.sync = sync;
401
402     }
403
404     public boolean getSync() {
405
406         return sync;
407     }
408
409     public void setFaultTo(String JavaDoc faultTo) {
410         this.faultTo = faultTo;
411     }
412
413     public String JavaDoc getFaultTo() {
414         return faultTo;
415     }
416 }
Popular Tags