KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > Components > CCMObjectImpl


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2005 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): Mathieu Vadet, Philippe Merle.
23 Contributor(s): Sylvain Leblanc, Romain Rouvoy________.
24
25 ====================================================================
26 $Id: CCMObjectImpl.java,v 1.3 2005/06/27 14:57:18 merle Exp $
27 ====================================================================*/

28
29 package org.objectweb.openccm.Components;
30
31 import org.objectweb.openccm.Containers.MetaInformation.ConsumerPortInstance;
32 import org.objectweb.openccm.Containers.MetaInformation.EmitterPortInstance;
33 import org.objectweb.openccm.Containers.MetaInformation.FacetPortInstance;
34 import org.objectweb.openccm.Containers.MetaInformation.PublisherPortInstance;
35 import org.objectweb.openccm.Containers.MetaInformation.ReceptaclePortInstance;
36
37 /**
38  * This class is a basic implementation of the CCMObject interface.
39  * It also implements all generic operations for CCM components.
40  *
41  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
42  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
43  *
44  * @version 0.3
45  */

46
47 public abstract class CCMObjectImpl
48 extends org.omg.CORBA.LocalObject JavaDoc
49   implements org.omg.Components.CCMObjectOperations,
50            org.omg.Components.SessionContext
51 {
52     // ==================================================================
53
//
54
// Internal state.
55
//
56
// ==================================================================
57

58     /**
59      ** The default maximum connections for multiple receptacles.
60      **/

61     private static final int MAX_CONNECTIONS = java.lang.Integer.MAX_VALUE;
62
63     /**
64      ** Is the component ready to be used?
65      **/

66     private boolean ready_;
67
68     /**
69      ** Infos related to the facet ports.
70      **/

71     private org.objectweb.ccm.util.Table facets_;
72
73     /**
74      ** Infos related to the receptacle ports.
75      **/

76     private org.objectweb.ccm.util.Table receptacles_;
77
78     /**
79      ** Infos related to the event ports.
80      **/

81     private org.objectweb.ccm.util.Table consumers_;
82     private org.objectweb.ccm.util.Table publishers_;
83     private org.objectweb.ccm.util.Table emitters_;
84
85       
86     private void trace_debug(String JavaDoc method, String JavaDoc msg)
87     {
88       System.err.println("### debug : in '" +
89                          method +"' -> " + msg);
90     }
91     
92     // ==================================================================
93
//
94
// Constructor.
95
//
96
// ==================================================================
97

98     /**
99      ** The default constructor.
100      **/

101     public
102     CCMObjectImpl()
103     {
104         ready_ = false;
105
106         facets_ = new org.objectweb.ccm.util.Table();
107         receptacles_ = new org.objectweb.ccm.util.Table();
108         consumers_ = new org.objectweb.ccm.util.Table();
109         publishers_ = new org.objectweb.ccm.util.Table();
110         emitters_ = new org.objectweb.ccm.util.Table();
111     }
112
113     // ==================================================================
114
//
115
// Internal methods.
116
//
117
// ==================================================================
118

119     /**
120      ** Search something in a Table.
121      **
122      ** @param key The searched key.
123      ** @param table The table where search.
124      **
125      ** @return The information found.
126      **
127      ** @exception org.omg.Components.InvalidName
128      ** Thrown if the key does not refer any information.
129      **/

130     protected Object JavaDoc
131     _search_key(String JavaDoc key,
132                 org.objectweb.ccm.util.Table table)
133     throws org.omg.Components.InvalidName
134     {
135                 // Search the key in the table.
136
Object JavaDoc info = table.get(key);
137                 
138                 // If not found then throw the appropriate exception.
139
if(info == null)
140                 {
141             throw new org.omg.Components.InvalidName();
142                 }
143                 
144                 return info;
145     }
146
147     /**
148      ** Search a facet information.
149      **
150      ** @param facet_name The facet port name.
151      **
152      ** @return The facet information.
153      **
154      ** @exception org.omg.Components.InvalidName
155      ** Thrown if the name does not refer to a facet port.
156      **/

157     protected ProvidesInfo
158     _search_facet(String JavaDoc facet_name)
159     throws org.omg.Components.InvalidName
160     {
161                 // Search the facet information.
162
return (ProvidesInfo)_search_key(facet_name, facets_);
163     }
164
165     /**
166      ** Search a receptacle information.
167      **
168      ** @param receptacle_name The receptacle port name.
169      **
170      ** @return The receptable information.
171      **
172      ** @exception org.omg.Components.InvalidName
173      ** Thrown if the name does not refer to a receptacle port.
174      **/

175     protected UsesInfo
176     _search_receptacle(String JavaDoc receptacle_name)
177     throws org.omg.Components.InvalidName
178     {
179                 // Search the receptacle information.
180
return (UsesInfo)_search_key(receptacle_name, receptacles_);
181     }
182
183     /**
184      ** Search a consumer information.
185      **
186      ** @param consumer_name The consumer port name.
187      **
188      ** @return The consumer information.
189      **
190      ** @exception org.omg.Components.InvalidName
191      ** Thrown if the name does not refer to a consumer port.
192      **/

193     protected ConsumesInfo
194     _search_consumer(String JavaDoc consumer_name)
195     throws org.omg.Components.InvalidName
196     {
197                 // Search the consumer information.
198
return (ConsumesInfo)_search_key(consumer_name, consumers_);
199     }
200
201     /**
202      ** Search a publisher information.
203      **
204      ** @param publisher_name The publisher port name.
205      **
206      ** @return The publisher information.
207      **
208      ** @exception org.omg.Components.InvalidName
209      ** Thrown if the name does not refer to a publisher port.
210      **/

211     protected PublishesInfo
212     _search_publisher(String JavaDoc publisher_name)
213     throws org.omg.Components.InvalidName
214     {
215                 // Search the publisher information.
216
return (PublishesInfo)_search_key(publisher_name, publishers_);
217     }
218
219     /**
220      ** Search an emitter information.
221      **
222      ** @param emitter_name The emitter port name.
223      **
224      ** @return The emitter information.
225      **
226      ** @exception org.omg.Components.InvalidName
227      ** Thrown if the name does not refer to an emitter port.
228      **/

229     protected EmitsInfo
230     _search_emitter(String JavaDoc emitter_name)
231     throws org.omg.Components.InvalidName
232     {
233                 // Search the emitter information.
234
return (EmitsInfo)_search_key(emitter_name, emitters_);
235     }
236
237     /**
238      ** Push an event to a consumer.
239      **
240      ** @param consumer The consumer.
241      ** @param event The event.
242      **
243      ** Note: It launches a thread for each event.
244      **/

245     protected void
246     _call_push(EventConsumerBaseHolder consumer,
247                java.lang.String JavaDoc value_name,
248                org.omg.CORBA.Any JavaDoc event)
249     {
250                 // Create a thread to push the event to the consumer.
251
ThreadPushEvent pusher = new ThreadPushEvent(consumer, value_name, event);
252         pusher.start();
253     }
254
255     /**
256      **
257      **/

258     protected org.omg.Components.CCMHome
259     _home_ref()
260     {
261         return _component_servant().the_home_servant().the_home_ref();
262     }
263
264     /**
265      **
266      **/

267     protected org.omg.Components.PrimaryKeyBase
268     _primary_key()
269     {
270         return _component_servant().the_registration_info();
271     }
272
273     /**
274      **
275      **/

276     protected org.objectweb.openccm.Containers.ComponentServant
277     _component_servant()
278     {
279         return _the_component_executor()._component_servant();
280     }
281
282     /**
283      **
284      **/

285     protected org.objectweb.openccm.Containers.HomeServant
286     _home_servant()
287     {
288         return _component_servant().the_home_servant();
289     }
290
291     /**
292      ** Declare a facet port.
293      **
294      **/

295     protected void
296     _declare_facet(ProvidesInfo facet)
297     {
298        
299         
300         org.omg.CORBA.Object JavaDoc ref = _component_servant().get_reference(facet.id());
301
302         facet.facet(ref);
303         
304    
305       if(_component_servant().the_component_instance() != null)
306       {
307
308       FacetPortInstance _fpi = _component_servant()
309                               .the_component_instance()
310                               .create_facet_port_instance(facet.name()); // TODO modif
311

312         if(_fpi.type_reference() != null)
313         {
314             _fpi.object_ref(ref); // TODO modif
315
_component_servant()
316             .the_component_instance()
317             .facet_port_instance_list()
318             .add_facet_port_instance(_fpi);
319         }
320       }
321                 // Store a facet information.
322
facets_.put(facet.name(), facet);
323     }
324
325     /**
326      ** Declare a simple receptacle port.
327      **
328      **/

329     protected void
330     _declare_receptacle(UsesInfo rec)
331     {
332    
333     // Store the receptacle information.
334

335     if(_component_servant().the_component_instance() != null)
336     {
337       ReceptaclePortInstance _rpi = _component_servant()
338                                           .the_component_instance()
339                                           .create_receptacle_port_instance(rec.name());
340         if(_rpi.type_reference() != null)
341         {
342             _component_servant()
343             .the_component_instance()
344             .receptacle_port_instance_list()
345             .add_receptacle_port_instance(_rpi);
346       }
347     }
348     
349         receptacles_.put(rec.name(), rec);
350     }
351
352     /**
353      ** Declare a consumer port.
354      **
355      **/

356     protected void
357     _declare_consumer(ConsumesInfo sink)
358     {
359       org.omg.CORBA.Object JavaDoc ref = _component_servant().get_reference(sink.id());
360       sink.consumer(org.omg.Components.EventConsumerBaseHelper.narrow(ref));
361       // Insert a descriptor in the consumers table.
362
consumers_.put(sink.name(), sink);
363       if (_component_servant().the_component_instance() != null)
364       {
365         ConsumerPortInstance _cpi =
366           _component_servant()
367             .the_component_instance()
368             .create_consumer_port_instance(
369             sink.name());
370
371             if(_cpi.type_reference() != null)
372             {
373                     _cpi.object_ref(ref);
374                     _component_servant()
375                 .the_component_instance()
376                 .consumer_port_instance_list()
377                 .add_consumer_port_instance(_cpi);
378           }
379       }
380     }
381
382     /**
383      ** Declare a publisher port.
384      **
385      **/

386     protected void
387     _declare_publisher(PublishesInfo source)
388     {
389       publishers_.put(source.name(), source);
390       if (_component_servant().the_component_instance() != null)
391       {
392         PublisherPortInstance _ppi =
393           _component_servant()
394             .the_component_instance()
395             .create_publisher_port_instance(
396             source.name());
397         // Insert a descriptor in the publishers table.
398
if(_ppi.type_reference() != null)
399         {
400             _component_servant()
401           .the_component_instance()
402           .publisher_port_instance_list()
403           .add_publisher_port_instance(_ppi);
404         }
405       }
406     }
407
408     /**
409      ** Declare an emitter port.
410      **
411      **/

412     
413     protected void
414     _declare_emitter(EmitsInfo source)
415     {
416       if (_component_servant().the_component_instance() != null)
417       {
418         EmitterPortInstance _epi =
419           _component_servant()
420             .the_component_instance()
421             .create_emitter_port_instance(
422             source.name());
423         // Insert a descriptor in the emitters table.
424
if(_epi.type_reference() != null)
425         {
426             _component_servant()
427           .the_component_instance()
428           .emitter_port_instance_list()
429           .add_emitter_port_instance(_epi);
430         }
431       }
432       emitters_.put(source.name(), source);
433     }
434
435     // ==================================================================
436
//
437
// Abstract Public methods that must be implemented by subclasses.
438
//
439
// ==================================================================
440

441     /**
442      **
443      **/

444     public abstract org.objectweb.openccm.Containers.ComponentExecutor
445     _the_component_executor();
446
447     // ==================================================================
448
//
449
// Public methods.
450
//
451
// ==================================================================
452

453     /**
454      **
455      **/

456     public void
457     _declare_port(PortInfo port)
458     {
459         switch(port.kind())
460         {
461             case PortInfo.pk_provides :
462                 _declare_facet((ProvidesInfo)port);
463                 break;
464             case PortInfo.pk_uses :
465                 _declare_receptacle((UsesInfo)port);
466                 break;
467             case PortInfo.pk_consumes :
468                 _declare_consumer((ConsumesInfo)port);
469                 break;
470             case PortInfo.pk_emits :
471                 _declare_emitter((EmitsInfo)port);
472                 break;
473             case PortInfo.pk_publishes :
474                 _declare_publisher((PublishesInfo)port);
475                 break;
476             default :
477                 // should not happen !!!
478
break;
479         }
480     }
481
482     /**
483      * Push an event on a publisher port.
484      *
485      * @param publisher_name The publisher name.
486      * @param value_name The value name.
487      * @param event The event to push.
488      */

489     public void
490     _push(String JavaDoc publisher_name,
491           String JavaDoc value_name,
492           org.omg.CORBA.Any JavaDoc event)
493     {
494         PublishesInfo info = null;
495
496         try
497         {
498             // Search the publisher descriptor.
499
info = _search_publisher(publisher_name);
500         }
501         catch(org.omg.Components.InvalidName exc)
502         {
503             // Should never happen as this method is called by generated code.
504
exc.printStackTrace(System.err);
505             // TODO: Use a better way to trace errors.
506
return;
507         }
508
509         // Notify all the consumers.
510
for(java.util.Enumeration JavaDoc enumeration=info.consumers().elements(); enumeration.hasMoreElements(); )
511         {
512             _call_push(((EventConsumerBaseHolder)enumeration.nextElement()), value_name, event);
513         }
514     }
515
516     /**
517      ** Push an event on a emitter port.
518      **
519      ** @param emitter_name The emitter name.
520      ** @param event The event to push.
521      **/

522     public void
523     _push_emitter(String JavaDoc emitter_name,
524                   String JavaDoc value_name,
525                   org.omg.CORBA.Any JavaDoc event)
526     throws org.omg.Components.InvalidName
527     {
528         EmitsInfo info = null;
529         // Search the emitter information.
530
info = _search_emitter(emitter_name);
531
532         // If there is a consumer then notify it.
533
if(info.getEventConsumerBase() != null)
534         {
535             _call_push((EventConsumerBaseHolder)info, value_name, event);
536         }
537     }
538
539     /**
540      **
541      **/

542     public org.omg.Components.Cookie
543     _connect(String JavaDoc name,
544              org.omg.CORBA.Object JavaDoc connexion)
545     throws org.omg.Components.InvalidName,
546            org.omg.Components.ExceededConnectionLimit
547     {
548         try
549         {
550             return connect(name, connexion);
551         }
552         catch(org.omg.Components.AlreadyConnected ex)
553         {
554             // should never happen
555
}
556         catch(org.omg.Components.InvalidConnection ex)
557         {
558             // should never happen
559
}
560         return null;
561     }
562
563     /**
564      **
565      **/

566     public void
567     _connect_simple_receptacle(String JavaDoc name,
568                                org.omg.CORBA.Object JavaDoc connexion)
569     throws org.omg.Components.AlreadyConnected,
570            org.omg.Components.InvalidName
571     {
572         try
573         {
574             connect(name, connexion);
575         }
576         catch(org.omg.Components.ExceededConnectionLimit ex)
577         {
578             // should never happen
579
}
580         catch(org.omg.Components.InvalidConnection ex)
581         {
582             // should never happen
583
}
584     }
585
586     /**
587      **
588      **/

589     public org.omg.CORBA.Object JavaDoc
590     _disconnect(String JavaDoc receptacle_name,
591                 org.omg.Components.Cookie ck)
592     throws org.omg.Components.InvalidName
593     {
594         try
595         {
596             return disconnect(receptacle_name, ck);
597         }
598         catch(org.omg.Components.NoConnection ex)
599         {
600             // should never happen
601
}
602         catch(org.omg.Components.CookieRequired ex)
603         {
604             // should never happen
605
}
606         catch(org.omg.Components.InvalidConnection ex)
607         {
608             // should never happen
609
}
610         return null;
611     }
612
613     /**
614      **
615      **/

616     public org.omg.CORBA.Object JavaDoc
617     _disconnect_simple_receptacle(String JavaDoc receptacle_name)
618     throws org.omg.Components.NoConnection,
619            org.omg.Components.InvalidName
620     {
621         try
622         {
623             return disconnect(receptacle_name, null);
624         }
625         catch(org.omg.Components.InvalidConnection ex)
626         {
627             // should never happen
628
}
629         catch(org.omg.Components.CookieRequired ex)
630         {
631             // should never happen
632
}
633         return null;
634     }
635
636     /**
637      **
638      **/

639     public org.omg.CORBA.Object JavaDoc
640     _get_connection_simple_receptacle(String JavaDoc receptacle_name)
641     throws org.omg.Components.InvalidName
642     {
643         UsesInfo info = null;
644
645         // Search the receptacle information.
646
info = _search_receptacle(receptacle_name);
647
648 /* Bug #316
649    OLD CODE
650
651                 // Return the first connection.
652         return ((org.omg.Components.ConnectionDescription)
653                 (info.connections().elements().nextElement()))
654                             .objref;
655
656    NEW CODE
657 */

658
659         // If no connection return null.
660
if(info.connections().size()==0)
661         {
662             return null;
663         }
664
665     // Else return the first connection.
666
return ((org.omg.Components.ConnectionDescription)
667                 (info.connections().elements().nextElement())).objref;
668     }
669
670     /**
671      **
672      **/

673     public org.omg.Components.ConnectionDescription[]
674     _get_connections(String JavaDoc receptacle_name)
675     throws org.omg.Components.InvalidName
676     {
677         return get_connections(receptacle_name);
678     }
679
680     /**
681      **
682      **/

683     public org.omg.Components.Cookie
684     _subscribe(String JavaDoc publisher_name,
685                org.omg.Components.EventConsumerBase subscriber)
686     throws org.omg.Components.InvalidName,
687            org.omg.Components.ExceededConnectionLimit
688     {
689         try
690         {
691             return subscribe(publisher_name, subscriber);
692         }
693         catch(org.omg.Components.InvalidConnection ex)
694         {
695             // should never happen
696
}
697         return null;
698     }
699
700     /**
701      **
702      **/

703     public org.omg.Components.EventConsumerBase
704     _unsubscribe(String JavaDoc publisher_name,
705                  org.omg.Components.Cookie ck)
706     throws org.omg.Components.InvalidName,
707            org.omg.Components.InvalidConnection
708     {
709         return unsubscribe(publisher_name, ck);
710     }
711
712     /**
713      **
714      **/

715     public org.omg.Components.EventConsumerBase[]
716     _get_subscribers(String JavaDoc publisher_name)
717     throws org.omg.Components.InvalidName
718     {
719         PublishesInfo info = _search_publisher(publisher_name);
720         org.omg.Components.SubscriberDescription[] connections = null;
721         org.omg.Components.EventConsumerBase[] result = null;
722
723         connections = (org.omg.Components.SubscriberDescription[])info.
724             consumers().values().toArray(new org.omg.Components.SubscriberDescription[0]);
725         result = new org.omg.Components.EventConsumerBase[connections.length];
726
727         for (int i=0;i<result.length;i++)
728             result[i] = connections[i].consumer;
729
730         return result;
731     }
732
733     /**
734      **
735      **/

736     public void
737     _connect_emitter(String JavaDoc emitter_name,
738                      org.omg.Components.EventConsumerBase consumer)
739     throws org.omg.Components.InvalidName,
740            org.omg.Components.AlreadyConnected
741     {
742         try
743         {
744             connect_consumer(emitter_name, consumer);
745         }
746         catch(org.omg.Components.InvalidConnection ex)
747         {
748             // should never happen
749
}
750     }
751
752     /**
753      **
754      **/

755     public org.omg.Components.EventConsumerBase
756     _disconnect_emitter(String JavaDoc source_name)
757     throws org.omg.Components.InvalidName,
758            org.omg.Components.NoConnection
759     {
760         return disconnect_consumer(source_name);
761     }
762
763     /**
764      **
765      **/

766     public org.omg.Components.EventConsumerBase
767     _get_emitter(String JavaDoc emitter_name)
768     throws org.omg.Components.InvalidName
769     {
770         EmitsInfo info = _search_emitter(emitter_name);
771         return info.consumer();
772     }
773
774     /**
775      **
776      **/

777     public org.omg.Components.EventConsumerBase
778     _get_consumer(String JavaDoc sink_name)
779     throws org.omg.Components.InvalidName
780     {
781         return get_consumer(sink_name);
782     }
783
784 // Added for Bug #466.
785
// Contributor: Philippe Merle
786

787     /**
788      * Waits until configuration_complete is called on the component.
789      */

790     public synchronized void
791     wait_until_configuration_complete()
792     {
793         // While the component is not configurated.
794
while(ready_ == false)
795         {
796             try
797             {
798                 // Blocks the caller thread until notifyAll() will be
799
// called in configuration_complete().
800
super.wait();
801             } catch(Exception JavaDoc exc) {
802                 // should not happen
803
System.err.println(exc);
804             }
805         }
806     }
807
808 // Add end.
809

810     // ==================================================================
811
//
812
// Methods for the Components::Navigation interface.
813
//
814
// ==================================================================
815

816     //
817
// IDL:omg.org/Components/Navigation/provide_facet:1.0
818
//
819
/**
820      ** Provides the reference of a facet.
821      **
822      ** @param name The name of the facet.
823      **
824      ** @return The reference of the facet.
825      **
826      ** @exception org.omg.Components.InvalidName
827      ** Thrown if the name does not refer to a facet.
828      **/

829     public org.omg.CORBA.Object JavaDoc
830     provide_facet(String JavaDoc name)
831     throws org.omg.Components.InvalidName
832     {
833     // Search the facet information and
834
// return the reference to the facet.
835
return _search_facet(name).facet();
836     }
837
838     //
839
// IDL:omg.org/Components/Navigation/get_all_facets:1.0
840
//
841
/**
842      ** Describes all facets.
843      **
844      ** @return All the facet descriptions.
845      **/

846     public org.omg.Components.FacetDescription[]
847     get_all_facets()
848     {
849                 // Allocate the result.
850
org.omg.Components.FacetDescription result[] = new org.omg.Components.FacetDescription[facets_.size()];
851                 
852                 // Iterate on all the facet information.
853
int idx = 0;
854         for(java.util.Enumeration JavaDoc enumeration = facets_.elements(); enumeration.hasMoreElements(); )
855         {
856             ProvidesInfo info = (ProvidesInfo)enumeration.nextElement();
857             result[idx++] = new FacetDescriptionImpl(info.name(),
858                                                      info.type_id(),
859                                                      info.facet());
860         }
861
862         return result;
863     }
864
865     //
866
// IDL:omg.org/Components/Navigation/get_named_facets:1.0
867
//
868
/**
869      ** Provides a sequence of facets.
870      **
871      ** @param names A sequence of facet names.
872      **
873      ** @return The facet descriptions and references.
874      **
875      ** @exception org.omg.Components.InvalidName
876      ** Thrown if a name does not refer to a facet.
877      **/

878     public org.omg.Components.FacetDescription[]
879     get_named_facets(String JavaDoc[] names)
880     throws org.omg.Components.InvalidName
881     {
882                 // Allocate the result.
883
org.omg.Components.FacetDescription result[] =
884             new org.omg.Components.FacetDescription[names.length];
885
886                 // Iterate on all the names.
887
for(int i=0;i<names.length;i++)
888                 {
889                         // Search and store the facet information.
890
ProvidesInfo info = _search_facet(names[i]);
891             result[i] = new FacetDescriptionImpl(info.name(),
892                                                  info.type_id(),
893                                                  info.facet());
894         }
895
896         return result;
897     }
898
899     //
900
// IDL:omg.org/Components/Navigation/same_component:1.0
901
//
902
/**
903      ** Test if a reference refers to a facet of the same component.
904      **
905      ** @param ref The reference to test.
906      **
907      ** @return True if ref refers to a facet of the same component.
908      **/

909     public boolean
910     same_component(org.omg.CORBA.Object JavaDoc ref)
911     {
912                 // Iterate on all the facet information.
913
int idx = 0;
914         ProvidesInfo info = null;
915                 for(java.util.Enumeration JavaDoc enumeration = facets_.elements();enumeration.hasMoreElements(); )
916         {
917             info = (ProvidesInfo)enumeration.nextElement();
918                         if (info.facet()._is_equivalent(ref))
919                                 return true;
920                 }
921
922         return false;
923     }
924
925     // ==================================================================
926
//
927
// Methods for the Components::Receptacles interface.
928
//
929
// ==================================================================
930

931     //
932
// IDL:omg.org/Components/Receptacles/connect:1.0
933
//
934
/**
935      ** Connects to a receptacle.
936      **
937      ** @param name The name of the receptacle.
938      ** @param connection The reference to the connection.
939      **
940      ** @return The cookie associated to the connection.
941      **
942      ** @exception org.omg.Components.InvalidName
943      ** Thrown if the name does not refer to a receptacle.
944      ** @exception org.omg.Components.InvalidConnection
945      ** Thrown if the connection is invalid for the receptacle.
946      ** @exception org.omg.Components.AlreadyConnected
947      ** Thrown if the receptacle is for single connection and
948      ** a connection is already connected.
949      ** @exception org.omg.Components.ExceededConnectionLimit
950      ** Thrown if there are too many connections.
951      **/

952     public org.omg.Components.Cookie
953     connect(String JavaDoc name,
954             org.omg.CORBA.Object JavaDoc connexion)
955     throws org.omg.Components.InvalidName,
956            org.omg.Components.InvalidConnection,
957            org.omg.Components.AlreadyConnected,
958            org.omg.Components.ExceededConnectionLimit
959     {
960                 // Search the receptacle information.
961
UsesInfo info = _search_receptacle(name);
962                 
963                 // Check that the connection supports the receptacle type.
964
if (!connexion._is_a(info.type_id()))
965                 {
966             throw new org.omg.Components.InvalidConnection();
967                 }
968
969         int nb_connections = info.connections().size();
970                 
971                 // Check that it is a simple receptacle not already connected.
972
if (info.simple() && nb_connections == 1)
973                 {
974             throw new org.omg.Components.AlreadyConnected();
975                 }
976
977                 // Check if the connection limit is exceeded.
978
if (!info.simple() && nb_connections >= info.limit())
979                 {
980             throw new org.omg.Components.ExceededConnectionLimit();
981                 }
982                 
983                 // Generate a cookie for this connection.
984
CookieImpl ck = CookieImpl.generate();
985                 
986         // create an interceptor for this connection.
987
// org.objectweb.openccm.Containers.HomeExecutorBase home = _home_servant().the_home_executor(); // bug #122
988
// org.objectweb.openccm.Containers.Interceptor inter = home._get_interceptor(info.id()); // bug #122
989

990         // create the call context for the interceptor and set the needed infos.
991

992         // org.objectweb.openccm.Containers.CallContext context = new org.objectweb.openccm.Containers.ComponentCallContext(_home_servant(), info.id()); // bug #122
993
// inter._call_context(context); // bug #122
994

995         // set the connection as the delegate.
996
// inter._delegate(home._get_executor_wrapper(connexion, info.id())); // bug #122
997

998                 // Add this connection to the list of connections of this receptacle.
999
info.connections().put(ck, new ConnectionDescriptionImpl(ck, connexion));
1000        // info.connections().put(ck, new ConnectionDescriptionImpl(ck, (org.omg.CORBA.Object)inter)); // bug #122
1001

1002                // Return the generated cookie.
1003
return ck;
1004    }
1005
1006    //
1007
// IDL:omg.org/Components/Receptacles/disconnect:1.0
1008
//
1009
/**
1010     ** Disconnects from a receptacle.
1011     **
1012     ** @param name The name of the receptacle.
1013     ** @param ck The cookie associated to the connection.
1014     **
1015     ** @exception org.omg.Components.InvalidName
1016     ** Thrown if the name does not refer to a receptacle.
1017     ** @exception org.omg.Components.InvalidConnection
1018     ** Thrown if the connection is invalid for the receptacle.
1019     ** @exception org.omg.Components.CookieRequired
1020     ** Thrown if the cookie is invalid.
1021     ** @exception org.omg.Components.NoConnection
1022     ** Thrown if there is no connection.
1023     **/

1024    public org.omg.CORBA.Object JavaDoc
1025    disconnect(String JavaDoc name,
1026               org.omg.Components.Cookie ck)
1027    throws org.omg.Components.InvalidName,
1028           org.omg.Components.InvalidConnection,
1029           org.omg.Components.CookieRequired,
1030           org.omg.Components.NoConnection
1031    {
1032                // Search the receptacle information.
1033
UsesInfo info = _search_receptacle(name);
1034
1035        org.omg.CORBA.Object JavaDoc result = null;
1036
1037                // If it is a simple receptacle.
1038
if(info.simple())
1039        {
1040                        // Check that a connection is available.
1041
if(info.connections().size() == 0)
1042                        {
1043                throw new org.omg.Components.NoConnection();
1044                        }
1045
1046                        // Obtain the connection.
1047
result = ((org.omg.Components.ConnectionDescription)
1048                      (info.connections().elements().nextElement())).objref;
1049
1050                        // Clean the connection list.
1051
info.connections().clear();
1052        }
1053        else // Then it is a multiple receptable.
1054
{
1055                        // Check that the cookie is right.
1056
if(ck == null)
1057            {
1058                                throw new org.omg.Components.CookieRequired();
1059                        }
1060
1061
1062           // Remove and obtain the connection associated to the cookie.
1063
/* Bug #349
1064               OLD CODE
1065            
1066              result = (org.omg.CORBA.Object)info.connections().remove(ck);
1067              
1068              NEW CODE
1069            */

1070
1071            org.omg.Components.ConnectionDescription cd =
1072              ((org.omg.Components.ConnectionDescription)
1073                      info.connections().remove(ck));
1074
1075            if(cd == null)
1076                {
1077                    throw new org.omg.Components.InvalidConnection();
1078                }
1079
1080            result = cd.objref;
1081        }
1082
1083        // Return the connection.
1084
return result;
1085    }
1086
1087    //
1088
// IDL:omg.org/Components/Receptacles/get_connections:1.0
1089
//
1090
/**
1091     ** Obtains connections for a receptacle.
1092     **
1093     ** @param name The name of the receptacle.
1094     **
1095     ** @return The description of all connections.
1096     **
1097     ** @exception org.omg.Components.InvalidName
1098     ** Thrown if the name does not refer to a receptacle.
1099     **/

1100    public org.omg.Components.ConnectionDescription[]
1101    get_connections(String JavaDoc name)
1102    throws org.omg.Components.InvalidName
1103    {
1104                // Search the receptacle information.
1105
UsesInfo info = _search_receptacle(name);
1106
1107        // Allocate the result.
1108
org.omg.Components.ConnectionDescription[] result =
1109            new org.omg.Components.ConnectionDescription[info.connections().size()];
1110
1111                // Iterate on all the connections.
1112
int idx = 0;
1113                for(java.util.Enumeration JavaDoc enumeration = info.connections().elements(); enumeration.hasMoreElements(); )
1114            result[idx++] = (org.omg.Components.ConnectionDescription)enumeration.nextElement();
1115
1116        return result;
1117    }
1118
1119    //
1120
// IDL:omg.org/Components/Receptacles/get_all_receptacles:1.0
1121
//
1122
/**
1123     ** Obtains all receptacles description.
1124     **
1125     **/

1126    public org.omg.Components.ReceptacleDescription[]
1127    get_all_receptacles()
1128    {
1129        org.objectweb.openccm.Containers.HomeExecutorBase home = _home_servant().the_home_executor();
1130
1131        // Allocate the result.
1132
org.omg.Components.ReceptacleDescription[] result =
1133            new org.omg.Components.ReceptacleDescription[receptacles_.size()];
1134
1135                // Iterate on all the connections.
1136
int idx = 0;
1137                for(java.util.Enumeration JavaDoc enumeration = receptacles_.elements(); enumeration.hasMoreElements(); )
1138                {
1139            UsesInfo info = (UsesInfo)enumeration.nextElement();
1140            result[idx++] = new ReceptacleDescriptionImpl(info.name(),
1141                                                          info.type_id(),
1142                                                          !info.simple(),
1143                                                          (org.omg.Components.ConnectionDescription[])
1144                                                          info.connections().values().toArray(
1145                                                                                                                                                                                            new org.omg.Components.ConnectionDescription[0]));
1146        }
1147
1148        return result;
1149    }
1150
1151    //
1152
// IDL:omg.org/Components/Receptacles/get_named_receptacles:1.0
1153
//
1154
/**
1155     ** Obtains all receptacles description.
1156     **
1157     **/

1158    public org.omg.Components.ReceptacleDescription[]
1159    get_named_receptacles(String JavaDoc[] names)
1160    throws org.omg.Components.InvalidName
1161    {
1162                // Allocate the result.
1163
org.omg.Components.ReceptacleDescription result[] =
1164            new org.omg.Components.ReceptacleDescription[names.length];
1165
1166                // Iterate on all the names.
1167
for(int i=0;i<names.length;i++)
1168        {
1169                        // Search and store the facet information.
1170
UsesInfo info = _search_receptacle(names[i]);
1171            result[i] = new ReceptacleDescriptionImpl(info.name(),
1172                                                      info.type_id(),
1173                                                      !info.simple(),
1174                                                      (org.omg.Components.ConnectionDescription[])
1175                                                      info.connections().values().toArray(
1176                                                          new org.omg.Components.ConnectionDescription[0]));
1177        }
1178
1179        return result;
1180    }
1181
1182    // ==================================================================
1183
//
1184
// Methods for the Components::Events interface.
1185
//
1186
// ==================================================================
1187

1188    //
1189
// IDL:omg.org/Components/Events/get_consumer:1.0
1190
//
1191
/**
1192     ** Obtains an event sink.
1193     **
1194     ** @param sink_name The name of the event sink.
1195     **
1196     ** @return The reference to the event sink.
1197     **
1198     ** @exception org.omg.Components.InvalidName
1199     ** Thrown if the name does not refer to an event sink.
1200     **/

1201    public org.omg.Components.EventConsumerBase
1202    get_consumer(String JavaDoc sink_name)
1203    throws org.omg.Components.InvalidName
1204    {
1205                // Search the consumer information.
1206
ConsumesInfo info = _search_consumer(sink_name);
1207
1208                // Return the consumer reference.
1209
return info.consumer();
1210    }
1211        
1212    //
1213
// IDL:omg.org/Components/Events/subscribe:1.0
1214
//
1215
/**
1216     ** Subscribes to an event source.
1217     **
1218     ** @param publisher_name The name of the event publisher source.
1219     ** @param subscriber The reference to the subscriber event sink.
1220     **
1221     ** @return The cookie associated to the subscription.
1222     **
1223     ** @exception org.omg.Components.InvalidName
1224     ** Thrown if the name does not refer to an event
1225     ** publisher source.
1226     **/

1227    public org.omg.Components.Cookie
1228    subscribe(String JavaDoc publisher_name,
1229              org.omg.Components.EventConsumerBase subscriber)
1230    throws org.omg.Components.InvalidName,
1231           org.omg.Components.InvalidConnection,
1232           org.omg.Components.ExceededConnectionLimit
1233    {
1234                // Search the publisher information.
1235
PublishesInfo info = _search_publisher(publisher_name);
1236
1237                // Check that the subscriber supports the event type.
1238
if (!subscriber._is_a(info.type_id()))
1239                {
1240            throw new org.omg.Components.InvalidConnection();
1241                }
1242                
1243        int nb_connections = info.consumers().size();
1244
1245                // Check if the connection limit is exceeded.
1246
if (nb_connections >= info.limit())
1247                {
1248                        throw new org.omg.Components.ExceededConnectionLimit();
1249                }
1250
1251                // Generate a cookie for this subscription.
1252
CookieImpl ck = CookieImpl.generate();
1253
1254        // create an interceptor for this connection.
1255
// org.objectweb.openccm.Containers.HomeExecutorBase home = _home_servant().the_home_executor(); // bug #122
1256
// org.objectweb.openccm.Containers.Interceptor inter = home._get_interceptor(info.id()); // bug #122
1257

1258        // create the call context for the interceptor and set the needed infos.
1259
// org.objectweb.openccm.Containers.CallContext context =
1260
// new org.objectweb.openccm.Containers.ComponentCallContext(_home_servant(), info.id()); // bug #122
1261
// inter._call_context(context); // bug #122
1262

1263        // set the connection as the delegate.
1264
// inter._delegate(home._get_executor_wrapper(subscriber, info.id())); // bug #122
1265

1266                // Add the subscription to the list of this publisher port.
1267
info.consumers().put(ck, new SubscriberDescriptionImpl(ck, subscriber));
1268        // info.consumers().put(ck, new SubscriberDescriptionImpl(ck, (org.omg.Components.EventConsumerBase)inter)); // bug #122
1269

1270                // Return the subscription cookie.
1271
return ck;
1272    }
1273
1274    //
1275
// IDL:omg.org/Components/Events/unsubscribe:1.0
1276
//
1277
/**
1278     ** Unsubscribes from an event source.
1279     **
1280     ** @param publisher_name The name of the event publisher source.
1281     ** @param ck The cookie associated to the subscription.
1282     **
1283     ** @exception org.omg.Components.InvalidName
1284     ** Thrown if the name does not refer to an event
1285     ** publisher source.
1286     ** @exception org.omg.Components.InvalidConnection
1287     ** Thrown if the connection is invalid for the event
1288     ** publisher source.
1289     **/

1290    public org.omg.Components.EventConsumerBase
1291    unsubscribe(String JavaDoc publisher_name,
1292                org.omg.Components.Cookie ck)
1293    throws org.omg.Components.InvalidName,
1294           org.omg.Components.InvalidConnection
1295    {
1296                // Search the publisher information.
1297
PublishesInfo info = _search_publisher(publisher_name);
1298
1299                // Remove and obtain the subscriber description associated to the cookie.
1300
Object JavaDoc sd = info.consumers().remove(ck);
1301
1302                // Check that the cookie is associated to a consumer.
1303
if(sd == null)
1304                {
1305            throw new org.omg.Components.InvalidConnection();
1306                }
1307
1308                // Return the consumer.
1309
return ((org.omg.Components.SubscriberDescription)sd).consumer;
1310    }
1311
1312    //
1313
// IDL:omg.org/Components/Events/connect_consumer:1.0
1314
//
1315
/**
1316     ** Connects to an event emitter source.
1317     **
1318     ** @param emitter_name The name of the event emitter source.
1319     ** @param consumer The reference to the event consumer sink.
1320     **
1321     ** @exception org.omg.Components.InvalidName
1322     ** Thrown if the name does not refer to an event
1323     ** emitter source.
1324     ** @exception org.omg.Components.AlreadyConnected
1325     ** Thrown if there is an already connected consumer
1326     ** to this event emitter source.
1327     **/

1328    public void
1329    connect_consumer(String JavaDoc emitter_name,
1330                     org.omg.Components.EventConsumerBase consumer)
1331    throws org.omg.Components.InvalidName,
1332           org.omg.Components.AlreadyConnected,
1333           org.omg.Components.InvalidConnection
1334    {
1335                // Search the emitter information.
1336
EmitsInfo info = _search_emitter(emitter_name);
1337
1338                // Check that the consumer supports the event type.
1339
if (!consumer._is_a(info.type_id()))
1340                {
1341            throw new org.omg.Components.InvalidConnection();
1342                }
1343
1344                // Chek that there is not an already connection.
1345
if(info.consumer() != null)
1346        {
1347                        throw new org.omg.Components.AlreadyConnected();
1348                }
1349
1350        // create an interceptor for this connection.
1351
// org.objectweb.openccm.Containers.HomeExecutorBase home = _home_servant().the_home_executor(); // bug #122
1352
// org.objectweb.openccm.Containers.Interceptor inter = home._get_interceptor(info.id()); // bug #122
1353

1354        // create the call context for the interceptor and set the needed infos.
1355
// org.objectweb.openccm.Containers.CallContext context = // bug #122
1356
// new org.objectweb.openccm.Containers.ComponentCallContext(_home_servant(), info.id()); // bug #122
1357
// inter._call_context(context); // bug #122
1358

1359        // set the connection as the delegate.
1360
// inter._delegate(home._get_executor_wrapper(consumer, info.id())); // bug #122
1361

1362                // Store the consumer.
1363
// info.consumer(consumer); // bug #122
1364
// info.consumer((org.omg.Components.EventConsumerBase)inter); // bug #122
1365
info.consumer(consumer);
1366    }
1367
1368    //
1369
// IDL:omg.org/Components/Events/disconnect_consumer:1.0
1370
//
1371
/**
1372     ** Disconnects from an event emitter source.
1373     **
1374     ** @param source_name The name of the event emitter source.
1375     **
1376     ** @return The reference to the previously connected event sink.
1377     **
1378     ** @exception org.omg.Components.InvalidName
1379     ** Thrown if the name does not refer to an event
1380     ** emitter source.
1381     ** @exception org.omg.Components.NoConnection
1382     ** Thrown if there is no connection.
1383     **/

1384    public org.omg.Components.EventConsumerBase
1385    disconnect_consumer(String JavaDoc source_name)
1386    throws org.omg.Components.InvalidName,
1387           org.omg.Components.NoConnection
1388    {
1389                // Search the emitter information.
1390
EmitsInfo info = _search_emitter(source_name);
1391
1392                // Check that there is a connection.
1393
if(info.consumer() == null)
1394        {
1395                        throw new org.omg.Components.NoConnection();
1396                }
1397
1398                // Conserve the previous consumer.
1399
org.omg.Components.EventConsumerBase consumer = info.consumer();
1400
1401                // Unset the consumer.
1402
info.consumer(null);
1403
1404                // Return the previous consumer.
1405
return info.consumer();
1406    }
1407
1408    //
1409
// IDL:omg.org/Components/Events/get_all_consumers:1.0
1410
//
1411
/**
1412     ** Obtains all event consumers description.
1413     **
1414     **/

1415    public org.omg.Components.ConsumerDescription[]
1416    get_all_consumers()
1417    {
1418        // Allocate the result.
1419
org.omg.Components.ConsumerDescription[] result =
1420            new org.omg.Components.ConsumerDescription[consumers_.size()];
1421
1422                // Iterate on all the connections.
1423
int idx = 0;
1424                for(java.util.Enumeration JavaDoc enumeration = consumers_.elements(); enumeration.hasMoreElements(); )
1425        {
1426            ConsumesInfo info = (ConsumesInfo)enumeration.nextElement();
1427            result[idx++] = new ConsumerDescriptionImpl(info.name(), info.type_id(), info.consumer());
1428        }
1429
1430        return result;
1431    }
1432
1433    //
1434
// IDL:omg.org/Components/Events/get_named_consumers:1.0
1435
//
1436
/**
1437     ** Obtains named event consumers description.
1438     **
1439     **/

1440    public org.omg.Components.ConsumerDescription[]
1441    get_named_consumers(String JavaDoc[] names)
1442    throws org.omg.Components.InvalidName
1443    {
1444                // Allocate the result.
1445
org.omg.Components.ConsumerDescription result[] =
1446            new org.omg.Components.ConsumerDescription[names.length];
1447                
1448                // Iterate on all the names.
1449
for(int i=0;i<names.length;i++)
1450                {
1451                        // Search and store the facet information.
1452
ConsumesInfo info = _search_consumer(names[i]);
1453            result[i] = new ConsumerDescriptionImpl(info.name(), info.type_id(), info.consumer());
1454        }
1455
1456        return result;
1457    }
1458
1459    //
1460
// IDL:omg.org/Components/Events/get_all_emitters:1.0
1461
//
1462
/**
1463     ** Obtains all event emitters description.
1464     **
1465     **/

1466    public org.omg.Components.EmitterDescription[]
1467    get_all_emitters()
1468    {
1469        // Allocate the result.
1470
org.omg.Components.EmitterDescription[] result =
1471            new org.omg.Components.EmitterDescription[emitters_.size()];
1472
1473                // Iterate on all the connections.
1474
int idx = 0;
1475                for(java.util.Enumeration JavaDoc enumeration = emitters_.elements(); enumeration.hasMoreElements(); )
1476              {
1477            EmitsInfo info = (EmitsInfo)enumeration.nextElement();
1478            result[idx++] = new EmitterDescriptionImpl(info.name(), info.type_id(), info.consumer());
1479        }
1480
1481        return result;
1482    }
1483
1484    //
1485
// IDL:omg.org/Components/Events/get_named_emitters:1.0
1486
//
1487
/**
1488     ** Obtains named event emitters description.
1489     **
1490     **/

1491    public org.omg.Components.EmitterDescription[]
1492    get_named_emitters(String JavaDoc[] names)
1493    throws org.omg.Components.InvalidName
1494    {
1495                // Allocate the result.
1496
org.omg.Components.EmitterDescription result[] =
1497            new org.omg.Components.EmitterDescription[names.length];
1498
1499                // Iterate on all the names.
1500
for(int i=0;i<names.length;i++)
1501        {
1502                        // Search and store the facet information.
1503
EmitsInfo info = _search_emitter(names[i]);
1504            result[i] = new EmitterDescriptionImpl(info.name(), info.type_id(), info.consumer());
1505        }
1506
1507        return result;
1508    }
1509
1510    //
1511
// IDL:omg.org/Components/Events/get_all_publishers:1.0
1512
//
1513
/**
1514     ** Obtains all event publishers description.
1515     **
1516     **/

1517    public org.omg.Components.PublisherDescription[]
1518    get_all_publishers()
1519    {
1520        // Allocate the result.
1521
org.omg.Components.PublisherDescription[] result =
1522            new org.omg.Components.PublisherDescription[publishers_.size()];
1523
1524                // Iterate on all the connections.
1525
int idx = 0;
1526                for(java.util.Enumeration JavaDoc enumeration = publishers_.elements(); enumeration.hasMoreElements(); )
1527        {
1528            PublishesInfo info = (PublishesInfo)enumeration.nextElement();
1529            result[idx++] = new PublisherDescriptionImpl(info.name(), info.type_id(),
1530                                                        (org.omg.Components.SubscriberDescription[])
1531                                                        info.consumers().values().toArray(
1532                                                            new org.omg.Components.SubscriberDescription[0]));
1533        }
1534
1535        return result;
1536    }
1537
1538    //
1539
// IDL:omg.org/Components/Events/get_named_publishers:1.0
1540
//
1541
/**
1542     ** Obtains named event publishers description.
1543     **
1544     **/

1545    public org.omg.Components.PublisherDescription[]
1546    get_named_publishers(String JavaDoc[] names)
1547    throws org.omg.Components.InvalidName
1548    {
1549                // Allocate the result.
1550
org.omg.Components.PublisherDescription result[] =
1551            new org.omg.Components.PublisherDescription[names.length];
1552
1553                // Iterate on all the names.
1554
for(int i=0;i<names.length;i++)
1555        {
1556                        // Search and store the facet information.
1557
PublishesInfo info = _search_publisher(names[i]);
1558            result[i] = new PublisherDescriptionImpl(info.name(), info.type_id(),
1559                                                     (org.omg.Components.SubscriberDescription[])
1560                                                     info.consumers().values().toArray(
1561                                                         new org.omg.Components.SubscriberDescription[0]));
1562        }
1563
1564        return result;
1565    }
1566
1567    // ==================================================================
1568
//
1569
// Methods for the Components::CCMObject interface.
1570
//
1571
// ==================================================================
1572

1573    //
1574
// IDL:omg.org/Components/CCMObject/get_component_def:1.0
1575
//
1576
/**
1577     ** Obtains the component definition into the Interface Repository.
1578     **
1579     ** @return The reference to the component definition.
1580     **/

1581    public org.omg.CORBA.IRObject JavaDoc
1582    get_component_def()
1583    {
1584    return _home_ref().get_component_def();
1585    }
1586
1587    //
1588
// IDL:omg.org/Components/CCMObject/get_ccm_home:1.0
1589
//
1590
/**
1591     ** Obtains the associated home.
1592     **
1593     ** @return The associated home.
1594     **/

1595    public org.omg.Components.CCMHome
1596    get_ccm_home()
1597    {
1598        return _home_ref();
1599    }
1600
1601    //
1602
// IDL:omg.org/Components/CCMObject/get_primary_key:1.0
1603
//
1604
/**
1605     ** Obtains the associated primary key.
1606     **
1607     ** @return The associated primary key.
1608     **
1609     ** @exception org.omg.Components.NoKeyAvailable
1610     ** Thrown if the component is keyless.
1611     **/

1612    public org.omg.Components.PrimaryKeyBase
1613    get_primary_key()
1614    throws org.omg.Components.NoKeyAvailable
1615    {
1616                // Check that there is an associated primary key.
1617
if(_primary_key() == null)
1618        {
1619                        throw new org.omg.Components.NoKeyAvailable();
1620                }
1621                
1622                // Return the associated primary key.
1623
return _primary_key();
1624    }
1625
1626    //
1627
// IDL:omg.org/Components/CCMObject/configuration_complete:1.0
1628
//
1629
/**
1630     ** Completes the component configuration.
1631     **
1632     ** @exception org.omg.Components.InvalidConfiguration
1633     ** Thrown if the configuration is invalid.
1634     **/

1635// Updated for Bug #466.
1636
// Contributor: Philippe Merle
1637

1638// public void
1639
public synchronized void
1640    configuration_complete()
1641    throws org.omg.Components.InvalidConfiguration
1642    {
1643    // TODO: Must be reviewed when configuration process
1644
// will be better understood ;-(
1645
// Currently, this must be defined by component implementors.
1646
ready_ = true;
1647
1648        // Notifies all threads waiting in wait_until_configuration_complete().
1649
super.notifyAll();
1650    }
1651
1652// Update end.
1653

1654    //
1655
// IDL:omg.org/Components/CCMObject/remove:1.0
1656
//
1657
/**
1658     ** Removes the component.
1659     **/

1660    public void
1661    remove()
1662    throws org.omg.Components.RemoveFailure
1663    {
1664/* Bug #306
1665   OLD CODE
1666
1667        get_ccm_home().remove_component(_component_servant().the_component_ref());
1668        _component_servant().remove();
1669
1670   NEW CODE
1671*/

1672        // 1) Stores the CCMObject reference.
1673
org.omg.Components.CCMObject component_ref = _component_servant().the_component_ref();
1674
1675        // 2) Removes the component.
1676
_component_servant().remove();
1677
1678        // 3) Signals to the home that the component must be unregistered.
1679
((CCMHomeImpl)_component_servant().the_home_servant().the_home_executor())
1680        .unregister_component(component_ref);
1681    }
1682
1683    //
1684
// IDL:omg.org/Components/CCMObject/get_all_ports:1.0
1685
//
1686
/**
1687     ** Obtain the description of all the component's ports.
1688     **/

1689    public org.omg.Components.ComponentPortDescription
1690    get_all_ports()
1691    {
1692        return new ComponentPortDescriptionImpl(get_all_facets(),
1693                                                get_all_receptacles(),
1694                                                get_all_consumers(),
1695                                                get_all_emitters(),
1696                                                get_all_publishers());
1697    }
1698
1699    // ==================================================================
1700
//
1701
// Methods for OMG IDL Components::SessionContext
1702
//
1703
// ==================================================================
1704

1705    //
1706
// IDL:omg.org/Components/CCMContext/get_CCM_home:1.0
1707
//
1708
/**
1709     ** Obtains the associated home.
1710     **
1711     ** @return The associated home.
1712     **/

1713    public org.omg.Components.CCMHome
1714    get_CCM_home()
1715    {
1716        return _home_ref();
1717    }
1718
1719    //
1720
// IDL:omg.org/Components/SessionContext/get_CCM_object:1.0
1721
//
1722
/**
1723     ** Obtains the associated component reference.
1724     **
1725     ** @return The associated component reference.
1726     **/

1727    public org.omg.CORBA.Object JavaDoc
1728    get_CCM_object()
1729    {
1730        return _component_servant().the_component_ref();
1731    }
1732
1733}
1734
1735/**
1736 ** This class launches threads to push events to consumers.
1737 ** Note: It uses DII to push events asynchronously.
1738 **/

1739class ThreadPushEvent
1740extends Thread JavaDoc
1741{
1742    // ==================================================================
1743
//
1744
// Internal state.
1745
//
1746
// ==================================================================
1747

1748    /** The event consumer. */
1749    private EventConsumerBaseHolder consumer;
1750
1751    /**
1752     ** The event to push.
1753     **/

1754    private org.omg.CORBA.Any JavaDoc event;
1755
1756    /**
1757     **
1758     **/

1759    private java.lang.String JavaDoc value_name;
1760
1761    // ==================================================================
1762
//
1763
// Constructor.
1764
//
1765
// ==================================================================
1766

1767    /**
1768     * The constructor.
1769     *
1770     * @param consumer The event consumer.
1771     * @param value_name The value name.
1772     * @param event The event to push.
1773     */

1774    public
1775    ThreadPushEvent(EventConsumerBaseHolder consumer,
1776                    java.lang.String JavaDoc value_name,
1777                    org.omg.CORBA.Any JavaDoc event)
1778    {
1779        this.consumer = consumer;
1780        this.value_name = value_name;
1781        this.event = event;
1782    }
1783
1784    // ==================================================================
1785
//
1786
// Methods for the java.lang.Runnable interface.
1787
//
1788
// ==================================================================
1789

1790    /**
1791     ** Send the DII request asynchronously.
1792     **/

1793    public void run()
1794    {
1795        // Gets the event consumer.
1796
org.omg.Components.EventConsumerBase ecb = consumer.getEventConsumerBase();
1797 
1798        // Create a DII request.
1799
org.omg.CORBA.Request JavaDoc request = ecb._request("push_"+value_name);
1800
1801        // Set the return type to void.
1802
request.set_return_type(org.objectweb.openccm.corba.TypeCodeUtils.getTC_void());
1803
1804        // Add one argument ("event", event, ARG_IN)
1805
request.arguments().add_value("event", event, org.omg.CORBA.ARG_IN.value);
1806
1807        try
1808        {
1809            // Send the request asynchronously.
1810
request.send_oneway();
1811
1812            Exception JavaDoc exc = request.env().exception();
1813            if(exc!=null)
1814            {
1815                // TO DO:
1816
// * log exceptions.
1817
// * disconnect the event consumer.
1818
System.err.println(exc);
1819                ecb = null;
1820            }
1821        }
1822        catch(org.omg.CORBA.SystemException JavaDoc exc)
1823        {
1824            // TO DO:
1825
// * log exceptions.
1826
// * disconnect the event consumer.
1827
System.err.println(exc);
1828            ecb = null;
1829        }
1830 
1831        // Resets the event consumer.
1832
consumer.setEventConsumerBase(ecb);
1833    }
1834}
1835
1836
Popular Tags