KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > SimpleTargetedChain


1 /*
2  * Copyright 2001-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.axis ;
18
19 import org.apache.axis.components.logger.LogFactory;
20 import org.apache.axis.handlers.BasicHandler;
21 import org.apache.commons.logging.Log;
22
23 /**
24  * A SimpleTargetedChain has a request handler, a pivot handler, and a response
25  * handler (any of which may themselves be chains).
26  *
27  * @author Doug Davis (dug@us.ibm.com)
28  * @author Glyn Normington (norm@uk.ibm.com)
29  */

30 public class SimpleTargetedChain extends SimpleChain implements TargetedChain
31 {
32     protected static Log log =
33             LogFactory.getLog(SimpleTargetedChain.class.getName());
34
35     protected Handler requestHandler ;
36     protected Handler pivotHandler ;
37     protected Handler responseHandler ;
38
39     /**
40      * Pivot indicator sets "past pivot point" before the response handler
41      * runs. This avoids having to reimplement SimpleChain.invoke and
42      * SimpleChain.generateWSDL.
43      */

44     private class PivotIndicator extends BasicHandler {
45         public PivotIndicator() {}
46
47         public void invoke(MessageContext msgContext) throws AxisFault {
48             msgContext.setPastPivot(true);
49         }
50     }
51
52     /**
53      * Default no-arg constructor.
54      */

55     public SimpleTargetedChain() {}
56
57     /**
58      * Constructor for an instance with effectively only a pivot handler.
59      *
60      * @param handler the <code>Handler</code> to use
61      */

62     public SimpleTargetedChain(Handler handler) {
63         pivotHandler = handler;
64         if (pivotHandler != null) {
65             addHandler(pivotHandler);
66             addHandler(new PivotIndicator());
67         }
68     }
69
70     /**
71      * Constructor which takes real or null request, pivot, and response
72      * handlers.
73      */

74     public SimpleTargetedChain(Handler reqHandler, Handler pivHandler,
75                                Handler respHandler) {
76         init(reqHandler, null, pivHandler, null, respHandler);
77     }
78
79     /**
80      * Initialiser which takes real or null request, pivot, and response
81      * handlers and which allows for special request and response
82      * handlers to be inserted just before and after any pivot handler.
83      *
84      * @param reqHandler the request <code>Handler</code>
85      * @param specialReqHandler the special request <code>Handler</code>
86      * @param pivHandler the pivot <code>Handler</code>
87      * @param specialRespHandler the special response <code>Handler</code>
88      * @param respHandler the response <code>Handler</code>
89      */

90     protected void init(Handler reqHandler, Handler specialReqHandler,
91                         Handler pivHandler, Handler specialRespHandler,
92                         Handler respHandler) {
93
94         requestHandler = reqHandler;
95         if (requestHandler != null)
96             addHandler(requestHandler);
97
98         if (specialReqHandler != null)
99             addHandler(specialReqHandler);
100
101         pivotHandler = pivHandler;
102         if (pivotHandler != null) {
103             addHandler(pivotHandler);
104             addHandler(new PivotIndicator());
105         }
106
107         if (specialRespHandler != null)
108             addHandler(specialRespHandler);
109
110         responseHandler = respHandler;
111         if (responseHandler != null)
112             addHandler(responseHandler);
113     }
114
115     public Handler getRequestHandler() { return( requestHandler ); }
116
117     public Handler getPivotHandler() { return( pivotHandler ); }
118
119     public Handler getResponseHandler() { return( responseHandler ); }
120 };
121
Popular Tags