KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > context > MessageContext


1 /*
2  * Copyright 2004,2005 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 package org.apache.axis2.context;
17
18 import org.apache.axis2.addressing.EndpointReference;
19 import org.apache.axis2.addressing.MessageInformationHeadersCollection;
20 import org.apache.axis2.addressing.miheaders.RelatesTo;
21 import org.apache.axis2.description.*;
22 import org.apache.axis2.engine.AxisConfiguration;
23 import org.apache.axis2.engine.AxisFault;
24 import org.apache.axis2.soap.SOAPEnvelope;
25
26 import javax.xml.namespace.QName JavaDoc;
27
28 /**
29  * The palce where all the service specific states are kept.
30  * All the Global states kept in the <code>EngineRegistry</code> and all the
31  * Service states kept in the <code>MessageContext</code>. Other runtime
32  * artifacts does not keep states foward from the execution.
33  */

34 public class MessageContext extends AbstractContext {
35     /**
36      * Field TRANSPORT_WRITER
37      */

38     public static final String JavaDoc TRANSPORT_OUT = "TRANSPORT_OUT";
39
40     /**
41      * Field TRANSPORT_READER
42      */

43     public static final String JavaDoc TRANSPORT_IN = "TRANSPORT_IN";
44     
45     
46
47     /**
48      * Field TRANSPORT_SUCCEED
49      */

50     public static final String JavaDoc TRANSPORT_SUCCEED = "TRANSPORT_SUCCEED";
51
52     /**
53      * Field processingFault
54      */

55     private boolean processingFault = false;
56
57     /**
58      * Addressing Information for Axis 2
59      * Following Properties will be kept inside this, these fields will be initially filled by
60      * the transport. Then later a addressing handler will make relevant changes to this, if addressing
61      * information is present in the SOAP header.
62      */

63
64     private MessageInformationHeadersCollection messageInformationHeaders;
65
66     private OperationContext operationContext;
67     private ServiceContext serviceContext;
68     private ConfigurationContext configurationContext;
69
70     private TransportInDescription transportIn;
71
72     private TransportOutDescription transportOut;
73
74     /**
75      * Field sessionContext
76      */

77     private final SessionContext sessionContext;
78
79     /**
80      * Field service
81      */

82
83     /**
84      * Field envelope
85      */

86     private SOAPEnvelope envelope;
87
88     /**
89      * Field responseWritten
90      */

91     private boolean responseWritten;
92
93     /**
94      * Field inFaultFlow
95      */

96     private boolean inFaultFlow;
97
98     /**
99      * Field serverSide
100      */

101     private boolean serverSide;
102
103     /**
104      * Field messageID
105      */

106     private String JavaDoc messageID;
107
108     /**
109      * Field newThreadRequired
110      */

111     private boolean newThreadRequired = false;
112
113     private boolean paused = false;
114
115     public boolean outPutWritten = false;
116
117     private String JavaDoc serviceInstanceID;
118     
119     private String JavaDoc pausedPhaseName;
120     
121     private QName JavaDoc pausedHandlerName;
122     
123     private String JavaDoc soapAction;
124     
125     
126     //Are we doing MTOM now?
127
private boolean doingMTOM = false;
128     //Are we doing REST now?
129
private boolean doingREST = false;
130     
131     /**
132      * Conveniance Method, but before call engine.send() or engine.receive() one must send transport in/out
133      * @param engineContext
134      * @throws AxisFault
135      */

136
137     public MessageContext(ConfigurationContext engineContext) throws AxisFault {
138         this(engineContext, null, null, null);
139     }
140
141     public MessageContext(
142         ConfigurationContext engineContext,
143         TransportInDescription transportIn,
144         TransportOutDescription transportOut)
145         throws AxisFault {
146         this(engineContext, null, transportIn, transportOut);
147     }
148
149     /**
150      * @param sessionContext
151      * @param transportIn
152      * @param transportOut
153      * @param configurationContext
154      * @throws AxisFault
155      */

156
157     public MessageContext(
158         ConfigurationContext engineContext,
159         SessionContext sessionContext,
160         TransportInDescription transportIn,
161         TransportOutDescription transportOut)
162         throws AxisFault {
163         super(null);
164
165         if (sessionContext == null) {
166             this.sessionContext = new SessionContext(null);
167         } else {
168             this.sessionContext = sessionContext;
169         }
170         messageInformationHeaders = new MessageInformationHeadersCollection();
171         this.transportIn = transportIn;
172         this.transportOut = transportOut;
173         this.configurationContext = engineContext;
174
175     }
176
177     /**
178      * @return
179      */

180     public EndpointReference getFaultTo() {
181         return messageInformationHeaders.getFaultTo();
182     }
183
184     /**
185      * @return
186      */

187     public EndpointReference getFrom() {
188         return messageInformationHeaders.getFrom();
189     }
190
191     /**
192      * @return
193      */

194     public boolean isInFaultFlow() {
195         return inFaultFlow;
196     }
197
198     /**
199      * @return
200      */

201     public SOAPEnvelope getEnvelope() {
202         return envelope;
203     }
204
205     /**
206      * @return
207      */

208     public String JavaDoc getMessageID() {
209         return messageInformationHeaders.getMessageId();
210     }
211
212     /**
213      * @return
214      */

215     public boolean isProcessingFault() {
216         return processingFault;
217     }
218
219     /**
220      * @return
221      */

222     public RelatesTo getRelatesTo() {
223         return messageInformationHeaders.getRelatesTo();
224     }
225
226     /**
227      * @return
228      */

229     public EndpointReference getReplyTo() {
230         return messageInformationHeaders.getReplyTo();
231     }
232
233     /**
234      * @return
235      */

236     public boolean isResponseWritten() {
237         return responseWritten;
238     }
239
240     /**
241      * @return
242      */

243     public boolean isServerSide() {
244         return serverSide;
245     }
246
247     /**
248      * @return
249      */

250     public SessionContext getSessionContext() {
251         return sessionContext;
252     }
253
254     /**
255      * @return
256      */

257     public EndpointReference getTo() {
258         return messageInformationHeaders.getTo();
259     }
260
261     /**
262      * @param reference
263      */

264     public void setFaultTo(EndpointReference reference) {
265         messageInformationHeaders.setFaultTo(reference);
266     }
267
268     /**
269      * @param reference
270      */

271     public void setFrom(EndpointReference reference) {
272         messageInformationHeaders.setFrom(reference);
273     }
274
275     /**
276      * @param b
277      */

278     public void setInFaultFlow(boolean b) {
279         inFaultFlow = b;
280     }
281
282     /**
283      * @param envelope
284      */

285     public void setEnvelope(SOAPEnvelope envelope) {
286         this.envelope = envelope;
287     }
288
289     /**
290      * @param string
291      */

292     public void setMessageID(String JavaDoc string) {
293         messageInformationHeaders.setMessageId(string);
294     }
295
296     /**
297      * @param b
298      */

299     public void setProcessingFault(boolean b) {
300         processingFault = b;
301     }
302
303     /**
304      * @param reference
305      */

306     public void setRelatesTo(RelatesTo reference) {
307         messageInformationHeaders.setRelatesTo(reference);
308     }
309
310     /**
311      * @param referance
312      */

313     public void setReplyTo(EndpointReference referance) {
314         messageInformationHeaders.setReplyTo(referance);
315     }
316
317     /**
318      * @param b
319      */

320     public void setResponseWritten(boolean b) {
321         responseWritten = b;
322     }
323
324     /**
325      * @param b
326      */

327     public void setServerSide(boolean b) {
328         serverSide = b;
329     }
330
331     /**
332      * @param referance
333      */

334     public void setTo(EndpointReference referance) {
335         messageInformationHeaders.setTo(referance);
336     }
337
338     /**
339      * @return
340      */

341     public boolean isNewThreadRequired() {
342         return newThreadRequired;
343     }
344
345     /**
346      * @param b
347      */

348     public void setNewThreadRequired(boolean b) {
349         newThreadRequired = b;
350     }
351
352     /**
353      * Method getExecutionChain
354      *
355      * @return
356      */

357
358     public void setWSAAction(String JavaDoc actionURI) {
359         messageInformationHeaders.setAction(actionURI);
360     }
361
362     public String JavaDoc getWSAAction() {
363         return messageInformationHeaders.getAction();
364     }
365
366     public void setWSAMessageId(String JavaDoc messageID) {
367         messageInformationHeaders.setMessageId(messageID);
368     }
369
370     public String JavaDoc getWSAMessageId() {
371         return messageInformationHeaders.getMessageId();
372     }
373
374     public MessageInformationHeadersCollection getMessageInformationHeaders() {
375         return messageInformationHeaders;
376     }
377
378     /**
379      * @return
380      */

381     public boolean isPaused() {
382         return paused;
383     }
384
385     /**
386      * @param b
387      */

388     public void setPausedTrue(QName JavaDoc handlerName) {
389         paused = true;
390         this.pausedHandlerName = handlerName;
391     }
392     
393     public void setPausedFalse() {
394           paused = false;
395       }
396
397     /**
398      * @return
399      */

400     public TransportInDescription getTransportIn() {
401         return transportIn;
402     }
403
404     /**
405      * @return
406      */

407     public TransportOutDescription getTransportOut() {
408         return transportOut;
409     }
410
411     /**
412      * @param in
413      */

414     public void setTransportIn(TransportInDescription in) {
415         transportIn = in;
416     }
417
418     /**
419      * @param out
420      */

421     public void setTransportOut(TransportOutDescription out) {
422         transportOut = out;
423     }
424
425     /**
426      * @return
427      */

428     public OperationContext getOperationContext() {
429         return operationContext;
430     }
431
432     /**
433      * @param context
434      */

435     public void setOperationContext(OperationContext context) {
436         operationContext = context;
437         if (serviceContext != null && operationContext.getParent() == null) {
438             operationContext.setParent(serviceContext);
439         }
440         this.setParent(operationContext);
441     }
442
443     /**
444      * @return
445      */

446     public boolean isOutPutWritten() {
447         return outPutWritten;
448     }
449
450     /**
451      * @param b
452      */

453     public void setOutPutWritten(boolean b) {
454         outPutWritten = b;
455     }
456
457     /**
458      * @return Returns the serviceInstanceID.
459      */

460     public String JavaDoc getServiceInstanceID() {
461         return serviceInstanceID;
462     }
463
464     /**
465      * @param serviceInstanceID The serviceInstanceID to set.
466      */

467     public void setServiceInstanceID(String JavaDoc serviceInstanceID) {
468         this.serviceInstanceID = serviceInstanceID;
469     }
470
471     public ConfigurationContext getSystemContext() {
472         return configurationContext;
473     }
474
475     /**
476      * @return
477      */

478     public ServiceContext getServiceContext() {
479         return serviceContext;
480     }
481
482     /**
483      * @param context
484      */

485     public void setConfigurationContext(ConfigurationContext context) {
486         configurationContext = context;
487     }
488
489     /**
490      * @param context
491      */

492     public void setServiceContext(ServiceContext context) {
493         serviceContext = context;
494         if (operationContext != null && operationContext.getParent() != null) {
495             operationContext.setParent(context);
496         }
497     }
498
499     /**
500      * @param collection
501      */

502     public void setMessageInformationHeaders(MessageInformationHeadersCollection collection) {
503         messageInformationHeaders = collection;
504     }
505
506     /* (non-Javadoc)
507      * @see org.apache.axis2.context.AbstractContext#getProperty(java.lang.Object, boolean)
508      */

509     public Object JavaDoc getProperty(String JavaDoc key, boolean persistent) {
510         Object JavaDoc obj = super.getProperty(key, persistent);
511
512         //The context hirachy might not have constructed fully, the check should
513
//look for the disconnected grandparents
514
if (obj == null && operationContext == null && serviceContext != null) {
515             obj = serviceContext.getProperty(key, persistent);
516         }
517         if (obj == null && operationContext == null) {
518             obj = configurationContext.getProperty(key, persistent);
519         }
520         //Search the configurations
521
Parameter param = null;
522         if (obj == null && operationContext != null) {
523             OperationDescription opDesc = operationContext.getAxisOperation();
524             param = opDesc.getParameter(key);
525         }
526         if (param == null && serviceContext != null) {
527             ServiceDescription serviceDesc = serviceContext.getServiceConfig();
528             param = serviceDesc.getParameter(key);
529         }
530         if (param == null && configurationContext != null) {
531             AxisConfiguration baseConfig = configurationContext.getAxisConfiguration();
532             param = baseConfig.getParameter(key);
533         }
534         if (param != null) {
535             obj = param.getValue();
536         }
537         return obj;
538     }
539     /**
540      * @return
541      */

542     public QName JavaDoc getPausedHandlerName() {
543         return pausedHandlerName;
544     }
545
546     /**
547      * @return
548      */

549     public String JavaDoc getPausedPhaseName() {
550         return pausedPhaseName;
551     }
552
553     /**
554      * @param name
555      */

556     public void setPausedPhaseName(String JavaDoc name) {
557         pausedPhaseName = name;
558     }
559
560     /**
561      * @return
562      */

563     public String JavaDoc getSoapAction() {
564         return soapAction;
565     }
566
567     /**
568      * @param string
569      */

570     public void setSoapAction(String JavaDoc string) {
571         soapAction = string;
572     }
573
574     /**
575      * @return
576      */

577     public boolean isDoingMTOM() {
578         return doingMTOM;
579     }
580
581     /**
582      * @param b
583      */

584     public void setDoingMTOM(boolean b) {
585         doingMTOM = b;
586     }
587
588     /**
589      * @return
590      */

591     public boolean isDoingREST() {
592         return doingREST;
593     }
594
595     /**
596      * @param b
597      */

598     public void setDoingREST(boolean b) {
599         doingREST = b;
600     }
601
602 }
603
Popular Tags