Salome HOME
PR: mergefrom_PAL_OCC_21Oct04
[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 +1];
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 //----------------------------------------------------------------------
742 /*! Function : Destroy_Name 
743  *  Purpose  : method to destroy an association Path-Object Reference.
744  *             WARNING : The complete Path should be given.
745  *  If the NamingService is out, the exception ServiceUnreachable is thrown 
746  * \param Path const char* arguments
747  */
748 //----------------------------------------------------------------------
749
750 void SALOME_NamingService::Destroy_Name(const char* Path)
751   throw(ServiceUnreachable)
752 {
753   MESSAGE("BEGIN OF Destroy_Name");
754   int dimension_Path = strlen(Path) + 1;
755   char** resultat_resolve_Path = new char* [dimension_Path];
756
757   // _current_context is replaced to the _root_context 
758   // if the Path begins whith '/'
759   if (Path[0]=='/') _current_context = _root_context;
760
761   
762   //the resolution of the directory path has to be done
763   //to place the currect_context to the correct node
764   int dimension_resultat = 0;
765   _result_resolve_Path (Path, dimension_resultat, resultat_resolve_Path);
766     
767   CosNaming::Name _context_name;
768   if (dimension_resultat>1)
769     {
770       // We go in the directory where the object to destroy is
771       _context_name.length(dimension_resultat-1);
772   
773       _create_context_name_dir(resultat_resolve_Path,dimension_resultat -1,
774                                _context_name); 
775       try
776         {
777           CORBA::Object_var _obj = _current_context->resolve(_context_name);
778           _current_context = CosNaming::NamingContext::_narrow(_obj);
779         } 
780       catch (CosNaming::NamingContext::NotFound& ex) 
781         {
782           CosNaming::Name n = ex.rest_of_name;
783           if (ex.why == CosNaming::NamingContext::missing_node)
784             INFOS(  "Destroy_Name() : " << (char *) n[0].id
785                   << " (" << (char *) n[0].kind << ") not found" )
786           if (ex.why == CosNaming::NamingContext::not_context)
787             INFOS( "Destroy_Name() : " << (char *) n[0].id
788                  << " (" << (char *) n[0].kind
789                  << ") is not a context" )
790           if (ex.why == CosNaming::NamingContext::not_object)
791             INFOS( "Destroy_Name() : " << (char *) n[0].id
792                  << " ("  << (char *) n[0].kind
793                  << ") is not an object" )
794         } 
795       catch (CosNaming::NamingContext::InvalidName &) 
796         {
797           INFOS( "!!!Destroy_Name() : CosNaming::NamingContext::InvalidName" )
798         }
799       catch (CosNaming::NamingContext::CannotProceed &)
800         {
801           INFOS( "!!!Destroy_Name(): CosNaming::NamingContext::CannotProceed" )
802         }
803       catch(CORBA::COMM_FAILURE&)
804         {
805           INFOS( "!!!Destroy_Name() : CORBA::COMM_FAILURE : unable to contact"
806                << " the naming service")
807           throw ServiceUnreachable();
808         }
809     }
810
811   // the last element is the object to destroy
812   _context_name.length(1);  
813   _context_name[0].id = 
814     CORBA::string_dup(resultat_resolve_Path[dimension_resultat -1]);
815   _context_name[0].kind = CORBA::string_dup("object");
816   SCRUTE(_context_name[0].id);
817   ASSERT(!CORBA::is_nil(_current_context));
818   // Object destruction
819   try 
820     {
821       _current_context->unbind(_context_name);
822       MESSAGE( "The object " << _context_name[0].id  << " has been deleted" )
823     }
824   catch(CosNaming::NamingContext::NotFound& ex)
825     {
826       CosNaming::Name n = ex.rest_of_name;
827       if (ex.why == CosNaming::NamingContext::missing_node)
828         INFOS(  "Destroy_Name() : " << (char *) n[0].id
829               << " (" << (char *) n[0].kind << ") not found" )
830       if (ex.why == CosNaming::NamingContext::not_context)
831         INFOS( "Destroy_Name() : " << (char *) n[0].id
832              << " (" << (char *) n[0].kind
833              << ") is not a context" )
834       if (ex.why == CosNaming::NamingContext::not_object)
835         INFOS( "Destroy_Name() : " << (char *) n[0].id
836              << " ("  << (char *) n[0].kind
837              << ") is not an object" )
838     }
839   catch(CosNaming::NamingContext::CannotProceed&)
840     {
841       INFOS( "!!!Destroy_Name() : CosNaming::NamingContext::CannotProceed")
842     } 
843   catch(CosNaming::NamingContext::InvalidName&) 
844     {
845       INFOS( "!!!Destroy_Name() : CosNaming::NamingContext::InvalidName")
846     }
847   catch(CORBA::COMM_FAILURE&)
848     {
849       INFOS( "!!!Destroy_Name() :CORBA::COMM_FAILURE : unable to contact" 
850            << " the naming service") 
851       throw ServiceUnreachable();
852     }
853   // Memory destruction
854   for (int i = 0 ; i <dimension_resultat ;i++) 
855     {
856       delete [] resultat_resolve_Path[i];     
857     }
858   delete[] resultat_resolve_Path ;
859 }
860
861 //----------------------------------------------------------------------
862 /*! Function : Destroy_Directory.
863  *  Purpose  : method to destroy a directory if it is empty.
864  *  WARNING : The complete Path  to the directory (from the root_context)
865  *  to destroy should be given.
866  *  If the NamingService is out, the exception ServiceUnreachable is thrown.
867  * \param Path const char* arguments
868  */
869 //----------------------------------------------------------------------
870
871 void SALOME_NamingService::Destroy_Directory(const char* Path)
872   throw(ServiceUnreachable)
873 {
874   MESSAGE("BEGIN OF Destroy_Directory");
875   int dimension_Path = strlen(Path) + 1;
876   char** resultat_resolve_Path = new char* [dimension_Path];
877
878   // _current_context is replaced to the _root_context 
879   // if the Path begins whith '/'
880   if (Path[0]=='/') _current_context = _root_context;
881
882   CosNaming::NamingContext_var _ref_context = _current_context;
883  
884   //the resolution of the directory path has to be done
885   //to place the currect_context to the correct node
886   int dimension_resultat = 0;
887   _result_resolve_Path (Path, dimension_resultat, resultat_resolve_Path);
888     
889   CosNaming::Name _context_name;
890   if (dimension_resultat>1)
891     {
892       // We go in the directory where the context to destroy is
893       _context_name.length(dimension_resultat-1);
894   
895       _create_context_name_dir(resultat_resolve_Path,dimension_resultat -1,
896                                _context_name); 
897       try
898         {
899           CORBA::Object_var _obj = _current_context->resolve(_context_name);
900           _current_context = CosNaming::NamingContext::_narrow(_obj);
901           _ref_context = _current_context ;
902         } 
903       catch (CosNaming::NamingContext::NotFound& ex) 
904         {
905           CosNaming::Name n = ex.rest_of_name;
906           if (ex.why == CosNaming::NamingContext::missing_node)
907             INFOS(  "Destroy_Directory() : " << (char *) n[0].id
908                   << " (" << (char *) n[0].kind << ") not found")
909           if (ex.why == CosNaming::NamingContext::not_context)
910             INFOS( "Destroy_Directory() : " << (char *) n[0].id
911                  << " (" << (char *) n[0].kind
912                  << ") is not a context" )
913           if (ex.why == CosNaming::NamingContext::not_object)
914             INFOS( "Destroy_Directory() : " << (char *) n[0].id
915                  << " ("  << (char *) n[0].kind
916                  << ") is not an object" )
917         } 
918       catch (CosNaming::NamingContext::InvalidName &) 
919         {
920           INFOS( "!!!Destroy_Directory() : CosNaming::NamingContext::InvalidName" )
921         }
922       catch (CosNaming::NamingContext::CannotProceed &)
923         {
924           INFOS("!!!Destroy_Directory(): CosNaming::NamingContext::CannotProceed" )
925         }
926       catch(CORBA::COMM_FAILURE&)
927         {
928           INFOS( "!!!Destroy_Directory() : CORBA::COMM_FAILURE : unable to contact"
929                << " the naming service" )
930           throw ServiceUnreachable();
931         }
932     }
933
934   // the last element is the context to destroy
935   _context_name.length(1);  
936   _context_name[0].id = 
937     CORBA::string_dup(resultat_resolve_Path[dimension_resultat -1]);
938   _context_name[0].kind = CORBA::string_dup("dir");
939   SCRUTE(_context_name[0].id);
940
941   try
942     {
943       // We go in the context to destroy
944       CORBA::Object_var _obj = _current_context->resolve(_context_name);
945       _current_context = CosNaming::NamingContext::_narrow(_obj);
946     } 
947   catch (CosNaming::NamingContext::NotFound& ex) 
948     {
949       CosNaming::Name n = ex.rest_of_name;
950       if (ex.why == CosNaming::NamingContext::missing_node)
951         INFOS(  "Destroy_Directory() : " << (char *) n[0].id
952               << " (" << (char *) n[0].kind << ") not found" )
953       if (ex.why == CosNaming::NamingContext::not_context)
954         INFOS( "Destroy_Directory() : " << (char *) n[0].id
955              << " (" << (char *) n[0].kind
956              << ") is not a context" )
957       if (ex.why == CosNaming::NamingContext::not_object)
958         INFOS( "Destroy_Directory() : " << (char *) n[0].id
959              << " ("  << (char *) n[0].kind
960              << ") is not an object" )
961     } 
962   catch (CosNaming::NamingContext::InvalidName &) 
963     {
964       INFOS( "!!!Destroy_Directory() : CosNaming::NamingContext::InvalidName" )
965     }
966   catch (CosNaming::NamingContext::CannotProceed &)
967     {
968       INFOS( "!!!Destroy_Directory(): CosNaming::NamingContext::CannotProceed" )
969     }
970   catch(CORBA::COMM_FAILURE&)
971     {
972       INFOS( "!!!Destroy_Directory() : CORBA::COMM_FAILURE : unable to contact"
973            << " the naming service" )
974       throw ServiceUnreachable();
975     }
976
977   ASSERT(!CORBA::is_nil(_current_context));
978   // Context Destruction
979   try 
980     {
981       _current_context->destroy();
982       MESSAGE( "The context " << _context_name[0].id << " has been deleted" )
983     }
984   catch(CosNaming::NamingContext::NotEmpty&)
985     {
986       INFOS( "!!!Destroy_Directory() : CosNaming::NamingContext::NoEmpty "
987            << Path << " is not empty" )
988     } 
989   catch(CORBA::COMM_FAILURE&)
990     {
991       INFOS( "!!!Destroy_Directory() :CORBA::COMM_FAILURE : "
992            << "unable to contact the naming service") 
993       throw ServiceUnreachable();
994     }
995   // We go to the directory just before the context to delete
996   _current_context = _ref_context ; 
997   try
998     {
999       _current_context->unbind(_context_name);
1000       MESSAGE( "The bind to the context " << _context_name[0].id  << " has been deleted" )
1001     }
1002   catch(CosNaming::NamingContext::NotFound& ex)
1003     {
1004       CosNaming::Name n = ex.rest_of_name;
1005       if (ex.why == CosNaming::NamingContext::missing_node)
1006         INFOS(  "Destroy_Directory() : " << (char *) n[0].id
1007               << " (" << (char *) n[0].kind << ") not found" )
1008       if (ex.why == CosNaming::NamingContext::not_context)
1009         INFOS( "Destroy_Directory() : " << (char *) n[0].id
1010              << " (" << (char *) n[0].kind
1011              << ") is not a context" )
1012       if (ex.why == CosNaming::NamingContext::not_object)
1013         INFOS( "Destroy_Directory() : " << (char *) n[0].id
1014              << " ("  << (char *) n[0].kind
1015              << ") is not an object" )
1016     }
1017   catch(CosNaming::NamingContext::CannotProceed&)
1018     {
1019       INFOS( "!!!Destroy_Directory() : CosNaming::NamingContext::CannotProceed")
1020     } 
1021   catch(CosNaming::NamingContext::InvalidName&) 
1022     {
1023       INFOS( "!!!Destroy_Directory() : CosNaming::NamingContext::InvalidName")
1024     }
1025   catch(CORBA::COMM_FAILURE&)
1026     {
1027       INFOS( "!!!Destroy_Directory() :CORBA::COMM_FAILURE : unable to contact" 
1028            << " the naming service") 
1029       throw ServiceUnreachable();
1030     }
1031   // Memory destruction
1032   for (int i = 0 ; i <dimension_resultat ;i++) 
1033     {
1034       delete [] resultat_resolve_Path[i];     
1035     }
1036   delete[] resultat_resolve_Path ;
1037 }
1038
1039 //----------------------------------------------------------------------
1040 /*! Function : _initialize_root_context
1041  * Purpose  :  method called by constructor to initialize _root_context
1042  */
1043 //----------------------------------------------------------------------
1044
1045 void SALOME_NamingService::_initialize_root_context()
1046 {
1047   //MESSAGE("Get the root context");
1048   try
1049     {
1050       CORBA::Object_var obj = _orb->resolve_initial_references("NameService");
1051       _root_context = CosNaming::NamingContext::_narrow(obj);
1052       _current_context = _root_context ;
1053       ASSERT(!CORBA::is_nil(_root_context)); 
1054     }
1055
1056   catch(CORBA::COMM_FAILURE&)
1057     {
1058       INFOS("CORBA::COMM_FAILURE: unable to contact the naming service");
1059       throw ServiceUnreachable();
1060     }
1061   catch(...)
1062     {
1063       INFOS("Unknown Exception: unable to contact the naming service");
1064       throw ServiceUnreachable();
1065     }
1066 }
1067
1068 //----------------------------------------------------------------------
1069 /*! Function : _resolve_Path
1070  * Purpose  : method to decompose a Path : /Kernel/Services/Sessions.
1071  * 
1072  * \return a char* containing the first char between '/' (in this case Kernel)
1073  */
1074 //----------------------------------------------------------------------
1075
1076 char* SALOME_NamingService::_resolve_Path(char* Path)
1077 {
1078   int i = 0 ;
1079   int length = strlen(Path);
1080   char *resultat;
1081
1082   if (length==0) return NULL;
1083   else
1084     {
1085       while ((i<length) && (Path[i]!='/'))
1086         i++;
1087       resultat = new char[i+1];
1088       strncpy(resultat,Path,i);
1089       resultat[i]='\0';    
1090       return resultat;
1091     }
1092 }
1093
1094 //----------------------------------------------------------------------
1095 /*! Function : _result_resolve_Path.
1096  *  Purpose  : method to decompose a Path : /Kernel/Services/Sessions.
1097  *  Gives an array of char* containing Kernel, Services, Sessions.
1098  * \param  Path const char* arguments, the Path to decompose
1099  * \param j int& arguments, the size of the array of char*
1100  * \param resultat_resolve_Path char** arguments
1101  */
1102 //----------------------------------------------------------------------
1103
1104 void 
1105 SALOME_NamingService::_result_resolve_Path(const char* Path, 
1106                                            int& j, 
1107                                            char ** resultat_resolve_Path)
1108 {  
1109   //MESSAGE("BEGIN OF _result_resolve_Path");
1110   int dimension_Path = strlen(Path) + 1;
1111   char** temp= new char* [dimension_Path];
1112   char** tempslash = new char* [dimension_Path];
1113
1114   temp[j] = new char[dimension_Path];
1115   strcpy(temp[j],Path);
1116
1117   while (strlen(temp[j])>0)
1118     {
1119       // temp[j] contains the characters to be treated :
1120       //  (Path - characters already treted)
1121       // tempslash[j] = temp[j] if the string temp[j] doesn't begin whith '/'
1122       // tempslash[j] = temp[j] without '/' if the string begins whith '/'
1123       int length_temp = strlen(temp[j]);
1124       if (temp[j][0]=='/')
1125         {
1126           // the characters to be treated begin whith '/'
1127           // we don't have to take the '/'
1128           tempslash[j] = new char [length_temp] ;
1129           for (int k = 0; k < length_temp-1; k++) 
1130             tempslash[j][k] = temp[j][k+1];
1131           tempslash[j][length_temp-1]='\0';
1132         }
1133       else
1134         {
1135           //the characters to be trated don't begin with '/'
1136           // Nothing to be done on the char
1137           tempslash[j] = new char [length_temp+1] ;
1138           strcpy(tempslash[j],temp[j]);   
1139         }
1140       // decomposition of the Path 
1141       resultat_resolve_Path[j]= _resolve_Path(tempslash[j]);
1142       //SCRUTE(resultat_resolve_Path[j]);
1143
1144       int length_resultat = strlen(resultat_resolve_Path[j]) ;
1145       int dimension_temp = length_temp -length_resultat ;
1146       j++;
1147       temp[j] = new char[dimension_temp +1];
1148       for (int i = 0 ; i <dimension_temp  ;i++)
1149         {
1150           temp[j][i] =tempslash[j-1][i+ length_resultat];
1151         }
1152       temp[j][dimension_temp]= '\0';
1153       //SCRUTE(temp[j]);
1154     } 
1155   // Memory destruction
1156   for (int i = 0 ; i <j;i++) 
1157     {
1158       delete [] temp[i];
1159       delete [] tempslash[i];    
1160     }
1161   delete[] temp;
1162   delete [] tempslash ;
1163 }
1164
1165 //----------------------------------------------------------------------
1166 /*! Function : _Find.
1167  *  Purpose  : method to research a name from the current directory 
1168  *             of the naming service.   
1169  *  The naming service changes directory to go to the directory where 
1170  *  the last occurence was found.
1171  *  \param name const char* arguments
1172  *  \param occurence_number CORBA::LONG (by value)
1173  */   
1174 //----------------------------------------------------------------------
1175
1176 void SALOME_NamingService::_Find(const char* name, 
1177                                  CORBA::Long& occurence_number)
1178 {
1179   //MESSAGE("BEGIN OF _Find") SCRUTE(name); 
1180   CosNaming::BindingList_var _binding_list;
1181   CosNaming::BindingIterator_var _binding_iterator;
1182   unsigned long nb=0 ; //for using only the BindingIterator 
1183                        // to access the bindings
1184   CosNaming::Binding_var _binding ;
1185   CosNaming::NamingContext_var _ref_context = _current_context;
1186   CosNaming::NamingContext_var _found_context = _current_context;
1187
1188   _current_context->list(nb, _binding_list, _binding_iterator) ;
1189
1190   while (_binding_iterator->next_one(_binding)) {
1191     CosNaming::Name _bindingName = _binding->binding_name;
1192     if (_binding->binding_type == CosNaming::ncontext) {
1193       // We work on a directory, the search should be done in this directory
1194       Change_Directory(_bindingName[0].id);
1195       _Find(name,occurence_number);
1196       // We'll go back to the initial context
1197       _current_context = _ref_context ;
1198     }
1199     else if (_binding->binding_type == CosNaming::nobject) {
1200       // We work on an object...
1201       if (!strcmp( _bindingName[0].id,name))
1202         {
1203           //MESSAGE("One occurence was found");
1204           occurence_number++;
1205           // We keep in memory the directory where one occurence was found
1206           _found_context = _current_context ;
1207         }
1208     }
1209   }
1210   _binding_iterator->destroy();  
1211   // We go to the last directory where an occurence was found
1212   _current_context = _found_context ;
1213   //SCRUTE(occurence_number);
1214 }
1215
1216 //----------------------------------------------------------------------
1217 /*! Function : _create_context_name_dir.
1218  *  Purpose  : method to create a Context_name from an array of char.
1219  *             The number of elements to be copied are indicated 
1220  *             with lenth_copy.
1221  *
1222  * \param resultat_resolve_Path char** arguments
1223  * \param length_copy int arguments
1224  * \param _context_name CosNaming::Name arguments (by value)
1225  */
1226 //----------------------------------------------------------------------
1227
1228 void 
1229 SALOME_NamingService::_create_context_name_dir(char** resultat_resolve_Path
1230                                                ,int length_copy,
1231                                                CosNaming::Name& _context_name) 
1232 {
1233   //MESSAGE("BEGIN OF _create_context_name_dir");
1234   for (int i = 0 ; i < length_copy;i++)
1235     {
1236       _context_name[i].id = CORBA::string_dup(resultat_resolve_Path[i]);
1237       _context_name[i].kind = CORBA::string_dup("dir");
1238       //SCRUTE(_context_name[i].id);
1239     }
1240 }
1241
1242 //----------------------------------------------------------------------
1243 /*! Function : _current_directory.
1244  * Purpose  : method to parse the naming service tree to find a context
1245  *            and determine the path to go to this context from the 
1246  *            _root_context.
1247  *  \param result_path char** arguments
1248  *  \param length_result int arguments by value
1249  *  \param context_to_found CosNaming::NamingContext_var arguments
1250  *  \param _continue boolean arguments
1251  */
1252 //----------------------------------------------------------------------
1253
1254 void
1255 SALOME_NamingService::_current_directory(char** result_path,
1256                                          int& length_result,
1257                                          CosNaming::NamingContext_var context_to_found,
1258                                          CORBA::Boolean& _continue) 
1259 {
1260   //MESSAGE("BEGIN OF _current_Directory");  
1261   CosNaming::BindingList_var _binding_list;
1262   CosNaming::BindingIterator_var _binding_iterator;
1263   unsigned long nb=0 ; //for using only the BindingIterator 
1264                        // to access the bindings
1265   CosNaming::Binding_var _binding ;
1266   CosNaming::NamingContext_var _ref_context = _current_context;
1267   CosNaming::NamingContext_var _temp_context = _current_context;
1268  
1269   _current_context->list(nb, _binding_list, _binding_iterator) ;
1270
1271   while ((_binding_iterator->next_one(_binding)) && _continue) {
1272     CosNaming::Name _bindingName = _binding->binding_name;
1273     if (_binding->binding_type == CosNaming::ncontext)
1274       {
1275         // We work on a directory, the search should be done in this directory
1276  
1277         result_path[length_result] = new char(strlen(_bindingName[0].id) + 1);
1278         strcpy(result_path[length_result],_bindingName[0].id);
1279         //SCRUTE(result_path[length_result])
1280           length_result++;
1281
1282         CORBA::Object_var  _obj =_current_context->resolve(_bindingName);
1283         _temp_context = CosNaming::NamingContext::_narrow(_obj);
1284
1285         if (_temp_context->_is_equivalent(context_to_found)) 
1286           {
1287             //MESSAGE("The context is found, we stop the search");
1288             _continue = false; 
1289             //SCRUTE(_continue);
1290           }
1291         if(_continue)
1292           {
1293             //SCRUTE(_bindingName[0].id);
1294             Change_Directory(_bindingName[0].id);
1295             _current_directory(result_path,length_result,
1296                                context_to_found, _continue );
1297             if (_continue)
1298               {
1299                 // We'll go back to the initial context
1300                 _current_context = _ref_context ;
1301                 //MESSAGE("Just before the delete of ")
1302                 //SCRUTE(result_path[length_result-1]);
1303                 delete result_path[length_result-1];
1304                 length_result--;
1305               }
1306           }
1307       }
1308   }
1309   _binding_iterator->destroy();  
1310   // We go to the last directory where an occurence was found
1311   _current_context = _ref_context ; 
1312 }
1313 //----------------------------------------------------------------------