KickJava   Java API By Example, From Geeks To Geeks.

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


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>Default implementation of the the <tt>ECA::ServerCallContext</tt> interface.</p>
36  **/

37 public class ServerCallContextImpl
38 extends org.omg.CORBA.LocalObject JavaDoc
39 implements org.coach.ECA.ServerCallContext
40 {
41     //
42
static private String JavaDoc _class_name = "ServerCallContextImpl";
43     private java.util.Hashtable JavaDoc _call_infos; // (thread id, ServerCallInformation)
44
private ORBService _orb_service;
45     private ServicesSet _services_set;
46     // NOTE: 2 cases
47
// - standard Components::ExecutorSegmentBase (no callback supported)
48
// - ECM::ECMExecutor (callback supported)
49
private org.omg.Components.ExecutorSegmentBase _segment_executor;
50     private org.coach.ECM.ECMExecutor _ecm_executor;
51
52     // default constructor
53
public
54     ServerCallContextImpl(ORBService orbs,
55                           ServicesSet services,
56                           org.omg.CORBA.Object JavaDoc exe)
57     {
58         _orb_service = orbs;
59         _services_set = services;
60         _ecm_executor = null;
61         _segment_executor = null;
62
63         if (exe instanceof org.coach.ECM.ECMExecutor) {
64             _ecm_executor = (org.coach.ECM.ECMExecutor)exe;
65         } else if (exe instanceof org.omg.Components.ExecutorSegmentBase) {
66             _segment_executor = (org.omg.Components.ExecutorSegmentBase)exe;
67         } else {
68             final String JavaDoc opname = "ServerCallContextImpl";
69             final String JavaDoc msg = "FAILED (class not supported: "+exe.getClass()+")";
70             TheLogger.error(_class_name, opname, msg);
71         }
72
73         _call_infos = new java.util.Hashtable JavaDoc();
74     }
75
76     //
77
// friend operations (for generated interceptor), keep public as in different packages
78
//
79

80     final public org.coach.ECA.ServerCallController
81     popController()
82     {
83         ServerCallInformation callinfo = (ServerCallInformation)_call_infos.get(Thread.currentThread().getName());
84         return (org.coach.ECA.ServerCallController)callinfo.controller_stack.pop();
85     }
86
87     final public void
88     pushController(org.coach.ECA.ServerCallController ctrl)
89     {
90         ServerCallInformation callinfo = (ServerCallInformation)_call_infos.get(Thread.currentThread().getName());
91         callinfo.controller_stack.push(ctrl);
92     }
93
94     final public boolean
95     isEmpty()
96     {
97         ServerCallInformation callinfo = (ServerCallInformation)_call_infos.get(Thread.currentThread().getName());
98         return callinfo.controller_stack.isEmpty();
99     }
100
101     final public void
102     addEntry(CallInformation cinfo, String JavaDoc opname)
103     {
104         // create storage
105
ServerCallInformation callinfo = new ServerCallInformation();
106
107         // fill
108
callinfo.call_information = cinfo;
109         callinfo.result = null;
110         callinfo.system_exception = null;
111         callinfo.user_exception = null;
112         callinfo.eca_call_information.operation_name = opname;
113
114         // store
115
_call_infos.put(Thread.currentThread().getName(), callinfo);
116     }
117
118     final public void
119     removeEntry()
120     {
121         // remove from storage
122
_call_infos.remove(Thread.currentThread().getName());
123     }
124
125     final public void
126     setResult(org.omg.CORBA.Any JavaDoc res)
127     {
128         ServerCallInformation callinfo = (ServerCallInformation)_call_infos.get(Thread.currentThread().getName());
129         callinfo.result = res;
130     }
131
132     //
133
// IDL:coach.org/ECA/CallContext:1.0
134
//
135

136     final public org.coach.ECA.CallInformation
137     call_information()
138     {
139         ServerCallInformation callinfo = (ServerCallInformation)_call_infos.get(Thread.currentThread().getName());
140         return callinfo.eca_call_information;
141     }
142
143     final public org.omg.CORBA.Any JavaDoc
144     result()
145     {
146         ServerCallInformation callinfo = (ServerCallInformation)_call_infos.get(Thread.currentThread().getName());
147         return callinfo.result;
148     }
149
150     final public org.omg.CORBA.Any JavaDoc
151     system_exception()
152     {
153         ServerCallInformation callinfo = (ServerCallInformation)_call_infos.get(Thread.currentThread().getName());
154         return callinfo.system_exception;
155     }
156
157     final public org.omg.CORBA.Any JavaDoc
158     user_exception()
159     {
160         ServerCallInformation callinfo = (ServerCallInformation)_call_infos.get(Thread.currentThread().getName());
161         return callinfo.user_exception;
162     }
163
164     final public void
165     send_system_exception(org.omg.CORBA.Any JavaDoc exc)
166     {
167         ServerCallInformation callinfo = (ServerCallInformation)_call_infos.get(Thread.currentThread().getName());
168         callinfo.system_exception = exc;
169     }
170
171     final public void
172     send_user_exception(org.omg.CORBA.Any JavaDoc exc)
173     {
174         ServerCallInformation callinfo = (ServerCallInformation)_call_infos.get(Thread.currentThread().getName());
175         callinfo.user_exception = exc;
176     }
177
178     final public org.omg.CORBA.Object JavaDoc
179     get_service_internal(String JavaDoc sid, String JavaDoc internal_id)
180     {
181         Service s = _services_set.find_service(sid);
182         if (s==null) {
183             return null;
184         }
185
186         return s.get_service_internal(internal_id);
187     }
188
189     final public org.omg.CORBA.Object JavaDoc
190     get_service_callback(String JavaDoc sid, String JavaDoc callback_id)
191     throws org.coach.ECM.UnknownService,
192            org.coach.ECM.UnknownServiceCallback
193     {
194         if (_ecm_executor==null) {
195             throw new org.coach.ECM.UnknownService();
196         }
197
198         return _ecm_executor.get_service_callback(sid, callback_id);
199     }
200
201     final public org.coach.ECA.Slot
202     get_slot(int slot_id)
203     {
204         return ComponentRuntime.getSlotFactory().getSlot(slot_id);
205     }
206
207     final public org.omg.CORBA.Any JavaDoc
208     create_any()
209     {
210         return _orb_service.create_any();
211     }
212
213     //
214
// IDL:coach.org/runtime/copis/ServerCallContext:1.0
215
//
216

217     final public org.omg.CORBA.Policy JavaDoc
218     get_server_policy(int ptype)
219     {
220         ServerCallInformation callinfo = (ServerCallInformation)_call_infos.get(Thread.currentThread().getName());
221         CallInformation cinfo = callinfo.call_information;
222         Policy[] pols = cinfo.policies;
223         for (int i=0;i<pols.length;i++) {
224             if (pols[i].corba_policy().policy_type()==ptype) {
225                 return pols[i].corba_policy();
226             }
227         }
228
229         return null;
230     }
231 }
232
233 class ServerCallInformation
234 {
235     public org.omg.CORBA.Any JavaDoc result;
236     public org.omg.CORBA.Any JavaDoc system_exception;
237     public org.omg.CORBA.Any JavaDoc user_exception;
238     public CallInformation call_information;
239     public java.util.Stack JavaDoc controller_stack;
240     public org.coach.ECA.CallInformation eca_call_information;
241
242     public
243     ServerCallInformation()
244     {
245         result = null;
246         system_exception = null;
247         user_exception = null;
248         call_information = null;
249         controller_stack = new java.util.Stack JavaDoc();
250         eca_call_information = new org.coach.ECA.CallInformation();
251     }
252 }
253
Popular Tags