KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > Deployment > ContainerBase


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2003 INRIA - USTL - LIFL - GOAL
5 Contact: openccm-team@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Mathieu Vadet.
23 Contributor(s): Sylvain Leblanc,
24                 Romain Rouvoy,
25                 Philippe Merle,
26                 Briclet Fr?d?ric,
27                 Christophe Demarey,
28                 Hameau Fabien.
29
30 ====================================================================*/

31
32 package org.objectweb.openccm.Deployment;
33
34 import org.objectweb.openccm.Containers.MetaInformation.HomeType;
35 import org.objectweb.openccm.Containers.MetaInformation.HomeInstance;
36
37 /**
38  * This class implements the OMG IDL
39  * OpenCCM::ComponentServer::Container interface.
40  *
41  * @author <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
42  * @author <a HREF="mailto:Sylvain.Leblanc@lifl.fr">Sylvain Leblanc</a>
43  * @author <a HREF="mailto:Romain.Rouvoy@lifl.fr">Romain Rouvoy</a>
44  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
45  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
46  * @author <a HREF="mailto:Fabien.Hameau@lifl.fr">Hameau Fabien</a>
47  *
48  * @version 0.5
49  */

50
51 public class ContainerBase
52 {
53     // ==================================================================
54
//
55
// Internal state.
56
//
57
// ==================================================================
58

59     /**
60      ** Fred Modification :
61      * Change the_component_server type from ComponentServerBase to
62      * component_server_impl. Because of split of ComponentServer and
63      * Component Installation in two JVM the Server object isn't required
64      * anymore. So a componentServerBase cannot retrieve the ComponentServer
65      * facette.
66      **/

67      protected ComponentServerImpl the_component_server_;
68     //protected ComponentServerBase the_component_server_;
69

70     /**
71      **
72      **/

73     protected org.omg.Components.ConfigValue[] configuration_;
74
75     /**
76      **
77      **/

78     protected org.objectweb.ccm.util.Vector homes_;
79
80     /**
81      **
82      **/

83     protected fr.lifl.cim.jidlscript.JOSInterpreter josh_;
84
85     /**
86      **
87      **/

88     protected org.objectweb.openccm.Containers.PCA rootPCA_;
89
90     /**
91      **
92      **/

93     protected org.objectweb.openccm.Containers.SystemConfiguration container_configuration_;
94
95     /**
96      **
97      **/

98     protected org.objectweb.openccm.Containers.SystemConfiguration home_configuration_;
99
100     /*fred adding*/
101     protected org.omg.Components.Deployment.ComponentInstallation the_component_installation;
102     
103     /**
104      **
105      **/

106     protected org.objectweb.openccm.Containers.SystemConfiguration component_configuration_;
107
108     /**
109      **
110      **/

111     protected SystemHomeManagerImpl home_manager_;
112     
113     /**
114      **
115      **/

116     protected org.objectweb.openccm.Deployment.listener.ContainerListener listener_;
117
118     /**
119      **
120      **/

121     protected org.omg.Components.Deployment.Container the_container_ref_;
122
123
124     protected ContainerHomeInformation containerHomeInfo;
125                 
126     // Adding a reference to the home type MI managed by
127
// this container
128

129     protected HomeType home_type_;
130     
131     // ==================================================================
132
//
133
// Constructor.
134
//
135
// ==================================================================
136

137     /**
138      ** The constructor.
139      **
140      ** @param classLoader The class loader used to load home classes.
141      ** @param script The base configuration of the container.
142      **
143      ** @throws BadConfiguration If the base configuration script is not valid.
144      **/

145     public
146     ContainerBase(org.omg.Components.ConfigValue[] config,
147                     /*---> Fred modification:
148                      * component_server type change from ComponentServerBase
149                      * to ComponentServerImpl*/

150                   ComponentServerImpl /*ComponentServerBase*/ component_server,
151                   org.omg.Components.Deployment.ComponentInstallation the_component_installation)
152     
153     throws org.omg.Components.CreateFailure,
154            org.omg.Components.Deployment.InvalidConfiguration
155     {
156         the_component_server_ = component_server;
157         this.the_component_installation=the_component_installation;
158         configuration_ = config;
159         homes_ = new org.objectweb.ccm.util.Vector();
160         home_manager_ = new SystemHomeManagerImpl();
161         listener_ = null;
162         the_container_ref_ = null;
163         
164         home_type_ = null; // no home type MI available at this point
165

166         
167         org.objectweb.openccm.Deployment.listener
168                                     .TheContainerConfigurator
169                                     .get_instance()
170                                     .configure_container(new ContainerLocalImpl(this));
171
172         container_configuration_ = null;
173         home_configuration_ = null;
174         component_configuration_ = null;
175         fr.lifl.cim.jidlscript.lang.JISScope scope = null;
176
177         // initialize the container.
178
try
179         {
180             // create the interpreter
181
josh_ = new fr.lifl.cim.jidlscript.JOSInterpreter();
182
183             // create the root PCA.
184
rootPCA_ = new org.objectweb.openccm.Containers.RootPCAImpl(home_manager_);
185             scope = new fr.lifl.cim.jidlscript.lang.JISScope("CONTAINER");
186             fr.lifl.cim.jidlscript.lang.JISRootScope.root().insertScoped(scope);
187             create_alias(scope, "org.objectweb.openccm.Deployment.ContainerBase", this, "container");
188             //
189
// TODO : other alias needed ???
190
//
191
}
192         catch(fr.lifl.cim.jidlscript.lang.JISError ex)
193         {
194             throw new org.omg.Components.CreateFailure();
195         }
196
197         // retrieve the script from the config values.
198
java.lang.String JavaDoc script = "";
199         for (int i=0;i<config.length;i++)
200         {
201             if (config[i].name.equals("container_script"))
202             {
203                 script = config[i].value.extract_string();
204                 break;
205             }
206         }
207
208         // executes the specific configuration script.
209
try
210         {
211             josh_.eval(script);
212         }
213         catch(fr.lifl.cim.jidlscript.lang.JISError ex)
214         {
215             //
216
// TODO : is it the good exception ???
217
//
218
// throw new org.omg.Components.Deployment.InvalidConfiguration(-1, "container_script");
219
throw new java.lang.Error JavaDoc("### script failure : \n"+ex.exception.toString());
220         }
221     }
222
223     // ==================================================================
224
//
225
// Internal methods.
226
//
227
// ==================================================================
228

229     /**
230      * Trace an error.
231      */

232     protected void
233     trace_error(String JavaDoc method,
234                 String JavaDoc msg,
235                 Throwable JavaDoc exc)
236     {
237         System.err.println("Components::Deployment::Container::" + method + ": " + msg);
238         if(exc != null)
239             exc.printStackTrace();
240     }
241
242     /**
243      **
244      **/

245     protected void
246     create_alias(fr.lifl.cim.jidlscript.lang.JISScope scope,
247                  java.lang.String JavaDoc clazz,
248                  java.lang.Object JavaDoc instance,
249                  java.lang.String JavaDoc alias)
250     {
251         try
252         {
253             fr.lifl.cim.jidlscript.java.JISJavaClass jc =
254                 fr.lifl.cim.jidlscript.java.JISJavaClass.importClass(new fr.lifl.cim.jidlscript.lang.JISString(clazz));
255             fr.lifl.cim.jidlscript.java.JISJavaInstance ji = new fr.lifl.cim.jidlscript.java.JISJavaInstance(jc, instance);
256             scope.insertScoped(new fr.lifl.cim.jidlscript.lang.JISAlias(alias, ji));
257         }
258         catch(fr.lifl.cim.jidlscript.lang.JISError ex)
259         {
260             //
261
// TODO : something else ???
262
//
263
}
264     }
265
266     /**
267      * Creates a home executor.
268      *
269      * @param entrypt The entry point in the archive.
270      *
271      * @return The created home executor.
272      *
273      * @exception org.omg.Components.Deployment.ImplEntryPointNotFound
274      * Thrown if the home executor entry point is invalid.
275      */

276     protected org.omg.Components.HomeExecutorBase
277     create_home_executor(java.lang.String JavaDoc entrypt)
278     throws org.omg.Components.Deployment.ImplEntryPointNotFound,
279            org.omg.Components.Deployment.InstallationFailure
280     {
281         try
282         {
283             // Call the static home executor 'entrypt' method.
284
java.lang.Object JavaDoc object =
285                 TheURLClassLoader.getURLClassLoader()
286                 .callStaticClassMethod(entrypt, new Object JavaDoc[0]);
287
288             // Check that the result is a CCMHome executor.
289
return (org.omg.Components.HomeExecutorBase)object;
290         }
291         catch(java.lang.ClassNotFoundException JavaDoc exc)
292         {
293             trace_error("install_home",
294                         "Class '" + exc.getMessage() + "' not found for home executor entry point '"
295                         + entrypt + "'!!!",
296                         null);
297             throw new org.omg.Components.Deployment.ImplEntryPointNotFound();
298         }
299         catch(java.lang.NoSuchMethodException JavaDoc exc)
300         {
301             trace_error("install_home",
302                         "Home executor entry point 'public static org.omg.Components.HomeExecutorBase "
303                         + entrypt + "();' not found, check the home executor entry point signature!!!",
304                          null);
305             throw new org.omg.Components.Deployment.ImplEntryPointNotFound();
306         }
307         catch(java.lang.reflect.InvocationTargetException JavaDoc exc)
308         {
309             trace_error("install_home",
310                         "Exception thrown by home executor entry point '" + entrypt + "'!!!",
311                         exc.getTargetException());
312             throw new org.omg.Components.Deployment.InstallationFailure(
313                           org.objectweb.openccm.Deployment.ExceptionThrownByHomeExecutorEntryPoint.value
314                   );
315         }
316         catch(java.lang.IllegalAccessException JavaDoc exc)
317         {
318             trace_error("install_home",
319                         "Illegal access by home executor entry point '" + entrypt + "'!!!",
320                         exc);
321             throw new org.omg.Components.Deployment.InstallationFailure(
322                           org.objectweb.openccm.Deployment.IllegalAccessByHomeExecutorEntryPoint.value
323                   );
324         }
325         catch(java.lang.ClassCastException JavaDoc exc)
326         {
327             trace_error("install_home",
328                         "Home executor entry point '" + entrypt +
329                         "' does not return org.omg.Components.HomeExecutorBase," +
330                         " check the home executor entry point signature!!!",
331                         null);
332             throw new org.omg.Components.Deployment.ImplEntryPointNotFound();
333         }
334     }
335
336     /**
337      * Used by the computeFullHomeServantClassName method in order
338      * to compute full home servant class names.
339      */

340     static private org.objectweb.openccm.generator.translator.idl2java.api.CommonTranslator
341         javaTranslator = new org.objectweb.openccm.generator.translator.idl2java.lib.CommonTranslator();
342
343     /**
344      * Compute the full home servant class name associated
345      * to a home executor class.
346      *
347      * @param homeExecutorClass The home executor class.
348      *
349      * @return The full home servant class name, or null if not found.
350      */

351     protected static String JavaDoc
352     computeFullHomeServantClassName(Class JavaDoc homeExecutorClass)
353     {
354         // If homeExecutorClass is null then returns null.
355
if(homeExecutorClass == null)
356             return null;
357
358         // The full class name with the package name.
359
String JavaDoc fullClassName = homeExecutorClass.getName();
360
361         // The short class name without the package name.
362
int idx = fullClassName.lastIndexOf(".") + 1;
363         String JavaDoc shortClassName = fullClassName.substring(idx);
364
365         // If the short class name is prefixed CCM_ then
366
// returns the full home servant class name.
367
if(shortClassName.startsWith("CCM_"))
368             return fullClassName.substring(0, idx)
369                  + javaTranslator.checkKeywords(shortClassName.substring(4))
370                  + "CCM";
371
372         // Find the CCM home executor interface into implemented interfaces.
373
//
374
Class JavaDoc[] itfs = homeExecutorClass.getInterfaces();
375
376     // Required to navigate in the reverse order
377
// else interface CCM_*Operations will be found
378
// before interface CCM_*
379
for(int i=itfs.length-1; i>=0; i--)
380         {
381              String JavaDoc className = computeFullHomeServantClassName(itfs[i]);
382              if(className != null)
383                  return className;
384         }
385
386     // Find the CCM home executor interface into the super class.
387
String JavaDoc className = computeFullHomeServantClassName(homeExecutorClass.getSuperclass());
388         if(className != null)
389             return className;
390
391         // Returns null as the home servant class was not found.
392
return null;
393     }
394
395     /**
396      * Load an already installed package in the container class
397      * loader.
398      *
399      * @param uuid The identifier used when the package has been
400      * installed. The corresponding package will be loaded in the
401      * container class loader.
402      *
403      * @exception org.omg.Components.Deployment.UnknownImplId If the
404      * given identifier is unknown in this container.
405      * @exception org.omg.Components.Deployment.InstallationFailure If
406      * the package cannot be retrieved or loaded.
407      */

408     protected void load_lib_dependency(String JavaDoc uuid)
409         throws org.omg.Components.Deployment.UnknownImplId,
410         org.omg.Components.Deployment.InstallationFailure
411     {
412         try{
413             TheURLClassLoader.getURLClassLoader()
414                 .addURL(new java.net.URL JavaDoc(the_component_installation
415                                          .get_implementation(uuid)));
416             
417         }
418         catch(java.net.MalformedURLException JavaDoc ef)
419         {
420             trace_error("load_lib_dependency",
421                         "Installation failuer for package related to " +
422                         uuid + ".", null);
423             throw new org.omg.Components.Deployment.InstallationFailure();
424         }
425     }
426
427     protected String JavaDoc retrieve_MI_name(String JavaDoc className)
428     {
429       
430       try
431       {
432         // isolate names
433
String JavaDoc tmpName = className.substring(0, className.lastIndexOf("Impl."));
434         // get the IDL name of home
435
String JavaDoc IDLName = tmpName.substring(tmpName.lastIndexOf(".") + 1);
436         // get the prefix for concerned nale
437
String JavaDoc prefix = tmpName.substring(0,tmpName.lastIndexOf("."));
438         prefix = tmpName.substring(0,prefix.lastIndexOf(".") + 1);
439         // compute the full name
440
if (IDLName != null)
441         {
442           return prefix + IDLName;
443         }
444       }
445       // problem during name computation
446
catch(Exception JavaDoc e)
447       {
448         trace_error("retrieve_MI_name","error when computing IDL name for MetaInformation", null);
449       }
450       return null;
451     }
452     
453     /**
454      **
455      **/

456     public void
457     unregister_home(org.omg.Components.CCMHome ref)
458     throws org.omg.Components.RemoveFailure
459     {
460         listener_.on_remove(ref);
461         for(java.util.Iterator JavaDoc it=homes_.iterator();it.hasNext(); )
462           if(ref._is_equivalent(((org.omg.Components.CCMHome)it.next()))){
463             it.remove();
464             if(containerHomeInfo!=null)
465                 get_container_home_info().unregister_home(ref);
466             return;
467             
468         }
469        // The reference was not foound throw a Remove Exception
470
throw new org.omg.Components.RemoveFailure();
471     }
472
473     // ==================================================================
474
//
475
// Public methods.
476
//
477
// ==================================================================
478

479     /**
480      ** Add a new plugin to the deployment process
481      **
482      ** @param listener the deployment listener to add
483      **/

484     public void
485     add_listener (org.objectweb.openccm.Deployment.listener.ContainerListener listener)
486     {
487         if (listener_ == null)
488             listener_ = listener;
489         else
490         listener_.set_delegate(listener);
491     }
492
493     /**
494      **
495      **/

496     public void
497     the_container_ref(org.omg.Components.Deployment.Container container)
498     {
499         the_container_ref_ = container;
500     }
501
502     /**
503      **
504      **/

505     public org.omg.Components.Deployment.Container
506     the_container_ref()
507     {
508         return the_container_ref_;
509     }
510
511     /**
512      **
513      **/

514     public org.objectweb.openccm.Containers.PCA
515     get_rootPCA()
516     {
517         return rootPCA_;
518     }
519
520     /**
521      **
522      **/

523     public org.objectweb.openccm.Containers.SystemHome
524     create_system_home(java.lang.String JavaDoc implUUID,
525                        java.lang.String JavaDoc alias,
526                        java.lang.String JavaDoc entrypt)
527     throws org.objectweb.openccm.Containers.CreationFailed
528     {
529         return home_manager_.create_system_home(implUUID, alias, entrypt);
530     }
531
532     /**
533      **
534      **/

535     public org.objectweb.openccm.Containers.SystemHome
536     find_system_home(java.lang.String JavaDoc alias)
537     throws org.objectweb.openccm.Containers.HomeNotFound
538     {
539         return home_manager_.find_system_home(alias);
540     }
541
542     /**
543      **
544      **/

545     public void
546     set_container_configuration(org.objectweb.openccm.Containers.SystemConfiguration config)
547     {
548         container_configuration_ = config;
549     }
550
551     /**
552      **
553      **/

554     public org.objectweb.openccm.Containers.SystemConfiguration
555     get_container_configuration()
556     {
557         return container_configuration_;
558     }
559
560     /**
561      **
562      **/

563     public void
564     set_home_configuration(org.objectweb.openccm.Containers.SystemConfiguration config)
565     {
566         home_configuration_ = config;
567     }
568
569     /**
570      **
571      **/

572     public org.objectweb.openccm.Containers.SystemConfiguration
573     get_home_configuration()
574     {
575         return home_configuration_;
576     }
577
578     /**
579      **
580      **/

581     public void
582     set_component_configuration(org.objectweb.openccm.Containers.SystemConfiguration config)
583     {
584         component_configuration_ = config;
585     }
586
587     /**
588      **
589      **/

590     public org.objectweb.openccm.Containers.SystemConfiguration
591     get_component_configuration()
592     {
593         return component_configuration_;
594     }
595
596     /**
597      ** Add the home to the container inner list
598      **
599      ** @param ref the reference of the home to add
600      **/

601     public void
602     add_home(org.omg.Components.CCMHome ref)
603     {
604         homes_.add(ref);
605         listener_.on_add(ref);
606     }
607     
608     /**
609      ** Add a reference on the parent ContainerSeg
610      **/

611     public void
612     set_container_home_info(ContainerHomeInformation containerHomeInfo)
613     {
614          this.containerHomeInfo=containerHomeInfo;
615     }
616                     
617     /**
618      ** Accessor to the containerSeg
619      **/

620     public ContainerHomeInformation
621     get_container_home_info()
622     {
623         return containerHomeInfo;
624     }
625      
626     
627     
628     // ==================================================================
629
//
630
// Methods for the Components::Deployment::Container interface.
631
//
632
// ==================================================================
633

634     //
635
// IDL:omg.org/Components/Deployment/ComponentServer/configuration:1.0
636
//
637
/**
638      ** To obtain the container configuration.
639      **
640      **/

641     public org.omg.Components.ConfigValue[]
642     configuration()
643     {
644         return configuration_;
645     }
646
647     //
648
// IDL:omg.org/Components/Deployment/Container/get_component_server:1.0
649
//
650
/**
651      ** To obtain a reference on the component server that has created this container.
652      **/

653     public org.omg.Components.Deployment.ComponentServer
654     get_component_server()
655     {
656         return the_component_server_.asComponentServer();
657     }
658
659     //
660
// IDL:omg.org/Components/Deployment/Container/install_home:1.0
661
//
662
/**
663      * Install a home in the container.
664      * This can be done more than once.
665      *
666      * @param uuid Implementation identifier.
667      * @param entrypt The entry point method.
668      * @param config The configuration values.
669      *
670      * @return The created home.
671      *
672      * @exception UnknownImplId Invalid implementation identifier.
673      * @exception ImplEntryPointNotFound Invalid entry point.
674      * @exception InstallationFailure Installation failure.
675      * @exception InvalidConfiguration Invalid configuration values.
676      */

677     public org.omg.Components.CCMHome
678     install_home(java.lang.String JavaDoc uuid,
679                  java.lang.String JavaDoc entrypt,
680                  org.omg.Components.ConfigValue[] config)
681     throws org.omg.Components.Deployment.UnknownImplId,
682            org.omg.Components.Deployment.ImplEntryPointNotFound,
683            org.omg.Components.Deployment.InstallationFailure,
684            org.omg.Components.Deployment.InvalidConfiguration
685     {
686         try {
687        
688             // Retrieve the archive and load it into the class loader.
689
// Here the ComponentInstallation is used to retrieve the archive
690
// local URL.
691
load_lib_dependency(uuid);
692             
693             // load lib dependencies in the container class loader.
694
for (int i=0; i<config.length; i++)
695              {
696                  if (config[i].name.equals("load_lib_dependency"))
697                  {
698                      load_lib_dependency(config[i].value.extract_string());
699                  }
700              }
701
702             // retrieve the script from the config values.
703
java.lang.String JavaDoc script = "";
704             for (int i=0; i<config.length; i++)
705             {
706                 if (config[i].name.equals("home_script"))
707                 {
708                     try
709                     {
710                         script = config[i].value.extract_string();
711                     }
712                     catch(org.omg.CORBA.SystemException JavaDoc exc)
713                     {
714                         trace_error("install_home",
715                                     "Invalid type for the 'home_script' configuration value, a string is expected!!!",
716                                     null);
717                         throw new org.omg.Components.Deployment.InvalidConfiguration(
718                                       org.omg.Components.Deployment.InvalidConfigValueType.value,
719                                       "home_script");
720                     }
721                     break;
722                 }
723             }
724
725             // executes the specific configuration script.
726
try
727             {
728                 josh_.eval(script);
729             }
730             catch(fr.lifl.cim.jidlscript.lang.JISError exc)
731             {
732                 trace_error("install_home",
733                             "Invalid value for the 'home_script' configuration value!!!\n"
734                             + script,
735                             null);
736                 throw new org.omg.Components.Deployment.InvalidConfiguration(
737                               org.objectweb.openccm.Deployment.InvalidConfigValue.value,
738                               "home_script");
739             }
740         // begin MI modif
741
/////////////////////////////////////////////
742
// create the home type MI for the given home
743
/////////////////////////////////////////////
744
// retrieving IDL Declaration name
745
String JavaDoc IDL_name = retrieve_MI_name(entrypt);
746         if (IDL_name != null)
747         {
748           // setting the class and method name
749
String JavaDoc methodName = IDL_name + "_homeMI.create_type_MI";
750           // call the computed name method (static)
751
try
752           {
753           home_type_ =
754             (HomeType) TheURLClassLoader
755               .getURLClassLoader()
756               .callStaticClassMethod(
757               methodName,
758               new Object JavaDoc[0]);
759           }
760           catch(Exception JavaDoc e)
761               {
762                   // the home type entrypt is not available and
763
// the home_type is not created
764
home_type_ = null;
765               }
766         }
767         // End of MI modif
768
// create the home executor.
769
org.omg.Components.HomeExecutorBase home =
770                 create_home_executor(entrypt);
771
772             String JavaDoc clazz_name = computeFullHomeServantClassName(home.getClass());
773             if (clazz_name == null)
774             {
775                 trace_error("install_home",
776                             "Home servant class for " + home.getClass().getName() + " not found!!!",
777                              null);
778                 throw new org.omg.Components.Deployment.InstallationFailure(
779                               org.objectweb.openccm.Deployment.HomeServantClassNotFound.value
780                           );
781             }
782
783             // Instantiate the executor.
784
org.objectweb.openccm.Containers.HomeExecutorBase home_exec =
785                 (org.objectweb.openccm.Containers.HomeExecutorBase)
786                 create_home_executor(clazz_name + "._create_home_executor");
787
788             home_exec._delegate(home);
789
790             // create the home servant and set infos.
791
org.objectweb.openccm.Containers.HomeServantImpl servant =
792                 new org.objectweb.openccm.Containers.HomeServantImpl();
793             servant.the_container_base(this);
794             home_exec._home_servant(servant);
795             servant.the_home_executor(home_exec);
796             servant.the_home_configuration(get_home_configuration());
797             servant.the_component_configuration(get_component_configuration());
798             servant.the_home_finder(home_manager_);
799         ///////////////////////////// MODIF MetaInformation
800
if (home_type_ != null)
801         {
802           HomeInstance _tmp_hi = home_type_.create_home_instance();
803           if (_tmp_hi == null)
804           {
805             trace_error("install_home", "home instance is null ", null);
806           }
807           servant.the_home_instance(_tmp_hi);
808           
809         }
810         else
811         {
812           trace_error(
813             "retrieve_MI_name",
814             "Instance MetaInformation for HomeFinder not supported ",
815             null);
816         }
817             // create and set the home reference.
818
org.omg.Components.CCMHome ref = rootPCA_.activate_home(servant);
819             
820
821             int h_s=homes_.size();
822             listener_.on_create(ref);
823             if(homes_.size()==h_s){
824                  homes_.add(ref);
825               }
826             return ref;
827         }
828         catch(org.omg.Components.Deployment.UnknownImplId exc)
829         {
830             trace_error("install_home", "Throw exception " + exc.getMessage(), null);
831             throw exc;
832         }
833         catch(org.omg.Components.Deployment.ImplEntryPointNotFound exc)
834         {
835             trace_error("install_home", "Throw exception " + exc.getMessage(), null);
836             throw exc;
837         }
838         catch(org.omg.Components.Deployment.InstallationFailure exc)
839         {
840             trace_error("install_home", "Throw exception " + exc.getMessage(), null);
841             throw exc;
842         }
843         catch(org.omg.Components.Deployment.InvalidConfiguration exc)
844         {
845             trace_error("install_home", "Throw exception " + exc.getMessage(), null);
846             throw exc;
847         }
848         catch(Throwable JavaDoc exc)
849         {
850             trace_error("install_home", "Unexpected Java exception!", exc);
851             trace_error("install_home", "Throw exception Components::Deployment::InstallationFailure", null);
852             throw new org.omg.Components.Deployment.InstallationFailure(
853                           org.objectweb.openccm.Deployment.UnknownInstallationFailureReason.value
854                       );
855         }
856     }
857
858     //
859
// IDL:omg.org/Components/Deployment/Container/remove_home:1.0
860
//
861
/**
862      **
863      **/

864     public void
865     remove_home(org.omg.Components.CCMHome ref)
866     throws org.omg.Components.RemoveFailure
867     {
868 /* Bug #306
869    OLD CODE
870
871         listener_.on_remove(ref);
872         boolean b = homes_.remove(ref);
873         if (!b)
874             throw new org.omg.Components.RemoveFailure();
875
876    NEW CODE
877 */

878
879       // Tests if ref is a home of this containers.
880
for(int i=0; i<homes_.size(); i++)
881       {
882           org.omg.Components.CCMHome h =
883               (org.omg.Components.CCMHome)homes_.get(i);
884
885           // If ref is a home of this container then removes it.
886
if(ref._is_equivalent(h))
887       {
888               ref.remove_home();
889               return;
890           }
891       }
892
893       // Else ref is not a home of this container.
894
throw new org.omg.Components.RemoveFailure();
895     }
896
897     //
898
// IDL:omg.org/Components/Deployment/Container/get_homes:1.0
899
//
900
/**
901      **
902      **/

903     public org.omg.Components.CCMHome[]
904     get_homes()
905     {
906         org.omg.Components.CCMHome[] result =
907             new org.omg.Components.CCMHome[homes_.size()];
908
909         for (int i=0;i<result.length;i++)
910             result[i] = (org.omg.Components.CCMHome)homes_.get(i);
911
912         return result;
913     }
914
915     //
916
// IDL:omg.org/Components/Deployment/Container/remove:1.0
917
//
918
/**
919      **
920      **/

921     public void
922     remove()
923     throws org.omg.Components.RemoveFailure
924     {
925 /* Bug #306
926    NEW CODE
927 */

928
929         // Removes all its homes.
930
org.omg.Components.CCMHome[] homes = get_homes();
931         for(int i=0; i<homes.length; i++)
932         {
933             homes[i].remove_home();
934         }
935         if(listener_!=null)
936             listener_.on_destroy();
937         
938         // Unregister the container from its component server.
939
if(the_component_server_!=null)
940             the_component_server_.unregister_container(the_container_ref());
941           
942         try {
943             org.objectweb.openccm.corba.TheRootPOA.getRootPOA().deactivate_object(org.objectweb.openccm.corba.TheRootPOA.getRootPOA().reference_to_id(the_container_ref()));
944             
945         } catch (org.omg.PortableServer.POAPackage.WrongAdapter JavaDoc ex) {
946             throw new org.omg.Components.RemoveFailure();
947         } catch (org.omg.PortableServer.POAPackage.WrongPolicy JavaDoc ex) {
948             throw new org.omg.Components.RemoveFailure();
949         } catch (org.omg.PortableServer.POAPackage.ObjectNotActive JavaDoc ex) {
950             throw new org.omg.Components.RemoveFailure();
951         }
952     }
953 }
954
Popular Tags