Salome HOME
PR: merge from tag mergeto_HEAD_25Jan05
[modules/kernel.git] / src / NamingService / SALOME_NamingService.cxx
1 //  SALOME NamingService : wrapping NamingService services
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SALOME_NamingService.cxx
25 //  Author : Estelle Deville
26 //  Module : SALOME
27 //  $Header$
28
29 #include "SALOME_NamingService.hxx"
30 #include "ServiceUnreachable.hxx"
31
32 #include "utilities.h"
33
34 #include <iostream>
35 #include <cstring>
36
37 using namespace std;
38
39 //----------------------------------------------------------------------
40 /*! Function : SALOME_NamingService
41  *  Purpose  : Constructor and Initialisation of _root_context
42  */
43 //----------------------------------------------------------------------
44
45 SALOME_NamingService::SALOME_NamingService()
46 {
47   MESSAGE("SALOME_NamingService default constructor");
48   _orb = CORBA::ORB::_nil();
49 }
50
51 //----------------------------------------------------------------------
52 /*! Function : SALOME_NamingService
53  * \param orb CORBA::ORB_ptr arguments
54  */
55 //----------------------------------------------------------------------
56
57 SALOME_NamingService::SALOME_NamingService(CORBA::ORB_ptr orb)
58 {
59   MESSAGE("SALOME_NamingService creation");
60   _orb = orb ;
61   _initialize_root_context();
62 }
63
64 //----------------------------------------------------------------------
65 /*! Function : ~SALOME_NamingService
66  *  Purpose  : Destructor
67  */
68 //----------------------------------------------------------------------
69
70 SALOME_NamingService::~SALOME_NamingService()
71 {
72   MESSAGE("SALOME_NamingService destruction");
73 }
74
75 //----------------------------------------------------------------------
76 /*! Function : init_orb
77  *  initialize ORB reference after default constructor
78  */
79 //----------------------------------------------------------------------
80
81 void SALOME_NamingService::init_orb(CORBA::ORB_ptr orb)
82 {
83   // MESSAGE("SALOME_NamingService initialisation");
84   _orb = orb ;
85   _initialize_root_context();
86 }
87
88
89 //----------------------------------------------------------------------
90 /*! Function : Register
91  *  Method to create an association in the NamingService between ObjRef
92  *  and Path.
93  *  If the NamingService is out, the exception ServiceUnreachable is thrown
94  * \param ObjRef CORBA::Object_ptr arguments
95  * \param Path const char* arguments
96  */ 
97 //----------------------------------------------------------------------
98
99 void SALOME_NamingService::Register(CORBA::Object_ptr ObjRef,
100                                     const char* Path) 
101   throw(ServiceUnreachable)
102 {
103   // MESSAGE("BEGIN OF Register: "<< Path);
104   int dimension_Path = strlen(Path) + 1;
105   char** resultat_resolve_Path = new char* [dimension_Path];
106
107   // _current_context is replaced to the _root_context 
108   // if the Path begins whith '/'
109   if (Path[0]=='/')  {
110     _current_context = _root_context;
111     //    MESSAGE("Gone to the _root_context");
112   }
113   
114   //the resolution of the directory path has to be done
115   //to place the currect_context to the correct node
116   int dimension_resultat = 0;
117   _result_resolve_Path (Path, dimension_resultat, resultat_resolve_Path);
118     
119   CosNaming::Name _context_name;
120   CORBA::Boolean _not_exist = false ;
121   CosNaming::NamingContext_var _temp_context;
122   
123   if(dimension_resultat>1)
124     {  
125       // A directory is treated (not only an object name)
126       // We had to test if the directory where ObjRef should be recorded 
127       // is already done
128       // If not, the new context has to be created
129
130       //      MESSAGE("A complet Path has to be treated, not only an object name");
131       _context_name.length(dimension_resultat-1);
132
133       _create_context_name_dir(resultat_resolve_Path,dimension_resultat-1,
134                                _context_name);  
135
136       try
137         {
138           CORBA::Object_var _obj = _current_context->resolve(_context_name);
139           _current_context = CosNaming::NamingContext::_narrow(_obj);
140         } 
141       catch (CosNaming::NamingContext::NotFound &) 
142         {
143           // failed to resolve, therefore assume cold start
144           _not_exist = true;
145         } 
146       catch (CosNaming::NamingContext::InvalidName &) 
147         {
148           INFOS("!!!Register() : CosNaming::NamingContext::InvalidName"); 
149         }
150       catch (CosNaming::NamingContext::CannotProceed &)
151         {
152           INFOS("!!!Register() : CosNaming::NamingContext::CannotProceed");
153         }
154       catch(CORBA::COMM_FAILURE&)
155         {
156           INFOS("!!!Register() : CORBA::COMM_FAILURE : unable to contact"
157                << " the naming service"); 
158           throw ServiceUnreachable();
159         }
160       if(_not_exist)
161         {
162           try
163             {
164               _context_name.length(1);
165               // MESSAGE("The Path indicated is not yet created. It will soon be done");
166               for (int i = 0 ; i <dimension_resultat -1 ;i++)
167                 {
168                   _context_name[0].id =
169                     CORBA::string_dup(resultat_resolve_Path[i]);
170                   _context_name[0].kind = CORBA::string_dup("dir");
171                   // SCRUTE(_context_name[0].id);
172                   //The Path could be in part already created. 
173                   //We had to test it
174                   try 
175                     {
176                       // this context is already created. 
177                       // Nothing to be done
178                       CORBA::Object_var _obj = 
179                         _current_context->resolve(_context_name);
180                       _current_context = 
181                         CosNaming::NamingContext::_narrow(_obj);
182                       //MESSAGE("This context was already created");
183                     } 
184                   catch (CosNaming::NamingContext::NotFound &) 
185                     {
186                       // This context is not created. It will be done
187                       _temp_context =
188                         _current_context->bind_new_context(_context_name);
189                       _current_context = _temp_context;
190                       //INFOS("This context was'nt created, it's now done");
191                     }
192                 }
193             }
194           catch (CosNaming::NamingContext::AlreadyBound&)
195             {
196               INFOS("!!!Register() : CosNaming::NamingContext::AlreadyBound");  
197             }
198           catch(CosNaming::NamingContext::NotFound& ex)
199             {
200               CosNaming::Name n = ex.rest_of_name;
201               if (ex.why == CosNaming::NamingContext::missing_node)
202                 INFOS("Register() : " << (char *) n[0].id
203                       << " (" << (char *) n[0].kind << ") not found");
204               if (ex.why == CosNaming::NamingContext::not_context)
205                 INFOS("Register() : " << (char *) n[0].id
206                      << " (" << (char *) n[0].kind
207                      << ") is not a context");
208               if (ex.why == CosNaming::NamingContext::not_object)
209                 INFOS("Register() : " << (char *) n[0].id
210                      << " (" << (char *) n[0].kind
211                      << ") is not an object");
212             }
213           catch(CosNaming::NamingContext::CannotProceed&)
214             {
215               INFOS("!!!Register() : CosNaming::NamingContext::CannotProceed");
216             } 
217           catch(CosNaming::NamingContext::InvalidName&) 
218             {
219               INFOS("!!!Register() : CosNaming::NamingContext::InvalidName");
220             }
221           catch(CORBA::COMM_FAILURE&)
222             {
223               INFOS("!!!Register() :CORBA::COMM_FAILURE : unable to contact"
224                    << " the naming service"); 
225               throw ServiceUnreachable();
226             }
227         }       
228     }
229
230   // The current directory is now the directory where the object should 
231   // be recorded
232   _context_name.length(1);
233   try 
234     {
235       // the last element is an object an not a directory
236       _context_name[0].id = 
237         CORBA::string_dup(resultat_resolve_Path[dimension_resultat -1]);
238       _context_name[0].kind = CORBA::string_dup("object");
239       //SCRUTE(_context_name[0].id);
240         
241       _current_context->bind(_context_name, ObjRef);
242       // MESSAGE("A new element " << _context_name[0].id 
243       //           << " is recorded in the _current_context");   
244     }
245   catch(CosNaming::NamingContext::NotFound& ex)
246     {
247       CosNaming::Name n = ex.rest_of_name;
248       if (ex.why == CosNaming::NamingContext::missing_node)
249         INFOS("Register() : "  << (char *) n[0].id
250               << " ("  << (char *) n[0].kind << ") not found");
251       if (ex.why == CosNaming::NamingContext::not_context)
252         INFOS("Register() : " << (char *) n[0].id
253              << " (" << (char *) n[0].kind
254              << ") is not a context");
255       if (ex.why == CosNaming::NamingContext::not_object)
256         INFOS("Register() : " << (char *) n[0].id
257              << " (" << (char *) n[0].kind
258              << ") is not an object");
259     }
260   catch(CosNaming::NamingContext::CannotProceed&)
261     {
262       INFOS("!!!Register() : CosNaming::NamingContext::CannotProceed"); 
263     } 
264   catch(CosNaming::NamingContext::InvalidName&) 
265     {
266       INFOS("!!!Register() : CosNaming::NamingContext::InvalidName"); 
267     }
268   catch(CosNaming::NamingContext::AlreadyBound&) 
269     {
270       INFOS("!!!Register() : CosNaming::NamingContext::AlreadyBound, object will be rebind"); 
271       _current_context->rebind(_context_name, ObjRef);
272     }
273   catch(CORBA::COMM_FAILURE&)
274     {
275       INFOS("!!!Register() :CORBA::COMM_FAILURE : unable to contact"
276             << " the naming service");
277       throw ServiceUnreachable();
278     }
279   
280   
281   // Memory destruction
282   for (int i = 0 ; i <dimension_resultat ;i++) 
283     {
284       delete [] resultat_resolve_Path[i];     
285     }
286   delete[] resultat_resolve_Path ;
287 }
288
289 //----------------------------------------------------------------------
290 /*! Function : Resolve 
291  *  Purpose  : method to get the ObjRef of a symbolic name
292  *  If the NamingService is out, the exception ServiceUnreachable is thrown 
293  * \param Path const char* arguments
294  * \return the object reference
295  */
296 //----------------------------------------------------------------------
297
298 CORBA::Object_ptr SALOME_NamingService::Resolve(const char* Path)
299   throw(ServiceUnreachable)
300 {
301   //MESSAGE("BEGIN OF Resolve: " << Path);
302   int dimension_Path = strlen(Path) + 1;
303   char** resultat_resolve_Path = new char* [dimension_Path];
304
305   // _current_context is replaced to the _root_context 
306   // if the Path begins whith '/'
307   if (Path[0]=='/') _current_context = _root_context;
308
309   
310   //the resolution of the directory path has to be done
311   //to place the currect_context to the correct node
312   int dimension_resultat = 0;
313   _result_resolve_Path (Path, dimension_resultat, resultat_resolve_Path);
314     
315   CosNaming::Name _context_name;
316   _context_name.length(dimension_resultat);
317   CORBA::Object_ptr _obj = NULL ;
318     
319   _create_context_name_dir(resultat_resolve_Path,dimension_resultat-1,
320                            _context_name);
321   // the last element is an object an not a directory
322   _context_name[dimension_resultat -1].id = 
323     CORBA::string_dup(resultat_resolve_Path[dimension_resultat -1]);
324   _context_name[dimension_resultat -1].kind = CORBA::string_dup("object");
325   // SCRUTE(_context_name[dimension_resultat -1].id);
326   ASSERT(!CORBA::is_nil(_current_context));
327   // Context creation
328   try 
329     {
330       _obj =_current_context->resolve(_context_name);
331     }
332   catch(CosNaming::NamingContext::NotFound& ex)
333     {
334       CosNaming::Name n = ex.rest_of_name;
335       if (ex.why == CosNaming::NamingContext::missing_node)
336         INFOS("Resolve() : " << (char *) n[0].id
337               << " (" << (char *) n[0].kind << ") not found");
338       if (ex.why == CosNaming::NamingContext::not_context)
339         INFOS("Resolve() : "
340              << (char *) n[0].id  << " (" << (char *) n[0].kind
341              << ") is not a context");
342       if (ex.why == CosNaming::NamingContext::not_object)
343         INFOS("Resolve() : " << (char *) n[0].id
344              << " (" << (char *) n[0].kind
345              << ") is not an object");
346     }
347   catch(CosNaming::NamingContext::CannotProceed&)
348     {
349       INFOS("!!!Resolve() : CosNaming::NamingContext::CannotProceed"); 
350     } 
351   catch(CosNaming::NamingContext::InvalidName&) 
352     {
353       INFOS("!!!Resolve() : CosNaming::NamingContext::InvalidName"); 
354     }
355   catch(CORBA::COMM_FAILURE&)
356     {
357       INFOS("!!!Resolve() :CORBA::COMM_FAILURE : unable to contact"
358             << "the naming service");
359       throw ServiceUnreachable();
360     }
361   // Memory destruction
362   for (int i = 0 ; i <dimension_resultat ;i++) 
363     {
364       delete [] resultat_resolve_Path[i];     
365     }
366   delete[] resultat_resolve_Path ;
367   
368   return _obj;
369 }
370
371 //----------------------------------------------------------------------
372 /*!  Function : Find
373  *  Purpose  : method to research a name from the current directory 
374  *            of the naming service. 
375  *  The naming service changes directory to go to the directory where 
376  *  the last occurence was found.
377  *  If the NamingService is out, the exception ServiceUnreachable is thrown
378  *  \param name const char* arguments
379  *  \return the number of occurences found
380  *  \sa _Find
381  */   
382 //----------------------------------------------------------------------
383
384 int SALOME_NamingService::Find(const char* name)
385   throw(ServiceUnreachable)
386 {
387   // MESSAGE("BEGIN OF Find " << name);
388   CORBA::Long occurence_number = 0 ; 
389   try
390     {
391       _Find(name,occurence_number);
392     }
393   catch(CORBA::COMM_FAILURE&)
394     {
395       INFOS("!!!Find() : CORBA::COMM_FAILURE : unable to contact"
396            << " the naming service"); 
397       throw ServiceUnreachable();
398     }
399   return occurence_number;
400 }
401
402 //----------------------------------------------------------------------
403 /*! Function : Create_Directory 
404  *  Purpose  : method to create a directory from the current directory.
405  * If the NamingService is out, the exception ServiceUnreachable is thrown
406  *  \param Path const char* arguments
407  *  \return a boolean to indicate if the creation succeeded
408  */
409 //----------------------------------------------------------------------
410
411 bool SALOME_NamingService::Create_Directory(const char* Path)
412   throw(ServiceUnreachable)
413 {
414   //MESSAGE("BEGIN OF Create_Directory");
415   int dimension_Path = strlen(Path) + 1;
416   char** resultat_resolve_Path= new char* [dimension_Path];;
417   CORBA::Boolean _return_code = true ;
418
419   // _current_context is replaced to the _root_context 
420   // if the Path begins whith '/'
421   if (Path[0]=='/') _current_context = _root_context;
422
423   int dimension_resultat = 0;
424   _result_resolve_Path (Path, dimension_resultat, resultat_resolve_Path);
425
426  
427   // We had to test if a part of the directory to treat 
428   // is already done
429   // If not, the new context has to be created
430  
431   CosNaming::Name _context_name;
432   _context_name.length(1);
433   CosNaming::NamingContext_var _temp_context;
434   ASSERT(!CORBA::is_nil(_current_context));
435   // Context creation
436   try
437     {
438         
439       for (int i = 0 ; i <dimension_resultat ;i++)
440         {
441           _context_name[0].id =
442             CORBA::string_dup(resultat_resolve_Path[i]);
443           _context_name[0].kind = CORBA::string_dup("dir");
444           // SCRUTE(_context_name[0].id);
445           //The Path could be in part already created. 
446           //We had to test it
447           try 
448             {
449               // this context is already created. 
450               // Nothing to be done
451               CORBA::Object_var _obj = 
452                 _current_context->resolve(_context_name);
453               _current_context = 
454                 CosNaming::NamingContext::_narrow(_obj);
455               MESSAGE("This context was already created");
456                 } 
457           catch (CosNaming::NamingContext::NotFound &) 
458             {
459               // This context is not created. It will be done
460               _temp_context =
461                 _current_context->bind_new_context(_context_name);
462               _current_context = _temp_context;
463               INFOS("This context was'nt created, it's now done");
464                 }
465         }
466     }
467   catch (CosNaming::NamingContext::AlreadyBound&)
468     {
469       INFOS("!!! Create_Directory() CosNaming::NamingContext::AlreadyBound");
470       _return_code = false;     
471     }
472   catch(CosNaming::NamingContext::NotFound& ex)
473     {
474       _return_code = false;
475       CosNaming::Name n = ex.rest_of_name;
476       if (ex.why == CosNaming::NamingContext::missing_node)
477         INFOS("Create_Directory() : " << (char *) n[0].id
478               << " (" << (char *) n[0].kind << ") not found");
479       if (ex.why == CosNaming::NamingContext::not_context)
480         INFOS("Create_Directory() : " << (char *) n[0].id
481              << " (" << (char *) n[0].kind
482              << ") is not a context");
483       if (ex.why == CosNaming::NamingContext::not_object)
484         INFOS("Create_Directory() : " << (char *) n[0].id
485              << " (" << (char *) n[0].kind
486              << ") is not an object");
487     }
488   catch(CosNaming::NamingContext::CannotProceed&)
489     {
490       _return_code = false;
491       INFOS("!!!Create_Directory():CosNaming::NamingContext::CannotProceed"); 
492     } 
493   catch(CosNaming::NamingContext::InvalidName&) 
494     {
495       _return_code = false;
496       INFOS("!!!Create_Directory():CosNaming::NamingContext::InvalidName");
497     }
498   catch(CORBA::COMM_FAILURE&)
499     {
500       _return_code = false;
501       INFOS("!!!Register() :CORBA::COMM_FAILURE : unable to contact"
502            << " the naming service"); 
503       throw ServiceUnreachable();
504     }
505   // Memory destruction
506   for (int i = 0 ; i <dimension_resultat;i++) 
507     {
508       delete [] resultat_resolve_Path[i];     
509     }
510   delete[] resultat_resolve_Path ;
511   return _return_code;
512 }
513
514 //----------------------------------------------------------------------
515 /*! Function : Change_Directory 
516  *  Purpose  : method to change the current directory to the
517  *             directory Path indicated in "in" Parameter.
518  *  If Path ="/", the current directory changes to the root directory.
519  *  If the NamingService is out, the exception ServiceUnreachable is thrown.
520  * \param Path const char* arguments
521  * \return a boolean to indicate if the change succeeded
522  */
523 //----------------------------------------------------------------------
524
525 bool SALOME_NamingService::Change_Directory(const char* Path)
526   throw(ServiceUnreachable)
527 {
528   //MESSAGE("BEGIN OF Change_Directory " << Path);
529   int dimension_Path = strlen(Path) + 1;
530   char** resultat_resolve_Path = new char* [dimension_Path];
531   CORBA::Boolean _return_code = true ;
532
533   // _current_context is replaced to the _root_context 
534   // if the Path begins whith '/'
535   if (Path[0]=='/') _current_context = _root_context;
536
537   if ((Path[0]=='/') && (dimension_Path == 2))
538     {
539       MESSAGE("Change_Directory is called to go to the root_context");
540     }
541   //nothing to de done, the change_dur is called to go to the root_context
542   // no Path to resolve
543   else
544     //the resolution of the directory path has to be done
545     //to place the currect_context to the correct node
546     {
547       int dimension_resultat = 0;
548       _result_resolve_Path(Path,dimension_resultat,resultat_resolve_Path);
549           
550       CosNaming::Name _context_name;
551       _context_name.length(dimension_resultat);
552       CORBA::Object_var _obj;
553
554       _create_context_name_dir(resultat_resolve_Path,dimension_resultat,
555                                _context_name);
556
557       ASSERT(!CORBA::is_nil(_current_context));
558       // Context creation
559       try 
560         {
561           _obj =_current_context->resolve(_context_name);
562           _current_context = CosNaming::NamingContext::_narrow(_obj);
563           ASSERT(!CORBA::is_nil(_current_context))
564             }
565       catch(CosNaming::NamingContext::NotFound& ex)
566         {
567           _return_code = false;
568           CosNaming::Name n = ex.rest_of_name;
569           if (ex.why == CosNaming::NamingContext::missing_node)
570             INFOS( "Change_Directory() : " << (char *) n[0].id
571                   << " (" << (char *) n[0].kind << ") not found")
572           if (ex.why == CosNaming::NamingContext::not_context)
573             INFOS("Change_Directory() : " << (char *) n[0].id
574                  << " (" << (char *) n[0].kind
575                  << ") is not a context" )
576           if (ex.why == CosNaming::NamingContext::not_object)
577             INFOS( "Change_Directory() : " << (char *) n[0].id
578                  << " (" << (char *) n[0].kind
579                  << ") is not an object" )
580         }
581       catch(CosNaming::NamingContext::CannotProceed&)
582         {
583           _return_code = false;
584           INFOS( "!!!Change_Directory() : CosNaming::NamingContext::CannotProceed" )
585         } 
586       catch(CosNaming::NamingContext::InvalidName&) 
587         {
588           _return_code = false;
589           INFOS( "!!!Change_Directory() : CosNaming::NamingContext::InvalidName" )
590         }
591       catch(CORBA::COMM_FAILURE&)
592         {
593           _return_code = false;
594           INFOS( "!!!Change_Directory() :CORBA::COMM_FAILURE : unable to contact"
595                << "the naming service")
596           throw ServiceUnreachable();
597         }
598       // Memory destruction
599       for (int i = 0 ; i <dimension_resultat ;i++) 
600         {
601           delete [] resultat_resolve_Path[i];     
602         }
603       delete[] resultat_resolve_Path ;
604     }
605   return _return_code;
606 }
607
608 //----------------------------------------------------------------------
609 /*! Function : Current_Directory 
610  *  Purpose  : method to get the current directory.
611  *  If the NamingService is out, the exception ServiceUnreachable is thrown
612  * \return the path of the current_context
613  * \sa  _current_directory
614  */ 
615 //----------------------------------------------------------------------
616
617 char* SALOME_NamingService::Current_Directory()
618   throw(ServiceUnreachable)
619 {
620   //MESSAGE("BEGIN OF Current_Directory");  
621
622   CosNaming::NamingContext_var _ref_context = _current_context;
623
624   int i = 0;
625   int length_path = 0;
626   char** result_path = new char*[50]; // 50 is it enough?
627
628  
629   // We go to the root_context to begin the search from the root
630   _current_context = _root_context ;
631   CORBA::Boolean _continue = true ;
632   try
633     {
634       _current_directory(result_path,i,_ref_context,_continue );
635     }
636   catch(CORBA::COMM_FAILURE&)
637     {
638       INFOS("!!!Current_Directory(): CORBA::COMM_FAILURE : unable to contact"
639            << " the naming service" )
640       throw ServiceUnreachable();
641     }
642   for (int k = 0 ; k <i ;k++) 
643     { 
644       // We count the length of the char* + 1 for the '/' to separate
645       // the directories
646       length_path = length_path + strlen(result_path[k]) + 1;
647     }
648   char* return_Path = new char[length_path +2];
649   return_Path[0] = '/' ;
650   return_Path[1] = '\0' ;
651   for (int k = 0 ; k <i ;k++) 
652     { 
653       //SCRUTE(result_path[k])
654         strcat(return_Path,result_path[k]);
655       strcat(return_Path,"/");
656     }
657   //SCRUTE(return_Path)
658     _current_context = _ref_context ;
659  
660   return return_Path;
661 }
662
663 //----------------------------------------------------------------------
664 /*! Function : list
665  *  Purpose  : method to list and print all the context contained from
666  *            the current context
667  *  If the NamingService is out, the exception ServiceUnreachable is thrown
668  */ 
669 //----------------------------------------------------------------------
670
671 void SALOME_NamingService::list()
672   throw(ServiceUnreachable)
673 {
674   MESSAGE("Begin of list");
675   CosNaming::BindingList_var _binding_list;
676   CosNaming::BindingIterator_var _binding_iterator;
677   unsigned long nb=0 ; // for using only the BindingIterator to access the bindings
678   CosNaming::Binding_var _binding ;
679   CosNaming::NamingContext_var _ref_context = _current_context;
680   _current_context->list(nb, _binding_list, _binding_iterator) ;
681
682   while (_binding_iterator->next_one(_binding)) {
683     CosNaming::Name _bindingName = _binding->binding_name;
684     if (_binding->binding_type == CosNaming::ncontext) {
685       MESSAGE( "Context : " << _bindingName[0].id );
686       try
687         {
688           Change_Directory(_bindingName[0].id);
689         }
690       catch (ServiceUnreachable&)
691         {
692           INFOS( "!!!list(): ServiceUnreachable" )
693           throw ServiceUnreachable(); 
694         }
695
696       list();
697       _current_context = _ref_context ;
698     }
699     else if (_binding->binding_type == CosNaming::nobject) {
700       MESSAGE( "Object : " << _bindingName[0].id );
701     }
702   }
703   _binding_iterator->destroy();
704 }
705
706 //----------------------------------------------------------------------
707 /*! Function : list_directory
708  *  Purpose  : method to get all the contexts contained in the current 
709  *             directory
710  *             Get only objects, isn't iterative 
711  *  If the NamingService is out, the exception ServiceUnreachable is thrown
712  */ 
713 //----------------------------------------------------------------------
714 vector<string> SALOME_NamingService::list_directory()
715   throw(ServiceUnreachable)
716 {
717   vector<string> _list ;
718   _list.resize(0);
719   CosNaming::BindingList_var _binding_list;
720   CosNaming::BindingIterator_var _binding_iterator;
721   unsigned long nb=0 ; // for using only the BindingIterator to access the bindings
722   CosNaming::Binding_var _binding ;
723   CosNaming::NamingContext_var _ref_context = _current_context;
724   _current_context->list(nb, _binding_list, _binding_iterator) ;
725   if (_binding_iterator->_is_nil()) return _list;
726
727   while (_binding_iterator->next_one(_binding)) {
728     CosNaming::Name _bindingName = _binding->binding_name;
729     if (_binding->binding_type == CosNaming::nobject) {
730       _list.push_back(CORBA::string_dup(_bindingName[0].id));
731     }
732   }
733   //for (unsigned int ind = 0; ind < _list.size(); ind++)
734   //  MESSAGE("list_directory : Object : " << _list[ind]);
735
736   _binding_iterator->destroy();
737   return _list;
738 }
739
740 //----------------------------------------------------------------------
741 /*! Function : list_directory_recurs
742  *  Purpose  : method to get all the contexts contained in the current 
743  *             directory
744  *             Get only objects and is recursive 
745  *  If the NamingService is out, the exception ServiceUnreachable is thrown
746  */ 
747 //----------------------------------------------------------------------
748 vector<string> SALOME_NamingService::list_directory_recurs()
749     throw(ServiceUnreachable)
750 {
751   vector<string> _list ;
752   char *currentDir=Current_Directory();
753   _list_directory_recurs(_list,0,currentDir);
754   delete [] currentDir;
755   return _list;
756 }
757
758 //----------------------------------------------------------------------
759 /*! Function : Destroy_Name 
760  *  Purpose  : method to destroy an association Path-Object Reference.
761  *             WARNING : The complete Path should be given.
762  *  If the NamingService is out, the exception ServiceUnreachable is thrown 
763  * \param Path const char* arguments
764  */
765 //----------------------------------------------------------------------
766
767 void SALOME_NamingService::Destroy_Name(const char* Path)
768   throw(ServiceUnreachable)
769 {
770   MESSAGE("BEGIN OF Destroy_Name");
771   int dimension_Path = strlen(Path) + 1;
772   char** resultat_resolve_Path = new char* [dimension_Path];
773
774   // _current_context is replaced to the _root_context 
775   // if the Path begins whith '/'
776   if (Path[0]=='/') _current_context = _root_context;
777
778   
779   //the resolution of the directory path has to be done
780   //to place the currect_context to the correct node
781   int dimension_resultat = 0;
782   _result_resolve_Path (Path, dimension_resultat, resultat_resolve_Path);
783     
784   CosNaming::Name _context_name;
785   if (dimension_resultat>1)
786     {
787       // We go in the directory where the object to destroy is
788       _context_name.length(dimension_resultat-1);
789   
790       _create_context_name_dir(resultat_resolve_Path,dimension_resultat -1,
791                                _context_name); 
792       try
793         {
794           CORBA::Object_var _obj = _current_context->resolve(_context_name);
795           _current_context = CosNaming::NamingContext::_narrow(_obj);
796         } 
797       catch (CosNaming::NamingContext::NotFound& ex) 
798         {
799           CosNaming::Name n = ex.rest_of_name;
800           if (ex.why == CosNaming::NamingContext::missing_node)
801             INFOS(  "Destroy_Name() : " << (char *) n[0].id
802                   << " (" << (char *) n[0].kind << ") not found" )
803           if (ex.why == CosNaming::NamingContext::not_context)
804             INFOS( "Destroy_Name() : " << (char *) n[0].id
805                  << " (" << (char *) n[0].kind
806                  << ") is not a context" )
807           if (ex.why == CosNaming::NamingContext::not_object)
808             INFOS( "Destroy_Name() : " << (char *) n[0].id
809                  << " ("  << (char *) n[0].kind
810                  << ") is not an object" )
811         } 
812       catch (CosNaming::NamingContext::InvalidName &) 
813         {
814           INFOS( "!!!Destroy_Name() : CosNaming::NamingContext::InvalidName" )
815         }
816       catch (CosNaming::NamingContext::CannotProceed &)
817         {
818           INFOS( "!!!Destroy_Name(): CosNaming::NamingContext::CannotProceed" )
819         }
820       catch(CORBA::COMM_FAILURE&)
821         {
822           INFOS( "!!!Destroy_Name() : CORBA::COMM_FAILURE : unable to contact"
823                << " the naming service")
824           throw ServiceUnreachable();
825         }
826     }
827
828   // the last element is the object to destroy
829   _context_name.length(1);  
830   _context_name[0].id = 
831     CORBA::string_dup(resultat_resolve_Path[dimension_resultat -1]);
832   _context_name[0].kind = CORBA::string_dup("object");
833   SCRUTE(_context_name[0].id);
834   ASSERT(!CORBA::is_nil(_current_context));
835   // Object destruction
836   try 
837     {
838       _current_context->unbind(_context_name);
839       MESSAGE( "The object " << _context_name[0].id  << " has been deleted" )
840     }
841   catch(CosNaming::NamingContext::NotFound& ex)
842     {
843       CosNaming::Name n = ex.rest_of_name;
844       if (ex.why == CosNaming::NamingContext::missing_node)
845         INFOS(  "Destroy_Name() : " << (char *) n[0].id
846               << " (" << (char *) n[0].kind << ") not found" )
847       if (ex.why == CosNaming::NamingContext::not_context)
848         INFOS( "Destroy_Name() : " << (char *) n[0].id
849              << " (" << (char *) n[0].kind
850              << ") is not a context" )
851       if (ex.why == CosNaming::NamingContext::not_object)
852         INFOS( "Destroy_Name() : " << (char *) n[0].id
853              << " ("  << (char *) n[0].kind
854              << ") is not an object" )
855     }
856   catch(CosNaming::NamingContext::CannotProceed&)
857     {
858       INFOS( "!!!Destroy_Name() : CosNaming::NamingContext::CannotProceed")
859     } 
860   catch(CosNaming::NamingContext::InvalidName&) 
861     {
862       INFOS( "!!!Destroy_Name() : CosNaming::NamingContext::InvalidName")
863     }
864   catch(CORBA::COMM_FAILURE&)
865     {
866       INFOS( "!!!Destroy_Name() :CORBA::COMM_FAILURE : unable to contact" 
867            << " the naming service") 
868       throw ServiceUnreachable();
869     }
870   // Memory destruction
871   for (int i = 0 ; i <dimension_resultat ;i++) 
872     {
873       delete [] resultat_resolve_Path[i];     
874     }
875   delete[] resultat_resolve_Path ;
876 }
877
878 //----------------------------------------------------------------------
879 /*! Function : Destroy_Directory.
880  *  Purpose  : method to destroy a directory if it is empty.
881  *  WARNING : The complete Path  to the directory (from the root_context)
882  *  to destroy should be given.
883  *  If the NamingService is out, the exception ServiceUnreachable is thrown.
884  * \param Path const char* arguments
885  */
886 //----------------------------------------------------------------------
887
888 void SALOME_NamingService::Destroy_Directory(const char* Path)
889   throw(ServiceUnreachable)
890 {
891   MESSAGE("BEGIN OF Destroy_Directory");
892   int dimension_Path = strlen(Path) + 1;
893   char** resultat_resolve_Path = new char* [dimension_Path];
894
895   // _current_context is replaced to the _root_context 
896   // if the Path begins whith '/'
897   if (Path[0]=='/') _current_context = _root_context;
898
899   CosNaming::NamingContext_var _ref_context = _current_context;
900  
901   //the resolution of the directory path has to be done
902   //to place the currect_context to the correct node
903   int dimension_resultat = 0;
904   _result_resolve_Path (Path, dimension_resultat, resultat_resolve_Path);
905     
906   CosNaming::Name _context_name;
907   if (dimension_resultat>1)
908     {
909       // We go in the directory where the context to destroy is
910       _context_name.length(dimension_resultat-1);
911   
912       _create_context_name_dir(resultat_resolve_Path,dimension_resultat -1,
913                                _context_name); 
914       try
915         {
916           CORBA::Object_var _obj = _current_context->resolve(_context_name);
917           _current_context = CosNaming::NamingContext::_narrow(_obj);
918           _ref_context = _current_context ;
919         } 
920       catch (CosNaming::NamingContext::NotFound& ex) 
921         {
922           CosNaming::Name n = ex.rest_of_name;
923           if (ex.why == CosNaming::NamingContext::missing_node)
924             INFOS(  "Destroy_Directory() : " << (char *) n[0].id
925                   << " (" << (char *) n[0].kind << ") not found")
926           if (ex.why == CosNaming::NamingContext::not_context)
927             INFOS( "Destroy_Directory() : " << (char *) n[0].id
928                  << " (" << (char *) n[0].kind
929                  << ") is not a context" )
930           if (ex.why == CosNaming::NamingContext::not_object)
931             INFOS( "Destroy_Directory() : " << (char *) n[0].id
932                  << " ("  << (char *) n[0].kind
933                  << ") is not an object" )
934         } 
935       catch (CosNaming::NamingContext::InvalidName &) 
936         {
937           INFOS( "!!!Destroy_Directory() : CosNaming::NamingContext::InvalidName" )
938         }
939       catch (CosNaming::NamingContext::CannotProceed &)
940         {
941           INFOS("!!!Destroy_Directory(): CosNaming::NamingContext::CannotProceed" )
942         }
943       catch(CORBA::COMM_FAILURE&)
944         {
945           INFOS( "!!!Destroy_Directory() : CORBA::COMM_FAILURE : unable to contact"
946                << " the naming service" )
947           throw ServiceUnreachable();
948         }
949     }
950
951   // the last element is the context to destroy
952   _context_name.length(1);  
953   _context_name[0].id = 
954     CORBA::string_dup(resultat_resolve_Path[dimension_resultat -1]);
955   _context_name[0].kind = CORBA::string_dup("dir");
956   SCRUTE(_context_name[0].id);
957
958   try
959     {
960       // We go in the context to destroy
961       CORBA::Object_var _obj = _current_context->resolve(_context_name);
962       _current_context = CosNaming::NamingContext::_narrow(_obj);
963     } 
964   catch (CosNaming::NamingContext::NotFound& ex) 
965     {
966       CosNaming::Name n = ex.rest_of_name;
967       if (ex.why == CosNaming::NamingContext::missing_node)
968         INFOS(  "Destroy_Directory() : " << (char *) n[0].id
969               << " (" << (char *) n[0].kind << ") not found" )
970       if (ex.why == CosNaming::NamingContext::not_context)
971         INFOS( "Destroy_Directory() : " << (char *) n[0].id
972              << " (" << (char *) n[0].kind
973              << ") is not a context" )
974       if (ex.why == CosNaming::NamingContext::not_object)
975         INFOS( "Destroy_Directory() : " << (char *) n[0].id
976              << " ("  << (char *) n[0].kind
977              << ") is not an object" )
978     } 
979   catch (CosNaming::NamingContext::InvalidName &) 
980     {
981       INFOS( "!!!Destroy_Directory() : CosNaming::NamingContext::InvalidName" )
982     }
983   catch (CosNaming::NamingContext::CannotProceed &)
984     {
985       INFOS( "!!!Destroy_Directory(): CosNaming::NamingContext::CannotProceed" )
986     }
987   catch(CORBA::COMM_FAILURE&)
988     {
989       INFOS( "!!!Destroy_Directory() : CORBA::COMM_FAILURE : unable to contact"
990            << " the naming service" )
991       throw ServiceUnreachable();
992     }
993
994   ASSERT(!CORBA::is_nil(_current_context));
995   // Context Destruction
996   try 
997     {
998       _current_context->destroy();
999       MESSAGE( "The context " << _context_name[0].id << " has been deleted" )
1000     }
1001   catch(CosNaming::NamingContext::NotEmpty&)
1002     {
1003       INFOS( "!!!Destroy_Directory() : CosNaming::NamingContext::NoEmpty "
1004            << Path << " is not empty" )
1005     } 
1006   catch(CORBA::COMM_FAILURE&)
1007     {
1008       INFOS( "!!!Destroy_Directory() :CORBA::COMM_FAILURE : "
1009            << "unable to contact the naming service") 
1010       throw ServiceUnreachable();
1011     }
1012   // We go to the directory just before the context to delete
1013   _current_context = _ref_context ; 
1014   try
1015     {
1016       _current_context->unbind(_context_name);
1017       MESSAGE( "The bind to the context " << _context_name[0].id  << " has been deleted" )
1018     }
1019   catch(CosNaming::NamingContext::NotFound& ex)
1020     {
1021       CosNaming::Name n = ex.rest_of_name;
1022       if (ex.why == CosNaming::NamingContext::missing_node)
1023         INFOS(  "Destroy_Directory() : " << (char *) n[0].id
1024               << " (" << (char *) n[0].kind << ") not found" )
1025       if (ex.why == CosNaming::NamingContext::not_context)
1026         INFOS( "Destroy_Directory() : " << (char *) n[0].id
1027              << " (" << (char *) n[0].kind
1028              << ") is not a context" )
1029       if (ex.why == CosNaming::NamingContext::not_object)
1030         INFOS( "Destroy_Directory() : " << (char *) n[0].id
1031              << " ("  << (char *) n[0].kind
1032              << ") is not an object" )
1033     }
1034   catch(CosNaming::NamingContext::CannotProceed&)
1035     {
1036       INFOS( "!!!Destroy_Directory() : CosNaming::NamingContext::CannotProceed")
1037     } 
1038   catch(CosNaming::NamingContext::InvalidName&) 
1039     {
1040       INFOS( "!!!Destroy_Directory() : CosNaming::NamingContext::InvalidName")
1041     }
1042   catch(CORBA::COMM_FAILURE&)
1043     {
1044       INFOS( "!!!Destroy_Directory() :CORBA::COMM_FAILURE : unable to contact" 
1045            << " the naming service") 
1046       throw ServiceUnreachable();
1047     }
1048   // Memory destruction
1049   for (int i = 0 ; i <dimension_resultat ;i++) 
1050     {
1051       delete [] resultat_resolve_Path[i];     
1052     }
1053   delete[] resultat_resolve_Path ;
1054 }
1055
1056 //----------------------------------------------------------------------
1057 /*! Function : _initialize_root_context
1058  * Purpose  :  method called by constructor to initialize _root_context
1059  */
1060 //----------------------------------------------------------------------
1061
1062 void SALOME_NamingService::_initialize_root_context()
1063 {
1064   //MESSAGE("Get the root context");
1065   try
1066     {
1067       CORBA::Object_var obj = _orb->resolve_initial_references("NameService");
1068       _root_context = CosNaming::NamingContext::_narrow(obj);
1069       _current_context = _root_context ;
1070       ASSERT(!CORBA::is_nil(_root_context)); 
1071     }
1072
1073   catch(CORBA::COMM_FAILURE&)
1074     {
1075       INFOS("CORBA::COMM_FAILURE: unable to contact the naming service");
1076       throw ServiceUnreachable();
1077     }
1078   catch(...)
1079     {
1080       INFOS("Unknown Exception: unable to contact the naming service");
1081       throw ServiceUnreachable();
1082     }
1083 }
1084
1085 //----------------------------------------------------------------------
1086 /*! Function : _resolve_Path
1087  * Purpose  : method to decompose a Path : /Kernel/Services/Sessions.
1088  * 
1089  * \return a char* containing the first char between '/' (in this case Kernel)
1090  */
1091 //----------------------------------------------------------------------
1092
1093 char* SALOME_NamingService::_resolve_Path(char* Path)
1094 {
1095   int i = 0 ;
1096   int length = strlen(Path);
1097   char *resultat;
1098
1099   if (length==0) return NULL;
1100   else
1101     {
1102       while ((i<length) && (Path[i]!='/'))
1103         i++;
1104       resultat = new char[i+1];
1105       strncpy(resultat,Path,i);
1106       resultat[i]='\0';    
1107       return resultat;
1108     }
1109 }
1110
1111 //----------------------------------------------------------------------
1112 /*! Function : _result_resolve_Path.
1113  *  Purpose  : method to decompose a Path : /Kernel/Services/Sessions.
1114  *  Gives an array of char* containing Kernel, Services, Sessions.
1115  * \param  Path const char* arguments, the Path to decompose
1116  * \param j int& arguments, the size of the array of char*
1117  * \param resultat_resolve_Path char** arguments
1118  */
1119 //----------------------------------------------------------------------
1120
1121 void 
1122 SALOME_NamingService::_result_resolve_Path(const char* Path, 
1123                                            int& j, 
1124                                            char ** resultat_resolve_Path)
1125 {  
1126   //MESSAGE("BEGIN OF _result_resolve_Path");
1127   int dimension_Path = strlen(Path) + 1;
1128   char** temp= new char* [dimension_Path];
1129   char** tempslash = new char* [dimension_Path];
1130
1131   temp[j] = new char[dimension_Path];
1132   strcpy(temp[j],Path);
1133
1134   while (strlen(temp[j])>0)
1135     {
1136       // temp[j] contains the characters to be treated :
1137       //  (Path - characters already treted)
1138       // tempslash[j] = temp[j] if the string temp[j] doesn't begin whith '/'
1139       // tempslash[j] = temp[j] without '/' if the string begins whith '/'
1140       int length_temp = strlen(temp[j]);
1141       if (temp[j][0]=='/')
1142         {
1143           // the characters to be treated begin whith '/'
1144           // we don't have to take the '/'
1145           tempslash[j] = new char [length_temp] ;
1146           for (int k = 0; k < length_temp-1; k++) 
1147             tempslash[j][k] = temp[j][k+1];
1148           tempslash[j][length_temp-1]='\0';
1149         }
1150       else
1151         {
1152           //the characters to be trated don't begin with '/'
1153           // Nothing to be done on the char
1154           tempslash[j] = new char [length_temp+1] ;
1155           strcpy(tempslash[j],temp[j]);   
1156         }
1157       // decomposition of the Path 
1158       resultat_resolve_Path[j]= _resolve_Path(tempslash[j]);
1159       //SCRUTE(resultat_resolve_Path[j]);
1160
1161       int length_resultat = strlen(resultat_resolve_Path[j]) ;
1162       int dimension_temp = length_temp -length_resultat ;
1163       j++;
1164       temp[j] = new char[dimension_temp +1];
1165       for (int i = 0 ; i <dimension_temp  ;i++)
1166         {
1167           temp[j][i] =tempslash[j-1][i+ length_resultat];
1168         }
1169       temp[j][dimension_temp]= '\0';
1170       //SCRUTE(temp[j]);
1171     } 
1172   // Memory destruction
1173   for (int i = 0 ; i <j;i++) 
1174     {
1175       delete [] temp[i];
1176       delete [] tempslash[i];    
1177     }
1178   delete[] temp;
1179   delete [] tempslash ;
1180 }
1181
1182 //----------------------------------------------------------------------
1183 /*! Function : _Find.
1184  *  Purpose  : method to research a name from the current directory 
1185  *             of the naming service.   
1186  *  The naming service changes directory to go to the directory where 
1187  *  the last occurence was found.
1188  *  \param name const char* arguments
1189  *  \param occurence_number CORBA::LONG (by value)
1190  */   
1191 //----------------------------------------------------------------------
1192
1193 void SALOME_NamingService::_Find(const char* name, 
1194                                  CORBA::Long& occurence_number)
1195 {
1196   //MESSAGE("BEGIN OF _Find") SCRUTE(name); 
1197   CosNaming::BindingList_var _binding_list;
1198   CosNaming::BindingIterator_var _binding_iterator;
1199   unsigned long nb=0 ; //for using only the BindingIterator 
1200                        // to access the bindings
1201   CosNaming::Binding_var _binding ;
1202   CosNaming::NamingContext_var _ref_context = _current_context;
1203   CosNaming::NamingContext_var _found_context = _current_context;
1204
1205   _current_context->list(nb, _binding_list, _binding_iterator) ;
1206
1207   while (_binding_iterator->next_one(_binding)) {
1208     CosNaming::Name _bindingName = _binding->binding_name;
1209     if (_binding->binding_type == CosNaming::ncontext) {
1210       // We work on a directory, the search should be done in this directory
1211       Change_Directory(_bindingName[0].id);
1212       _Find(name,occurence_number);
1213       // We'll go back to the initial context
1214       _current_context = _ref_context ;
1215     }
1216     else if (_binding->binding_type == CosNaming::nobject) {
1217       // We work on an object...
1218       if (!strcmp( _bindingName[0].id,name))
1219         {
1220           //MESSAGE("One occurence was found");
1221           occurence_number++;
1222           // We keep in memory the directory where one occurence was found
1223           _found_context = _current_context ;
1224         }
1225     }
1226   }
1227   _binding_iterator->destroy();  
1228   // We go to the last directory where an occurence was found
1229   _current_context = _found_context ;
1230   //SCRUTE(occurence_number);
1231 }
1232
1233 //----------------------------------------------------------------------
1234 /*! Function : _create_context_name_dir.
1235  *  Purpose  : method to create a Context_name from an array of char.
1236  *             The number of elements to be copied are indicated 
1237  *             with lenth_copy.
1238  *
1239  * \param resultat_resolve_Path char** arguments
1240  * \param length_copy int arguments
1241  * \param _context_name CosNaming::Name arguments (by value)
1242  */
1243 //----------------------------------------------------------------------
1244
1245 void 
1246 SALOME_NamingService::_create_context_name_dir(char** resultat_resolve_Path
1247                                                ,int length_copy,
1248                                                CosNaming::Name& _context_name) 
1249 {
1250   //MESSAGE("BEGIN OF _create_context_name_dir");
1251   for (int i = 0 ; i < length_copy;i++)
1252     {
1253       _context_name[i].id = CORBA::string_dup(resultat_resolve_Path[i]);
1254       _context_name[i].kind = CORBA::string_dup("dir");
1255       //SCRUTE(_context_name[i].id);
1256     }
1257 }
1258
1259 //----------------------------------------------------------------------
1260 /*! Function : _current_directory.
1261  * Purpose  : method to parse the naming service tree to find a context
1262  *            and determine the path to go to this context from the 
1263  *            _root_context.
1264  *  \param result_path char** arguments
1265  *  \param length_result int arguments by value
1266  *  \param context_to_found CosNaming::NamingContext_var arguments
1267  *  \param _continue boolean arguments
1268  */
1269 //----------------------------------------------------------------------
1270
1271 void
1272 SALOME_NamingService::_current_directory(char** result_path,
1273                                          int& length_result,
1274                                          CosNaming::NamingContext_var context_to_found,
1275                                          CORBA::Boolean& _continue) 
1276 {
1277   //MESSAGE("BEGIN OF _current_Directory");  
1278   CosNaming::BindingList_var _binding_list;
1279   CosNaming::BindingIterator_var _binding_iterator;
1280   unsigned long nb=0 ; //for using only the BindingIterator 
1281                        // to access the bindings
1282   CosNaming::Binding_var _binding ;
1283   CosNaming::NamingContext_var _ref_context = _current_context;
1284   CosNaming::NamingContext_var _temp_context = _current_context;
1285  
1286   _current_context->list(nb, _binding_list, _binding_iterator) ;
1287
1288   while ((_binding_iterator->next_one(_binding)) && _continue) {
1289     CosNaming::Name _bindingName = _binding->binding_name;
1290     if (_binding->binding_type == CosNaming::ncontext)
1291       {
1292         // We work on a directory, the search should be done in this directory
1293  
1294         result_path[length_result] = new char(strlen(_bindingName[0].id) + 1);
1295         strcpy(result_path[length_result],_bindingName[0].id);
1296         //SCRUTE(result_path[length_result])
1297           length_result++;
1298
1299         CORBA::Object_var  _obj =_current_context->resolve(_bindingName);
1300         _temp_context = CosNaming::NamingContext::_narrow(_obj);
1301
1302         if (_temp_context->_is_equivalent(context_to_found)) 
1303           {
1304             //MESSAGE("The context is found, we stop the search");
1305             _continue = false; 
1306             //SCRUTE(_continue);
1307           }
1308         if(_continue)
1309           {
1310             //SCRUTE(_bindingName[0].id);
1311             Change_Directory(_bindingName[0].id);
1312             _current_directory(result_path,length_result,
1313                                context_to_found, _continue );
1314             if (_continue)
1315               {
1316                 // We'll go back to the initial context
1317                 _current_context = _ref_context ;
1318                 //MESSAGE("Just before the delete of ")
1319                 //SCRUTE(result_path[length_result-1]);
1320                 delete result_path[length_result-1];
1321                 length_result--;
1322               }
1323           }
1324       }
1325   }
1326   _binding_iterator->destroy();  
1327   // We go to the last directory where an occurence was found
1328   _current_context = _ref_context ; 
1329 }
1330
1331
1332 //----------------------------------------------------------------------
1333 /*! Function :_list_directory_recurs.
1334  * Purpose  : method to list recursively all the objects contained in the tree of absCurDirectory/relativeSubDir.
1335  *  \param myList The list that will be filled.
1336  *  \param relativeSubDir The directory from absCurDirectory in which the objects are found.
1337  *  \param absCurDirectory The directory in ABSOLUTE form.
1338  *  _current_context must refer to absCurDirectory.
1339  */
1340 //----------------------------------------------------------------------
1341 void SALOME_NamingService::_list_directory_recurs(vector<string>& myList, const char *relativeSubDir,const char *absCurDirectory)
1342 {
1343   CosNaming::BindingList_var _binding_list;
1344   CosNaming::BindingIterator_var _binding_iterator;
1345   unsigned long nb=0 ; // for using only the BindingIterator to access the bindings
1346   CosNaming::Binding_var _binding ;
1347   char *absDir;
1348
1349   CosNaming::NamingContext_var _ref_context = _current_context;
1350   if(relativeSubDir)
1351     {
1352       Change_Directory(relativeSubDir);
1353       absDir=new char[strlen(absCurDirectory)+2+strlen(relativeSubDir)];
1354       strcpy(absDir,absCurDirectory);
1355       strcat(absDir,relativeSubDir);
1356       strcat(absDir,"/");
1357     }
1358   else
1359     absDir=(char *)absCurDirectory;
1360   _current_context->list(nb, _binding_list, _binding_iterator) ;
1361
1362   while (_binding_iterator->next_one(_binding)) {
1363     CosNaming::Name _bindingName = _binding->binding_name;
1364     if (_binding->binding_type == CosNaming::ncontext) {
1365       _list_directory_recurs(myList,_bindingName[0].id,absDir);
1366     }
1367     else if (_binding->binding_type == CosNaming::nobject) {
1368       char *elt=new char[strlen(absDir)+2+strlen(_bindingName[0].id)];
1369       strcpy(elt,absDir);
1370       strcat(elt,_bindingName[0].id);
1371       myList.push_back(elt);
1372       delete [] elt;
1373     }
1374   }
1375   if(relativeSubDir)
1376     {
1377       _current_context = _ref_context ;
1378       delete [] absDir;
1379     }
1380
1381   _binding_iterator->destroy();
1382 }
1383
1384 //----------------------------------------------------------------------
1385
1386 char * SALOME_NamingService::getIORaddr(){
1387    return _orb->object_to_string(_root_context);
1388 }