KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > ir3 > UsesDef_impl


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 INRIA & USTL - LIFL - GOAL
5 Contact: openccm@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): Philippe Merle.
23 Contributor(s): Mathieu Vadet, Christophe Demarey.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.ir3;
28
29 /**
30  * Implementation of the CORBA::ComponentIR::UsesDef interface.
31  *
32  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
33  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
34  *
35  * @version 0.5
36  */

37
38 public class UsesDef_impl
39      extends FeatureContained
40   implements org.omg.CORBA.ComponentIR.UsesDefOperations
41 {
42     // ==================================================================
43
//
44
// Internal state.
45
//
46
// ==================================================================
47

48     /** The provided interface. */
49     protected InterfaceDef_ref interface_type_;
50
51     /** Is multiple.*/
52     protected boolean is_multiple_;
53
54     // ==================================================================
55
//
56
// Constructor.
57
//
58
// ==================================================================
59

60     /** Default constructor. */
61     public
62     UsesDef_impl(IFR ifr,
63                  Container_impl container)
64     {
65         // Calls the FeatureContained contructor.
66
super(ifr, container);
67
68         // Sets the tie servant object.
69
setServant(new org.omg.CORBA.ComponentIR.UsesDefPOATie(this));
70
71         // Inits internal state.
72
interface_type_ = new InterfaceDef_ref(this);
73         is_multiple_ = false;
74     }
75
76     // ==================================================================
77
//
78
// Public methods.
79
//
80
// ==================================================================
81

82     /**
83      * Obtain its CORBA::ComponentIR::UsesDef object reference.
84      */

85     public org.omg.CORBA.ComponentIR.UsesDef
86     asUsesDef()
87     {
88         return org.omg.CORBA.ComponentIR.UsesDefHelper.narrow(asObject());
89     }
90
91     /**
92      * Obtain the CORBA::ComponentIR::UsesDescription of the declaration.
93      */

94     public org.omg.CORBA.ComponentIR.UsesDescription
95     describe_uses()
96     {
97         // create the CORBA::UsesDescription.
98
org.omg.CORBA.ComponentIR.UsesDescription description = new org.omg.CORBA.ComponentIR.UsesDescription();
99         description.name = name();
100         description.id = id();
101         description.defined_in = getContainerID();
102         description.version = version();
103         description.interface_type = interface_type().id();
104         description.is_multiple = is_multiple();
105
106         return description;
107     }
108
109     // ==================================================================
110
//
111
// For Contained_impl class.
112
//
113
// ==================================================================
114

115     /**
116      * To set the value field of the CORBA::Contained::Description struct.
117      */

118     public void
119     setDescriptionValue(org.omg.CORBA.Any JavaDoc any)
120     {
121         // insert it into the any.
122
org.omg.CORBA.ComponentIR.UsesDescriptionHelper.insert(any, describe_uses());
123     }
124
125     // ==================================================================
126
//
127
// Internal methods for managing dependencies.
128
//
129
// ==================================================================
130

131     /**
132      * Cuts dependencies to other objects.
133      */

134     protected void
135     cutDependencies()
136     {
137         // Cuts the dependency to the provided interface type.
138
interface_type_.cutDependency();
139         interface_type_ = null;
140
141         // Calls the Contained_impl::cutDependencies operation.
142
super.cutDependencies();
143     }
144
145     // ==================================================================
146
//
147
// For CORBA::IRObject interface.
148
//
149
// ==================================================================
150

151     /**
152      * IDL:omg.org/CORBA/IRObject/def_kind:1.0
153      */

154     public org.omg.CORBA.DefinitionKind JavaDoc
155     def_kind()
156     {
157         return org.omg.CORBA.DefinitionKind.dk_Uses;
158     }
159
160     // ==================================================================
161
//
162
// For CORBA::UsesDef interface.
163
//
164
// ==================================================================
165

166     /**
167      * IDL:omg.org/CORBA/UsesDef/interface_type:1.0
168      */

169     public org.omg.CORBA.InterfaceDef JavaDoc
170     interface_type()
171     {
172         // delegate to the InterfaceDef reference.
173
return interface_type_.asInterfaceDef();
174     }
175
176     // Warning: interface_type is a readonly attribute!
177
//
178
// Here, this allows us to implement the CORBA::ComponentIR::Component::create_uses()
179
// operation in the same way that other create_* operations.
180
//
181
/**
182      * IDL:omg.org/CORBA/UsesDef/interface_type:1.0
183      */

184     public void
185     interface_type(org.omg.CORBA.InterfaceDef JavaDoc val)
186     {
187         // try to cast val to a local InterfaceDef object
188
// and delegate to the IDLType reference.
189
interface_type_.setDependency(castToLocal(val));
190     }
191
192     /**
193      * IDL:omg.org/CORBA/UsesDef/is_multiple:1.0
194      */

195     public boolean
196     is_multiple()
197     {
198         return is_multiple_;
199     }
200
201     // Warning: is_multiple is a readonly attribute!
202
//
203
// Here, this allows us to implement the CORBA::Component::create_uses()
204
// operation in the same way that other create_* operations.
205
//
206
/**
207      * IDL:omg.org/CORBA/UsesDef/is_multiple:1.0
208      */

209     public void
210     is_multiple(boolean val)
211     {
212         is_multiple_ = val;
213     }
214
215     // ==================================================================
216
//
217
// For IDL2 mapping.
218
//
219
// ==================================================================
220

221     /**
222      * TODO
223      */

224     protected void
225     whenCreated()
226     {
227         // do nothing if mappings are not enabled.
228
if (!getIFR().getRepository().enable_mappings_)
229             return ;
230
231         // else create the mapping according to the CCM spec
232

233         //
234
// IDL2 mapping
235
//
236
// compute the container base repository id
237
String JavaDoc cont_base_id = getBaseContainerID();
238
239         String JavaDoc version = version();
240         String JavaDoc name = "";
241         String JavaDoc id = "";
242         InterfaceDef_impl container = (InterfaceDef_impl)container_;
243         org.omg.CORBA.AliasDef JavaDoc connection_sequence = null;
244
245         // uses multiple mapping :
246
if (is_multiple_)
247         {
248             //
249
// struct <receptacle_name>Connection {
250
// <interface_type> objref;
251
// Components::Cookie ck;
252
// };
253
//
254
name = name() + "Connection";
255             id = cont_base_id + name + ':' + version;
256             org.omg.CORBA.StructMember JavaDoc[] members = new org.omg.CORBA.StructMember JavaDoc[2];
257             members[0] = new org.omg.CORBA.StructMember JavaDoc();
258             members[0].name = "objref";
259             members[0].type_def = interface_type_.asIDLType();
260             members[0].type = members[0].type_def.type();
261             members[1] = new org.omg.CORBA.StructMember JavaDoc();
262             members[1].name = "ck";
263             members[1].type_def = org.omg.CORBA.IDLTypeHelper.narrow(
264                 getIFR().getRepository().lookup("::Components::Cookie"));
265             members[1].type = members[1].type_def.type();
266
267             container_.mapping_started_ = true;
268             org.omg.CORBA.IDLType JavaDoc struct = container_.create_struct(id, name, version, members);
269             container_.mapping_started_ = false;
270     
271             //
272
// sequence<<receptacle_name>Connection> <receptacle_name>Connections;
273
//
274
name = name() + "Connections";
275             id = cont_base_id + name + ':' + version;
276             org.omg.CORBA.IDLType JavaDoc type = getIFR().getRepository().create_sequence(0, struct);
277
278             container_.mapping_started_ = true;
279             connection_sequence = container_.create_alias(id, name, version, type);
280             container_.mapping_started_ = false;
281
282             //
283
// Components::Cookie connect_<receptacle_name>(in <interface_type> connection)
284
// raises(Components::ExceededConnectionLimit,
285
// Components::InvalidConnection);
286
//
287
name = "connect_" + name();
288             id = cont_base_id + name + ':' + version;
289             org.omg.CORBA.ParameterDescription JavaDoc[] params = new org.omg.CORBA.ParameterDescription JavaDoc[1];
290             params[0] = new org.omg.CORBA.ParameterDescription JavaDoc();
291             params[0].name = "connexion";
292             params[0].type_def = interface_type_.asIDLType();
293             params[0].type = params[0].type_def.type();
294             params[0].mode = org.omg.CORBA.ParameterMode.PARAM_IN;
295             org.omg.CORBA.ExceptionDef JavaDoc[] excs = new org.omg.CORBA.ExceptionDef JavaDoc[1];
296             excs[0] = org.omg.CORBA.ExceptionDefHelper.narrow(
297                 getIFR().getRepository().lookup("::Components::ExceededConnectionLimit"));
298 /**
299  * TODO : change from spec : this exception is removed because not consistent with other mappings
300  *
301             excs[1] = org.omg.CORBA.ExceptionDefHelper.narrow(
302                 getIFR().getRepository().lookup("::Components::InvalidConnection"));
303  */

304
305             container_.mapping_started_ = true;
306             container.create_operation(id, name, version,
307                                        members[1].type_def,
308                                        org.omg.CORBA.OperationMode.OP_NORMAL,
309                                        params, excs, new java.lang.String JavaDoc[0]);
310             container_.mapping_started_ = false;
311     
312             //
313
// <interface_type> disconnect_<receptacle_name>(in Components::Cookie)
314
// raises(Components::InvalidConnection);
315
//
316
name = "disconnect_" + name();
317             id = cont_base_id + name + ':' + version;
318             params = new org.omg.CORBA.ParameterDescription JavaDoc[1];
319             params[0] = new org.omg.CORBA.ParameterDescription JavaDoc();
320             params[0].name = "ck";
321             params[0].type_def = members[1].type_def;
322             params[0].type = params[0].type_def.type();
323             params[0].mode = org.omg.CORBA.ParameterMode.PARAM_IN;
324             org.omg.CORBA.ExceptionDef JavaDoc[] excs2 = new org.omg.CORBA.ExceptionDef JavaDoc[1];
325             excs2[0] = org.omg.CORBA.ExceptionDefHelper.narrow(
326                 getIFR().getRepository().lookup("::Components::InvalidConnection"));
327
328             container_.mapping_started_ = true;
329             container.create_operation(id, name, version,
330                                        interface_type_.asIDLType(),
331                                        org.omg.CORBA.OperationMode.OP_NORMAL,
332                                        params, excs, new java.lang.String JavaDoc[0]);
333             container_.mapping_started_ = false;
334     
335             //
336
// <receptacle_name>Connections get_connections_<receptacle_name>();
337
//
338
name = "get_connections_" + name();
339             id = cont_base_id + name + ':' + version;
340             params = new org.omg.CORBA.ParameterDescription JavaDoc[0];
341             excs = new org.omg.CORBA.ExceptionDef JavaDoc[0];
342
343             container_.mapping_started_ = true;
344             container.create_operation(id, name, version,
345                                        connection_sequence,
346                                        org.omg.CORBA.OperationMode.OP_NORMAL,
347                                        params, excs, new java.lang.String JavaDoc[0]);
348             container_.mapping_started_ = false;
349         }
350         // uses mapping :
351
else
352         {
353             //
354
// void connect_<receptacle_name>(in <interface_type> connection)
355
// raises(Components::AlreadyConnected,
356
// Components::InvalidConnection);
357
//
358
name = "connect_" + name();
359             id = cont_base_id + name + ':' + version;
360             org.omg.CORBA.ParameterDescription JavaDoc[] params = new org.omg.CORBA.ParameterDescription JavaDoc[1];
361             params[0] = new org.omg.CORBA.ParameterDescription JavaDoc();
362             params[0].name = "connexion";
363             params[0].type_def = interface_type_.asIDLType();
364             params[0].type = params[0].type_def.type();
365             params[0].mode = org.omg.CORBA.ParameterMode.PARAM_IN;
366             org.omg.CORBA.ExceptionDef JavaDoc[] excs = new org.omg.CORBA.ExceptionDef JavaDoc[1];
367             excs[0] = org.omg.CORBA.ExceptionDefHelper.narrow(
368                 getIFR().getRepository().lookup("::Components::AlreadyConnected"));
369 /**
370  * TODO : change from spec : this exception is removed because not consistent with other mappings
371  *
372             excs[1] = org.omg.CORBA.ExceptionDefHelper.narrow(
373                 getIFR().getRepository().lookup("::Components::InvalidConnection"));
374  */

375
376             container_.mapping_started_ = true;
377             container.create_operation(id, name, version,
378                                        getIFR().getRepository().get_primitive(
379                                            org.omg.CORBA.PrimitiveKind.pk_void),
380                                        org.omg.CORBA.OperationMode.OP_NORMAL,
381                                        params, excs, new java.lang.String JavaDoc[0]);
382             container_.mapping_started_ = false;
383
384             //
385
// <interface_type> disconnect_<receptacle_name>()
386
// raises(Components::NoConnection);
387
//
388
name = "disconnect_" + name();
389             id = cont_base_id + name + ':' + version;
390             params = new org.omg.CORBA.ParameterDescription JavaDoc[0];
391             excs = new org.omg.CORBA.ExceptionDef JavaDoc[1];
392             excs[0] = org.omg.CORBA.ExceptionDefHelper.narrow(
393                 getIFR().getRepository().lookup("::Components::NoConnection"));
394
395             container_.mapping_started_ = true;
396             container.create_operation(id, name, version,
397                                        interface_type_.asIDLType(),
398                                        org.omg.CORBA.OperationMode.OP_NORMAL,
399                                        params, excs, new java.lang.String JavaDoc[0]);
400             container_.mapping_started_ = false;
401     
402             //
403
// <receptacle_name>Connection get_connection_<receptacle_name>();
404
//
405
name = "get_connection_" + name();
406             id = cont_base_id + name + ':' + version;
407             params = new org.omg.CORBA.ParameterDescription JavaDoc[0];
408             excs = new org.omg.CORBA.ExceptionDef JavaDoc[0];
409
410             container_.mapping_started_ = true;
411             container.create_operation(id, name, version,
412                                        interface_type_.asIDLType(),
413                                        org.omg.CORBA.OperationMode.OP_NORMAL,
414                                        params, excs, new java.lang.String JavaDoc[0]);
415             container_.mapping_started_ = false;
416         }
417
418         //
419
// CIDL mapping
420
//
421
// check if the CCM_<interface_name> already exists.
422
cont_base_id = interface_type_.getImpl().getBaseContainerID();
423         version = interface_type_.getImpl().version();
424
425         name = "CCM_"+interface_type_.getImpl().name();
426         id = cont_base_id + name + ':' + version;
427         org.omg.CORBA.Contained JavaDoc contained = getIFR().getRepository().lookup_mapped_id(id);
428         org.omg.CORBA.InterfaceDef JavaDoc facet_executor = null;
429         if (contained==null)
430         {
431             //
432
// local interface CCM_<interface_name> : <interface_name> {};
433
//
434
org.omg.CORBA.InterfaceDef JavaDoc[] bases = new org.omg.CORBA.InterfaceDef JavaDoc[1];
435             bases[0] = interface_type();
436             interface_type_.getImpl().container_.mapping_started_ = true;
437             facet_executor = interface_type_.getImpl().container_.create_ext_local_interface(id, name, version, bases);
438             interface_type_.getImpl().container_.mapping_started_ = false;
439         }
440         else
441         {
442             facet_executor = org.omg.CORBA.InterfaceDefHelper.narrow(contained);
443         }
444
445         //
446
// local interface CCM_<component_name>_Context : ...
447
// {
448
// <interface_name> get_connection_<name>();
449
// };
450
//
451
cont_base_id = container_.getBaseContainerID();
452         version = container_.version();
453
454         String JavaDoc litf_id = cont_base_id + "CCM_" + container_.name() + "_Context:" + version;
455         org.omg.CORBA.ExtLocalInterfaceDef litf = org.omg.CORBA.ExtLocalInterfaceDefHelper.narrow(
456              getIFR().getRepository().lookup_mapped_id(litf_id));
457
458         cont_base_id = computeBaseID(litf_id);
459         version = litf.version();
460         // uses multiple mapping
461
if (!is_multiple_)
462         {
463             name = "get_connection_" + name();
464             id = cont_base_id + name + ':' + version;
465
466             litf.create_operation(id, name, version,
467                                   interface_type_.asIDLType(),
468                                   org.omg.CORBA.OperationMode.OP_NORMAL,
469                                   new org.omg.CORBA.ParameterDescription JavaDoc[0],
470                                   new org.omg.CORBA.ExceptionDef JavaDoc[0],
471                                   new java.lang.String JavaDoc[0]);
472         }
473         // uses mapping
474
else
475         {
476             name = "get_connections_" + name();
477             id = cont_base_id + name + ':' + version;
478
479             litf.create_operation(id, name, version,
480                                   connection_sequence,
481                                   org.omg.CORBA.OperationMode.OP_NORMAL,
482                                   new org.omg.CORBA.ParameterDescription JavaDoc[0],
483                                   new org.omg.CORBA.ExceptionDef JavaDoc[0],
484                                   new java.lang.String JavaDoc[0]);
485         }
486     }
487 }
488
Popular Tags