KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > ir3 > EventDef_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::EventDef 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 EventDef_impl
39      extends ExtValueDef_impl
40   implements org.omg.CORBA.ComponentIR.EventDefOperations
41 {
42     // ==================================================================
43
//
44
// Internal state.
45
//
46
// ==================================================================
47

48     /** The ::Components::EventBase value. */
49     protected ValueDef_ref event_base_;
50
51     /** Reference to the IDL equivalent consumer interface. */
52     protected org.omg.CORBA.InterfaceDef JavaDoc consumer_itf_;
53
54     /** Reference to the IDL equivalent local consumer interface. */
55     protected org.omg.CORBA.LocalInterfaceDef ccm_consumer_itf_;
56
57     // ==================================================================
58
//
59
// Constructor.
60
//
61
// ==================================================================
62

63     /** The default contructor. */
64     public
65     EventDef_impl(IFR ifr,
66                   Container_impl container)
67     {
68         // Calls the Container_impl contructor.
69
super(ifr, container);
70
71         // Sets the tie servant object.
72
setServant(new org.omg.CORBA.ComponentIR.EventDefPOATie(this));
73
74         // Inits internal state.
75
event_base_ = null;
76         consumer_itf_ = null;
77         ccm_consumer_itf_ = null;
78     }
79
80     // ==================================================================
81
//
82
// Internal methods.
83
//
84
// ==================================================================
85

86     /**
87      * To obtain the list of abstract base values.
88      */

89     protected ValueDef_ref[]
90     getAbstractBaseValues()
91     {
92         if ((!getIFR().getRepository().isIDL2Repository()) ||
93             (event_base_==null))
94             return abstract_base_values_;
95
96         ValueDef_ref[] values = new ValueDef_ref[abstract_base_values_.length+1];
97         values[0] = event_base_;
98         for (int i=0;i<abstract_base_values_.length;i++)
99             values[i+1] = abstract_base_values_[i];
100
101         return values;
102     }
103
104     // ==================================================================
105
//
106
// Public methods.
107
//
108
// ==================================================================
109

110     /**
111      * Obtain its CORBA::ComponentIR::EventDef object reference.
112      */

113     public org.omg.CORBA.ComponentIR.EventDef
114     asEventDef()
115     {
116         return org.omg.CORBA.ComponentIR.EventDefHelper.narrow(asObject());
117     }
118
119     // ==================================================================
120
//
121
// Internal methods for managing dependencies.
122
//
123
// ==================================================================
124

125     /**
126      * Checks if there is no dependencies.
127      */

128     protected void
129     checkDependencies()
130     {
131         // If there is only 2 dependencies
132
// one is on the remote consumer interface
133
// other is on the local consumer interface
134
// then it is OK.
135
if (getReferencedByCounter() == 2)
136         {
137             // Obtains all IR objects referencing this object.
138
org.objectweb.util.ref.api.Referencable[] referenced_by = getReferencedBy();
139
140             if ( ((Contained_impl)referenced_by[0]).defined_in()._is_equivalent(consumer_itf_)
141               && ((Contained_impl)referenced_by[1]).defined_in()._is_equivalent(ccm_consumer_itf_))
142             {
143                 return;
144             }
145         }
146
147         // Else checking dependencies.
148
super.checkDependencies();
149     }
150
151     /**
152      * Cuts dependencies to other objects.
153      */

154     protected void
155     cutDependencies()
156     {
157         // Destroys the equivalent local consumer interface.
158
if(ccm_consumer_itf_ != null)
159         {
160             try
161             {
162                 ccm_consumer_itf_.destroy();
163             }
164             catch(org.omg.CORBA.OBJECT_NOT_EXIST JavaDoc exc)
165             {
166                 // Thrown because this interface was previously destroyed.
167
}
168             ccm_consumer_itf_ = null;
169         }
170
171         // Destroys the equivalent consumer interface.
172
if(consumer_itf_ != null)
173         {
174             try
175             {
176                 consumer_itf_.destroy();
177             }
178             catch(org.omg.CORBA.OBJECT_NOT_EXIST JavaDoc exc)
179             {
180                 // Thrown because this interface was previously destroyed.
181
}
182             consumer_itf_ = null;
183         }
184
185         // Cuts the dependency to the eventbase value.
186
if (event_base_!=null)
187         {
188             event_base_.cutDependency();
189             event_base_ = null;
190         }
191
192         // Calls the ValueDef_impl:::cutDependencies operation.
193
super.cutDependencies();
194     }
195
196     // ==================================================================
197
//
198
// For CORBA::IRObject interface.
199
//
200
// ==================================================================
201

202     /**
203      * IDL:omg.org/CORBA/IRObject/def_kind:1.0
204      */

205     public org.omg.CORBA.DefinitionKind JavaDoc
206     def_kind()
207     {
208         if (getIFR().getRepository().isIDL2Repository())
209             return org.omg.CORBA.DefinitionKind.dk_Value;
210
211         return org.omg.CORBA.DefinitionKind.dk_Event;
212     }
213
214     // ==================================================================
215
//
216
// For CORBA::Contained interface.
217
//
218
// ==================================================================
219

220     /**
221      * IDL:omg.org/CORBA/Contained/move:1.0
222      */

223     public void
224     move(org.omg.CORBA.Container JavaDoc new_container,
225          String JavaDoc new_name,
226          String JavaDoc new_version)
227     {
228         // move the event first
229
super.move(new_container, new_name, new_version);
230
231         // do nothing if mappings are not enabled.
232
if (!getIFR().getRepository().enable_mappings_)
233             return ;
234                       
235         org.omg.CORBA.InterfaceDef JavaDoc litf = null;
236         String JavaDoc cont_base_id = getBaseContainerID();
237
238         container_.mapping_started_ = true;
239
240         // move the consumer
241
java.lang.String JavaDoc name = name()+"Consumer";
242         java.lang.String JavaDoc id = cont_base_id + name + ':' + new_version;
243         litf = org.omg.CORBA.InterfaceDefHelper.narrow(
244             getIFR().getRepository().lookup_mapped_id(id));
245         litf.move(new_container, name, new_version);
246
247         // move the local consumer
248
name = "CCM_"+name()+"Consumer";
249         id = cont_base_id + name + ':' + new_version;
250         litf = org.omg.CORBA.InterfaceDefHelper.narrow(
251             getIFR().getRepository().lookup_mapped_id(id));
252         litf.move(new_container, name, new_version);
253
254         container_.mapping_started_ = false;
255     }
256
257
258     // ==================================================================
259
//
260
// For IDL2 mapping.
261
//
262
// ==================================================================
263

264     /**
265      * TODO
266      */

267     protected void
268     whenCreated()
269     {
270         // do nothing if mappings are not enabled.
271
if (!getIFR().getRepository().enable_mappings_)
272             return ;
273
274         //
275
// IDL2 mapping
276
//
277
//
278
// add inheritance from ::Components::EventBase
279
//
280
if (getBaseValue().getImpl()==null)
281         {
282             ValueDef_impl val_impl = castToLocal(org.omg.CORBA.ValueDefHelper.narrow(
283                 getIFR().getRepository().lookup("::Components::EventBase")));
284             event_base_ = new ValueDef_ref(this, val_impl);
285         }
286
287         // REQUIRED TO ADD IT ALSO IN TABLE OF MAPPED ELEMENTS
288
container_.mapping_started_ = true;
289         getIFR().getRepository().addRID(id(), this);
290         container_.mapping_started_ = false;
291
292         //
293
// create the <event_type>Consumer interface
294
//
295
String JavaDoc base_id = computeIDWithoutVersion(id());
296         String JavaDoc name = name() + "Consumer";
297         String JavaDoc version = version();
298         String JavaDoc id = base_id + "Consumer:" + version;
299         org.omg.CORBA.InterfaceDef JavaDoc[] bases = new org.omg.CORBA.InterfaceDef JavaDoc[1];
300         if ( ( getBaseValue().getImpl()==null )
301           || !(getBaseValue().getImpl() instanceof EventDef_impl) )
302         {
303         // The mapped event type Consumer interface inherits from
304
// ::Components::EventConsumerBase when the event type has
305
// no base value type or when this base value type is not
306
// an event type.
307
//
308
bases[0] = org.omg.CORBA.InterfaceDefHelper.narrow(
309                 getIFR().getRepository().lookup("::Components::EventConsumerBase"));
310         }
311         else
312         {
313         // The mapped event type Consumer interface inherits from
314
// the base event type Consumer interface.
315
//
316
String JavaDoc base_consumer_id = computeIDWithoutVersion(getBaseValue().getId());
317             base_consumer_id = base_consumer_id +
318                                "Consumer:" + getBaseValue().getImpl().version();
319             bases[0] = org.omg.CORBA.InterfaceDefHelper.narrow(
320                 getIFR().getRepository().lookup_mapped_id(base_consumer_id));
321         }
322
323         container_.mapping_started_ = true;
324         consumer_itf_ = container_.create_ext_interface(id, name, version, bases);
325         container_.mapping_started_ = false;
326
327         //
328
// add the push operation
329
//
330
id = base_id + "Consumer/push_" + name() + ':' + version;
331         name = "push_" + name();
332         org.omg.CORBA.ParameterDescription JavaDoc[] params = new org.omg.CORBA.ParameterDescription JavaDoc[1];
333         params[0] = new org.omg.CORBA.ParameterDescription JavaDoc();
334         params[0].name = "the_" + name().toLowerCase();
335         params[0].type_def = asValueDef();
336         params[0].type = params[0].type_def.type();
337         params[0].mode = org.omg.CORBA.ParameterMode.PARAM_IN;
338
339         consumer_itf_.create_operation(id, name, version,
340             getIFR().getRepository().get_primitive(org.omg.CORBA.PrimitiveKind.pk_void),
341             org.omg.CORBA.OperationMode.OP_NORMAL,
342             params,
343             new org.omg.CORBA.ExceptionDef JavaDoc[0],
344             new java.lang.String JavaDoc[0]);
345
346         //
347
// CIDL mapping
348
//
349
//
350
// local interface CCM_<eventtype_name>Consumer {
351
// void push(in <eventtype_name> event);
352
// };
353
//
354
String JavaDoc cont_base_id = getBaseContainerID();
355         name = "CCM_"+name()+"Consumer";
356         id = cont_base_id + name + ':' + version;
357
358         container_.mapping_started_ = true;
359         org.omg.CORBA.LocalInterfaceDef litf =
360             container_.create_ext_local_interface(id, name, version,
361                                                   new org.omg.CORBA.InterfaceDef JavaDoc[0]);
362     ccm_consumer_itf_ = litf;
363         container_.mapping_started_ = false;
364         
365         id = cont_base_id + name + "/push" + ':' + version;
366         name = "push";
367         params = new org.omg.CORBA.ParameterDescription JavaDoc[1];
368         params[0] = new org.omg.CORBA.ParameterDescription JavaDoc();
369         params[0].name = "event";
370         params[0].type_def = asValueDef();
371         params[0].type = params[0].type_def.type();
372         params[0].mode = org.omg.CORBA.ParameterMode.PARAM_IN;
373         litf.create_operation(id, name, version,
374             getIFR().getRepository().get_primitive(org.omg.CORBA.PrimitiveKind.pk_void),
375             org.omg.CORBA.OperationMode.OP_NORMAL,
376             params,
377             new org.omg.CORBA.ExceptionDef JavaDoc[0],
378             new java.lang.String JavaDoc[0]);
379     }
380 }
381
Popular Tags