KickJava   Java API By Example, From Geeks To Geeks.

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


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>Home specific implementation for the <tt>Components::Session2Context</tt> interface. This
36  ** class implements the features which are common to all component instance in a particular
37  ** home instance and is therefore provided to the home instances.</p>
38  **/

39 public class HomeSegmentedSession2ContextImpl
40 extends org.omg.CORBA.LocalObject JavaDoc
41 implements org.omg.Components.SegmentedSession2Context, org.coach.ECM.ECMContext
42 {
43     // segmented session context
44
static private String JavaDoc _class_name = "SegmentedSession2ContextImpl";
45     private org.omg.Components.CCMHome _home_ref;
46     private ORBService _orb_service;
47     private ComponentPOAService _poa_service;
48     private ServicesSet _services_set;
49     private HomeLocalEventsImpl _events;
50     private HomeLocalReceptaclesImpl _receptacles;
51     private SegmentedIdCodec _idcodec;
52
53     // empty constructor
54
protected
55     HomeSegmentedSession2ContextImpl()
56     {
57         // segmented session context
58
_home_ref = null;
59         _orb_service = null;
60         _poa_service = null;
61         _services_set = null;
62         _events = null;
63         _receptacles = null;
64         _idcodec = null;
65     }
66
67     // default constructor
68
protected
69     HomeSegmentedSession2ContextImpl(org.omg.Components.CCMHome href,
70                                      ORBService orbs,
71                                      ComponentPOAService poas,
72                                      ServicesSet sset,
73                                      HomeLocalEventsImpl levts,
74                                      HomeLocalReceptaclesImpl lrecs)
75     {
76         // segmented session context
77
_home_ref = href;
78         _orb_service = orbs;
79         _poa_service = poas;
80         _services_set = sset;
81         _events = levts;
82         _receptacles = lrecs;
83
84         // create ObjectId codec
85
_idcodec = new SegmentedIdCodec(_orb_service);
86     }
87
88     //
89
// internal operations
90
//
91

92     private org.omg.PortableServer.Current JavaDoc
93     getPOACurrent()
94     {
95         // get poa current
96
org.omg.CORBA.Object JavaDoc curr = _orb_service.resolve_initial_references("POACurrent");
97         return org.omg.PortableServer.CurrentHelper.narrow(curr);
98     }
99
100     //
101
// public operations (for component context)
102
//
103

104     final public HomeLocalEventsImpl
105     getLocalEvents()
106     {
107         return _events;
108     }
109
110     final public HomeLocalReceptaclesImpl
111     getLocalReceptacles()
112     {
113         return _receptacles;
114     }
115
116     //
117
// IDL:omg.org/Components/CCMContext:1.0
118
//
119

120     final public org.omg.Components.CCMHome
121     get_CCM_home()
122     {
123         return _home_ref;
124     }
125
126     //
127
// IDL:omg.org/Components/CCM2Context:1.0
128
//
129

130     final public org.omg.Components.HomeRegistrationLocal
131     get_home_registration()
132     {
133         // TODO
134
return null;
135     }
136
137     final public void
138     req_passivate()
139     throws org.omg.Components.IllegalState,
140            org.omg.Components.PolicyMismatch
141     {
142         final String JavaDoc opname = "req_passivate";
143         try {
144             org.omg.PortableServer.Current JavaDoc curr = getPOACurrent();
145             byte[] id = curr.get_object_id();
146             _poa_service.passivate_component(id);
147         } catch (org.omg.PortableServer.CurrentPackage.NoContext JavaDoc ex) {
148             TheLogger.debug(_class_name, opname, "FAILED (no context, rethrown)", ex);
149             throw new org.omg.Components.IllegalState();
150         } catch (org.objectweb.ccm.runtime.WrongPolicy ex) {
151             TheLogger.debug(_class_name, opname, "FAILED (wrong policy, rethrown)", ex);
152             throw new org.omg.Components.PolicyMismatch();
153         }
154     }
155
156     final public org.omg.Components.LocalEvents
157     get_events()
158     {
159         // NOTE: not supported in home context implementation
160
return null;
161     }
162
163     final public org.omg.Components.LocalReceptacles
164     get_receptacles()
165     {
166         // NOTE: not supported in home context implementation
167
return null;
168     }
169
170     final public void
171     remove_component(org.omg.Components.CCMObject comp)
172     {
173         _poa_service.remove_component(comp);
174     }
175
176     final public void
177     register_valuefactory(String JavaDoc repid, org.omg.CORBA.portable.ValueFactory JavaDoc vfact)
178     {
179         ValueFactory fact = new ValueFactoryImpl(repid, vfact);
180         _orb_service.register_valuefactory(fact);
181     }
182
183     final public org.omg.CORBA.Any JavaDoc
184     create_any()
185     {
186         return _orb_service.create_any();
187     }
188
189     //
190
// IDL:omg.org/Components/SessionContext:1.0
191
//
192

193     final public org.omg.CORBA.Object JavaDoc
194     get_CCM_object()
195     throws org.omg.Components.IllegalState
196     {
197         try {
198             org.omg.PortableServer.Current JavaDoc curr = getPOACurrent();
199             byte[] id = curr.get_object_id();
200             org.omg.PortableServer.POA JavaDoc poa = curr.get_POA();
201
202             return poa.id_to_reference(id);
203         } catch (org.omg.PortableServer.CurrentPackage.NoContext JavaDoc exc) {
204             throw new org.omg.Components.IllegalState();
205         } catch (Exception JavaDoc ex) {
206             // NOTE: should not happen
207
final String JavaDoc opname = "get_CCM_object";
208             TheLogger.error(_class_name, opname, "FAILED", ex);
209             return null;
210         }
211     }
212
213     //
214
// IDL:omg.org/Components/SegmentedSession2Context:1.0
215
//
216

217     final public org.omg.Components.ComponentId
218     get_component_id()
219     throws org.omg.Components.IllegalState
220     {
221         try {
222             return get_cid_from_ref(get_CCM_object());
223         } catch (org.omg.Components.BadComponentReference ex) {
224             // should not happen
225
final String JavaDoc opname = "get_component_id";
226             TheLogger.error(_class_name, opname, "FAILED", ex);
227             return null;
228         }
229     }
230
231     final public org.omg.Components.ComponentId
232     create_main_segment(org.omg.Components.SegmentDescr[] descrs)
233     {
234         return new ComponentIdImpl(org.omg.Components.COMPONENT_FACET.value,
235                                    org.omg.Components.COMPONENT_ID.value,
236                                    descrs);
237     }
238
239     final public org.omg.CORBA.Object JavaDoc
240     create_ref_from_cid(String JavaDoc repid,
241                         org.omg.Components.ComponentId cid)
242     {
243         final String JavaDoc opname = "create_ref_from_cid";
244
245         // NOTE: the caller MUST be the home
246
// NOTE2: obtain the object id of the home
247
byte[] home_id = null;
248         try {
249             home_id = getPOACurrent().get_object_id();
250         } catch (org.omg.PortableServer.CurrentPackage.NoContext JavaDoc exc) {
251             // should not happen
252
TheLogger.error(_class_name, opname, "FAILED (no context)", exc);
253         }
254
255         // create and encode oid
256
SegmentedId sid = new SegmentedId();
257         sid.home_id = home_id;
258         sid.facet_id = cid.get_facet_id();
259         sid.segment_id = cid.get_segment_id();
260         sid.segment_descrs = cid.get_segment_descrs();
261         byte[] rid = _idcodec.encode(sid);
262
263         // create a ref
264
return _poa_service.create_ref_with_id(rid, repid);
265     }
266
267     final public org.omg.Components.ComponentId
268     get_cid_from_ref(org.omg.CORBA.Object JavaDoc ref)
269     throws org.omg.Components.BadComponentReference
270     {
271         final String JavaDoc opname = "get_cid_from_ref";
272         byte[] id = null;
273         try {
274             id = _poa_service.get_id_from_ref(ref);
275         } catch (org.objectweb.ccm.runtime.InvalidReference ex) {
276             // NOTE: to be completed with a reason
277
TheLogger.debug(_class_name, opname, "FAILED (invalid ref, rethrown)", ex);
278             throw new org.omg.Components.BadComponentReference();
279         }
280
281         // decode
282
SegmentedId sid = _idcodec.decode(id);
283         if (sid==null) {
284             // NOTE: to be completed with a reason
285
TheLogger.debug(_class_name, opname, "FAILED (wrong format)");
286             throw new org.omg.Components.BadComponentReference();
287         }
288
289         // create ComponentId
290
return new ComponentIdImpl(sid.facet_id, sid.segment_id, sid.segment_descrs);
291     }
292
293     //
294
// IDL:coach.org/ECM/ECMContext:1.0
295
//
296

297     final public org.omg.CORBA.Object JavaDoc
298     get_service_internal(String JavaDoc sid, String JavaDoc siid)
299     throws org.coach.ECM.UnknownService,
300            org.coach.ECM.UnknownServiceInternal
301     {
302         // find service
303
Service service = _services_set.find_service(sid);
304         if (service==null) {
305             throw new org.coach.ECM.UnknownService();
306         }
307
308         // find internal
309
org.omg.CORBA.Object JavaDoc internal = service.get_service_internal(siid);
310         if (internal==null) {
311             throw new org.coach.ECM.UnknownServiceInternal();
312         }
313
314         return internal;
315     }
316 }
317
Popular Tags