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