KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > runtime > CallInterceptorSkBase


1 // ====================================================================
2
//
3
// ECM: The Extensible Container Model
4
// Copyright (C) 2004 THALES
5
// Contact: openccm-ecm@objectweb.org
6
//
7
// This library is free software; you can redistribute it and/or
8
// modify it under the terms of the GNU Lesser General Public
9
// License as published by the Free Software Foundation; either
10
// version 2.1 of the License, or any later version.
11
//
12
// This library is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
// Lesser General Public License for more details.
16
//
17
// You should have received a copy of the GNU Lesser General Public
18
// License along with this library; if not, write to the Free Software
19
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20
// USA
21
//
22
// Initial developer(s): Mathieu Vadet.
23
// Initial Funding: IST COACH European project (IST-2001-34445)
24
// http://www.ist-coach.org
25
//
26
// ====================================================================
27

28
29
30 package org.objectweb.ccm.runtime;
31
32 import org.objectweb.corba.runtime.*;
33
34 /**
35  ** <p>Base class for server-side interceptors.</p>
36  **
37  ** <p><i>NOTE: </i>not used, the generated interceptors directly includes this code, so that the
38  ** inheritance link is available and can be used to inherit from the generated CORBA skeleton.</p>
39  **/

40 abstract public class CallInterceptorSkBase
41 {
42     // call interceptor skeleton
43
static private String JavaDoc _class_name = "CallInterceptorSkBase";
44     private ORBService _orb_service;
45     private ServicesSet _services_set;
46     private String JavaDoc _uuid;
47
48     private org.omg.CORBA.Object JavaDoc _delegate;
49     private ServerCallContextImpl _call_ctx;
50     private java.util.Hashtable JavaDoc _informations;
51
52     // default constructor
53
protected
54     CallInterceptorSkBase(ORBService orbs, ServicesSet sset, String JavaDoc uuid,
55                           org.omg.CORBA.Object JavaDoc executor)
56     {
57         // call interceptor sk
58
_orb_service = orbs;
59         _services_set = sset;
60         _uuid = uuid;
61         _delegate = executor;
62         _informations = new java.util.Hashtable JavaDoc();
63
64         // create call context
65
_call_ctx = new ServerCallContextImpl(_orb_service, _services_set, executor);
66     }
67
68     //
69
// internal operations
70
//
71

72     final protected ORBService
73     _getORBService()
74     {
75         return _orb_service;
76     }
77
78     final protected ServerCallContextImpl
79     _getCallCtx()
80     {
81         return _call_ctx;
82     }
83
84     final protected CallInformation
85     _getCallInformation(String JavaDoc sname)
86     {
87         // check if information is already computed
88
CallInformation info = (CallInformation)_informations.get(sname);
89
90         if (info==null) {
91             // create information
92
info = new CallInformation();
93             // store
94
_informations.put(sname, info);
95         }
96
97         // obtain policies in effect
98
// check if policies are already computed
99
if (info.policies==null) {
100             info.policies = _services_set.get_policies(_uuid, sname);
101         }
102
103         // NOTE: controllers are created on demand in the CallInformation class
104

105         return info;
106     }
107  
108     final protected short
109     _preinvoke(org.coach.ECA.ServerCallController[] ctrls)
110     {
111         final String JavaDoc opname = "_preinvoke";
112         org.omg.CORBA.Any JavaDoc curr_exc = null;
113         org.omg.CORBA.Any JavaDoc curr_res = null;
114
115         // initialization
116
short fstate = FlowState.RECEIVE_REQUEST;
117         int ctrl_idx = 0;
118         boolean finished = false;
119         org.coach.ECA.ServerCallController ctrl = null;
120
121         while ((!finished) && (ctrl_idx<ctrls.length)){
122             // check if a system exception was set
123
curr_exc = _getCallCtx().system_exception();
124             if (curr_exc!=null) {
125                 // change flow state
126
fstate = FlowState.SEND_SYSTEM_EXCEPTION;
127             }
128
129             // check if a user exception was set
130
curr_exc = _getCallCtx().user_exception();
131             if (curr_exc!=null) {
132                 // change flow state
133
fstate = FlowState.SEND_USER_EXCEPTION;
134             }
135
136             // check if a result was set
137
curr_res = _getCallCtx().result();
138             if (curr_res!=null) {
139                 // not possible in preinvoke as result is not modifiable by controllers
140
final String JavaDoc msg = "FAILED (unexpected state in preinvoke: SEND_REPLY)";
141                 TheLogger.error(_class_name, opname, msg);
142             }
143
144             // we are on the receive_request IP
145
if (fstate==FlowState.RECEIVE_REQUEST) {
146                 // take next controller
147
ctrl = ctrls[ctrl_idx++];
148                 ctrl.receive_request(_getCallCtx());
149
150                 // push completed controller on the flow stack (starting IP)
151
_getCallCtx().pushController(ctrl);
152             }
153             // check if there's anymore controllers on the flow stack
154
else if (_getCallCtx().isEmpty()) {
155                 finished = true;
156             }
157             // we are on the send_system_exception IP
158
else if (fstate==FlowState.SEND_SYSTEM_EXCEPTION) {
159                 // get controller from flow stack (ending IP)
160
ctrl = _getCallCtx().popController();
161                 ctrl.send_system_exception(_getCallCtx());
162             }
163             // we are on the send_user_exception IP
164
else if (fstate==FlowState.SEND_SYSTEM_EXCEPTION) {
165                 // get controller from flow stack (ending IP)
166
ctrl = _getCallCtx().popController();
167                 ctrl.send_user_exception(_getCallCtx());
168             }
169             // we are on the send_reply IP
170
else {
171                 // not possible in preinvoke as result is not modifiable by controllers
172
final String JavaDoc msg = "FAILED (unexpected state in preinvoke: SEND_REPLY)";
173                 TheLogger.error(_class_name, opname, msg);
174             }
175         }
176
177         // return flow state
178
return fstate;
179     }
180
181     final protected short
182     _postinvoke(short fstate)
183     {
184         org.omg.CORBA.Any JavaDoc curr_exc = null;
185         org.omg.CORBA.Any JavaDoc curr_res = null;
186         boolean finished = false;
187         org.coach.ECA.ServerCallController ctrl = null;
188
189         // intialization of the flow state to take into account
190
// business code actions
191

192         // check if a system exception was set
193
curr_exc = _getCallCtx().system_exception();
194         curr_exc = _getCallCtx().user_exception();
195         if (curr_exc!=null) {
196             // change flow state
197
fstate = FlowState.SEND_SYSTEM_EXCEPTION;
198         }
199         // check if a user exception was set
200
else if (curr_exc!=null) {
201             // change flow state
202
fstate = FlowState.SEND_USER_EXCEPTION;
203         }
204         else {
205             // change flow state
206
fstate = FlowState.SEND_REPLY;
207         }
208
209         while (!finished) {
210             // check if there's anymore controllers on the flow stack
211
if (_getCallCtx().isEmpty()) {
212                 finished = true;
213             }
214             // we are on the send_system_exception IP
215
else if (fstate==FlowState.SEND_SYSTEM_EXCEPTION) {
216                 // get controller from flow stack (ending IP)
217
ctrl = _getCallCtx().popController();
218                 ctrl.send_system_exception(_getCallCtx());
219             }
220             // we are on the send_user_exception IP
221
else if (fstate==FlowState.SEND_SYSTEM_EXCEPTION) {
222                 // get controller from flow stack (ending IP)
223
ctrl = _getCallCtx().popController();
224                 ctrl.send_user_exception(_getCallCtx());
225             }
226             // we are on the send_reply IP
227
else {
228                 // get controller from flow stack (ending IP)
229
ctrl = _getCallCtx().popController();
230                 ctrl.send_reply(_getCallCtx());
231             }
232
233             // check if a system exception was set
234
curr_exc = _getCallCtx().system_exception();
235             if (curr_exc!=null) {
236                 // change flow state
237
fstate = FlowState.SEND_SYSTEM_EXCEPTION;
238             }
239
240             // check if a user exception was set
241
curr_exc = _getCallCtx().user_exception();
242             if (curr_exc!=null) {
243                 // change flow state
244
fstate = FlowState.SEND_USER_EXCEPTION;
245             }
246
247             // check if a result was set
248
curr_res = _getCallCtx().result();
249             if (curr_res!=null) {
250                 // change flow state
251
fstate = FlowState.SEND_REPLY;
252             }
253         }
254
255         // return flow state
256
return fstate;
257     }
258 }
Popular Tags