KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > ir3 > ComponentDef_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, Sylvain Leblanc, Christophe Demarey.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.ir3;
28
29 // Package dependencies
30
import org.omg.CORBA.DefinitionKind JavaDoc;
31 import org.omg.CORBA.ExtAttributeDescription;
32
33
34 /**
35  * Implementation of the CORBA::ComponentIR::ComponentDef interface.
36  *
37  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
38  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
39  *
40  * @version 0.5
41  */

42
43 public class ComponentDef_impl
44      extends ExtInterfaceDef_impl
45   implements org.omg.CORBA.ComponentIR.ComponentDefOperations
46 {
47     // ==================================================================
48
//
49
// Internal state.
50
//
51
// ==================================================================
52

53     /** The supported interfaces. */
54     protected InterfaceDef_ref[] supported_interfaces_;
55
56     /** The base component type. */
57     protected ComponentDef_ref base_component_;
58
59     /**
60      * To know if the component must be considered as an interface
61      * during contained objects type checking.
62      */

63     protected boolean as_interface_;
64
65     /** Reference to the IDL equivalent local main executor interface. */
66     protected org.omg.CORBA.ExtLocalInterfaceDef ccm_main_executor_itf_;
67
68     /** Reference to the IDL equivalent local monolithic executor interface. */
69     protected org.omg.CORBA.ExtLocalInterfaceDef ccm_monolithic_executor_itf_;
70
71     /** Reference to the IDL equivalent local context interface. */
72     protected org.omg.CORBA.ExtLocalInterfaceDef ccm_context_itf_;
73
74     // ==================================================================
75
//
76
// Constructor.
77
//
78
// ==================================================================
79

80     /**
81      * Default constructor.
82      */

83     public
84     ComponentDef_impl(IFR ifr,
85                       Container_impl container)
86     {
87         // Calls the InterfaceDef_impl constructor.
88
super(ifr, container, false);
89
90         // Sets the tie servant object.
91
setServant(new org.omg.CORBA.ComponentIR.ComponentDefPOATie(this));
92
93         // init internal state.
94
supported_interfaces_ = null;
95         base_component_ = new ComponentDef_ref(this);
96         as_interface_ = false;
97         ccm_main_executor_itf_ = null;
98         ccm_monolithic_executor_itf_ = null;
99         ccm_context_itf_ = null;
100     }
101
102     // ==================================================================
103
//
104
// Internal methods.
105
//
106
// ==================================================================
107

108     /**
109      * To obtain the list of base interfaces.
110      */

111     protected InterfaceDef_ref[]
112     getBaseInterfaces()
113     {
114         if (!getIFR().getRepository().isIDL2Repository())
115             return new InterfaceDef_ref[0];
116         else
117             return base_interfaces_;
118     }
119
120     /**
121      * Add a contained object to the container.
122      */

123     protected void
124     addContained(Contained_impl contained)
125     {
126         // check if the kind of this contained object is accepted.
127
if (!checkDefinitionKind(contained.def_kind()))
128             throw exceptionInvalidContainer();
129
130         if (!mapping_started_)
131             contained_elements_.add(contained);
132
133         if (mapping_started_)
134             contained_with_mappings_.add(contained);
135
136         if (contained.def_kind() == org.omg.CORBA.DefinitionKind.dk_Attribute)
137             contained_with_mappings_.add(contained);
138     }
139
140     // Added for Bug #300152
141
/**
142      * Compute its CORBA::ExtAttrDescriptionSeq.
143      */

144     public ExtAttributeDescription[]
145     getLocalExtAttrDescriptionSeq()
146     {
147         java.util.List JavaDoc selection = new java.util.ArrayList JavaDoc();
148
149         selectContained(selection, DefinitionKind.dk_Attribute, true);
150
151         ExtAttributeDescription[] result =
152                   new ExtAttributeDescription[selection.size()];
153
154         for(int i=0; i<selection.size(); i++)
155         {
156             result[i] = ((ExtAttributeDef_impl)selection.get(i))
157                         .getExtAttributeDescription();
158         }
159
160         return result;
161      }
162      
163     /**
164      * Obtain the CORBA::ComponentIR::ProvidesDescriptionSeq of the component.
165      */

166     protected org.omg.CORBA.ComponentIR.ProvidesDescription[]
167     getProvidesDescriptionSeq()
168     {
169         java.util.List JavaDoc selection = new java.util.ArrayList JavaDoc();
170
171         selectContained(selection, org.omg.CORBA.DefinitionKind.dk_Provides, true);
172
173         org.omg.CORBA.ComponentIR.ProvidesDescription[] result =
174             new org.omg.CORBA.ComponentIR.ProvidesDescription[selection.size()];
175
176         for(int i=0; i<selection.size(); i++)
177             result[i] = ((ProvidesDef_impl)selection.get(i))
178                         .describe_provides();
179
180         return result;
181     }
182
183     /**
184      * Obtain the CORBA::ComponentIR::UsesDescriptionSeq of the component.
185      */

186     protected org.omg.CORBA.ComponentIR.UsesDescription[]
187     getUsesDescriptionSeq()
188     {
189         java.util.List JavaDoc selection = new java.util.ArrayList JavaDoc();
190
191         selectContained(selection, org.omg.CORBA.DefinitionKind.dk_Uses, true);
192
193         org.omg.CORBA.ComponentIR.UsesDescription[] result =
194             new org.omg.CORBA.ComponentIR.UsesDescription[selection.size()];
195
196         for(int i=0; i<selection.size(); i++)
197             result[i] = ((UsesDef_impl)selection.get(i))
198                         .describe_uses();
199
200         return result;
201     }
202
203     /**
204      * Obtain the CORBA::ComponentIR::EventPortDescriptionSeq of the component
205      * for a specific DefinitionKind.
206      */

207     protected org.omg.CORBA.ComponentIR.EventPortDescription[]
208     getEventPortDescriptionSeq(org.omg.CORBA.DefinitionKind JavaDoc kind)
209     {
210         java.util.List JavaDoc selection = new java.util.ArrayList JavaDoc();
211
212         selectContained(selection, kind, true);
213
214         org.omg.CORBA.ComponentIR.EventPortDescription[] result =
215             new org.omg.CORBA.ComponentIR.EventPortDescription[selection.size()];
216
217         for(int i=0; i<selection.size(); i++)
218             result[i] = ((EventPortDef_impl)selection.get(i))
219                         .describe_event_port();
220
221         return result;
222     }
223
224     /**
225      * Obtain the CORBA::ComponentIR::EventPortDescriptionSeq of the component
226      * for the emits declarations.
227      */

228     protected org.omg.CORBA.ComponentIR.EventPortDescription[]
229     getEmitsDescriptionSeq()
230     {
231         return getEventPortDescriptionSeq(org.omg.CORBA.DefinitionKind.dk_Emits);
232     }
233
234     /**
235      * Obtain the CORBA::ComponentIR::EventPortDescriptionSeq of the component
236      * for the publishes declarations.
237      */

238     protected org.omg.CORBA.ComponentIR.EventPortDescription[]
239     getPublishesDescriptionSeq()
240     {
241         return getEventPortDescriptionSeq(org.omg.CORBA.DefinitionKind.dk_Publishes);
242     }
243
244     /**
245      * Obtain the CORBA::ComponentIR::EventPortDescriptionSeq of the component
246      * for the consumes declarations.
247      */

248     protected org.omg.CORBA.ComponentIR.EventPortDescription[]
249     getConsumesDescriptionSeq()
250     {
251         return getEventPortDescriptionSeq(org.omg.CORBA.DefinitionKind.dk_Consumes);
252     }
253
254     // ==================================================================
255
//
256
// Public methods.
257
//
258
// ==================================================================
259

260     /**
261      * Obtain its CORBA::ComponentIR::ComponentDef object reference.
262      */

263     public org.omg.CORBA.ComponentIR.ComponentDef
264     asComponentDef()
265     {
266         return org.omg.CORBA.ComponentIR.ComponentDefHelper.narrow(asObject());
267     }
268
269     // ==================================================================
270
//
271
// For Contained_impl class.
272
//
273
// ==================================================================
274

275     /**
276      * To set the value field of the CORBA::Contained::Description struct.
277      */

278     public void
279     setDescriptionValue(org.omg.CORBA.Any JavaDoc any)
280     {
281         // create the CORBA::ComponentIR::ComponentDef::ComponentDescription.
282
org.omg.CORBA.ComponentIR.ComponentDescription description =
283             new org.omg.CORBA.ComponentIR.ComponentDescription();
284         description.name = name();
285         description.id = id();
286         description.defined_in = getContainerID();
287         description.version = version();
288         description.base_component = base_component_.getId();
289         description.supported_interfaces = InterfaceDef_ref.
290                          computeRepositoryIdSeq(supported_interfaces_);
291         description.provided_interfaces = getProvidesDescriptionSeq();
292         description.used_interfaces = getUsesDescriptionSeq();
293         description.emits_events = getEmitsDescriptionSeq();
294         description.publishes_events = getPublishesDescriptionSeq();
295         description.consumes_events = getConsumesDescriptionSeq();
296         description.attributes = getLocalExtAttrDescriptionSeq();
297         // description.is_basic = is_basic();
298
description.type = type();
299
300         // insert it into the any.
301
org.omg.CORBA.ComponentIR.ComponentDescriptionHelper.insert(any, description);
302     }
303
304     // ==================================================================
305
//
306
// For Container_impl class.
307
//
308
// ==================================================================
309

310     /**
311      * Check if this kind of objects is accepted by the container.
312      */

313     public boolean
314     checkDefinitionKind(org.omg.CORBA.DefinitionKind JavaDoc dk)
315     {
316         if ((as_interface_) || (getIFR().getRepository().isIDL2Repository()))
317             // check kind as for an interface
318
// necessary for IDL2 mapping creation
319
return super.checkDefinitionKind(dk);
320
321         return (dk == org.omg.CORBA.DefinitionKind.dk_Attribute)
322             || (dk == org.omg.CORBA.DefinitionKind.dk_Provides)
323             || (dk == org.omg.CORBA.DefinitionKind.dk_Uses)
324             || (dk == org.omg.CORBA.DefinitionKind.dk_Emits)
325             || (dk == org.omg.CORBA.DefinitionKind.dk_Publishes)
326             || (dk == org.omg.CORBA.DefinitionKind.dk_Consumes);
327     }
328
329     /**
330      * Check a new name according to already contained names.
331      */

332     public void
333     checkName(String JavaDoc name,
334               boolean exclude_inherited,
335               boolean in_inherited)
336     {
337         // calls the InterfaceDef_impl::checkName operations.
338
super.checkName(name, exclude_inherited, in_inherited);
339
340         if(!exclude_inherited)
341         {
342             // TODO;
343
}
344     }
345
346     // ==================================================================
347
//
348
// Internal methods for managing dependencies.
349
//
350
// ==================================================================
351

352     /**
353      * Cuts dependencies to other objects.
354      */

355     protected void
356     cutDependencies()
357     {
358         // Destroys equivalent local interfaces.
359
if(ccm_context_itf_ != null)
360         {
361             try
362             {
363                 ccm_context_itf_.destroy();
364             }
365             catch(org.omg.CORBA.OBJECT_NOT_EXIST JavaDoc exc)
366             {
367                 // Thrown because this interface was previously destroyed.
368
}
369             ccm_context_itf_ = null;
370         }
371
372         if(ccm_monolithic_executor_itf_ != null)
373         {
374             try
375             {
376                 ccm_monolithic_executor_itf_.destroy();
377             }
378             catch(org.omg.CORBA.OBJECT_NOT_EXIST JavaDoc exc)
379             {
380                 // Thrown because this interface was previously destroyed.
381
}
382             ccm_monolithic_executor_itf_ = null;
383         }
384
385         if(ccm_main_executor_itf_ != null)
386         {
387             try
388             {
389                 ccm_main_executor_itf_.destroy();
390             }
391             catch(org.omg.CORBA.OBJECT_NOT_EXIST JavaDoc exc)
392             {
393                 // Thrown because this interface was previously destroyed.
394
}
395             ccm_main_executor_itf_ = null;
396         }
397
398         // Cuts the dependency to supported interfaces.
399
InterfaceDef_ref.cutDependencies(supported_interfaces_);
400         supported_interfaces_ = null;
401
402         // Cuts the dependency to the base component.
403
base_component_.cutDependency();
404         base_component_ = null;
405
406         // Destroys all the contained objects.
407
while(contained_elements_.size() != 0)
408         {
409             ((Contained_impl) contained_elements_.get(contained_elements_.size() -1)).destroy();
410         }
411
412         // Calls the InterfaceDef_impl::cutDependencies operation.
413
super.cutDependencies();
414     }
415
416     // ==================================================================
417
//
418
// For CORBA::IRObject interface.
419
//
420
// ==================================================================
421

422     /**
423      * IDL:omg.org/CORBA/IRObject/def_kind:1.0
424      */

425     public org.omg.CORBA.DefinitionKind JavaDoc
426     def_kind()
427     {
428         if (getIFR().getRepository().isIDL2Repository())
429             return org.omg.CORBA.DefinitionKind.dk_Interface;
430
431         return org.omg.CORBA.DefinitionKind.dk_Component;
432     }
433
434     // ==================================================================
435
//
436
// For CORBA::IDLType interface.
437
//
438
// ==================================================================
439

440     /**
441      * IDL:omg.org/CORBA/IDLType/type:1.0
442      */

443     public org.omg.CORBA.TypeCode JavaDoc
444     type()
445     {
446         // delegate to the TypeCodeFactory.
447

448         //
449
// TODO: need to use ORBs compliant with the CORBA 3.0 specification.
450
//
451
// return getIFR().getTCF().create_component_tc(id(), name());
452

453         return getIFR().getTCF().create_interface_tc(id(), name());
454     }
455
456     // ==================================================================
457
//
458
// For CORBA::Contained interface.
459
//
460
// ==================================================================
461

462     /**
463      * IDL:omg.org/CORBA/Contained/move:1.0
464      */

465     public void
466     move(org.omg.CORBA.Container JavaDoc new_container,
467          String JavaDoc new_name,
468          String JavaDoc new_version)
469     {
470         // move the component first
471
super.move(new_container, new_name, new_version);
472
473         // do nothing if mappings are not enabled.
474
if (!getIFR().getRepository().enable_mappings_)
475             return ;
476                       
477         org.omg.CORBA.LocalInterfaceDef litf = null;
478         String JavaDoc cont_base_id = getBaseContainerID();
479
480         container_.mapping_started_ = true;
481
482         // move the main executor
483
java.lang.String JavaDoc name = "CCM_"+name()+"_Executor";
484         java.lang.String JavaDoc id = cont_base_id + name + ':' + new_version;
485         litf = org.omg.CORBA.LocalInterfaceDefHelper.narrow(
486             getIFR().getRepository().lookup_mapped_id(id));
487         litf.move(new_container, name, new_version);
488
489         // move the monolithic executor
490
name = "CCM_"+name();
491         id = cont_base_id + name + ':' + new_version;
492         litf = org.omg.CORBA.LocalInterfaceDefHelper.narrow(
493             getIFR().getRepository().lookup_mapped_id(id));
494         litf.move(new_container, name, new_version);
495
496         // move the context
497
name = "CCM_"+name()+"_Context";
498         id = cont_base_id + name + ':' + new_version;
499         litf = org.omg.CORBA.LocalInterfaceDefHelper.narrow(
500             getIFR().getRepository().lookup_mapped_id(id));
501         litf.move(new_container, name, new_version);
502
503         container_.mapping_started_ = false;
504
505         // make the mappings completion
506
whenMoved();
507     }
508
509     // ==================================================================
510
//
511
// For CORBA::Container interface.
512
//
513
// ==================================================================
514

515     /**
516      * IDL:omg.org/CORBA/Container/lookup:1.0
517      */

518     public org.omg.CORBA.Contained JavaDoc
519     lookup(String JavaDoc search_name)
520     {
521         // calls the InterfaceDef_impl::lookup operation.
522
org.omg.CORBA.Contained JavaDoc contained = super.lookup(search_name);
523
524         if (contained == null)
525         {
526             // TODO
527
}
528
529         return contained;
530     }
531
532     /**
533      * IDL:omg.org/CORBA/Container/contents:1.0
534      */

535     public org.omg.CORBA.Contained JavaDoc[]
536     contents(org.omg.CORBA.DefinitionKind JavaDoc limit_type,
537              boolean exclude_inherited)
538     {
539         // calls the InterfaceDef_impl::contents operation.
540
org.omg.CORBA.Contained JavaDoc[] result = super.contents(limit_type, exclude_inherited);
541
542         if(!exclude_inherited && (base_component() != null))
543         {
544             org.omg.CORBA.Contained JavaDoc[] result2 = base_component().contents(limit_type, exclude_inherited);
545             org.omg.CORBA.Contained JavaDoc[] result3 = result;
546             result = new org.omg.CORBA.Contained JavaDoc[result3.length + result2.length];
547             System.arraycopy(result2, 0, result, 0, result2.length);
548             System.arraycopy(result3, 0, result, result2.length, result3.length);
549         }
550
551         return result;
552     }
553
554     /**
555      * IDL:omg.org/CORBA/Container/lookup_name:1.0
556      */

557     public org.omg.CORBA.Contained JavaDoc[]
558     lookup_name(String JavaDoc search_name,
559                 int levels_to_search,
560                 org.omg.CORBA.DefinitionKind JavaDoc limit_type,
561                 boolean exclude_inherited)
562     {
563         // calls the InterfaceDef_impl::contents operation.
564
org.omg.CORBA.Contained JavaDoc[] result =
565             super.lookup_name(search_name, levels_to_search,
566                               limit_type, exclude_inherited);
567
568         if(!exclude_inherited)
569         {
570             // TODO
571
}
572  
573         return result;
574     }
575
576     // ==================================================================
577
//
578
// For CORBA::ComponentIR::ComponentDef interface.
579
//
580
// ==================================================================
581

582     /**
583      * IDL:omg.org/CORBA/ComponentIR/ComponentDef/supported_interfaces:1.0
584      */

585     public org.omg.CORBA.InterfaceDef JavaDoc[]
586     supported_interfaces()
587     {
588         return InterfaceDef_ref.computeInterfaceDefSeq(supported_interfaces_);
589     }
590
591     /**
592      * IDL:omg.org/CORBA/ComponentIR/ComponentDef/supported_interfaces:1.0
593      */

594     public void
595     supported_interfaces(org.omg.CORBA.InterfaceDef JavaDoc[] val)
596     {
597         InterfaceDef_impl[] itfs = new InterfaceDef_impl[val.length];
598         for (int i=0; i<val.length; i++)
599             itfs[i] = castToLocal(val[i]);
600
601         // TODO: check inheritance
602

603         InterfaceDef_ref[] refs = new InterfaceDef_ref[val.length];
604         for (int i=0; i<val.length; i++)
605             refs[i] = new InterfaceDef_ref( this, itfs[i] );
606
607         // cut the previous dependency to base interfaces.
608
InterfaceDef_ref.cutDependencies(supported_interfaces_);
609
610         supported_interfaces_ = refs;
611     }
612
613     /**
614      * IDL:omg.org/CORBA/ComponentIR/ComponentDef/base_component:1.0
615      */

616     public org.omg.CORBA.ComponentIR.ComponentDef
617     base_component()
618     {
619         // delegate to the ComponentDef reference.
620
return base_component_.asComponentDef();
621     }
622
623     // Warning: base_component is a readonly attribute!
624
//
625
// Here, this allows us to implement the CORBA::Repository::
626
// create_component() operation in the same way that other
627
// create_* operations.
628
//
629
/**
630      * IDL:omg.org/CORBA/ComponentIR/ComponentDef/base_component:1.0
631      */

632     public void
633     base_component(org.omg.CORBA.ComponentIR.ComponentDef val)
634     {
635         if (val == null)
636             base_component_.setDependency( null );
637         else
638         {
639             // try to cast val to a local ComponentDef object
640
// and delegate to the ComponentDef reference.
641
base_component_.setDependency(castToLocal(val));
642         }
643     }
644
645     /**
646      * IDL:omg.org/CORBA/ComponentIR/ComponentDef/create_provides:1.0
647      */

648     public org.omg.CORBA.ComponentIR.ProvidesDef
649     create_provides(String JavaDoc id,
650                     String JavaDoc name,
651                     String JavaDoc version,
652                     org.omg.CORBA.InterfaceDef JavaDoc interface_type)
653     {
654         ProvidesDef_impl pr = new ProvidesDef_impl(getIFR(), this);
655
656         try
657         {
658             addContained(pr, id, name, version);
659             pr.interface_type(interface_type);
660         }
661         catch(org.omg.CORBA.SystemException JavaDoc exc)
662         {
663             pr.destroy();
664             throw exc;
665         }
666
667         as_interface_ = true;
668         pr.whenCreated();
669         as_interface_ = false;
670         return pr.asProvidesDef();
671     }
672
673     /**
674      * IDL:omg.org/CORBA/ComponentIR/ComponentDef/create_uses:1.0
675      */

676     public org.omg.CORBA.ComponentIR.UsesDef
677     create_uses(String JavaDoc id,
678                 String JavaDoc name,
679                 String JavaDoc version,
680                 org.omg.CORBA.InterfaceDef JavaDoc interface_type,
681                 boolean is_multiple)
682     {
683         UsesDef_impl uses = new UsesDef_impl(getIFR(), this);
684
685         try
686         {
687             addContained(uses, id, name, version);
688             uses.interface_type(interface_type);
689             uses.is_multiple(is_multiple);
690         }
691         catch(org.omg.CORBA.SystemException JavaDoc exc)
692         {
693             uses.destroy();
694             throw exc;
695         }
696
697         as_interface_ = true;
698         uses.whenCreated();
699         as_interface_ = false;
700         return uses.asUsesDef();
701     }
702
703     /**
704      * IDL:omg.org/CORBA/ComponentIR/ComponentDef/create_emits:1.0
705      */

706     public org.omg.CORBA.ComponentIR.EmitsDef
707     create_emits(String JavaDoc id,
708                  String JavaDoc name,
709                  String JavaDoc version,
710                  org.omg.CORBA.ComponentIR.EventDef value)
711     {
712         EmitsDef_impl e = new EmitsDef_impl(getIFR(), this);
713
714         try
715         {
716             addContained(e, id, name, version);
717             e.event(value);
718         }
719         catch(org.omg.CORBA.SystemException JavaDoc exc)
720         {
721             e.destroy();
722             throw exc;
723         }
724
725         as_interface_ = true;
726         e.whenCreated();
727         as_interface_ = false;
728         return e.asEmitsDef();
729     }
730
731     /**
732      * IDL:omg.org/CORBA/ComponentIR/ComponentDef/create_publishes:1.0
733      */

734     public org.omg.CORBA.ComponentIR.PublishesDef
735     create_publishes(String JavaDoc id,
736                      String JavaDoc name,
737                      String JavaDoc version,
738                      org.omg.CORBA.ComponentIR.EventDef value)
739     {
740         PublishesDef_impl p = new PublishesDef_impl(getIFR(), this);
741
742         try
743         {
744             addContained(p, id, name, version);
745             p.event(value);
746         }
747         catch(org.omg.CORBA.SystemException JavaDoc exc)
748         {
749             p.destroy();
750             throw exc;
751         }
752
753         as_interface_ = true;
754         p.whenCreated();
755         as_interface_ = false;
756         return p.asPublishesDef();
757     }
758
759     /**
760      * IDL:omg.org/CORBA/ComponentIR/ComponentDef/create_consumes:1.0
761      */

762     public org.omg.CORBA.ComponentIR.ConsumesDef
763     create_consumes(String JavaDoc id,
764                     String JavaDoc name,
765                     String JavaDoc version,
766                     org.omg.CORBA.ComponentIR.EventDef value)
767     {
768         ConsumesDef_impl c = new ConsumesDef_impl(getIFR(), this);
769
770         try
771         {
772             addContained(c, id, name, version);
773             c.event(value);
774         }
775         catch(org.omg.CORBA.SystemException JavaDoc exc)
776         {
777             c.destroy();
778             throw exc;
779         }
780
781         as_interface_ = true;
782         c.whenCreated();
783         as_interface_ = false;
784         return c.asConsumesDef();
785     }
786
787     // ==================================================================
788
//
789
// For IDL2 mapping.
790
//
791
// ==================================================================
792

793     /**
794      * TODO
795      */

796     protected void
797     whenCreated()
798     {
799         // do nothing if mappings are not enabled.
800
if (!getIFR().getRepository().enable_mappings_)
801             return ;
802
803         // else create the mapping according to the CCM spec
804

805         //
806
// CIDL mapping
807
//
808
// Component Main Executor Interface
809
//
810
// local CCM_<component_name>_Executor :
811
// ( CCM_<base_component_name>_Executor | Components::EnterpriseComponent )
812
// [ <supported_interface_names> ]
813
// {
814
// <component_attributes>
815
// };
816
//
817
String JavaDoc cont_base_id = getBaseContainerID();
818         String JavaDoc name = "CCM_"+name()+"_Executor";
819         String JavaDoc version = version();
820         String JavaDoc id = cont_base_id + name + ':' + version;
821         container_.mapping_started_ = true;
822         org.omg.CORBA.ExtLocalInterfaceDef litf =
823             container_.create_ext_local_interface(id, name, version, new org.omg.CORBA.InterfaceDef JavaDoc[0]);
824
825         // Stores the equivalent local main executor interface.
826
ccm_main_executor_itf_ = litf;
827
828         container_.mapping_started_ = false;
829
830         //
831
// Component Monolithic Executor Interface
832
//
833
// local CCM_<component_name> : CCM_<component_name>_Executor
834
// {
835
// <base_monolithic_equivalent_operations>
836
// <facets_operations>
837
// <event_sinks_operations>
838
// };
839
//
840
name = "CCM_"+name();
841         id = cont_base_id + name + ':' + version;
842
843         container_.mapping_started_ = true;
844         org.omg.CORBA.ExtLocalInterfaceDef litf2 =
845             container_.create_ext_local_interface(id, name, version, new org.omg.CORBA.InterfaceDef JavaDoc[0]);
846
847         // Stores the equivalent local monolithic executor interface.
848
ccm_monolithic_executor_itf_ = litf2;
849
850         container_.mapping_started_ = false;
851
852         //
853
// Component Context Interface
854
//
855
// local interface CCM_<component_name>_Context :
856
// ( CCM_<base_component_name>_Context | Components::CCMContext )
857
// {
858
// <facets_operations>
859
// <event_sinks_operations>
860
// };
861
//
862
name = "CCM_"+name()+"_Context";
863         id = cont_base_id + name + ':' + version;
864         container_.mapping_started_ = true;
865         // Creates and stores the equivalent local context interface.
866
ccm_context_itf_ = container_.create_ext_local_interface(id, name, version,
867                                                                  new org.omg.CORBA.InterfaceDef JavaDoc[0]);
868         container_.mapping_started_ = false;
869     }
870
871     /**
872      * TODO
873      */

874     protected void
875     whenMoved()
876     {
877         // do nothing if mappings are not enabled.
878
if (!getIFR().getRepository().enable_mappings_)
879             return ;
880
881         // else complete the mapping according to the CCM spec
882

883         //
884
// IDL2 mapping
885
//
886
//
887
//
888
// add inheritance for ::ComponentsEventBase or <base_component>
889
//
890
org.omg.CORBA.InterfaceDef JavaDoc[] itfs =
891             new org.omg.CORBA.InterfaceDef JavaDoc[1+supported_interfaces_.length];
892         if (base_component_.getImpl()==null)
893         {
894             itfs[0] = org.omg.CORBA.InterfaceDefHelper.narrow(
895                 getIFR().getRepository().lookup("::Components::CCMObject"));
896         }
897         else
898         {
899             itfs[0] = base_component_.asComponentDef();
900         }
901         //
902
// add inheritance for the supported interfaces
903
//
904
for (int i=0;i<supported_interfaces_.length;i++)
905         {
906             itfs[1+i] = supported_interfaces_[i].asInterfaceDef();
907         }
908
909         base_interfaces(itfs);
910
911         // REQUIRED TO ADD IT ALSO IN TABLE OF MAPPED ELEMENTS
912
container_.mapping_started_ = true;
913         getIFR().getRepository().addRID(id(), this);
914         container_.mapping_started_ = false;
915
916         //
917
// CIDL mapping
918
//
919
// Component Main Executor Interface
920
//
921
// local CCM_<component_name>_Executor :
922
// ( CCM_<base_component_name>_Executor | Components::EnterpriseComponent )
923
// [ <supported_interface_names> ]
924
// {
925
// <component_attributes>
926
// };
927
//
928

929         // Retrieve the interface declaration
930
String JavaDoc cont_base_id = getBaseContainerID();
931         String JavaDoc name = "CCM_"+name()+"_Executor";
932         String JavaDoc version = version();
933         String JavaDoc id = cont_base_id + name + ':' + version;
934         org.omg.CORBA.ExtLocalInterfaceDef litf = org.omg.CORBA.ExtLocalInterfaceDefHelper.narrow(getIFR().getRepository().lookup_mapped_id(id));
935
936         // complete this declaration
937
org.omg.CORBA.InterfaceDef JavaDoc[] bases = new org.omg.CORBA.InterfaceDef JavaDoc[supported_interfaces_.length+1];
938         if (base_component_.getImpl()==null)
939         {
940             bases[0] = org.omg.CORBA.InterfaceDefHelper.narrow(
941                 getIFR().getRepository().lookup("::Components::EnterpriseComponent"));
942         }
943         else
944         {
945             String JavaDoc base_cont_base_id = base_component_.getImpl().getBaseContainerID();
946             String JavaDoc base_component_exe_id = base_cont_base_id + "CCM_" +
947                                            base_component_.getImpl().name() + "_Executor:" +
948                                            base_component_.getImpl().version();
949             bases[0] = org.omg.CORBA.InterfaceDefHelper.narrow(
950                 getIFR().getRepository().lookup_mapped_id(base_component_exe_id));
951         }
952
953         for (int i=0;i<supported_interfaces_.length;i++)
954         {
955             bases[1+i] = supported_interfaces_[i].asInterfaceDef();
956         }
957
958         container_.mapping_started_ = true;
959         litf.base_interfaces(bases);
960         container_.mapping_started_ = false;
961
962
963         //
964
// Component Monolithic Executor Interface
965
//
966
// local CCM_<component_name> : CCM_<component_name>_Executor
967
// {
968
// <base_monolithic_equivalent_operations>
969
// <facets_operations>
970
// <event_sinks_operations>
971
// };
972
//
973
bases = new org.omg.CORBA.InterfaceDef JavaDoc[1];
974         bases[0] = litf;
975         name = "CCM_"+name();
976         id = cont_base_id + name + ':' + version;
977         org.omg.CORBA.ExtLocalInterfaceDef litf2 = org.omg.CORBA.ExtLocalInterfaceDefHelper.narrow(getIFR().getRepository().lookup_mapped_id(id));
978
979         container_.mapping_started_ = true;
980         litf2.base_interfaces(bases);
981         container_.mapping_started_ = false;
982
983         // copy the contents of base monolithic executor.
984
if (base_component_.getImpl()!=null)
985         {
986             String JavaDoc base_cont_base_id = base_component_.getImpl().getBaseContainerID();
987             String JavaDoc base_component_exe_id = base_cont_base_id + "CCM_" +
988                                            base_component_.getImpl().name() + ':' +
989                                            base_component_.getImpl().version();
990             org.omg.CORBA.LocalInterfaceDef base_monolithic =
991                 org.omg.CORBA.LocalInterfaceDefHelper.narrow(
992                     getIFR().getRepository().lookup_mapped_id(base_component_exe_id));
993
994             org.omg.CORBA.Contained JavaDoc[] contents =
995                 base_monolithic.contents(org.omg.CORBA.DefinitionKind.dk_Operation,
996                                          true);
997
998             org.omg.CORBA.OperationDef JavaDoc op = null;
999             String JavaDoc op_base_id = cont_base_id + name + '/';
1000
1001
1002            for (int i=0;i<contents.length;i++)
1003            {
1004
1005                op = org.omg.CORBA.OperationDefHelper.narrow(contents[i]);
1006                litf2.create_operation(op_base_id+op.name()+':'+op.version(),
1007                                       op.name(),
1008                                       op.version(),
1009                                       op.result_def(),
1010                                       op.mode(),
1011                                       op.params(),
1012                                       op.exceptions(),
1013                                       op.contexts());
1014            }
1015        }
1016
1017
1018
1019        //
1020
// Component Context Interface
1021
//
1022
// local interface CCM_<component_name>_Context :
1023
// ( CCM_<base_component_name>_Context | Components::CCMContext )
1024
// {
1025
// <facets_operations>
1026
// <event_sinks_operations>
1027
// };
1028
//
1029
name = "CCM_"+name()+"_Context";
1030        id = cont_base_id + name + ':' + version;
1031        org.omg.CORBA.ExtLocalInterfaceDef litf3 = org.omg.CORBA.ExtLocalInterfaceDefHelper.narrow(getIFR().getRepository().lookup_mapped_id(id));
1032
1033        bases = new org.omg.CORBA.InterfaceDef JavaDoc[1];
1034        if (base_component_.getImpl()==null)
1035        {
1036            bases[0] = org.omg.CORBA.InterfaceDefHelper.narrow(
1037                getIFR().getRepository().lookup("::Components::CCMContext"));
1038        }
1039        else
1040        {
1041            String JavaDoc base_cont_base_id = base_component_.getImpl().getBaseContainerID();
1042            String JavaDoc base_component_exe_id = base_cont_base_id + "CCM_" +
1043                                           base_component().name() + "_Context:" +
1044                                           base_component().version();
1045            bases[0] = org.omg.CORBA.InterfaceDefHelper.narrow(
1046                getIFR().getRepository().lookup_mapped_id(base_component_exe_id));
1047        }
1048
1049        container_.mapping_started_ = true;
1050        litf3.base_interfaces(bases);
1051        container_.mapping_started_ = false;
1052    }
1053}
1054
Popular Tags