Salome HOME
PR: merge from branch BR_UT_V310a2 tag BR_UT_V310a2_20051115
authorprascle <prascle>
Tue, 15 Nov 2005 20:46:16 +0000 (20:46 +0000)
committerprascle <prascle>
Tue, 15 Nov 2005 20:46:16 +0000 (20:46 +0000)
31 files changed:
bin/appliskel/runAppli
bin/appliskel/runTests
bin/runSalome.py
idl/nstest.idl [new file with mode: 0644]
salome_adm/unix/config_files/check_lam.m4
src/Communication/Makefile.in
src/Communication/MultiCommException.hxx
src/Communication/SALOMEMultiComm.hxx
src/Communication/SenderFactory.hxx
src/Communication_SWIG/Makefile.in [new file with mode: 0644]
src/Communication_SWIG/libSALOME_Comm.i [new file with mode: 0644]
src/Container/Makefile.in
src/LifeCycleCORBA/Test/Makefile.in
src/LifeCycleCORBA/Test/TestLifeCycleCORBA.cxx
src/MPIContainer/Makefile.in
src/Makefile.in
src/NamingService/SALOME_NamingService.cxx
src/NamingService/SALOME_NamingService.hxx
src/NamingService/Test/Makefile.in [new file with mode: 0644]
src/NamingService/Test/NamingServiceTest.cxx [new file with mode: 0644]
src/NamingService/Test/NamingServiceTest.hxx [new file with mode: 0644]
src/NamingService/Test/TestNamingService.cxx [new file with mode: 0644]
src/NamingService/Test/TestNamingService.py [new file with mode: 0644]
src/ResourcesManager/SALOME_ResourcesManager.cxx
src/SALOMELocalTrace/FileTraceCollector.cxx
src/SALOMELocalTrace/LocalTraceBufferPool.cxx
src/SALOMELocalTrace/LocalTraceCollector.cxx
src/SALOMETraceCollector/SALOMETraceCollector.cxx
src/TestMPIContainer/Makefile.in
src/UnitTests/Makefile.in
src/UnitTests/UnitTests.cxx

index 39083ff0187534b46e9ac4e704fc2a210d93a034..700e669d4e5a1342548b7a24be3d469a049ae939 100755 (executable)
@@ -55,6 +55,13 @@ searchFreePort() {
     done
 }
 
+# --- if mpi lam, start lam (seems safe to be done several times)
+#     arret manuel avec lamhalt
+
+if [ "$LAMBHOST" ]; then
+  lamboot
+fi
+
 # --- run SALOME
 #    (default arguments defined in local salome.launch could be completed
 #     by arguments to this command)
@@ -63,9 +70,9 @@ searchFreePort
 
 if [ $# -ne 0 ] ; then
     ${KERNEL_ROOT_DIR}/bin/salome/envSalome.py python -i ${KERNEL_ROOT_DIR}/bin/salome/runSalome.py $*
+    # --- todo delete omniORB config files in relation to the naming service kill
+    rm ${OMNIORB_CONFIG}
+    rm ${LAST_RUNNING_CONFIG}
 else
     ${KERNEL_ROOT_DIR}/bin/salome/envSalome.py python ${KERNEL_ROOT_DIR}/bin/salome/runSalome.py 
 fi
-
-rm ${OMNIORB_CONFIG}
-rm ${LAST_RUNNING_CONFIG}
index 487b4a302da0d760af77008bfb6b1641a82aab49..6e625f0a0e82ecf4768f660c84c1ea1893e6fae9 100755 (executable)
@@ -55,6 +55,13 @@ searchFreePort() {
     done
 }
 
+# --- if mpi lam, start lam (seems safe to be done several times)
+#     arret manuel avec lamhalt
+
+if [ "$LAMBHOST" ]; then
+  lamboot
+fi
+
 # --- invoque shell with or without args
 
 searchFreePort
index 6e7b0938edc00fede9a2d0a4d04559978ae9beab..311dc45ed8f2248347ffb5bdf1b8b086a83042da 100755 (executable)
@@ -106,26 +106,33 @@ def set_env(args, modules_list, modules_root_dir):
     modules_list = modules_list[:] + ["GUI"] 
     modules_list = modules_list[:] + ["KERNEL"] 
     for module in modules_list :
-        module_root_dir = modules_root_dir[module]
-        modules_root_dir_list[:0] = [module_root_dir]
-        add_path(os.path.join(module_root_dir,"lib",salome_subdir),
-                 "LD_LIBRARY_PATH")
-        add_path(os.path.join(module_root_dir,"bin",salome_subdir),
-                 "PATH")
-        if os.path.exists(module_root_dir + "/examples") :
-            add_path(os.path.join(module_root_dir,"examples"),
+        if modules_root_dir.has_key(module):
+            module_root_dir = modules_root_dir[module]
+            modules_root_dir_list[:0] = [module_root_dir]
+            add_path(os.path.join(module_root_dir,"lib",salome_subdir),
+                     "LD_LIBRARY_PATH")
+            add_path(os.path.join(module_root_dir,"bin",salome_subdir),
+                     "PATH")
+            if os.path.exists(module_root_dir + "/examples") :
+                add_path(os.path.join(module_root_dir,"examples"),
+                         "PYTHONPATH")
+                pass
+            add_path(os.path.join(module_root_dir,"bin",salome_subdir),
                      "PYTHONPATH")
-        add_path(os.path.join(module_root_dir,"bin",salome_subdir),
-                 "PYTHONPATH")
-        add_path(os.path.join(module_root_dir,"lib",
-                              python_version,"site-packages",salome_subdir),
-                 "PYTHONPATH")
-        add_path(os.path.join(module_root_dir,"lib",salome_subdir),
-                 "PYTHONPATH")
-        add_path(os.path.join(module_root_dir,"lib",
-                              python_version,"site-packages",salome_subdir,
-                              "shared_modules"),
-                 "PYTHONPATH")
+            add_path(os.path.join(module_root_dir,"lib",
+                                  python_version,"site-packages",
+                                  salome_subdir),
+                     "PYTHONPATH")
+            add_path(os.path.join(module_root_dir,"lib",salome_subdir),
+                     "PYTHONPATH")
+            add_path(os.path.join(module_root_dir,"lib",
+                                  python_version,"site-packages",
+                                  salome_subdir,
+                                  "shared_modules"),
+                     "PYTHONPATH")
+            pass
+        pass
+
 
     os.environ["SALOMEPATH"]=":".join(modules_root_dir_list)
     
@@ -304,13 +311,16 @@ class CatalogServer(Server):
         list_modules = modules_list[:]
         list_modules.reverse()
         for module in ["KERNEL", "GUI"] + list_modules:
-            module_root_dir=modules_root_dir[module]
-            module_cata=module+"Catalog.xml"
-            #print "   ", module_cata
-            cata_path.extend(
-                glob.glob(os.path.join(module_root_dir,
-                                       "share",salome_subdir,
-                                       "resources",module_cata)))
+            if modules_root_dir.has_key(module):
+                module_root_dir=modules_root_dir[module]
+                module_cata=module+"Catalog.xml"
+                #print "   ", module_cata
+                cata_path.extend(
+                    glob.glob(os.path.join(module_root_dir,
+                                           "share",salome_subdir,
+                                           "resources",module_cata)))
+                pass
+            pass
         self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2
 
 # ---
@@ -438,13 +448,16 @@ class ContainerManagerServer(Server):
         list_modules = modules_list[:]
         list_modules.reverse()
         for module in ["KERNEL", "GUI"] + list_modules:
-            module_root_dir=modules_root_dir[module]
-            module_cata=module+"Catalog.xml"
-            #print "   ", module_cata
-            cata_path.extend(
-                glob.glob(os.path.join(module_root_dir,"share",
-                                       self.args['appname'],"resources",
-                                       module_cata)))
+            if modules_root_dir.has_key(module):
+                module_root_dir=modules_root_dir[module]
+                module_cata=module+"Catalog.xml"
+                #print "   ", module_cata
+                cata_path.extend(
+                    glob.glob(os.path.join(module_root_dir,"share",
+                                           self.args['appname'],"resources",
+                                           module_cata)))
+                pass
+            pass
         if 'moduleCatalog' in self.args['embedded']:
             self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2
         else:
diff --git a/idl/nstest.idl b/idl/nstest.idl
new file mode 100644 (file)
index 0000000..9d36923
--- /dev/null
@@ -0,0 +1,18 @@
+
+#ifndef NSTEST_IDL
+#define NSTEST_IDL
+
+module NSTEST
+{
+  interface echo
+  {
+    long getId();
+  };
+
+  interface aFactory
+  {
+    echo createInstance();
+  };
+};
+
+#endif
\ No newline at end of file
index 994a2b0a538d5ca0e2f4b9cd643a6fe59acfb321..bde79d7e60460356bd778f267dda9f4c89b97e95 100644 (file)
@@ -69,7 +69,7 @@ if test "$WITHLAM" = yes; then
   if test "$WITHLAM" = "yes";then
      WITHMPI="yes"
      mpi_ok=yes
-     MPI_LIBS="$MPI_LIBS -lmpi -llam"
+     MPI_LIBS="$MPI_LIBS -llammpi++"
   else
      mpi_ok=no
   fi
index e859ea4fbaaa666d6b44317ca895274f9b2e60c4..15886f867d404847ed760c8af01b474237a789d7 100644 (file)
@@ -13,7 +13,9 @@ EXPORT_HEADERS = \
        ReceiverFactory.hxx \
        SenderFactory.hxx \
        SALOMEMultiComm.hxx \
-       MultiCommException.hxx
+       MultiCommException.hxx \
+       SALOME_Comm_i.hxx
+
 # Libraries targets
 
 LIB = libSalomeCommunication.la 
index 6313ab5e43e23c3cb3742a43e96f71d516f7884a..fe029fc4a17832dd4f56ef280c4d7dee8a448362 100644 (file)
@@ -3,13 +3,8 @@
 
 #include <string>
 
-#if defined WNT && defined COMMUNICATION_EXPORTS
-#define COMMUNICATION_EXPORT __declspec( dllexport )
-#else
-#define COMMUNICATION_EXPORT
-#endif
 
-class COMMUNICATION_EXPORT MultiCommException {
+class MultiCommException {
 private:
   std::string _message;
 public:
index 8c46251af175d281086b2f61a15b52349bbe47bb..2537dc042b3b3487a62faac8e399d8cd790e4fc8 100644 (file)
@@ -4,17 +4,11 @@
 #include <SALOMEconfig.h>
 #include CORBA_SERVER_HEADER(SALOME_Comm)
 
-#if defined WNT && defined COMMUNICATION_EXPORTS
-#define COMMUNICATION_EXPORT __declspec( dllexport )
-#else
-#define COMMUNICATION_EXPORT
-#endif
-
 /*!
   Class is designed to ease the use of multi communication.\n
   Simply inherite from it your servant class you want to emit data with senders.
  */
-class COMMUNICATION_EXPORT SALOMEMultiComm : public virtual POA_SALOME::MultiCommClass {
+class SALOMEMultiComm : public virtual POA_SALOME::MultiCommClass {
 protected:
   SALOME::TypeOfCommunication _type;
 public:
index 39edaa3a11f70d6d8322b008f6f5768e1d97216e..ce3a0ad9130ab7a0133cc445b22f3047d5f05e90 100644 (file)
@@ -5,12 +5,6 @@
 #include <SALOMEconfig.h>
 #include CORBA_SERVER_HEADER(SALOME_Comm)
 
-#if defined WNT && defined COMMUNICATION_EXPORTS
-#define COMMUNICATION_EXPORT __declspec( dllexport )
-#else
-#define COMMUNICATION_EXPORT
-#endif
-
 class SALOMEMultiComm;
 
 class SALOME_SenderDouble_i;
@@ -19,7 +13,7 @@ class SALOME_SenderInt_i;
 /*!
   This class implements the factory pattern of GoF by making a sender by giving an array and a communicator.It completely hides the type of sender from the user.
  */
-class COMMUNICATION_EXPORT SenderFactory
+class SenderFactory
 {
 public:
   static SALOME::SenderDouble_ptr buildSender(SALOMEMultiComm &multiCommunicator,const double *tab,long lgr,bool ownTab=false) throw(MultiCommException);
diff --git a/src/Communication_SWIG/Makefile.in b/src/Communication_SWIG/Makefile.in
new file mode 100644 (file)
index 0000000..42f8f3f
--- /dev/null
@@ -0,0 +1,24 @@
+
+top_srcdir=@top_srcdir@
+top_builddir=../..
+srcdir=@srcdir@
+VPATH=.:@srcdir@:@top_srcdir@/idl
+
+@COMMENCE@
+
+# header files 
+EXPORT_HEADERS= libSALOME_Comm.i
+
+# Libraries targets
+
+LIB = libSALOME_Commcmodule.la
+LIB_SERVER_IDL = SALOME_Exception.idl
+
+SWIG_DEF = libSALOME_Comm.i
+EXPORT_PYSCRIPTS = libSALOME_Comm.py 
+
+CPPFLAGS+=$(PYTHON_INCLUDES) $(MPI_INCLUDES) -I$(top_srcdir)/src/Communication/src
+LIBS+= $(PYTHON_LIBS)
+LDFLAGS+= -lSalomeCommunication
+
+@CONCLUDE@
diff --git a/src/Communication_SWIG/libSALOME_Comm.i b/src/Communication_SWIG/libSALOME_Comm.i
new file mode 100644 (file)
index 0000000..42d4d5a
--- /dev/null
@@ -0,0 +1,119 @@
+%module libSALOME_Comm
+
+%{
+  #include "ReceiverFactory.hxx"
+  #include "SALOME_Comm_i.hxx"
+%}
+
+%typemap(python,in) SALOME::SenderDouble_ptr
+{
+  PyObject* pdict = PyDict_New();
+  PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
+  PyRun_String("import CORBA", Py_single_input, pdict, pdict);
+  PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
+                   pdict, pdict);
+  PyObject* orb = PyDict_GetItemString(pdict, "o");
+
+  // Ask omniORBpy to transform SUPPORT (python Corba) ptr to IOR string
+
+  PyObject* iorSupport = PyObject_CallMethod(orb, "object_to_string", "O", $input);
+  if (iorSupport == Py_None)
+    return NULL;
+  char * s = PyString_AsString(PyObject_Str(iorSupport));
+  // Ask omniORB to convert IOR string to SALOME::SenderDouble_ptr
+
+  int argc = 0;
+  char *xargv = "";
+  char **argv = &xargv;
+  CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
+  CORBA::Object_var O =  ORB->string_to_object(s);
+  SALOME::SenderDouble_ptr t = SALOME::SenderDouble::_narrow(O);
+  $1 = t;
+}
+
+%typemap(python,in) SALOME::SenderInt_ptr
+{
+  PyObject* pdict = PyDict_New();
+  PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
+  PyRun_String("import CORBA", Py_single_input, pdict, pdict);
+  PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
+                   pdict, pdict);
+  PyObject* orb = PyDict_GetItemString(pdict, "o");
+
+  // Ask omniORBpy to transform SUPPORT (python Corba) ptr to IOR string
+
+  PyObject* iorSupport = PyObject_CallMethod(orb, "object_to_string", "O", $input);
+  if (iorSupport == Py_None)
+    return NULL;
+  char * s = PyString_AsString(PyObject_Str(iorSupport));
+  // Ask omniORB to convert IOR string to SALOME::SenderInt_ptr
+
+  int argc = 0;
+  char *xargv = "";
+  char **argv = &xargv;
+  CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
+  CORBA::Object_var O =  ORB->string_to_object(s);
+  SALOME::SenderInt_ptr t = SALOME::SenderInt::_narrow(O);
+  $1 = t;
+}
+
+PyObject * getValueForSenderDouble(SALOME::SenderDouble_ptr senderDouble);
+
+%{
+PyObject * getValueForSenderDouble(SALOME::SenderDouble_ptr senderDouble)
+{
+  PyObject *py_list;
+  long size;
+  double *ret=ReceiverFactory::getValue(senderDouble,size);
+  py_list = PyList_New(size);
+  for (int i=0; i < size; i++)
+    {
+            int err = PyList_SetItem(py_list, i, Py_BuildValue("d", (double) ret[i]));
+            if(err)
+              {
+                char * message = "Error in SUPPORT::getTypes";
+                PyErr_SetString(PyExc_RuntimeError, message);
+                return NULL;
+              }
+    }
+  PyObject * result = Py_BuildValue("O", py_list);
+  delete [] ret;
+  Py_DECREF(py_list);
+  return result;
+}
+%}
+
+
+PyObject * getValueForSenderInt(SALOME::SenderInt_ptr senderInt);
+
+%{
+PyObject * getValueForSenderInt(SALOME::SenderInt_ptr senderInt)
+{
+  PyObject *py_list;
+  long size;
+  int *ret=ReceiverFactory::getValue(senderInt,size);
+  py_list = PyList_New(size);
+  for (int i=0; i < size; i++)
+    {
+            int err = PyList_SetItem(py_list, i, Py_BuildValue("i", (int) ret[i]));
+            if(err)
+              {
+                char * message = "Error in SUPPORT::getTypes";
+                PyErr_SetString(PyExc_RuntimeError, message);
+                return NULL;
+              }
+    }
+  PyObject * result = Py_BuildValue("O", py_list);
+  delete [] ret;
+  Py_DECREF(py_list);
+  return result;
+}
+%}
index cd185a90d34237595ceb9ac183b98a0bb239843e..cb00f685fa0b3ae41b952f2a24308ce168a45802 100644 (file)
@@ -60,7 +60,7 @@ BIN = SALOME_Container SALOME_ContainerManagerServer
 BIN_SRC = SALOME_Container_SignalsHandler.cxx
 BIN_SERVER_IDL = SALOME_Component.idl SALOME_ContainerManager.idl
 
-CPPFLAGS+= $(PYTHON_INCLUDES) $(MPI_INCLUDE) $(OCC_INCLUDES) $(QT_MT_INCLUDES)
+CPPFLAGS+= $(PYTHON_INCLUDES) $(MPI_INCLUDES) $(OCC_INCLUDES) $(QT_MT_INCLUDES)
 CXXFLAGS+=$(OCC_CXXFLAGS)
 
 LDFLAGS+= $(QT_MT_LIBS) -lSalomeNS -lRegistry -lOpUtil -lSalomeNotification -lSALOMELocalTrace -lSalomeResourcesManager
index dff2dac8224d73f6b85838ad27db803bd792e195..cf8d73628edcc23f969c98f565800be55423777e 100644 (file)
@@ -44,7 +44,7 @@ EXPORT_PYSCRIPTS = TestLifeCycleCORBA.py
 LIB = libLifeCycleCORBATest.la 
 LIB_SRC = LifeCycleCORBATest.cxx
 LIB_CLIENT_IDL = SALOME_Component.idl SALOME_TestComponent.idl \
-                SALOME_Exception.idl
+                SALOME_Exception.idl nstest.idl
 
 # Executables targets
 
@@ -62,7 +62,8 @@ LDFLAGSFORBIN+= \
  -lSALOMELocalTraceTest -lSALOMELocalTrace -lSALOMEBasics \
  -lSALOMETraceCollectorTest \
  -lUtilsTest -lOpUtil \
- -lSalomeNS -lSalomeContainer -lSalomeResourcesManager \
+ -lNamingServiceTest -lSalomeNS \
+ -lSalomeContainer -lSalomeResourcesManager \
  -lRegistry -lSalomeNotification \
  -lLifeCycleCORBATest -lSalomeLifeCycleCORBA
 
index 987e3049ca619d3d6055ab55d27262a754f3958f..ee91e638eb33fd63e07a144b04d5ba4775c02e4a 100644 (file)
@@ -4,6 +4,7 @@
 #include "SALOMELocalTraceTest.hxx"
 #include "SALOMETraceCollectorTest.hxx"
 #include "UtilsTest.hxx"
+#include "NamingServiceTest.hxx"
 #include "LifeCycleCORBATest.hxx"
 
 // --- Registers the fixture into the 'registry'
@@ -11,6 +12,7 @@
 CPPUNIT_TEST_SUITE_REGISTRATION( SALOMELocalTraceTest );
 CPPUNIT_TEST_SUITE_REGISTRATION( SALOMETraceCollectorTest );
 CPPUNIT_TEST_SUITE_REGISTRATION( UtilsTest );
+CPPUNIT_TEST_SUITE_REGISTRATION( NamingServiceTest );
 CPPUNIT_TEST_SUITE_REGISTRATION( LifeCycleCORBATest );
 
 // --- generic Main program from Basic/Test
index 6aa39f7ce08ef9a8651b180695877b84ea61e810..808e9a42287f0257372ed30452ca5f8426848a63 100644 (file)
@@ -50,7 +50,7 @@ LIB_SERVER_IDL = SALOME_MPIObject.idl SALOME_MPIContainer.idl
 # Executables targets
 BIN = SALOME_MPIContainer
 BIN_SRC = 
-BIN_SERVER_IDL = SALOME_MPIObject.idl SALOME_MPIContainer.idl
+BIN_SERVER_IDL = SALOME_MPIObject.idl SALOME_MPIContainer.idl SALOME_Exception.idl
 
 CPPFLAGS+= $(PYTHON_INCLUDES) 
 LDFLAGS+= -lSalomeContainer -lSalomeNS -lRegistry -lOpUtil -lSalomeNotification -lSALOMELocalTrace -lSalomeResourcesManager
@@ -59,7 +59,7 @@ ifeq (@WITHMPI@,yes)
   LIBS += $(PYTHON_LIBS) $(MPI_LIBS)
   CXXFLAGS+=${MPI_INCLUDES}
   CXX_DEPEND_FLAG+=${MPI_INCLUDES}
-  LDFLAGSFORBIN= $(LDFLAGS)
+  LDFLAGSFORBIN= $(LDFLAGS) -lSALOMEBasics 
   LIBSFORBIN= $(LIBS)
 endif
 
index 2b5bb4c7deaadd86e17575855b9f4402ecbd6552..2830eaca5a5eaaeb2ce194f3f19c0f660e184181 100644 (file)
@@ -59,7 +59,8 @@ SUBDIRS = \
  SALOMEDS \
  KERNEL_PY \
  ModuleGenerator \
- Communication 
+ Communication \
+ Communication_SWIG
 
 ifeq (@mpi_ok@,yes)
   SUBDIRS+= MPIContainer TestMPIContainer
@@ -76,6 +77,7 @@ ifeq (@cppunit_ok@,yes)
  Logger/Test \
  SALOMETraceCollector/Test \
  Utils/Test \
+ NamingService/Test \
  LifeCycleCORBA/Test \
  UnitTests
 endif
index 0692af4951adff1b1bccbef8bac49de6fba397ff..a13dd52d46736c30467500f2b5da3038b7d427e3 100644 (file)
@@ -1,23 +1,23 @@
 //  SALOME NamingService : wrapping NamingService services
 //
 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
-// 
-//  This library is free software; you can redistribute it and/or 
-//  modify it under the terms of the GNU Lesser General Public 
-//  License as published by the Free Software Foundation; either 
-//  version 2.1 of the License. 
-// 
-//  This library is distributed in the hope that it will be useful, 
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-//  Lesser General Public License for more details. 
-// 
-//  You should have received a copy of the GNU Lesser General Public 
-//  License along with this library; if not, write to the Free Software 
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
-// 
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
 //
 //
 //
 
 using namespace std;
 
-//----------------------------------------------------------------------
-/*! Function : SALOME_NamingService
- *  Purpose  : Constructor and Initialisation of _root_context
- */
-//----------------------------------------------------------------------
+// ============================================================================
+/*! \brief Default Constructor without ORB reference.
+ *
+ *  After Default Constructor, one needs to initialize ORB.
+ *  \sa init_orb(CORBA::ORB_ptr orb), SALOME_NamingService(CORBA::ORB_ptr orb)
+ */ 
+// ============================================================================
 
 SALOME_NamingService::SALOME_NamingService()
 {
   MESSAGE("SALOME_NamingService default constructor");
   _orb = CORBA::ORB::_nil();
+  _root_context = CosNaming::NamingContext::_nil();
 }
 
-//----------------------------------------------------------------------
-/*! Function : SALOME_NamingService
+// ============================================================================
+/*! \brief Standard Constructor, with ORB reference. 
+ * 
+ * Initializes the naming service root context
  * \param orb CORBA::ORB_ptr arguments
- */
-//----------------------------------------------------------------------
+ */ 
+// ============================================================================
 
 SALOME_NamingService::SALOME_NamingService(CORBA::ORB_ptr orb)
 {
@@ -62,421 +67,512 @@ SALOME_NamingService::SALOME_NamingService(CORBA::ORB_ptr orb)
   _initialize_root_context();
 }
 
-//----------------------------------------------------------------------
-/*! Function : ~SALOME_NamingService
- *  Purpose  : Destructor
- */
-//----------------------------------------------------------------------
+// ============================================================================
+/*! \brief Standard destructor.
+ *
+ *  The standard destructor does nothing special.
+ */ 
+// ============================================================================
 
 SALOME_NamingService::~SALOME_NamingService()
 {
-  // Problem MESSAGE with singleton: late destruction, after trace system destruction ?
+  // Problem MESSAGE with singleton: late destruction,
+  // after trace system destruction ?
   //MESSAGE("SALOME_NamingService destruction");
 }
 
-//----------------------------------------------------------------------
-/*! Function : init_orb
- *  initialize ORB reference after default constructor
- */
-//----------------------------------------------------------------------
+// ============================================================================
+/*! \brief initializes ORB reference and naming service root context.
+ * 
+ *  Initializes ORB reference and naming service root context.
+ *  For use after default constructor.
+ *  \param orb CORBA::ORB_ptr arguments
+ */ 
+// ============================================================================
 
 void SALOME_NamingService::init_orb(CORBA::ORB_ptr orb)
 {
   MESSAGE("SALOME_NamingService initialisation");
-  Utils_Locker lock(&_myMutex);
-  _orb = orb ;
+
+  Utils_Locker lock (&_myMutex);
+  _orb = orb;
+
   _initialize_root_context();
 }
 
-
-//----------------------------------------------------------------------
-/*! Function : Register
- *  Method to create an association in the NamingService between ObjRef
- *  and Path.
- *  If the NamingService is out, the exception ServiceUnreachable is thrown
- * \param ObjRef CORBA::Object_ptr arguments
- * \param Path const char* arguments
+// ============================================================================
+/*! \brief Registers a CORBA object reference under a path.
+ *
+ * Registers a CORBA object reference under a path. If the path ends with '/',
+ * only a directory is created.
+ * If the NamingService is out, the exception ServiceUnreachable is thrown.
+ * \param ObjRef CORBA object reference to associate to the path. To create
+ *               only a directory, give nil pointer.
+ * \param Path   A relative or absolute pathname to store the object reference.
+ *               If the pathname begins with a '/', pathname is taken
+ *               as an absolute pathname. Else, pathname is taken as a relative
+ *               path, to current context. Prefer absolute pathname, relative
+ *               pathname are not safe, when SALOME_NamingService object is
+ *               shared or use in multithreaded context. 
+ *               If the path ends with '/', only a directory is created.
+ * \sa           Change_Directory(const char* Path),
+ *               Create_Directory(const char* Path)
+ *               CORBA::Object_ptr Resolve(const char* Path)
  */ 
-//----------------------------------------------------------------------
+// ============================================================================
 
 void SALOME_NamingService::Register(CORBA::Object_ptr ObjRef,
-                                   const char* Path) 
+                                    const char* Path)
   throw(ServiceUnreachable)
 {
-  MESSAGE("BEGIN OF Register: "<< Path);
-  Utils_Locker lock(&_myMutex);
-  int dimension_Path = strlen(Path) + 1;
-  char** resultat_resolve_Path = new char* [dimension_Path];
-
-  // _current_context is replaced to the _root_context 
-  // if the Path begins whith '/'
-  if (Path[0]=='/')  {
-    _current_context = _root_context;
-    //    MESSAGE("Gone to the _root_context");
-  }
-  
-  //the resolution of the directory path has to be done
-  //to place the currect_context to the correct node
-  int dimension_resultat = 0;
-  _result_resolve_Path (Path, dimension_resultat, resultat_resolve_Path);
-    
-  CosNaming::Name _context_name;
-  CORBA::Boolean _not_exist = false ;
-  CosNaming::NamingContext_var _temp_context;
-  
-  if(dimension_resultat>1)
-    {  
+  MESSAGE("BEGIN OF Register: " << Path);
+
+  Utils_Locker lock (&_myMutex);
+
+  // --- _current_context is replaced to the _root_context
+  //     if the Path begins whith '/'
+
+  if (Path[0] == '/')
+    {
+      _current_context = _root_context;
+    }
+
+  // --- the resolution of the directory path has to be done
+  //      to place the current_context to the correct node
+
+  CosNaming::Name context_name;
+  vector<string> splitPath;
+  int dimension_resultat = _createContextNameDir(Path,
+                                                context_name,
+                                                splitPath,
+                                                true);
+
+  CORBA::Boolean not_exist = false;
+
+  if (dimension_resultat > 0)
+    {
       // A directory is treated (not only an object name)
-      // We had to test if the directory where ObjRef should be recorded 
-      // is already done
-      // If not, the new context has to be created
+      // test if the directory where ObjRef should be recorded already exists
+      // If not, create the new context
+
+      try
+        {
+          CORBA::Object_var obj = _current_context->resolve(context_name);
+          _current_context = CosNaming::NamingContext::_narrow(obj);
+        }
+
+      catch (CosNaming::NamingContext::NotFound &)
+        {
+          // --- failed to resolve, therefore assume cold start
+          not_exist = true;
+        }
+
+      catch (CosNaming::NamingContext::InvalidName &)
+        {
+          INFOS("Register() : CosNaming::NamingContext::InvalidName");
+        }
+
+      catch (CosNaming::NamingContext::CannotProceed &)
+        {
+          INFOS("Register() : CosNaming::NamingContext::CannotProceed");
+        }
+
+      catch (CORBA::SystemException&)
+        {
+          INFOS("Register() : CORBA::SystemException: "
+                << "unable to contact the naming service");
+          throw ServiceUnreachable();
+        }
+
+      if (not_exist)
+        {
+          try
+            {
+              context_name.length(1);
+              for (int i = 0 ; i < dimension_resultat ;i++)
+                {
+                  context_name[0].id =
+                    CORBA::string_dup(splitPath[i].c_str());
+                  context_name[0].kind = CORBA::string_dup("dir");
+                  // SCRUTE(_context_name[0].id);
+                  // --- check if the path is created
+                  try
+                    {
+                      // --- if the context is already created, nothing to do
+                      CORBA::Object_var obj =
+                        _current_context->resolve(context_name);
+                      _current_context =
+                        CosNaming::NamingContext::_narrow(obj);
+                    }
+
+                  catch (CosNaming::NamingContext::NotFound &)
+                    {
+                      // --- the context must be created
+                      CosNaming::NamingContext_var temp_context =
+                        _current_context->bind_new_context(context_name);
+                      _current_context = temp_context;
+                    }
+                }
+            }
+
+          catch (CosNaming::NamingContext::AlreadyBound&)
+            {
+              INFOS("Register() : CosNaming::NamingContext::AlreadyBound");
+            }
+
+          catch (CosNaming::NamingContext::NotFound& ex)
+            {
+              CosNaming::Name n = ex.rest_of_name;
+
+              if (ex.why == CosNaming::NamingContext::missing_node)
+                INFOS("Register() : " << (char *) n[0].id
+                      << " (" << (char *) n[0].kind << ") not found");
+
+              if (ex.why == CosNaming::NamingContext::not_context)
+                INFOS("Register() : " << (char *) n[0].id
+                      << " (" << (char *) n[0].kind
+                      << ") is not a context");
+
+              if (ex.why == CosNaming::NamingContext::not_object)
+                INFOS("Register() : " << (char *) n[0].id
+                      << " (" << (char *) n[0].kind
+                      << ") is not an object");
+            }
+
+          catch (CosNaming::NamingContext::CannotProceed&)
+            {
+              INFOS("Register(): CosNaming::NamingContext::CannotProceed");
+            }
+
+          catch (CosNaming::NamingContext::InvalidName&)
+            {
+              INFOS("Register(): CosNaming::NamingContext::InvalidName");
+            }
+
+          catch (CORBA::SystemException&)
+            {
+              INFOS("Register():CORBA::SystemException: "
+                    << "unable to contact the naming service");
+              throw ServiceUnreachable();
+            }
+        }
+    }
 
-      //      MESSAGE("A complet Path has to be treated, not only an object name");
-      _context_name.length(dimension_resultat-1);
+  // --- The current directory is now the directory where the object should
+  //     be recorded
 
-      _create_context_name_dir(resultat_resolve_Path,dimension_resultat-1,
-                              _context_name);  
+  int sizePath = splitPath.size();
+  if (sizePath > dimension_resultat)
+    {
+      ASSERT(sizePath == dimension_resultat+1);
+      context_name.length(1);
 
       try
        {
-         CORBA::Object_var _obj = _current_context->resolve(_context_name);
-         _current_context = CosNaming::NamingContext::_narrow(_obj);
-       } 
-      catch (CosNaming::NamingContext::NotFound &) 
-       {
-         // failed to resolve, therefore assume cold start
-         _not_exist = true;
-       } 
-      catch (CosNaming::NamingContext::InvalidName &) 
+         // --- the last element is an object and not a directory
+
+         context_name[0].id =
+           CORBA::string_dup(splitPath[dimension_resultat].c_str());
+         context_name[0].kind = CORBA::string_dup("object");
+         //SCRUTE(context_name[0].id);
+
+         _current_context->bind(context_name, ObjRef);
+       }
+
+      catch (CosNaming::NamingContext::NotFound& ex)
        {
-         INFOS("!!!Register() : CosNaming::NamingContext::InvalidName"); 
+         CosNaming::Name n = ex.rest_of_name;
+
+         if (ex.why == CosNaming::NamingContext::missing_node)
+           INFOS("Register() : " << (char *) n[0].id
+                 << " (" << (char *) n[0].kind << ") not found");
+
+         if (ex.why == CosNaming::NamingContext::not_context)
+           INFOS("Register() : " << (char *) n[0].id
+                 << " (" << (char *) n[0].kind
+                 << ") is not a context");
+
+         if (ex.why == CosNaming::NamingContext::not_object)
+           INFOS("Register() : " << (char *) n[0].id
+                 << " (" << (char *) n[0].kind
+                 << ") is not an object");
        }
-      catch (CosNaming::NamingContext::CannotProceed &)
+
+      catch (CosNaming::NamingContext::CannotProceed&)
        {
-         INFOS("!!!Register() : CosNaming::NamingContext::CannotProceed");
+         INFOS("Register(): CosNaming::NamingContext::CannotProceed");
        }
-      catch(CORBA::SystemException&)
+
+      catch (CosNaming::NamingContext::InvalidName&)
        {
-         INFOS("!!!Register() : CORBA::SystemException : unable to contact"
-              << " the naming service"); 
-         throw ServiceUnreachable();
+         INFOS("Register(): CosNaming::NamingContext::InvalidName");
        }
-      if(_not_exist)
+
+      catch (CosNaming::NamingContext::AlreadyBound&)
        {
-         try
-           {
-             _context_name.length(1);
-             // MESSAGE("The Path indicated is not yet created. It will soon be done");
-             for (int i = 0 ; i <dimension_resultat -1 ;i++)
-               {
-                 _context_name[0].id =
-                   CORBA::string_dup(resultat_resolve_Path[i]);
-                 _context_name[0].kind = CORBA::string_dup("dir");
-                 // SCRUTE(_context_name[0].id);
-                 //The Path could be in part already created. 
-                 //We had to test it
-                 try 
-                   {
-                     // this context is already created. 
-                     // Nothing to be done
-                     CORBA::Object_var _obj = 
-                       _current_context->resolve(_context_name);
-                     _current_context = 
-                       CosNaming::NamingContext::_narrow(_obj);
-                     //MESSAGE("This context was already created");
-                   } 
-                 catch (CosNaming::NamingContext::NotFound &) 
-                   {
-                     // This context is not created. It will be done
-                     _temp_context =
-                       _current_context->bind_new_context(_context_name);
-                     _current_context = _temp_context;
-                     //INFOS("This context was'nt created, it's now done");
-                   }
-               }
-           }
-         catch (CosNaming::NamingContext::AlreadyBound&)
-           {
-             INFOS("!!!Register() : CosNaming::NamingContext::AlreadyBound");  
-           }
-         catch(CosNaming::NamingContext::NotFound& ex)
-           {
-             CosNaming::Name n = ex.rest_of_name;
-             if (ex.why == CosNaming::NamingContext::missing_node)
-               INFOS("Register() : " << (char *) n[0].id
-                     << " (" << (char *) n[0].kind << ") not found");
-             if (ex.why == CosNaming::NamingContext::not_context)
-               INFOS("Register() : " << (char *) n[0].id
-                    << " (" << (char *) n[0].kind
-                    << ") is not a context");
-             if (ex.why == CosNaming::NamingContext::not_object)
-               INFOS("Register() : " << (char *) n[0].id
-                    << " (" << (char *) n[0].kind
-                    << ") is not an object");
-           }
-         catch(CosNaming::NamingContext::CannotProceed&)
-           {
-             INFOS("!!!Register() : CosNaming::NamingContext::CannotProceed");
-           } 
-         catch(CosNaming::NamingContext::InvalidName&) 
-           {
-             INFOS("!!!Register() : CosNaming::NamingContext::InvalidName");
-           }
-         catch(CORBA::SystemException&)
-           {
-             INFOS("!!!Register() :CORBA::SystemException : unable to contact"
-                  << " the naming service"); 
-             throw ServiceUnreachable();
-           }
-       }       
-    }
+         INFOS("Register(): CosNaming::NamingContext::AlreadyBound, "
+               << "object will be rebind");
+         _current_context->rebind(context_name, ObjRef);
+       }
 
-  // The current directory is now the directory where the object should 
-  // be recorded
-  _context_name.length(1);
-  try 
-    {
-      // the last element is an object an not a directory
-      _context_name[0].id = 
-       CORBA::string_dup(resultat_resolve_Path[dimension_resultat -1]);
-      _context_name[0].kind = CORBA::string_dup("object");
-      //SCRUTE(_context_name[0].id);
-       
-      _current_context->bind(_context_name, ObjRef);
-      // MESSAGE("A new element " << _context_name[0].id 
-      //          << " is recorded in the _current_context");   
-    }
-  catch(CosNaming::NamingContext::NotFound& ex)
-    {
-      CosNaming::Name n = ex.rest_of_name;
-      if (ex.why == CosNaming::NamingContext::missing_node)
-       INFOS("Register() : "  << (char *) n[0].id
-             << " ("  << (char *) n[0].kind << ") not found");
-      if (ex.why == CosNaming::NamingContext::not_context)
-       INFOS("Register() : " << (char *) n[0].id
-            << " (" << (char *) n[0].kind
-            << ") is not a context");
-      if (ex.why == CosNaming::NamingContext::not_object)
-       INFOS("Register() : " << (char *) n[0].id
-            << " (" << (char *) n[0].kind
-            << ") is not an object");
-    }
-  catch(CosNaming::NamingContext::CannotProceed&)
-    {
-      INFOS("!!!Register() : CosNaming::NamingContext::CannotProceed"); 
-    } 
-  catch(CosNaming::NamingContext::InvalidName&) 
-    {
-      INFOS("!!!Register() : CosNaming::NamingContext::InvalidName"); 
-    }
-  catch(CosNaming::NamingContext::AlreadyBound&) 
-    {
-      INFOS("!!!Register() : CosNaming::NamingContext::AlreadyBound, object will be rebind"); 
-      _current_context->rebind(_context_name, ObjRef);
-    }
-  catch(CORBA::SystemException&)
-    {
-      INFOS("!!!Register() :CORBA::SystemException : unable to contact"
-           << " the naming service");
-      throw ServiceUnreachable();
-    }
-  
-  
-  // Memory destruction
-  for (int i = 0 ; i <dimension_resultat ;i++) 
-    {
-      delete [] resultat_resolve_Path[i];     
+      catch (CORBA::SystemException&)
+       {
+         INFOS("!!!Register(): CORBA::SystemException: "
+               << "unable to contact the naming service");
+         throw ServiceUnreachable();
+       }
     }
-  delete[] resultat_resolve_Path ;
 }
 
-//----------------------------------------------------------------------
-/*! Function : Resolve 
- *  Purpose  : method to get the ObjRef of a symbolic name
+// ============================================================================
+/*! \brief get the CORBA object reference associated to a name.
+ * 
+ *  get the CORBA object reference associated to a complete name with a path.
  *  If the NamingService is out, the exception ServiceUnreachable is thrown 
- * \param Path const char* arguments
- * \return the object reference
- */
-//----------------------------------------------------------------------
+ * \param Path pathname. If the pathname begins with a '/', pathname is taken
+ *             as an absolute pathname. Else, pathname is taken as a relative
+ *             path, to current context. Prefer absolute pathname, relative
+ *             pathname are not safe, when SALOME_NamingService object is
+ *             shared or use in multithreaded context.
+ * \return the object reference if it exists under the pathname,
+ *             or nil reference in other cases.
+ * \sa         Register(CORBA::Object_ptr ObjRef, const char* Path),
+ *             Change_Directory(const char* Path)
+ */ 
+// ============================================================================
 
 CORBA::Object_ptr SALOME_NamingService::Resolve(const char* Path)
   throw(ServiceUnreachable)
 {
   MESSAGE("BEGIN OF Resolve: " << Path);
-  Utils_Locker lock(&_myMutex);
-  int dimension_Path = strlen(Path) + 1;
-  char** resultat_resolve_Path = new char* [dimension_Path];
 
-  // _current_context is replaced to the _root_context 
-  // if the Path begins whith '/'
-  if (Path[0]=='/') _current_context = _root_context;
+  Utils_Locker lock (&_myMutex);
+
+  // --- _current_context is replaced to the _root_context
+  //     if the Path begins whith '/'
+
+  if (Path[0] == '/')
+    {
+      _current_context = _root_context;
+    }
+
+  // --- the resolution of the directory path has to be done
+  //     to place the current_context to the correct node
+
+  CosNaming::Name context_name;
+  vector<string> splitPath;
+  int dimension_resultat = _createContextNameDir(Path,
+                                                context_name,
+                                                splitPath,
+                                                false);
 
-  
-  //the resolution of the directory path has to be done
-  //to place the currect_context to the correct node
-  int dimension_resultat = 0;
-  _result_resolve_Path (Path, dimension_resultat, resultat_resolve_Path);
-    
-  CosNaming::Name _context_name;
-  _context_name.length(dimension_resultat);
-  CORBA::Object_ptr _obj = NULL ;
-    
-  _create_context_name_dir(resultat_resolve_Path,dimension_resultat-1,
-                          _context_name);
-  // the last element is an object an not a directory
-  _context_name[dimension_resultat -1].id = 
-    CORBA::string_dup(resultat_resolve_Path[dimension_resultat -1]);
-  _context_name[dimension_resultat -1].kind = CORBA::string_dup("object");
-  // SCRUTE(_context_name[dimension_resultat -1].id);
   ASSERT(!CORBA::is_nil(_current_context));
-  // Context creation
-  try 
+
+  CORBA::Object_ptr obj =  CORBA::Object::_nil();
+
+  try
     {
-      _obj =_current_context->resolve(_context_name);
+      obj = _current_context->resolve(context_name);
     }
-  catch(CosNaming::NamingContext::NotFound& ex)
+
+  catch (CosNaming::NamingContext::NotFound& ex)
     {
       CosNaming::Name n = ex.rest_of_name;
+
       if (ex.why == CosNaming::NamingContext::missing_node)
-       INFOS("Resolve() : " << (char *) n[0].id
-             << " (" << (char *) n[0].kind << ") not found");
+        INFOS("Resolve() : " << (char *) n[0].id
+              << " (" << (char *) n[0].kind << ") not found");
+
       if (ex.why == CosNaming::NamingContext::not_context)
-       INFOS("Resolve() : "
-            << (char *) n[0].id  << " (" << (char *) n[0].kind
-            << ") is not a context");
+        INFOS("Resolve() : "
+              << (char *) n[0].id << " (" << (char *) n[0].kind
+              << ") is not a context");
+
       if (ex.why == CosNaming::NamingContext::not_object)
-       INFOS("Resolve() : " << (char *) n[0].id
-            << " (" << (char *) n[0].kind
-            << ") is not an object");
+        INFOS("Resolve() : " << (char *) n[0].id
+              << " (" << (char *) n[0].kind
+              << ") is not an object");
     }
-  catch(CosNaming::NamingContext::CannotProceed&)
-    {
-      INFOS("!!!Resolve() : CosNaming::NamingContext::CannotProceed"); 
-    } 
-  catch(CosNaming::NamingContext::InvalidName&) 
+
+  catch (CosNaming::NamingContext::CannotProceed&)
     {
-      INFOS("!!!Resolve() : CosNaming::NamingContext::InvalidName"); 
+      INFOS("Resolve(): CosNaming::NamingContext::CannotProceed");
     }
-  catch(CORBA::SystemException&)
+
+  catch (CosNaming::NamingContext::InvalidName&)
     {
-      INFOS("!!!Resolve() :CORBA::SystemException : unable to contact"
-           << "the naming service");
-      throw ServiceUnreachable();
+      INFOS("Resolve(): CosNaming::NamingContext::InvalidName");
     }
-  // Memory destruction
-  for (int i = 0 ; i <dimension_resultat ;i++) 
+
+  catch (CORBA::SystemException&)
     {
-      delete [] resultat_resolve_Path[i];     
+      INFOS("Resolve():CORBA::SystemException : unable to contact"
+            << "the naming service");
+      throw ServiceUnreachable();
     }
-  delete[] resultat_resolve_Path ;
-  
-  return _obj;
+
+  return obj;
 }
 
-//----------------------------------------------------------------------
-/*! Function : ResolveFirst 
- *  Purpose  : method to get an ObjRef with a symbolic name
- * \param Path const char* argument like "/path/name"
- *  search the fist reference like "/path(.dir)/name*(.kind)"
+// ============================================================================
+/*! \brief get the CORBA object reference associated to an uncomplete name.
+ *
+ *  get the CORBA object reference associated to an uncomplete name with a
+ *  path. Look for the first occurence of name*.
  *  If the NamingService is out, the exception ServiceUnreachable is thrown 
-
-
-
-
- * \return the object reference
+ * \param Path pathname under the form "/path/name" (Absolute reference !)
+ *             search the fist reference like "/path(.dir)/name*(.kind)"
+ * \return     the object reference if found, or nil reference.
+ * \sa         Resolve(const char* Path)
  */
-//----------------------------------------------------------------------
+// ============================================================================
 
 CORBA::Object_ptr SALOME_NamingService::ResolveFirst(const char* Path)
   throw(ServiceUnreachable)
 {
   MESSAGE("ResolveFirst");
-  Utils_Locker lock(&_myMutex);
+
+  Utils_Locker lock (&_myMutex);
   SCRUTE(Path);
-  string thePath =Path;
-  string basePath ="/";
+
+  string thePath = Path;
+  string basePath = "";
   string name = thePath;
+
   string::size_type idx = thePath.rfind('/');
+
   if (idx != string::npos) // at least one '/' found
     {
-      basePath = thePath.substr(0,idx);
-      name = thePath.substr(idx+1);
+      basePath = thePath.substr(0, idx);
+      name = thePath.substr(idx + 1);
       SCRUTE(basePath);
     }
+
   SCRUTE(name);
   CORBA::Object_ptr obj = CORBA::Object::_nil();
-  bool isOk = Change_Directory(basePath.c_str());
+
+  bool isOk = false;
+  if (basePath.empty())
+    isOk =true;
+  else
+    isOk = Change_Directory(basePath.c_str());
+  
   if (isOk)
     {
       vector<string> listElem = list_directory();
       vector<string>::iterator its = listElem.begin();
+      
       while (its != listElem.end())
        {
          MESSAGE(*its);
+         
          if ((*its).find(name) == 0)
            {
-             //string instance = basePath + "/" + *its;
              return Resolve((*its).c_str());
            }
+         
          its++;
        }
     }
+
   return obj;
 }
 
-//----------------------------------------------------------------------
-/*! Function : Resolve Component  from hostname, containername, componentName and number of prcoessors
- *  Purpose  : method to get the ObjRef of a component
- *  If the NamingService is out, the exception ServiceUnreachable is thrown 
- * \param hostname const char* argument
- * \param containername const char* argument
- * \param componentname const char* argument
- * \param nbproc const int argument
+// ============================================================================
+/*! \brief find a component instance from hostname, containername,
+ *         componentName and number of processors.
+ *
+ *  find a component instance from hostname, containername, componentName and
+ *  number of processors.
+ *  If the NamingService is out, the exception ServiceUnreachable is thrown.
+ * \param hostname      name of the machine on which the component is searched.
+ * \param containername name of the container in which the component is
+                        instanciated.
+ * \param componentname name of the component we are looking for an existing 
+                        instance.
+ * \param nbproc        in case of multi processor machine, container name is
+ *                      suffixed with _nbproc.
  * \return the object reference
- */
-//----------------------------------------------------------------------
+ */ 
+// ============================================================================
 
-CORBA::Object_ptr SALOME_NamingService::ResolveComponent(const char* hostname, const char* containerName, const char* componentName, const int nbproc)
+CORBA::Object_ptr
+SALOME_NamingService::ResolveComponent(const char* hostname,
+                                      const char* containerName,
+                                      const char* componentName,
+                                      const int nbproc)
+  throw(ServiceUnreachable)
 {
   MESSAGE("ResolveComponent");
-  Utils_Locker lock(&_myMutex);
 
-  string name="/Containers/";
+  Utils_Locker lock (&_myMutex);
+
+  string name = "/Containers/";
+
   name += hostname;
-  if( strlen(containerName) != 0 ){
-    name += "/";
-    if( nbproc >=1 ){
-      char *newContainerName = new char[strlen(containerName)+8];
-      sprintf(newContainerName,"%s_%d",containerName,nbproc);
-      name += newContainerName;
-    }
-    else
-      name += containerName;
-    name += "/";
-    name += componentName;
-    return ResolveFirst(name.c_str());
-  }
-  else {
-    Change_Directory(name.c_str());
-    vector<string> contList = list_directory();
-    for(unsigned int ind = 0; ind < contList.size(); ind++){
-      name = contList[ind].c_str();
+
+  if ( strlen(containerName) != 0 )
+    {
+      name += "/";
+
+      if ( nbproc >= 1 )
+        {
+          char *newContainerName = new char[strlen(containerName) + 8];
+          sprintf(newContainerName, "%s_%d", containerName, nbproc);
+          name += newContainerName;
+         delete [] newContainerName;
+        }
+
+      else
+        name += containerName;
+
       name += "/";
+
       name += componentName;
-      CORBA::Object_ptr obj = ResolveFirst(name.c_str());
-      if( !CORBA::is_nil(obj) )
-       return obj;
+
+      return ResolveFirst(name.c_str());
     }
-    return CORBA::Object::_nil();
-  }
 
+  else
+    {
+      SCRUTE(name);
+      if (Change_Directory(name.c_str()))
+       {
+         vector<string> contList = list_subdirs();
+
+         for (unsigned int ind = 0; ind < contList.size(); ind++)
+           {
+             name = contList[ind].c_str();
+             name += "/";
+             name += componentName;
+             SCRUTE(name);
+             CORBA::Object_ptr obj = ResolveFirst(name.c_str());
+
+             if ( !CORBA::is_nil(obj) )
+               return obj;
+           }
+       }
+
+      return CORBA::Object::_nil();
+    }
 }
 
+// ============================================================================
+/*! \brief provide a default container name if empty.
+ *
+ *  the given container name is returned unchanged, unless it is empty.
+ * \param  containerName
+ * \return container name, where empty input is replaced by "FactoryServer",
+ *         without the path.
+ * \sa BuildContainerNameForNS(const char *containerName, const char *hostname)
+ */
+// ============================================================================
+
 string SALOME_NamingService::ContainerName(const char *containerName)
 {
   string ret;
 
-  if (strlen(containerName)== 0)
+  if (strlen(containerName) == 0)
     ret = "FactoryServer";
   else
     ret = containerName;
@@ -484,1103 +580,1250 @@ string SALOME_NamingService::ContainerName(const char *containerName)
   return ret;
 }
 
-string SALOME_NamingService::ContainerName(const Engines::MachineParameters& params)
+// ============================================================================
+/*! \brief build a container name, given a MachineParameters struct.
+ *
+ *  Build a container name with a MachineParameters struct. In case of multi
+ *  processor machine, container name is suffixed with _nbproc. nproc equals
+ *  (number of nodes)*(number of processor per nodes).
+ * \param params struct from which we get container name (may be
+ *               empty),  number of nodes and number of processor
+ *               per node.
+ * \return a container name without the path.
+ * \sa BuildContainerNameForNS(const Engines::MachineParameters& params,
+ *                             const char *hostname)
+ */
+// ============================================================================
+
+string 
+SALOME_NamingService::ContainerName(const Engines::MachineParameters& params)
 {
   int nbproc;
-  if( !params.isMPI )
+
+  if ( !params.isMPI )
     nbproc = 0;
-  else if( (params.nb_node <= 0) && (params.nb_proc_per_node <= 0) )
+  else if ( (params.nb_node <= 0) && (params.nb_proc_per_node <= 0) )
     nbproc = 1;
-  else if( params.nb_node == 0 )
+  else if ( params.nb_node == 0 )
     nbproc = params.nb_proc_per_node;
-  else if( params.nb_proc_per_node == 0 )
+  else if ( params.nb_proc_per_node == 0 )
     nbproc = params.nb_node;
   else
     nbproc = params.nb_node * params.nb_proc_per_node;
 
-  string ret=ContainerName(params.container_name);
+  string ret = ContainerName(params.container_name);
 
-  if( nbproc >=1 ){
-    char *suffix = new char[8];
-    sprintf(suffix,"_%d",nbproc);
-    ret += suffix;
-  }
+  if ( nbproc >= 1 )
+    {
+      char *suffix = new char[8];
+      sprintf(suffix, "_%d", nbproc);
+      ret += suffix;
+    }
 
   return ret;
 }
 
-string SALOME_NamingService::BuildContainerNameForNS(const char *containerName, const char *hostname)
+// ============================================================================
+/*! \brief build a string representing a container in Naming Service.
+ *
+ *  Build a string representing the absolute pathname of a container in
+ *  SALOME_NamingService. This form gives a suffixed containerName in case of
+ *  multi processor machine.
+ * \param params struct from which we get container name (may be
+ *               empty),  number of nodes and number of processor
+ *               per node.
+ * /param hostname name of the host of the container, without domain names.
+ * /return the path under the form /Containers/hostname/containerName
+ * /sa ContainerName(const Engines::MachineParameters& params)
+ */
+// ============================================================================
+
+string SALOME_NamingService::BuildContainerNameForNS(const char *containerName,
+                                                    const char *hostname)
 {
-  string ret="/Containers/";
+  string ret = "/Containers/";
   ret += hostname;
-  ret+="/";
-  ret+=ContainerName(containerName);
+  ret += "/";
+  ret += ContainerName(containerName);
 
   return ret;
 }
 
-string SALOME_NamingService::BuildContainerNameForNS(const Engines::MachineParameters& params, const char *hostname)
+// ============================================================================
+/*! \brief build a string representing a container in Naming Service.
+ *
+ *  Build a string representing the absolute pathname of a container in
+ *  SALOME_NamingService.
+ * /param params used as it is, or replaced by FactoryServer if empty.
+ * /param hostname name of the host of the container, without domain names.
+ * /return the path under the form /Containers/hostname/containerName
+ * /sa ContainerName(const char *containerName)
+ */
+// ============================================================================
+
+string
+SALOME_NamingService::
+BuildContainerNameForNS(const Engines::MachineParameters& params,
+                       const char *hostname)
 {
-  string ret="/Containers/";
+  string ret = "/Containers/";
   ret += hostname;
-  ret+="/";
-  ret+=ContainerName(params);
+  ret += "/";
+  ret += ContainerName(params);
 
   return ret;
 }
 
-//----------------------------------------------------------------------
-/*!  Function : Find
- *  Purpose  : method to research a name from the current directory 
- *            of the naming service. 
- *  The naming service changes directory to go to the directory where 
- *  the last occurence was found.
- *  If the NamingService is out, the exception ServiceUnreachable is thrown
- *  \param name const char* arguments
- *  \return the number of occurences found
- *  \sa _Find
- */   
-//----------------------------------------------------------------------
+// ============================================================================
+/*! \brief search a name in current directory.
+ *
+ *  Search a name in the current directory. after call, the current directory
+ *  is changed to the directory containing the last occurence of name found.
+ *  If no occurence found (see return value), current directory remains
+ *  unchanged.
+ *
+ * \param  name the name to search.
+ * \return number of occurences found.
+ * \sa Change_Directory(const char* Path)
+ */ 
+// ============================================================================
 
 int SALOME_NamingService::Find(const char* name)
-  throw(ServiceUnreachable)
+throw(ServiceUnreachable)
 {
   MESSAGE("BEGIN OF Find " << name);
-  Utils_Locker lock(&_myMutex);
-  CORBA::Long occurence_number = 0 ; 
+
+  Utils_Locker lock (&_myMutex);
+
+  CORBA::Long occurence_number = 0 ;
+
   try
     {
-      _Find(name,occurence_number);
+      _Find(name, occurence_number);
     }
-  catch(CORBA::SystemException&)
+
+  catch (CORBA::SystemException&)
     {
       INFOS("!!!Find() : CORBA::SystemException : unable to contact"
-          << " the naming service"); 
+            << " the naming service");
       throw ServiceUnreachable();
     }
+
   return occurence_number;
 }
 
-//----------------------------------------------------------------------
-/*! Function : Create_Directory 
- *  Purpose  : method to create a directory from the current directory.
- * If the NamingService is out, the exception ServiceUnreachable is thrown
- *  \param Path const char* arguments
- *  \return a boolean to indicate if the creation succeeded
- */
-//----------------------------------------------------------------------
+// ============================================================================
+/*! \brief Creates a directory (context_name)
+ *
+ *  Creates a directory (context_name) relative to the current directory 
+ *  (current context) or relative to the root directory (root context), if
+ *  the path given begins with a '/'.
+ *  If the NamingService is out, the exception ServiceUnreachable is thrown.
+ * \param Path   A relative or absolute pathname to store the object reference.
+ *               If the pathname begins with a '/', pathname is taken
+ *               as an absolute pathname. Else, pathname is taken as a relative
+ *               path, to current context. Prefer absolute pathname, relative
+ *               pathname are not safe, when SALOME_NamingService object is
+ *               shared or use in multithreaded context.   
+ *  \return true if successfull
+ *          (creation not strictly garanteed if true, because Register may
+ *           catch some specific unlikely exception without throw anything
+ *           --- to be corrected ---)
+ *  \sa RegisterCORBA::Object_ptr ObjRef, const char* Path)
+ */ 
+// ============================================================================
 
 bool SALOME_NamingService::Create_Directory(const char* Path)
-  throw(ServiceUnreachable)
+throw(ServiceUnreachable)
 {
   MESSAGE("BEGIN OF Create_Directory");
-  Utils_Locker lock(&_myMutex);
-  int dimension_Path = strlen(Path) + 1;
-  char** resultat_resolve_Path= new char* [dimension_Path];;
-  CORBA::Boolean _return_code = true ;
 
-  // _current_context is replaced to the _root_context 
-  // if the Path begins whith '/'
-  if (Path[0]=='/') _current_context = _root_context;
+  Utils_Locker lock (&_myMutex);
 
-  int dimension_resultat = 0;
-  _result_resolve_Path (Path, dimension_resultat, resultat_resolve_Path);
+  string path(Path);
 
-  // We had to test if a part of the directory to treat 
-  // is already done
-  // If not, the new context has to be created
-  CosNaming::Name _context_name;
-  _context_name.length(1);
-  CosNaming::NamingContext_var _temp_context;
-  ASSERT(!CORBA::is_nil(_current_context));
-  // Context creation
-  try
+  // --- if path empty, nothing to create, no context change
+
+  if (path.empty())
+    return false;
+
+  // --- if path ='/', nothing to create, only change to root_context
+
+  if (path == "/")
     {
-       
-      for (int i = 0 ; i <dimension_resultat ;i++)
-       {
-         _context_name[0].id =
-           CORBA::string_dup(resultat_resolve_Path[i]);
-         _context_name[0].kind = CORBA::string_dup("dir");
-         // SCRUTE(_context_name[0].id);
-         //The Path could be in part already created. 
-         //We had to test it
-         try 
-           {
-             // this context is already created. 
-             // Nothing to be done
-             CORBA::Object_var _obj = 
-               _current_context->resolve(_context_name);
-             _current_context = 
-               CosNaming::NamingContext::_narrow(_obj);
-             MESSAGE("This context was already created");
-               } 
-         catch (CosNaming::NamingContext::NotFound &) 
-           {
-             // This context is not created. It will be done
-             _temp_context =
-               _current_context->bind_new_context(_context_name);
-             _current_context = _temp_context;
-             INFOS("This context was'nt created, it's now done");
-               }
-       }
+      MESSAGE("Create Directory '/', just change to root_context");
+      _current_context = _root_context;
+      return true;
+    }
+
+  // --- path must end with '/'
+  
+  if (path[path.length()-1] != '/') path += '/';
+
+  Register(CORBA::Object::_nil(), path.c_str());
+  return true;
+}
+
+// ============================================================================
+/*! \brief change current directory to the given path
+ *
+ *  change the current directory to the given path in parameter.
+ *  Warning: avoid use when the SALOME_NamingService instance is shared by
+ *  several threads (current context may be modified by another thread).
+ *  If the path is empty, nothing done return OK.
+ *  If Path ="/", the current directory changes to the root directory.
+ *  If the NamingService is out, the exception ServiceUnreachable is thrown.
+ * \param  Path the new current directory
+ * \return true if the change succeeded
+ */ 
+// ============================================================================
+
+bool SALOME_NamingService::Change_Directory(const char* Path)
+throw(ServiceUnreachable)
+{
+  MESSAGE("BEGIN OF Change_Directory " << Path);
+  Utils_Locker lock (&_myMutex);
+
+  string path(Path);
+
+  // --- if path empty, nothing to do
+
+  if (path.empty())
+    return true;
+
+  // --- if path ='/', nothing to resolve, only change to root_context
+
+  if (path == "/")
+    {
+      MESSAGE("Change_Directory is called to go to the root_context");
+      _current_context = _root_context;
+      return true;
     }
-  catch (CosNaming::NamingContext::AlreadyBound&)
+
+  CosNaming::NamingContext_var current_context = _current_context;
+  bool changeOK = false;
+
+  // --- replace _current_context with _root_context if Path begins whith '/'
+
+  if (path[0] == '/')
+    current_context = _root_context;
+
+  // --- need to resolve directory path
+
+  ASSERT(!CORBA::is_nil(current_context));
+  
+  if (path[path.length()-1] != '/') path += '/';
+  SCRUTE(path);
+  CosNaming::Name context_name;
+  vector<string> splitPath;
+  int dimension_resultat = _createContextNameDir(path.c_str(),
+                                                context_name,
+                                                splitPath,
+                                                true);
+  
+  // --- Context creation
+  
+  try
     {
-      INFOS("!!! Create_Directory() CosNaming::NamingContext::AlreadyBound");
-      _return_code = false;    
+      CORBA::Object_var obj = current_context->resolve(context_name);
+      current_context = CosNaming::NamingContext::_narrow(obj);
+      ASSERT(!CORBA::is_nil(current_context));
+      _current_context = current_context;
+      changeOK = true;
     }
-  catch(CosNaming::NamingContext::NotFound& ex)
+  
+  catch (CosNaming::NamingContext::NotFound& ex)
     {
-      _return_code = false;
       CosNaming::Name n = ex.rest_of_name;
+      
       if (ex.why == CosNaming::NamingContext::missing_node)
-       INFOS("Create_Directory() : " << (char *) n[0].id
-             << " (" << (char *) n[0].kind << ") not found");
+       INFOS( "Change_Directory() : " << (char *) n[0].id
+              << " (" << (char *) n[0].kind << ") not found");
       if (ex.why == CosNaming::NamingContext::not_context)
-       INFOS("Create_Directory() : " << (char *) n[0].id
-            << " (" << (char *) n[0].kind
-            << ") is not a context");
+       INFOS("Change_Directory() : " << (char *) n[0].id
+             << " (" << (char *) n[0].kind
+                 << ") is not a context" );
       if (ex.why == CosNaming::NamingContext::not_object)
-       INFOS("Create_Directory() : " << (char *) n[0].id
-            << " (" << (char *) n[0].kind
-            << ") is not an object");
+       INFOS( "Change_Directory() : " << (char *) n[0].id
+              << " (" << (char *) n[0].kind
+              << ") is not an object" );
     }
-  catch(CosNaming::NamingContext::CannotProceed&)
-    {
-      _return_code = false;
-      INFOS("!!!Create_Directory():CosNaming::NamingContext::CannotProceed"); 
-    } 
-  catch(CosNaming::NamingContext::InvalidName&) 
+  
+  catch (CosNaming::NamingContext::CannotProceed&)
     {
-      _return_code = false;
-      INFOS("!!!Create_Directory():CosNaming::NamingContext::InvalidName");
+      INFOS("Change_Directory(): CosNaming::NamingContext::CannotProceed");
     }
-  catch(CORBA::SystemException&)
+  
+  catch (CosNaming::NamingContext::InvalidName&)
     {
-      _return_code = false;
-      INFOS("!!!Register() :CORBA::SystemException : unable to contact"
-          << " the naming service"); 
-      throw ServiceUnreachable();
+      INFOS("Change_Directory(): CosNaming::NamingContext::InvalidName");
     }
-  // Memory destruction
-  for (int i = 0 ; i <dimension_resultat;i++) 
+  
+  catch (CORBA::SystemException&)
     {
-      delete [] resultat_resolve_Path[i];     
+      INFOS("Change_Directory():CORBA::SystemException : unable to contact"
+           << "the naming service");
+      throw ServiceUnreachable();
     }
-  delete[] resultat_resolve_Path ;
-  return _return_code;
+
+  return changeOK;
 }
 
-//----------------------------------------------------------------------
-/*! Function : Change_Directory 
- *  Purpose  : method to change the current directory to the
- *             directory Path indicated in "in" Parameter.
- *  If Path ="/", the current directory changes to the root directory.
+// ============================================================================
+/*! \brief get the current directory path
+ *
+ *  Get the current directory path.
  *  If the NamingService is out, the exception ServiceUnreachable is thrown.
- * \param Path const char* arguments
- * \return a boolean to indicate if the change succeeded
- */
-//----------------------------------------------------------------------
+ * \return the path of the current_context
+ * \sa  _current_directory
+ */ 
+// ============================================================================
 
-bool SALOME_NamingService::Change_Directory(const char* Path)
-  throw(ServiceUnreachable)
+char* SALOME_NamingService::Current_Directory()
+throw(ServiceUnreachable)
 {
-  MESSAGE("BEGIN OF Change_Directory " << Path);
-  Utils_Locker lock(&_myMutex);
-  int dimension_Path = strlen(Path) + 1;
-  char** resultat_resolve_Path = new char* [dimension_Path];
-  CORBA::Boolean _return_code = true ;
+  MESSAGE("BEGIN OF Current_Directory");
 
-  // _current_context is replaced to the _root_context 
-  // if the Path begins whith '/'
-  if (Path[0]=='/') _current_context = _root_context;
+  Utils_Locker lock (&_myMutex);
 
-  if ((Path[0]=='/') && (dimension_Path == 2))
-    {
-      MESSAGE("Change_Directory is called to go to the root_context");
-    }
-  //nothing to de done, the change_dur is called to go to the root_context
-  // no Path to resolve
-  else
-    //the resolution of the directory path has to be done
-    //to place the currect_context to the correct node
-    {
-      int dimension_resultat = 0;
-      _result_resolve_Path(Path,dimension_resultat,resultat_resolve_Path);
-         
-      CosNaming::Name _context_name;
-      _context_name.length(dimension_resultat);
-      CORBA::Object_var _obj;
+  CosNaming::NamingContext_var ref_context = _current_context;
 
-      _create_context_name_dir(resultat_resolve_Path,dimension_resultat,
-                              _context_name);
+  vector<string> splitPath;
+  splitPath.resize(0);
+  int lengthPath = 0;
+  bool notFound = true ;
 
-      ASSERT(!CORBA::is_nil(_current_context));
-      // Context creation
-      try 
-       {
-         _obj =_current_context->resolve(_context_name);
-         _current_context = CosNaming::NamingContext::_narrow(_obj);
-         ASSERT(!CORBA::is_nil(_current_context))
-           }
-      catch(CosNaming::NamingContext::NotFound& ex)
-       {
-         _return_code = false;
-         CosNaming::Name n = ex.rest_of_name;
-         if (ex.why == CosNaming::NamingContext::missing_node)
-           INFOS( "Change_Directory() : " << (char *) n[0].id
-                 << " (" << (char *) n[0].kind << ") not found")
-         if (ex.why == CosNaming::NamingContext::not_context)
-           INFOS("Change_Directory() : " << (char *) n[0].id
-                << " (" << (char *) n[0].kind
-                << ") is not a context" )
-         if (ex.why == CosNaming::NamingContext::not_object)
-           INFOS( "Change_Directory() : " << (char *) n[0].id
-                << " (" << (char *) n[0].kind
-                << ") is not an object" )
-       }
-      catch(CosNaming::NamingContext::CannotProceed&)
-       {
-         _return_code = false;
-         INFOS( "!!!Change_Directory() : CosNaming::NamingContext::CannotProceed" )
-       } 
-      catch(CosNaming::NamingContext::InvalidName&) 
-       {
-         _return_code = false;
-         INFOS( "!!!Change_Directory() : CosNaming::NamingContext::InvalidName" )
-       }
-      catch(CORBA::SystemException&)
-       {
-         _return_code = false;
-         INFOS( "!!!Change_Directory() :CORBA::SystemException : unable to contact"
-              << "the naming service")
-         throw ServiceUnreachable();
-       }
-      // Memory destruction
-      for (int i = 0 ; i <dimension_resultat ;i++) 
-       {
-         delete [] resultat_resolve_Path[i];     
-       }
-      delete[] resultat_resolve_Path ;
-    }
-  return _return_code;
-}
-
-//----------------------------------------------------------------------
-/*! Function : Current_Directory 
- *  Purpose  : method to get the current directory.
- *  If the NamingService is out, the exception ServiceUnreachable is thrown
- * \return the path of the current_context
- * \sa  _current_directory
- */ 
-//----------------------------------------------------------------------
-
-char* SALOME_NamingService::Current_Directory()
-  throw(ServiceUnreachable)
-{
-  MESSAGE("BEGIN OF Current_Directory");  
-  Utils_Locker lock(&_myMutex);
-
-  CosNaming::NamingContext_var _ref_context = _current_context;
-
-  int i = 0;
-  int length_path = 0;
-  char** result_path = new char*[50]; // 50 is it enough?
+  // --- start search from root context
 
-  // We go to the root_context to begin the search from the root
   _current_context = _root_context ;
-  CORBA::Boolean _continue = true ;
+
   try
     {
-      _current_directory(result_path,i,_ref_context,_continue );
+      _current_directory(splitPath, lengthPath, ref_context, notFound );
     }
-  catch(CORBA::SystemException&)
+
+  catch (CORBA::SystemException&)
     {
-      INFOS("!!!Current_Directory(): CORBA::SystemException : unable to contact"
-          << " the naming service" )
+      INFOS("Current_Directory(): CORBA::SystemException: unable to contact"
+            << " the naming service" )
       throw ServiceUnreachable();
     }
-  for (int k = 0 ; k <i ;k++) 
-    { 
-      // We count the length of the char* + 1 for the '/' to separate
-      // the directories
-      length_path = length_path + strlen(result_path[k]) + 1;
-    }
-  char* return_Path = new char[length_path +2];
-  return_Path[0] = '/' ;
-  return_Path[1] = '\0' ;
-#ifndef WNT
-  for (int k = 0 ; k <i ;k++) 
-#else
-  for (k = 0 ; k <i ;k++) 
-#endif
-    { 
-      //SCRUTE(result_path[k])
-       strcat(return_Path,result_path[k]);
-      strcat(return_Path,"/");
+
+  string path;
+  lengthPath = splitPath.size();
+  for (int k = 0 ; k < lengthPath ;k++)
+    {
+      path += "/";
+      path += splitPath[k];
     }
-  //SCRUTE(return_Path)
-    _current_context = _ref_context ;
-  return return_Path;
+
+  SCRUTE(path)
+  _current_context = ref_context ;
+
+  return strdup(path.c_str());
 }
 
-//----------------------------------------------------------------------
-/*! Function : list
- *  Purpose  : method to list and print all the context contained from
- *            the current context
+// ============================================================================
+/*! \brief list recursively all objects in the current context
+ *
+ *  List and print via trace all directories and objects in the current
+ *  context. Trace must be activated: compile option _DEBUG_
  *  If the NamingService is out, the exception ServiceUnreachable is thrown
  */ 
-//----------------------------------------------------------------------
+// ============================================================================
 
 void SALOME_NamingService::list()
-  throw(ServiceUnreachable)
+throw(ServiceUnreachable)
 {
   MESSAGE("Begin of list");
-  Utils_Locker lock(&_myMutex);
-  CosNaming::BindingList_var _binding_list;
-  CosNaming::BindingIterator_var _binding_iterator;
-  unsigned long nb=0 ; // for using only the BindingIterator to access the bindings
-  CosNaming::Binding_var _binding ;
-  CosNaming::NamingContext_var _ref_context = _current_context;
-  _current_context->list(nb, _binding_list, _binding_iterator) ;
-
-  while (_binding_iterator->next_one(_binding)) {
-    CosNaming::Name _bindingName = _binding->binding_name;
-    if (_binding->binding_type == CosNaming::ncontext) {
-      MESSAGE( "Context : " << _bindingName[0].id );
-      try
-       {
-         Change_Directory(_bindingName[0].id);
-       }
-      catch (ServiceUnreachable&)
+
+  Utils_Locker lock (&_myMutex)
+
+    ;
+  CosNaming::BindingList_var binding_list;
+  CosNaming::BindingIterator_var binding_iterator;
+  CosNaming::Binding_var binding ;
+
+  unsigned long nb = 0 ; // --- only for the BindingIterator use,
+                         //     to access the bindings
+
+  CosNaming::NamingContext_var ref_context = _current_context;
+
+  _current_context->list(nb, binding_list, binding_iterator) ;
+
+  if (! CORBA::is_nil(binding_iterator))
+    {
+      while (binding_iterator->next_one(binding))
        {
-         INFOS( "!!!list(): ServiceUnreachable" )
-         throw ServiceUnreachable(); 
+         CosNaming::Name bindingName = binding->binding_name;
+
+         if (binding->binding_type == CosNaming::ncontext)
+           {
+             MESSAGE( "Context : " << bindingName[0].id );
+
+             try
+               {
+                 Change_Directory(bindingName[0].id);
+               }
+
+             catch (ServiceUnreachable&)
+               {
+                 INFOS( "list(): ServiceUnreachable" )
+                   throw ServiceUnreachable();
+               }
+
+             list();
+             _current_context = ref_context ;
+           }
+
+         else if (binding->binding_type == CosNaming::nobject)
+           {
+             MESSAGE( "Object : " << bindingName[0].id );
+           }
        }
 
-      list();
-      _current_context = _ref_context ;
-    }
-    else if (_binding->binding_type == CosNaming::nobject) {
-      MESSAGE( "Object : " << _bindingName[0].id );
+      binding_iterator->destroy();
     }
-  }
-  _binding_iterator->destroy();
 }
 
-//----------------------------------------------------------------------
-/*! Function : list_directory
- *  Purpose  : method to get all the contexts contained in the current 
- *             directory
- *             Get only objects, isn't iterative 
- *  If the NamingService is out, the exception ServiceUnreachable is thrown
+// ============================================================================
+/*! \brief list all the objects in the current directory.
+ *
+ *  get a list of all the objects in the current directory, without recursion
+ *  on the subdirectories. Only the objects are listed, not the directories.
+ *  If the NamingService is out, the exception ServiceUnreachable is thrown.
+ * \return list of strings with objects found.
+ * \sa vector<string> list_directory_recurs()
  */ 
-//----------------------------------------------------------------------
+// ============================================================================
+
 vector<string> SALOME_NamingService::list_directory()
-  throw(ServiceUnreachable)
+throw(ServiceUnreachable)
 {
-  vector<string> _list ;
-  _list.resize(0);
-  CosNaming::BindingList_var _binding_list;
-  CosNaming::BindingIterator_var _binding_iterator;
-  unsigned long nb=0 ; // for using only the BindingIterator to access the bindings
-  CosNaming::Binding_var _binding ;
-  CosNaming::NamingContext_var _ref_context = _current_context;
-  _current_context->list(nb, _binding_list, _binding_iterator) ;
-  if (_binding_iterator->_is_nil()) return _list;
-
-  while (_binding_iterator->next_one(_binding)) {
-    CosNaming::Name _bindingName = _binding->binding_name;
-    if (_binding->binding_type == CosNaming::nobject) {
-      _list.push_back(CORBA::string_dup(_bindingName[0].id));
+  MESSAGE("list_directory");
+  vector<string> dirList ;
+  dirList.resize(0);
+
+  CosNaming::BindingList_var binding_list;
+  CosNaming::BindingIterator_var binding_iterator;
+  CosNaming::Binding_var binding ;
+
+  unsigned long nb = 0 ; // --- only for the BindingIterator use,
+                         //     to access the bindings
+
+  CosNaming::NamingContext_var ref_context = _current_context;
+
+  _current_context->list(nb, binding_list, binding_iterator);
+
+  if (binding_iterator->_is_nil())
+    return dirList;
+
+  while (binding_iterator->next_one(binding))
+    {
+      CosNaming::Name bindingName = binding->binding_name;
+
+      if (binding->binding_type == CosNaming::nobject)
+        {
+          dirList.push_back(CORBA::string_dup(bindingName[0].id));
+        }
     }
-  }
-  //for (unsigned int ind = 0; ind < _list.size(); ind++)
-  //  MESSAGE("list_directory : Object : " << _list[ind]);
 
-  _binding_iterator->destroy();
-  return _list;
+  for (unsigned int ind = 0; ind < dirList.size(); ind++)
+    MESSAGE("list_directory : Object : " << dirList[ind]);
+
+  binding_iterator->destroy();
+
+  return dirList;
 }
 
-//----------------------------------------------------------------------
-/*! Function : list_directory_recurs
- *  Purpose  : method to get all the contexts contained in the current 
- *             directory
- *             Get only objects and is recursive 
- *  If the NamingService is out, the exception ServiceUnreachable is thrown
+
+// ============================================================================
+/*! \brief list all the subdirectories in the current directory.
+ *
+ *  get a list of all the subdirectories in the current directory,
+ *  without recursion on the subdirectories.
+ *  Only the subdirectories are listed, not the objects.
+ *  If the NamingService is out, the exception ServiceUnreachable is thrown.
+ * \return list of strings with directories found.
+ * \sa vector<string> list_directory()
  */ 
-//----------------------------------------------------------------------
+// ============================================================================
+
+vector<string> SALOME_NamingService::list_subdirs()
+throw(ServiceUnreachable)
+{
+  MESSAGE("list_subdirs");
+  vector<string> dirList ;
+  dirList.resize(0);
+
+  CosNaming::BindingList_var binding_list;
+  CosNaming::BindingIterator_var binding_iterator;
+  CosNaming::Binding_var binding ;
+
+  unsigned long nb = 0 ; // --- only for the BindingIterator use,
+                         //     to access the bindings
+
+  CosNaming::NamingContext_var ref_context = _current_context;
+
+  _current_context->list(nb, binding_list, binding_iterator) ;
+
+  if (binding_iterator->_is_nil())
+    return dirList;
+
+  while (binding_iterator->next_one(binding))
+    {
+      CosNaming::Name bindingName = binding->binding_name;
+
+      if (binding->binding_type == CosNaming::ncontext)
+        {
+          dirList.push_back(CORBA::string_dup(bindingName[0].id));
+        }
+    }
+
+  for (unsigned int ind = 0; ind < dirList.size(); ind++)
+    MESSAGE("list_directory : Object : " << dirList[ind]);
+
+  binding_iterator->destroy();
+
+  return dirList;
+}
+
+// ============================================================================
+/*! \brief  list all the objects in the current directory and subdirectories.
+ *
+ *  get a list of all the objects in the current directory, with recursion
+ *  on the subdirectories. Only the objects are listed, not the directories.
+ *  If the NamingService is out, the exception ServiceUnreachable is thrown.
+ * \return list of strings with objects found.
+ * \sa vector<string> list_directory()
+ */ 
+// ============================================================================
+
 vector<string> SALOME_NamingService::list_directory_recurs()
-    throw(ServiceUnreachable)
+throw(ServiceUnreachable)
 {
   MESSAGE("list_directory_recurs");
-  Utils_Locker lock(&_myMutex);
-  vector<string> _list ;
-  char *currentDir=Current_Directory();
-  _list_directory_recurs(_list,0,currentDir);
-  delete [] currentDir;
-  return _list;
+
+  Utils_Locker lock (&_myMutex);
+
+  vector<string> dirList ;
+
+  string currentDir = Current_Directory();
+
+  _list_directory_recurs(dirList, "", currentDir);
+
+  return dirList;
 }
 
-//----------------------------------------------------------------------
-/*! Function : Destroy_Name 
- *  Purpose  : method to destroy an association Path-Object Reference.
- *             WARNING : The complete Path should be given.
+// ============================================================================
+/*! \brief destroy an entry in naming service.
+ *
+ *  Destroy an association Path - Object Reference.
  *  If the NamingService is out, the exception ServiceUnreachable is thrown 
- * \param Path const char* arguments
- */
-//----------------------------------------------------------------------
+ * \param Path object path
+ */ 
+// ============================================================================
 
 void SALOME_NamingService::Destroy_Name(const char* Path)
-  throw(ServiceUnreachable)
+throw(ServiceUnreachable)
 {
-  MESSAGE("BEGIN OF Destroy_Name");
-  Utils_Locker lock(&_myMutex);
-  int dimension_Path = strlen(Path) + 1;
-  char** resultat_resolve_Path = new char* [dimension_Path];
+  MESSAGE("BEGIN OF Destroy_Name " << Path);
 
-  // _current_context is replaced to the _root_context 
-  // if the Path begins whith '/'
-  if (Path[0]=='/') _current_context = _root_context;
+  Utils_Locker lock (&_myMutex);
 
-  
-  //the resolution of the directory path has to be done
-  //to place the currect_context to the correct node
-  int dimension_resultat = 0;
-  _result_resolve_Path (Path, dimension_resultat, resultat_resolve_Path);
-    
-  CosNaming::Name _context_name;
-  if (dimension_resultat>1)
+  string path(Path);
+
+  // --- if path empty, nothing to do
+
+  if (path.empty())
+    return;
+
+  // --- if path = '/' not applicable, nothing to do
+
+  if (path == "/")
+    return;
+
+  // --- if path begins with '/', set current directory to root context
+
+  if (path[0] == '/')
+    _current_context = _root_context;
+
+  // --- context of the directory containing the object
+
+  CosNaming::Name context_name;
+  vector<string> splitPath;
+  int dimension_resultat = _createContextNameDir(path.c_str(),
+                                                context_name,
+                                                splitPath,
+                                                true);
+
+  bool exist = false;
+
+  if (dimension_resultat > 0)
     {
-      // We go in the directory where the object to destroy is
-      _context_name.length(dimension_resultat-1);
-  
-      _create_context_name_dir(resultat_resolve_Path,dimension_resultat -1,
-                              _context_name); 
+      // --- path contains a directory, not only an object name
+      //     switch to the new directory (or return if directory not found)
+
+      try
+        {
+          CORBA::Object_var obj = _current_context->resolve(context_name);
+          _current_context = CosNaming::NamingContext::_narrow(obj);
+         exist = true;
+        }
+
+      catch (CosNaming::NamingContext::NotFound &ex)
+        {
+          // --- failed to resolve
+          exist = false;
+
+          CosNaming::Name n = ex.rest_of_name;
+
+          if (ex.why == CosNaming::NamingContext::missing_node)
+            INFOS( "Destroy_Name(): " << (char *) n[0].id
+                   << " (" << (char *) n[0].kind << ") not found" );
+         if (ex.why == CosNaming::NamingContext::not_context)
+           INFOS( "Destroy_Name() : " << (char *) n[0].id
+                  << " (" << (char *) n[0].kind
+                  << ") is not a context" );
+         if (ex.why == CosNaming::NamingContext::not_object)
+           INFOS( "Destroy_Name() : " << (char *) n[0].id
+                  << " (" << (char *) n[0].kind
+                  << ") is not an object" );
+        }
+
+      catch (CosNaming::NamingContext::InvalidName &)
+        {
+          INFOS("Destroy_Name: CosNaming::NamingContext::InvalidName");
+        }
+
+      catch (CosNaming::NamingContext::CannotProceed &)
+        {
+          INFOS("Destroy_Name: CosNaming::NamingContext::CannotProceed");
+        }
+
+      catch (CORBA::SystemException&)
+        {
+          INFOS("Destroy_Name : CORBA::SystemException: "
+                << "unable to contact the naming service");
+          throw ServiceUnreachable();
+        }
+
+      if (! exist) return;
+    }
+
+  ASSERT(!CORBA::is_nil(_current_context));
+
+  // --- The current directory is now the directory where the object should
+  //     be destroyed
+
+  int sizePath = splitPath.size();
+  if (sizePath > dimension_resultat)
+    {
+      ASSERT(sizePath == dimension_resultat+1);
+      context_name.length(1);
+
       try
        {
-         CORBA::Object_var _obj = _current_context->resolve(_context_name);
-         _current_context = CosNaming::NamingContext::_narrow(_obj);
-       } 
-      catch (CosNaming::NamingContext::NotFound& ex) 
+         // --- the last element is an object and not a directory
+
+         context_name[0].id =
+           CORBA::string_dup(splitPath[dimension_resultat].c_str());
+         context_name[0].kind = CORBA::string_dup("object");
+         SCRUTE(context_name[0].id);
+         _current_context->unbind(context_name);
+         MESSAGE("The object " << context_name[0].id << " has been deleted");
+       }
+
+      catch (CosNaming::NamingContext::NotFound& ex)
        {
          CosNaming::Name n = ex.rest_of_name;
+
          if (ex.why == CosNaming::NamingContext::missing_node)
-           INFOS(  "Destroy_Name() : " << (char *) n[0].id
-                 << " (" << (char *) n[0].kind << ") not found" )
-         if (ex.why == CosNaming::NamingContext::not_context)
            INFOS( "Destroy_Name() : " << (char *) n[0].id
-                << " (" << (char *) n[0].kind
-                << ") is not a context" )
-         if (ex.why == CosNaming::NamingContext::not_object)
+                  << " (" << (char *) n[0].kind << ") not found" );
+         if (ex.why == CosNaming::NamingContext::not_context)
            INFOS( "Destroy_Name() : " << (char *) n[0].id
-                << " ("  << (char *) n[0].kind
-                << ") is not an object" )
-       } 
-      catch (CosNaming::NamingContext::InvalidName &) 
+                  << " (" << (char *) n[0].kind
+                  << ") is not a context" );
+          if (ex.why == CosNaming::NamingContext::not_object)
+            INFOS( "Destroy_Name() : " << (char *) n[0].id
+                   << " (" << (char *) n[0].kind
+                   << ") is not an object" );
+          }
+
+      catch (CosNaming::NamingContext::CannotProceed&)
        {
-         INFOS( "!!!Destroy_Name() : CosNaming::NamingContext::InvalidName" )
+         INFOS( "Destroy_Name(): CosNaming::NamingContext::CannotProceed");
        }
-      catch (CosNaming::NamingContext::CannotProceed &)
+
+      catch (CosNaming::NamingContext::InvalidName&)
        {
-         INFOS( "!!!Destroy_Name(): CosNaming::NamingContext::CannotProceed" )
+         INFOS( "Destroy_Name(): CosNaming::NamingContext::InvalidName");
        }
-      catch(CORBA::SystemException&)
+
+      catch (CORBA::SystemException&)
        {
-         INFOS( "!!!Destroy_Name() : CORBA::SystemException : unable to contact"
-              << " the naming service")
+         INFOS( "Destroy_Name(): CORBA::SystemException: unable to contact"
+                << " the naming service");
          throw ServiceUnreachable();
        }
     }
+}
 
-  // the last element is the object to destroy
-  _context_name.length(1);  
-  _context_name[0].id = 
-    CORBA::string_dup(resultat_resolve_Path[dimension_resultat -1]);
-  _context_name[0].kind = CORBA::string_dup("object");
-  SCRUTE(_context_name[0].id);
-  ASSERT(!CORBA::is_nil(_current_context));
-  // Object destruction
-  try 
+// ============================================================================
+/*! \brief Destroy an empty directory
+ *
+ *  Destroy an empty directory in Naming Service.
+ *  If the NamingService is out, the exception ServiceUnreachable is thrown.
+ * \param Path directory path
+ */ 
+// ============================================================================
+
+void SALOME_NamingService::Destroy_Directory(const char* Path)
+throw(ServiceUnreachable)
+{
+  MESSAGE("BEGIN OF Destroy_Directory" << Path);
+
+  Utils_Locker lock (&_myMutex);
+
+  string path(Path);
+
+  // --- if path empty, nothing to do
+
+  if (path.empty())
+    return;
+
+  // --- if path begins with '/', set current directory to root context
+
+  if (path[0] == '/')
+    _current_context = _root_context;
+
+  CosNaming::NamingContext_var ref_context = _current_context;
+
+  // --- path must ends with '/' for a directory
+
+  if (path[path.size() -1] != '/')
+    path += '/';
+
+  // --- context of the directory
+
+  CosNaming::Name context_name;
+  vector<string> splitPath;
+  int dimension_resultat = _createContextNameDir(path.c_str(),
+                                                context_name,
+                                                splitPath,
+                                                true);
+  bool exist = false;
+
+  if (dimension_resultat > 0)
     {
-      _current_context->unbind(_context_name);
-      MESSAGE( "The object " << _context_name[0].id  << " has been deleted" )
+      // --- path contains a directory, not only an object name
+      //     switch to the new directory (or return if directory not found)
+
+      try
+        {
+          CORBA::Object_var obj = _current_context->resolve(context_name);
+          _current_context = CosNaming::NamingContext::_narrow(obj);
+         exist = true;
+        }
+
+      catch (CosNaming::NamingContext::NotFound &ex)
+        {
+          // --- failed to resolve
+          exist = false;
+
+          CosNaming::Name n = ex.rest_of_name;
+
+          if (ex.why == CosNaming::NamingContext::missing_node)
+            INFOS( "Destroy_Directory(): " << (char *) n[0].id
+                   << " (" << (char *) n[0].kind << ") not found" );
+         if (ex.why == CosNaming::NamingContext::not_context)
+           INFOS( "Destroy_Directory() : " << (char *) n[0].id
+                  << " (" << (char *) n[0].kind
+                  << ") is not a context" );
+         if (ex.why == CosNaming::NamingContext::not_object)
+           INFOS( "Destroy_Directory() : " << (char *) n[0].id
+                  << " (" << (char *) n[0].kind
+                  << ") is not an object" );
+        }
+
+      catch (CosNaming::NamingContext::InvalidName &)
+        {
+          INFOS("Destroy_Directory: CosNaming::NamingContext::InvalidName");
+        }
+
+      catch (CosNaming::NamingContext::CannotProceed &)
+        {
+          INFOS("Destroy_Directory: CosNaming::NamingContext::CannotProceed");
+        }
+
+      catch (CORBA::SystemException&)
+        {
+          INFOS("Destroy_Directory : CORBA::SystemException: "
+                << "unable to contact the naming service");
+          throw ServiceUnreachable();
+        }
+
+      if (! exist) return;
     }
-  catch(CosNaming::NamingContext::NotFound& ex)
+
+  ASSERT(!CORBA::is_nil(_current_context));
+
+  // --- Context Destruction
+
+  bool isContextDestroyed = false;
+  try
     {
-      CosNaming::Name n = ex.rest_of_name;
-      if (ex.why == CosNaming::NamingContext::missing_node)
-       INFOS(  "Destroy_Name() : " << (char *) n[0].id
-             << " (" << (char *) n[0].kind << ") not found" )
-      if (ex.why == CosNaming::NamingContext::not_context)
-       INFOS( "Destroy_Name() : " << (char *) n[0].id
-            << " (" << (char *) n[0].kind
-            << ") is not a context" )
-      if (ex.why == CosNaming::NamingContext::not_object)
-       INFOS( "Destroy_Name() : " << (char *) n[0].id
-            << " ("  << (char *) n[0].kind
-            << ") is not an object" )
+      _current_context->destroy();
+      MESSAGE( "The context " << path << " has been deleted" );
+      isContextDestroyed = true;
     }
-  catch(CosNaming::NamingContext::CannotProceed&)
-    {
-      INFOS( "!!!Destroy_Name() : CosNaming::NamingContext::CannotProceed")
-    } 
-  catch(CosNaming::NamingContext::InvalidName&) 
+
+  catch (CosNaming::NamingContext::NotEmpty&)
     {
-      INFOS( "!!!Destroy_Name() : CosNaming::NamingContext::InvalidName")
+      INFOS( "Destroy_Directory(): CosNaming::NamingContext::NoEmpty "
+             << path << " is not empty" );
     }
-  catch(CORBA::SystemException&)
+
+  catch (CORBA::SystemException&)
     {
-      INFOS( "!!!Destroy_Name() :CORBA::SystemException : unable to contact" 
-          << " the naming service") 
+      INFOS( "Destroy_Directory():CORBA::SystemException : "
+             << "unable to contact the naming service");
       throw ServiceUnreachable();
     }
-  // Memory destruction
-  for (int i = 0 ; i <dimension_resultat ;i++) 
-    {
-      delete [] resultat_resolve_Path[i];     
-    }
-  delete[] resultat_resolve_Path ;
-}
 
-//----------------------------------------------------------------------
-/*! Function : Destroy_Directory.
- *  Purpose  : method to destroy a directory if it is empty.
- *  WARNING : The complete Path  to the directory (from the root_context)
- *  to destroy should be given.
- *  If the NamingService is out, the exception ServiceUnreachable is thrown.
- * \param Path const char* arguments
- */
-//----------------------------------------------------------------------
+  // --- go to the reference directory
 
-void SALOME_NamingService::Destroy_Directory(const char* Path)
-  throw(ServiceUnreachable)
-{
-  MESSAGE("BEGIN OF Destroy_Directory");
-  Utils_Locker lock(&_myMutex);
-  int dimension_Path = strlen(Path) + 1;
-  char** resultat_resolve_Path = new char* [dimension_Path];
+  _current_context = ref_context ;
 
-  // _current_context is replaced to the _root_context 
-  // if the Path begins whith '/'
-  if (Path[0]=='/') _current_context = _root_context;
+  ASSERT(!CORBA::is_nil(_current_context));
 
-  CosNaming::NamingContext_var _ref_context = _current_context;
-  //the resolution of the directory path has to be done
-  //to place the currect_context to the correct node
-  int dimension_resultat = 0;
-  _result_resolve_Path (Path, dimension_resultat, resultat_resolve_Path);
-    
-  CosNaming::Name _context_name;
-  if (dimension_resultat>1)
+  if (isContextDestroyed)
     {
-      // We go in the directory where the context to destroy is
-      _context_name.length(dimension_resultat-1);
-  
-      _create_context_name_dir(resultat_resolve_Path,dimension_resultat -1,
-                              _context_name); 
       try
        {
-         CORBA::Object_var _obj = _current_context->resolve(_context_name);
-         _current_context = CosNaming::NamingContext::_narrow(_obj);
-          _ref_context = _current_context ;
-       } 
-      catch (CosNaming::NamingContext::NotFound& ex) 
+         _current_context->unbind(context_name);
+         MESSAGE( "The bind to the context "
+                  << context_name[0].id
+                  << " has been deleted" );
+       }
+
+      catch (CosNaming::NamingContext::NotFound& ex)
        {
          CosNaming::Name n = ex.rest_of_name;
+
          if (ex.why == CosNaming::NamingContext::missing_node)
-           INFOS(  "Destroy_Directory() : " << (char *) n[0].id
-                 << " (" << (char *) n[0].kind << ") not found")
+           INFOS( "Destroy_Directory() : " << (char *) n[0].id
+                  << " (" << (char *) n[0].kind << ") not found" );
          if (ex.why == CosNaming::NamingContext::not_context)
            INFOS( "Destroy_Directory() : " << (char *) n[0].id
-                << " (" << (char *) n[0].kind
-                << ") is not a context" )
+                  << " (" << (char *) n[0].kind
+                  << ") is not a context" );
          if (ex.why == CosNaming::NamingContext::not_object)
            INFOS( "Destroy_Directory() : " << (char *) n[0].id
-                << " ("  << (char *) n[0].kind
-                << ") is not an object" )
-       } 
-      catch (CosNaming::NamingContext::InvalidName &) 
-       {
-         INFOS( "!!!Destroy_Directory() : CosNaming::NamingContext::InvalidName" )
+                  << " (" << (char *) n[0].kind
+                  << ") is not an object" );
        }
-      catch (CosNaming::NamingContext::CannotProceed &)
+
+      catch (CosNaming::NamingContext::CannotProceed&)
        {
-         INFOS("!!!Destroy_Directory(): CosNaming::NamingContext::CannotProceed" )
+         INFOS("Destroy_Directory: CosNaming::NamingContext::CannotProceed");
        }
-      catch(CORBA::SystemException&)
+
+      catch (CosNaming::NamingContext::InvalidName&)
        {
-         INFOS( "!!!Destroy_Directory() : CORBA::SystemException : unable to contact"
-              << " the naming service" )
+         INFOS("Destroy_Directory: CosNaming::NamingContext::InvalidName");
+           }
+
+      catch (CORBA::SystemException&)
+       {
+         INFOS("Destroy_Directory:CORBA::SystemException : unable to contact"
+                << " the naming service");
          throw ServiceUnreachable();
        }
     }
-
-  // the last element is the context to destroy
-  _context_name.length(1);  
-  _context_name[0].id = 
-    CORBA::string_dup(resultat_resolve_Path[dimension_resultat -1]);
-  _context_name[0].kind = CORBA::string_dup("dir");
-  SCRUTE(_context_name[0].id);
-
-  try
-    {
-      // We go in the context to destroy
-      CORBA::Object_var _obj = _current_context->resolve(_context_name);
-      _current_context = CosNaming::NamingContext::_narrow(_obj);
-    } 
-  catch (CosNaming::NamingContext::NotFound& ex) 
-    {
-      CosNaming::Name n = ex.rest_of_name;
-      if (ex.why == CosNaming::NamingContext::missing_node)
-       INFOS(  "Destroy_Directory() : " << (char *) n[0].id
-             << " (" << (char *) n[0].kind << ") not found" )
-      if (ex.why == CosNaming::NamingContext::not_context)
-       INFOS( "Destroy_Directory() : " << (char *) n[0].id
-            << " (" << (char *) n[0].kind
-            << ") is not a context" )
-      if (ex.why == CosNaming::NamingContext::not_object)
-       INFOS( "Destroy_Directory() : " << (char *) n[0].id
-            << " ("  << (char *) n[0].kind
-            << ") is not an object" )
-    } 
-  catch (CosNaming::NamingContext::InvalidName &) 
-    {
-      INFOS( "!!!Destroy_Directory() : CosNaming::NamingContext::InvalidName" )
-    }
-  catch (CosNaming::NamingContext::CannotProceed &)
-    {
-      INFOS( "!!!Destroy_Directory(): CosNaming::NamingContext::CannotProceed" )
-    }
-  catch(CORBA::SystemException&)
-    {
-      INFOS( "!!!Destroy_Directory() : CORBA::SystemException : unable to contact"
-          << " the naming service" )
-      throw ServiceUnreachable();
-    }
-
-  ASSERT(!CORBA::is_nil(_current_context));
-  // Context Destruction
-  try 
-    {
-      _current_context->destroy();
-      MESSAGE( "The context " << _context_name[0].id << " has been deleted" )
-    }
-  catch(CosNaming::NamingContext::NotEmpty&)
-    {
-      INFOS( "!!!Destroy_Directory() : CosNaming::NamingContext::NoEmpty "
-          << Path << " is not empty" )
-    } 
-  catch(CORBA::SystemException&)
-    {
-      INFOS( "!!!Destroy_Directory() :CORBA::SystemException : "
-          << "unable to contact the naming service") 
-      throw ServiceUnreachable();
-    }
-  // We go to the directory just before the context to delete
-  _current_context = _ref_context ; 
-  try
-    {
-      _current_context->unbind(_context_name);
-      MESSAGE( "The bind to the context " << _context_name[0].id  << " has been deleted" )
-    }
-  catch(CosNaming::NamingContext::NotFound& ex)
-    {
-      CosNaming::Name n = ex.rest_of_name;
-      if (ex.why == CosNaming::NamingContext::missing_node)
-       INFOS(  "Destroy_Directory() : " << (char *) n[0].id
-             << " (" << (char *) n[0].kind << ") not found" )
-      if (ex.why == CosNaming::NamingContext::not_context)
-       INFOS( "Destroy_Directory() : " << (char *) n[0].id
-            << " (" << (char *) n[0].kind
-            << ") is not a context" )
-      if (ex.why == CosNaming::NamingContext::not_object)
-       INFOS( "Destroy_Directory() : " << (char *) n[0].id
-            << " ("  << (char *) n[0].kind
-            << ") is not an object" )
-    }
-  catch(CosNaming::NamingContext::CannotProceed&)
-    {
-      INFOS( "!!!Destroy_Directory() : CosNaming::NamingContext::CannotProceed")
-    } 
-  catch(CosNaming::NamingContext::InvalidName&) 
-    {
-      INFOS( "!!!Destroy_Directory() : CosNaming::NamingContext::InvalidName")
-    }
-  catch(CORBA::SystemException&)
-    {
-      INFOS( "!!!Destroy_Directory() :CORBA::SystemException : unable to contact" 
-          << " the naming service") 
-      throw ServiceUnreachable();
-    }
-  // Memory destruction
-  for (int i = 0 ; i <dimension_resultat ;i++) 
-    {
-      delete [] resultat_resolve_Path[i];     
-    }
-  delete[] resultat_resolve_Path ;
 }
 
-//----------------------------------------------------------------------
-/*! Function : Destroy_Directory.
- *  Purpose  : method to destroy a directory if it is empty.
- *  WARNING : The complete Path  to the directory (from the root_context)
- *  to destroy should be given.
+// ============================================================================
+/*! \brief Destroy a directory with its contents.
+ *
+ *  Destroy the objects associations in a directory, and the directory itself,
+ *  if there is no subdirectories. 
  *  If the NamingService is out, the exception ServiceUnreachable is thrown.
- * \param Path const char* arguments
- */
-//----------------------------------------------------------------------
+ * \param Path the directory path.
+ */ 
+// ============================================================================
 
 void SALOME_NamingService::Destroy_FullDirectory(const char* Path)
-  throw(ServiceUnreachable)
+throw(ServiceUnreachable)
 {
   Change_Directory(Path);
   vector<string> contList = list_directory();
-  for(unsigned int ind = 0; ind < contList.size(); ind++)
+
+  for (unsigned int ind = 0; ind < contList.size(); ind++)
     Destroy_Name(contList[ind].c_str());
+
   Destroy_Directory(Path);
+
   Destroy_Name(Path);
 }
 
-//----------------------------------------------------------------------
-/*! Function : _initialize_root_context
- * Purpose  :  method called by constructor to initialize _root_context
- */
-//----------------------------------------------------------------------
+// ============================================================================
+/*! \brief  initialize root context (root directory)
+ *
+ * the root context initialisation must be done when the SALOME_NamingService
+ * instance is created and before any othe call. See constructors.
+ */ 
+// ============================================================================
 
 void SALOME_NamingService::_initialize_root_context()
 {
   //MESSAGE("Get the root context");
+
   try
     {
       CORBA::Object_var obj = _orb->resolve_initial_references("NameService");
       _root_context = CosNaming::NamingContext::_narrow(obj);
       _current_context = _root_context ;
-      ASSERT(!CORBA::is_nil(_root_context)); 
+      ASSERT(!CORBA::is_nil(_root_context));
     }
 
-  catch(CORBA::SystemException&)
+  catch (CORBA::SystemException&)
     {
       INFOS("CORBA::SystemException: unable to contact the naming service");
       throw ServiceUnreachable();
     }
-  catch(...)
+
+  catch (...)
     {
       INFOS("Unknown Exception: unable to contact the naming service");
       throw ServiceUnreachable();
     }
 }
 
-//----------------------------------------------------------------------
-/*! Function : _resolve_Path
- * Purpose  : method to decompose a Path : /Kernel/Services/Sessions.
- * 
- * \return a char* containing the first char between '/' (in this case Kernel)
- */
-//----------------------------------------------------------------------
+// ============================================================================
+/*! \brief transform a string path in CosNaming structure.
+ *
+ *  Transform a path given as a string in a CosNaming structure.
+ *  \param path         a relative or absolute path, with or without an object.
+ *                      An absolute path begins with '/'.
+ *                      A path without an object ends with '/'.
+ *  \param context_name CosNaming structure to put the path.
+ *  \param splitPath    a vector of string with subdirectories and final
+ *                      object, if any.
+ *  \param onlyDir      if true, final object (if any) is ommited
+ *                      in context_name.
+ *                      if false, final object (if any) is included in
+ *                      context_name.
+ *  \return             dimension of context_name
+ */ 
+// ============================================================================
 
-char* SALOME_NamingService::_resolve_Path(char* Path)
+int
+SALOME_NamingService::_createContextNameDir(string path,
+                                           CosNaming::Name& context_name,
+                                           vector<string>& splitPath,
+                                           bool onlyDir)
 {
-  int i = 0 ;
-  int length = strlen(Path);
-  char *resultat;
+  if (path.empty())
+    return 0;
 
-  if (length==0) return NULL;
-  else
+  string::size_type begIdx, endIdx;
+  const string delims("/");
+  splitPath.resize(0);
+  bool endWithDelim = false;
+
+  begIdx = path.find_first_not_of(delims);
+  while (begIdx != string::npos)
     {
-      while ((i<length) && (Path[i]!='/'))
-       i++;
-      resultat = new char[i+1];
-      strncpy(resultat,Path,i);
-      resultat[i]='\0';    
-      return resultat;
+      endIdx = path.find_first_of(delims, begIdx);
+      if (endIdx == path.length()-1)
+       endWithDelim = true;
+      if (endIdx == string::npos)
+       endIdx = path.length();
+      int lsub = endIdx - begIdx;
+      if (lsub > 1)
+       splitPath.push_back(path.substr(begIdx, lsub));
+      begIdx = path.find_first_not_of(delims, endIdx);
     }
-}
 
-//----------------------------------------------------------------------
-/*! Function : _result_resolve_Path.
- *  Purpose  : method to decompose a Path : /Kernel/Services/Sessions.
- *  Gives an array of char* containing Kernel, Services, Sessions.
- * \param  Path const char* arguments, the Path to decompose
- * \param j int& arguments, the size of the array of char*
- * \param resultat_resolve_Path char** arguments
- */
-//----------------------------------------------------------------------
-
-void 
-SALOME_NamingService::_result_resolve_Path(const char* Path, 
-                                          int& j, 
-                                          char ** resultat_resolve_Path)
-{  
-  //MESSAGE("BEGIN OF _result_resolve_Path");
-  int dimension_Path = strlen(Path) + 1;
-  char** temp= new char* [dimension_Path];
-  char** tempslash = new char* [dimension_Path];
-
-  temp[j] = new char[dimension_Path];
-  strcpy(temp[j],Path);
-
-  while (strlen(temp[j])>0)
+  int dim;
+  if (onlyDir)                  // only directory part
     {
-      // temp[j] contains the characters to be treated :
-      //  (Path - characters already treted)
-      // tempslash[j] = temp[j] if the string temp[j] doesn't begin whith '/'
-      // tempslash[j] = temp[j] without '/' if the string begins whith '/'
-      int length_temp = strlen(temp[j]);
-      if (temp[j][0]=='/')
+      dim = splitPath.size()-1; // omit final object
+      if (endWithDelim)         // unless the path ends with a delimiter 
+       dim++;
+      endWithDelim = true;
+    }
+  else
+    dim = splitPath.size();     // directories and final object
+
+  context_name.length(dim);
+  for (int i=0; i<dim; i++)
+    {
+      SCRUTE(splitPath[i]);
+      context_name[i].id = CORBA::string_dup(splitPath[i].c_str());
+      if (!endWithDelim && (i == dim-1)) // here, the last string is an object
        {
-         // the characters to be treated begin whith '/'
-         // we don't have to take the '/'
-         tempslash[j] = new char [length_temp] ;
-         for (int k = 0; k < length_temp-1; k++) 
-           tempslash[j][k] = temp[j][k+1];
-          tempslash[j][length_temp-1]='\0';
+         context_name[i].kind = CORBA::string_dup("object");
+         MESSAGE("--- " <<splitPath[i] <<".object");
        }
       else
        {
-         //the characters to be trated don't begin with '/'
-         // Nothing to be done on the char
-         tempslash[j] = new char [length_temp+1] ;
-         strcpy(tempslash[j],temp[j]);   
-       }
-      // decomposition of the Path 
-      resultat_resolve_Path[j]= _resolve_Path(tempslash[j]);
-      //SCRUTE(resultat_resolve_Path[j]);
-
-      int length_resultat = strlen(resultat_resolve_Path[j]) ;
-      int dimension_temp = length_temp -length_resultat ;
-      j++;
-      temp[j] = new char[dimension_temp +1];
-      for (int i = 0 ; i <dimension_temp  ;i++)
-       {
-         temp[j][i] =tempslash[j-1][i+ length_resultat];
+         context_name[i].kind = CORBA::string_dup("dir");
+         MESSAGE("--- " <<splitPath[i] <<".dir");
        }
-      temp[j][dimension_temp]= '\0';
-      //SCRUTE(temp[j]);
-    } 
-  // Memory destruction
-  for (int i = 0 ; i <j;i++) 
-    {
-      delete [] temp[i];
-      delete [] tempslash[i];    
     }
-  delete[] temp;
-  delete [] tempslash ;
+  return dim;
 }
 
-//----------------------------------------------------------------------
-/*! Function : _Find.
- *  Purpose  : method to research a name from the current directory 
- *             of the naming service.   
- *  The naming service changes directory to go to the directory where 
- *  the last occurence was found.
- *  \param name const char* arguments
- *  \param occurence_number CORBA::LONG (by value)
- */   
-//----------------------------------------------------------------------
-
-void SALOME_NamingService::_Find(const char* name, 
-                                CORBA::Long& occurence_number)
+// ============================================================================
+/*! \brief search a name in current directory.
+ *
+ *  Search a name in the current directory. after call, the current directory
+ *  is changed to the directory containing the last occurence of name found.
+ *  If no occurence found (see return value), current directory remains
+ *  unchanged. The call is recursive.
+ *
+ * \param  name the name to search.
+ * \param  occurence_number number of occurence already found (incremented)
+ */ 
+// ============================================================================
+
+void SALOME_NamingService::_Find(const char* name,
+                                 CORBA::Long& occurence_number)
 {
-  //MESSAGE("BEGIN OF _Find") SCRUTE(name); 
-  CosNaming::BindingList_var _binding_list;
-  CosNaming::BindingIterator_var _binding_iterator;
-  unsigned long nb=0 ; //for using only the BindingIterator 
-                       // to access the bindings
-  CosNaming::Binding_var _binding ;
-  CosNaming::NamingContext_var _ref_context = _current_context;
-  CosNaming::NamingContext_var _found_context = _current_context;
-
-  _current_context->list(nb, _binding_list, _binding_iterator) ;
-
-  while (_binding_iterator->next_one(_binding)) {
-    CosNaming::Name _bindingName = _binding->binding_name;
-    if (_binding->binding_type == CosNaming::ncontext) {
-      // We work on a directory, the search should be done in this directory
-      Change_Directory(_bindingName[0].id);
-      _Find(name,occurence_number);
-      // We'll go back to the initial context
-      _current_context = _ref_context ;
-    }
-    else if (_binding->binding_type == CosNaming::nobject) {
-      // We work on an object...
-      if (!strcmp( _bindingName[0].id,name))
+  MESSAGE("BEGIN OF _Find "<<  occurence_number << " " << name);
+
+  CosNaming::BindingList_var binding_list;
+  CosNaming::BindingIterator_var binding_iterator;
+  CosNaming::Binding_var binding;
+
+  unsigned long nb = 0 ; // --- only for the use of the BindingIterator,
+                         //     to access the bindings
+
+  CosNaming::NamingContext_var ref_context = _current_context;
+  CosNaming::NamingContext_var found_context = _current_context;
+
+  _current_context->list(nb, binding_list, binding_iterator) ;
+
+  if (! CORBA::is_nil(binding_iterator))
+    {
+      while (binding_iterator->next_one(binding))
        {
-         //MESSAGE("One occurence was found");
-         occurence_number++;
-         // We keep in memory the directory where one occurence was found
-         _found_context = _current_context ;
+         CosNaming::Name bindingName = binding->binding_name;
+         
+         if (binding->binding_type == CosNaming::ncontext)
+           {
+             // --- We work on a directory,
+             //     the search should be done in this directory
+             
+             Change_Directory(bindingName[0].id);
+             _Find(name, occurence_number);
+             
+             // --- We'll go back to the initial context
+             
+             _current_context = ref_context ;
+           }
+         
+         else if (binding->binding_type == CosNaming::nobject)
+           {
+             // --- We work on an object...
+             
+             if (!strcmp( bindingName[0].id, name))
+               {
+                 //MESSAGE("One occurence was found");
+                 occurence_number++;
+                 
+                 // --- We keep in memory the directory where
+                 //     one occurence was found
+                 
+                 found_context = _current_context ;
+               }
+           }
        }
+      
+      binding_iterator->destroy();
     }
-  }
-  _binding_iterator->destroy();  
-  // We go to the last directory where an occurence was found
-  _current_context = _found_context ;
-  //SCRUTE(occurence_number);
+  // --- We go to the last directory where an occurence was found
+
+  _current_context = found_context;
+
+  SCRUTE(occurence_number);
 }
 
-//----------------------------------------------------------------------
-/*! Function : _create_context_name_dir.
- *  Purpose  : method to create a Context_name from an array of char.
- *             The number of elements to be copied are indicated 
- *             with lenth_copy.
- *
- * \param resultat_resolve_Path char** arguments
- * \param length_copy int arguments
- * \param _context_name CosNaming::Name arguments (by value)
- */
-//----------------------------------------------------------------------
+// ============================================================================
+/*! \brief find the current directory path.
+ * 
+ *  Parse the naming service tree to find the current context and give the
+ *  associated directory path (relative to root context).
+ * \param splitPath 
+ * \param lengthResult
+ * \param contextToFind
+ * \param _notFound
+ */ 
+// ============================================================================
 
-void 
-SALOME_NamingService::_create_context_name_dir(char** resultat_resolve_Path
-                                              ,int length_copy,
-                                              CosNaming::Name& _context_name) 
+void
+SALOME_NamingService::
+_current_directory(vector<string>& splitPath,
+                  int& lengthResult,
+                  CosNaming::NamingContext_var contextToFind,
+                  bool& notFound)
 {
-  //MESSAGE("BEGIN OF _create_context_name_dir");
-  for (int i = 0 ; i < length_copy;i++)
+  MESSAGE("BEGIN OF _current_Directory");
+
+  CosNaming::BindingList_var binding_list;
+  CosNaming::BindingIterator_var binding_iterator;
+  CosNaming::Binding_var binding;
+
+  unsigned long nb = 0 ; // --- only for the BindingIterator use,
+                         //     to access the bindings
+
+  CosNaming::NamingContext_var ref_context = _current_context;
+  CosNaming::NamingContext_var temp_context = _current_context;
+
+  _current_context->list(nb, binding_list, binding_iterator);
+
+  if ( !binding_iterator->_is_nil() )
     {
-      _context_name[i].id = CORBA::string_dup(resultat_resolve_Path[i]);
-      _context_name[i].kind = CORBA::string_dup("dir");
-      //SCRUTE(_context_name[i].id);
+      while ((binding_iterator->next_one(binding)) && notFound)
+        {
+          CosNaming::Name bindingName = binding->binding_name;
+
+          if (binding->binding_type == CosNaming::ncontext)
+            {
+              // --- directory, search in it
+
+             splitPath.push_back(CORBA::string_dup(bindingName[0].id));
+              lengthResult++;
+
+              CORBA::Object_var obj = _current_context->resolve(bindingName);
+              temp_context = CosNaming::NamingContext::_narrow(obj);
+
+              if (temp_context->_is_equivalent(contextToFind))
+                {
+                  MESSAGE("The context is found, we stop the search");
+                  notFound = false;
+                  SCRUTE(notFound);
+                }
+
+              if (notFound)
+                {
+                  SCRUTE(bindingName[0].id);
+                  Change_Directory(bindingName[0].id);
+                  _current_directory(splitPath,
+                                    lengthResult,
+                                     contextToFind,
+                                    notFound);
+
+                  if (notFound)
+                    {
+                      // --- go back to the initial context
+
+                      _current_context = ref_context;
+
+                      MESSAGE("Just before the delete of "
+                             << splitPath[lengthResult-1]);
+                     splitPath.pop_back();
+                      lengthResult--;
+                    }
+                }
+            }
+        }
+
+      binding_iterator->destroy();
     }
-}
 
-//----------------------------------------------------------------------
-/*! Function : _current_directory.
- * Purpose  : method to parse the naming service tree to find a context
- *            and determine the path to go to this context from the 
- *            _root_context.
- *  \param result_path char** arguments
- *  \param length_result int arguments by value
- *  \param context_to_found CosNaming::NamingContext_var arguments
- *  \param _continue boolean arguments
- */
-//----------------------------------------------------------------------
+  // --- return to the last directory where an occurence was found
 
-void
-SALOME_NamingService::_current_directory(char** result_path,
-                                        int& length_result,
-                                        CosNaming::NamingContext_var context_to_found,
-                                        CORBA::Boolean& _continue) 
-{
-  //MESSAGE("BEGIN OF _current_Directory");  
-  CosNaming::BindingList_var _binding_list;
-  CosNaming::BindingIterator_var _binding_iterator;
-  unsigned long nb=0 ; //for using only the BindingIterator 
-                       // to access the bindings
-  CosNaming::Binding_var _binding ;
-  CosNaming::NamingContext_var _ref_context = _current_context;
-  CosNaming::NamingContext_var _temp_context = _current_context;
-  _current_context->list(nb, _binding_list, _binding_iterator) ;
-  if ( !_binding_iterator->_is_nil() ) {
-  while ((_binding_iterator->next_one(_binding)) && _continue) {
-    CosNaming::Name _bindingName = _binding->binding_name;
-    if (_binding->binding_type == CosNaming::ncontext)
-      {
-       // We work on a directory, the search should be done in this directory
-       result_path[length_result] = new char(strlen(_bindingName[0].id) + 1);
-       strcpy(result_path[length_result],_bindingName[0].id);
-       //SCRUTE(result_path[length_result])
-         length_result++;
-
-       CORBA::Object_var  _obj =_current_context->resolve(_bindingName);
-       _temp_context = CosNaming::NamingContext::_narrow(_obj);
-
-       if (_temp_context->_is_equivalent(context_to_found)) 
-         {
-           //MESSAGE("The context is found, we stop the search");
-           _continue = false; 
-           //SCRUTE(_continue);
-         }
-       if(_continue)
-         {
-            //SCRUTE(_bindingName[0].id);
-           Change_Directory(_bindingName[0].id);
-           _current_directory(result_path,length_result,
-                              context_to_found, _continue );
-           if (_continue)
-             {
-               // We'll go back to the initial context
-               _current_context = _ref_context ;
-               //MESSAGE("Just before the delete of ")
-               //SCRUTE(result_path[length_result-1]);
-               delete result_path[length_result-1];
-               length_result--;
-             }
-         }
-      }
-  }
-  _binding_iterator->destroy();  
-  }    
-  // We go to the last directory where an occurence was found
-  _current_context = _ref_context ; 
+  _current_context = ref_context ;
 }
 
 
-//----------------------------------------------------------------------
-/*! Function :_list_directory_recurs.
+// ============================================================================
+/*! \brief list recursively all objects in the given directory and subdirs.
+ *
+ *  get a list of all the objects in the current directory, with recursion
+ *  on the subdirectories. Only the objects are listed, not the directories.
+ *  If the NamingService is out, the exception ServiceUnreachable is thrown.
+ * \param myList the list of objects
+ * \
+Function :_list_directory_recurs.
  * Purpose  : method to list recursively all the objects contained in the tree of absCurDirectory/relativeSubDir.
  *  \param myList The list that will be filled.
  *  \param relativeSubDir The directory from absCurDirectory in which the objects are found.
  *  \param absCurDirectory The directory in ABSOLUTE form.
  *  _current_context must refer to absCurDirectory.
- */
-//----------------------------------------------------------------------
-void SALOME_NamingService::_list_directory_recurs(vector<string>& myList, const char *relativeSubDir,const char *absCurDirectory)
+ */ 
+// ============================================================================
+
+void SALOME_NamingService::_list_directory_recurs(vector<string>& myList,
+                                                 string relativeSubDir,
+                                                 string absCurDirectory)
 {
-  CosNaming::BindingList_var _binding_list;
-  CosNaming::BindingIterator_var _binding_iterator;
-  unsigned long nb=0 ; // for using only the BindingIterator to access the bindings
-  CosNaming::Binding_var _binding ;
-  char *absDir;
-
-  CosNaming::NamingContext_var _ref_context = _current_context;
-  if(relativeSubDir)
+  CosNaming::BindingList_var binding_list;
+  CosNaming::BindingIterator_var binding_iterator;
+  CosNaming::Binding_var binding ;
+
+  unsigned long nb = 0 ; // --- only for thethe use of BindingIterator
+                         //     to access the bindings
+
+  string absDir;
+
+  CosNaming::NamingContext_var ref_context = _current_context;
+
+  if (! relativeSubDir.empty())
     {
-      Change_Directory(relativeSubDir);
-      absDir=new char[strlen(absCurDirectory)+2+strlen(relativeSubDir)];
-      strcpy(absDir,absCurDirectory);
-      strcat(absDir,relativeSubDir);
-      strcat(absDir,"/");
+      Change_Directory(relativeSubDir.c_str());
+      absDir = absCurDirectory + "/" + relativeSubDir;
     }
+
   else
-    absDir=(char *)absCurDirectory;
-  _current_context->list(nb, _binding_list, _binding_iterator) ;
+    absDir = absCurDirectory;
 
-  while (_binding_iterator->next_one(_binding)) {
-    CosNaming::Name _bindingName = _binding->binding_name;
-    if (_binding->binding_type == CosNaming::ncontext) {
-      _list_directory_recurs(myList,_bindingName[0].id,absDir);
-    }
-    else if (_binding->binding_type == CosNaming::nobject) {
-      char *elt=new char[strlen(absDir)+2+strlen(_bindingName[0].id)];
-      strcpy(elt,absDir);
-      strcat(elt,_bindingName[0].id);
-      myList.push_back(elt);
-      delete [] elt;
+  SCRUTE(absDir);
+  _current_context->list(nb, binding_list, binding_iterator) ;
+
+  if (! CORBA::is_nil(binding_iterator))
+    {
+      while (binding_iterator->next_one(binding))
+       {
+         CosNaming::Name bindingName = binding->binding_name;
+
+         if (binding->binding_type == CosNaming::ncontext)
+           {
+             string relativeSdir(bindingName[0].id);
+             _list_directory_recurs(myList, relativeSdir, absDir);
+           }
+
+         else if (binding->binding_type == CosNaming::nobject)
+           {
+             string objName(bindingName[0].id);
+             string elt = absDir + "/" + objName;
+             SCRUTE(elt);
+             myList.push_back(elt);
+           }
+       }
+
+      binding_iterator->destroy();
     }
-  }
-  if(relativeSubDir)
+  if (! relativeSubDir.empty())
     {
-      _current_context = _ref_context ;
-      delete [] absDir;
+      _current_context = ref_context;
     }
-
-  _binding_iterator->destroy();
 }
 
-//----------------------------------------------------------------------
+// ============================================================================
+/*! \brief return a stringified reference of root context
+ *
+ * \return a stringified reference of root context
+ */
+// ============================================================================
 
 char * SALOME_NamingService::getIORaddr()
 {
-   return _orb->object_to_string(_root_context);
+  return _orb->object_to_string(_root_context);
 }
 
index d418b47b723fca64214d27bd6f38fc5782c2db56..6ad5b69ceec42852fd503b65210451178c96cfcf 100644 (file)
 #ifndef SALOME_NAMINGSERVICE_H
 #define SALOME_NAMINGSERVICE_H
 
-#include "utilities.h"
-#include <CORBA.h>
-#include <vector>
-#include <string>
-#include "Utils_Mutex.hxx"
-
 #include <SALOMEconfig.h>
 #include CORBA_CLIENT_HEADER(SALOME_ContainerManager)
 #include CORBA_CLIENT_HEADER(SALOME_Component)
-//class ServiceUnreachable;
+
+#include <vector>
+#include <string>
+#include "utilities.h"
+#include "Utils_Mutex.hxx"
 #include "ServiceUnreachable.hxx"
 
 #if defined NAMINGSERVICE_EXPORTS
 class NAMINGSERVICE_EXPORT SALOME_NamingService
 {
 public:
-  //! default constructor
   SALOME_NamingService();
-
-  //! standard constructor
   SALOME_NamingService(CORBA::ORB_ptr orb);
 
-  //! standard destructor
   virtual ~SALOME_NamingService();
 
-  //! initialize ORB reference after default constructor
   void init_orb(CORBA::ORB_ptr orb);
-  //! method to create an association in the NamingService between an object reference and a path
-  void Register(CORBA::Object_ptr ObjRef, const char* Path) 
+  void Register(CORBA::Object_ptr ObjRef,
+               const char* Path) 
     throw(ServiceUnreachable);
-
-  //! method to get the ObjRef of a symbolic name
   CORBA::Object_ptr Resolve(const char* Path)
     throw( ServiceUnreachable); 
-
-  //! method to get the ObjRef of a component
-  CORBA::Object_ptr ResolveComponent(const char* hostname, const char* containerName, const char* componentName, const int nbproc=0);
-
- //! method to get an ObjRef, given a symbolic name without instance suffix "/Path/Name*.kind"
   CORBA::Object_ptr ResolveFirst(const char* Path)
     throw( ServiceUnreachable); 
-
+  CORBA::Object_ptr ResolveComponent(const char* hostname,
+                                    const char* containerName,
+                                    const char* componentName,
+                                    const int nbproc=0)
+    throw(ServiceUnreachable);
   std::string ContainerName(const char *ContainerName);
   std::string ContainerName(const Engines::MachineParameters& params);
-
-  std::string BuildContainerNameForNS(const char *ContainerName, const char *hostname);
-  std::string BuildContainerNameForNS(const Engines::MachineParameters& params, const char *hostname);
-
-  //! method to research a name from the naming service's current directory 
+  std::string BuildContainerNameForNS(const char *ContainerName,
+                                     const char *hostname);
+  std::string 
+  BuildContainerNameForNS(const Engines::MachineParameters& params,
+                         const char *hostname);
   int Find(const char* name)
     throw(ServiceUnreachable);
-  
-  //! method to create a directory from the current directory
   bool Create_Directory(const char* Path)
     throw(ServiceUnreachable);
-  
-  //! method to change the current directory to the directory Path indicated in "in" Parameter
   bool Change_Directory(const char* Path)
     throw(ServiceUnreachable);
-  //!method to get the current directory
   char* Current_Directory()
     throw(ServiceUnreachable);
-
-  //!method to print all the contexts contained from the current directory
   void list()
     throw(ServiceUnreachable);
-
-  //!method to get all the contexts contained in the current direcotry
-  // Get only objects, isn't iterative
   std::vector<std::string> list_directory()
     throw(ServiceUnreachable);
-
-  //!methods that lists all objects RECUSIVELY in the current directory
+  std::vector<std::string> list_subdirs()
+    throw(ServiceUnreachable);
   std::vector<std::string> list_directory_recurs()
     throw(ServiceUnreachable);
-  //! method to destroy an association Path-Object Reference
   void Destroy_Name(const char* Path)
     throw(ServiceUnreachable);
-  //! method to destroy a directory if it is empty
   virtual void Destroy_Directory(const char* Path)
     throw(ServiceUnreachable);
-
-  //! method to destroy a directory even if it is not empty
   virtual void Destroy_FullDirectory(const char* Path)
     throw(ServiceUnreachable);
-
-  //! get IORstring naming service address 
-  char * getIORaddr();
+  char* getIORaddr();
 
 protected:
   Utils_Mutex _myMutex;
   CORBA::ORB_ptr _orb;
   CosNaming::NamingContext_var _root_context, _current_context;
 
-  //! method called by constructor to initialize _root_context
   void _initialize_root_context();
-  
-  //! method to decompose a Path : /Kernel/Services/Sessions
-  char* _resolve_Path(char* Path);
-
-  //! method to decompose a Path : /Kernel/Services/Sessions
-  void _result_resolve_Path(const char* Path, int& j,
-                           char ** resultat_resolve_Path);
-
-  //! internal method called by Find to research a name from the naming service's current directory 
+  int _createContextNameDir(std::string path,
+                           CosNaming::Name& context_name,
+                           std::vector<std::string>& splitPath,
+                           bool onlyDir);
   void _Find(const char* name, CORBA::Long& occurence_number);
-
-  //! internal method to create a context name from a Path
-  void _create_context_name_dir(char** resultat_resolve_Path,
-                               int length_copy,
-                               CosNaming::Name& _context_name);
-
-  //! internal method to create a parse the naming service tree 
-  void _current_directory(char** result_path,
-                         int& length_result,
-                         CosNaming::NamingContext_var context_to_found,
-                         CORBA::Boolean& _continue);
-
-  //! internal method to list all (recursively) the objects contains in absCurDirectory/relativeSubDir.
-  void _list_directory_recurs(std::vector<std::string>& myList, const char *relativeSubDir,const char *absCurDirectory);
+  void _current_directory(std::vector<std::string>& splitPath,
+                         int& lengthResult,
+                         CosNaming::NamingContext_var contextToFind,
+                         bool& notFound);
+  void _list_directory_recurs(std::vector<std::string>& myList,
+                             std::string relativeSubDir,
+                             std::string absCurDirectory);
 
 };
 
diff --git a/src/NamingService/Test/Makefile.in b/src/NamingService/Test/Makefile.in
new file mode 100644 (file)
index 0000000..36d8bcd
--- /dev/null
@@ -0,0 +1,70 @@
+#  SALOMELocalTrace : log on local machine
+#
+#  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+#  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+# 
+#  This library is free software; you can redistribute it and/or 
+#  modify it under the terms of the GNU Lesser General Public 
+#  License as published by the Free Software Foundation; either 
+#  version 2.1 of the License. 
+# 
+#  This library is distributed in the hope that it will be useful, 
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+#  Lesser General Public License for more details. 
+# 
+#  You should have received a copy of the GNU Lesser General Public 
+#  License along with this library; if not, write to the Free Software 
+#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
+# 
+#  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+#
+#
+#
+#  File   : Makefile.in
+#  Author : Paul RASCLE (EDF)
+#  Module : SALOME
+#  $Header$
+
+top_srcdir=@top_srcdir@
+top_builddir=../../..
+srcdir=@srcdir@
+VPATH=.:@srcdir@:@top_srcdir@/idl
+
+
+@COMMENCE@
+
+# header files  
+EXPORT_HEADERS= NamingServiceTest.hxx
+
+EXPORT_PYSCRIPTS = TestNamingService.py
+
+# Libraries targets
+
+LIB = libNamingServiceTest.la 
+LIB_SRC = NamingServiceTest.cxx
+
+LIB_SERVER_IDL = nstest.idl
+
+LIB_CLIENT_IDL = SALOME_Component.idl SALOME_TestComponent.idl \
+                SALOME_Exception.idl
+
+# Executables targets
+
+BIN = TestNamingService
+BIN_SRC = 
+
+CXXFLAGS += @CPPUNIT_INCLUDES@
+CPPFLAGS += @CPPUNIT_INCLUDES@
+
+LIBS= @LIBS@ @CPPUNIT_LIBS@
+
+LDFLAGS+=
+
+LDFLAGSFORBIN+= \
+ -lSALOMELocalTraceTest -lSALOMELocalTrace -lSALOMEBasics \
+ -lSALOMETraceCollectorTest \
+ -lUtilsTest -lOpUtil \
+ -lSalomeNS
+
+@CONCLUDE@
diff --git a/src/NamingService/Test/NamingServiceTest.cxx b/src/NamingService/Test/NamingServiceTest.cxx
new file mode 100644 (file)
index 0000000..2d4d5d9
--- /dev/null
@@ -0,0 +1,1165 @@
+
+#include "NamingServiceTest.hxx"
+#include "Utils_ORB_INIT.hxx"
+#include "Utils_SINGLETON.hxx"
+
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <cstdlib>
+#include <cstdio>
+
+using namespace std;
+
+// --- uncomment to have some traces on standard error
+//     (useful only when adding new tests...)
+//#define _DEVDEBUG_
+
+#ifdef _DEVDEBUG_
+#define MYDEVTRACE {std::cerr << __FILE__ << " [" << __LINE__ << "] : ";}
+#define DEVTRACE(msg) {MYDEVTRACE; std::cerr<<msg<<std::endl<<std::flush;}
+#else
+#define MYDEVTRACE
+#define DEVTRACE(msg)
+#endif
+
+#define TRACEFILE "/tmp/traceUnitTest.log"
+
+// ============================================================================
+/*!
+ * a basic CORBA object implementation for use with namingService tests
+ */
+// ============================================================================
+
+NSTEST_echo_i::NSTEST_echo_i()
+{
+  _num=-1;
+}
+
+NSTEST_echo_i::NSTEST_echo_i(CORBA::Long num)
+{
+  _num=num;
+}
+
+NSTEST_echo_i::~NSTEST_echo_i()
+{
+}
+
+CORBA::Long NSTEST_echo_i::getId()
+{
+  return _num;
+}
+
+// ============================================================================
+/*!
+ * a factory of CORBA objects for use with namingService tests
+ */
+// ============================================================================
+
+NSTEST_aFactory_i::NSTEST_aFactory_i()
+{
+  _num=0;
+}
+
+NSTEST_aFactory_i::~NSTEST_aFactory_i()
+{
+}
+
+NSTEST::echo_ptr NSTEST_aFactory_i::createInstance()
+{
+  NSTEST_echo_i * anEcho = new NSTEST_echo_i(_num);
+  _num++;
+  NSTEST::echo_var anEchoRef = anEcho->_this();
+  return anEchoRef._retn();
+}
+
+// ============================================================================
+/*!
+ * Set Trace mecanism
+ * - delete preexisting trace classes if any
+ * - set trace on file
+ * Get or initialize the orb
+ * Create a SALOME_NamingService instance
+ */
+// ============================================================================
+
+void 
+NamingServiceTest::setUp()
+{
+  LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
+  CPPUNIT_ASSERT(bp1);
+  bp1->deleteInstance(bp1);
+
+  // --- trace on file
+  char *theFileName = TRACEFILE;
+
+  string s = "file:";
+  s += theFileName;
+  //s="local";
+  //s="with_logger";
+  CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite
+
+  ofstream traceFile;
+  //  traceFile.open(theFileName, ios::out | ios::trunc);
+  traceFile.open(theFileName, ios::out | ios::app);
+  CPPUNIT_ASSERT(traceFile); // file created empty, then closed
+  traceFile.close();
+
+  bp1 = LocalTraceBufferPool::instance();
+  CPPUNIT_ASSERT(bp1);
+
+  // --- Get or initialize the orb
+
+  int _argc = 1;
+  char* _argv[] = {""};
+  ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
+  ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
+  _orb = init(_argc , _argv ) ;
+
+  // --- Create a SALOME_NamingService instance
+
+  _NS.init_orb(_orb) ;
+
+  // --- Create an NSTEST::factory
+
+  CORBA::Object_var obj = _orb->resolve_initial_references("RootPOA");
+  ASSERT(!CORBA::is_nil(obj));
+  _root_poa = PortableServer::POA::_narrow(obj);
+  _pman = _root_poa->the_POAManager();
+  _myFactory  = new NSTEST_aFactory_i();
+  _myFactoryId = _root_poa->activate_object(_myFactory);
+  _factoryRef = _myFactory->_this();
+  _pman->activate();
+  
+}
+
+// ============================================================================
+/*!
+ *  - delete trace classes
+ */
+// ============================================================================
+
+void 
+NamingServiceTest::tearDown()
+{
+
+  LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
+  CPPUNIT_ASSERT(bp1);
+  bp1->deleteInstance(bp1);
+}
+
+// ============================================================================
+/*!
+ *  Test default constructor: must be followed by a call to init_orb(ORB)
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testConstructorDefault()
+{
+  SALOME_NamingService  NS;
+  //CPPUNIT_ASSERT_THROW(NS.getIORaddr(),CORBA::Exception);
+  NS.init_orb(_orb);
+
+  char *root = NS.getIORaddr();
+  CORBA::Object_var obj = _orb->string_to_object(root);
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+
+  CosNaming::NamingContext_var rootContext =
+    CosNaming::NamingContext::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(rootContext));
+}
+
+// ============================================================================
+/*!
+ *  Test constructor with ORB parameter
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testConstructorOrb()
+{
+  SALOME_NamingService  NS(_orb);
+  char *root = NS.getIORaddr();
+  CORBA::Object_var obj = _orb->string_to_object(root);
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+
+  CosNaming::NamingContext_var rootContext =
+    CosNaming::NamingContext::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(rootContext));
+}
+
+// ============================================================================
+/*!
+ * Test Register and resolve of a single CORBA object with absolute pathname,
+ * without subdirectories
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testRegisterResolveAbsNoPath()
+{
+  _NS.Register(_factoryRef,"/nstest_factory");
+  CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
+}
+
+// ============================================================================
+/*!
+ * Test Register and resolve of a single CORBA object with relative pathname,
+ * without subdirectories
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testRegisterResolveRelativeNoPath()
+{
+  CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
+
+  _NS.Create_Directory("/myContext");
+  _NS.Change_Directory("/myContext");
+
+  NSTEST::echo_var anEchoRef = myFactory->createInstance();
+  _NS.Register(anEchoRef,"echo_0");
+
+  obj = _NS.Resolve("echo_0");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::echo_var anEchoRef2 = NSTEST::echo::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef2));
+  CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRef2->getId());
+
+  obj = _NS.Resolve("/myContext/echo_0");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::echo_var anEchoRef3 = NSTEST::echo::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef3));
+  CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRef3->getId());
+}
+
+// ============================================================================
+/*!
+ * Test Register and resolve of a single CORBA object with absolute pathname,
+ * in a subdirectory
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testRegisterResolveAbsWithPath()
+{
+  CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
+
+  NSTEST::echo_var anEchoRef = myFactory->createInstance();
+  _NS.Register(anEchoRef,"/nstest/echo_0");
+
+  obj = _NS.Resolve("/nstest/echo_0");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::echo_var anEchoRefa = NSTEST::echo::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefa));
+  CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRefa->getId());
+
+  NSTEST::echo_var anEchoRef1 = myFactory->createInstance();
+  _NS.Register(anEchoRef1,"/nstest2/rep2/rep3/echo_1");
+  CPPUNIT_ASSERT(anEchoRef->getId() != anEchoRef1->getId());
+
+  obj = _NS.Resolve("/nstest2/rep2/rep3/echo_1");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::echo_var anEchoRef1a = NSTEST::echo::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef1a));
+  CPPUNIT_ASSERT(anEchoRef1->getId() == anEchoRef1a->getId());
+}
+
+// ============================================================================
+/*!
+ * Test Register and resolve of a single CORBA object with relative pathname,
+ * in a subdirectory.
+ * Relative Path is changed to the created subdirectory when Register()
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testRegisterResolveRelativeWithPath()
+{
+  CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
+  _NS.Create_Directory("/myContext");
+  _NS.Change_Directory("/myContext");
+
+  NSTEST::echo_var anEchoRef = myFactory->createInstance();
+  _NS.Register(anEchoRef,"subdir/echo_0");
+
+  obj = _NS.Resolve("echo_0");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::echo_var anEchoRef2 = NSTEST::echo::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef2));
+
+  obj = _NS.Resolve("/myContext/subdir/echo_0");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::echo_var anEchoRef3 = NSTEST::echo::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef3));
+  CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRef3->getId());
+
+  _NS.Change_Directory("/myContext");
+  obj = _NS.Resolve("subdir/echo_0");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::echo_var anEchoRef4 = NSTEST::echo::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef4));
+  CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRef4->getId());
+}
+
+// ============================================================================
+/*!
+ * Test resolve with a name not known
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testResolveBadName()
+{
+  CORBA::Object_var obj = _NS.Resolve("/notRegisteredName");
+  CPPUNIT_ASSERT(CORBA::is_nil(obj));
+
+  obj = _NS.Resolve("/nstest/notRegisteredName");
+  CPPUNIT_ASSERT(CORBA::is_nil(obj));
+
+  obj = _NS.Resolve("/unknownPath/notRegisteredName");
+  CPPUNIT_ASSERT(CORBA::is_nil(obj));
+
+  obj = _NS.Resolve("/anUnknown/ComplicatedPath/notRegisteredName");
+  CPPUNIT_ASSERT(CORBA::is_nil(obj));
+}
+
+// ============================================================================
+/*!
+ * Test resolve with a name not known, with a relative path
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testResolveBadNameRelative()
+{
+  _NS.Create_Directory("/myContext");
+  _NS.Change_Directory("/myContext");
+
+  CORBA::Object_var obj = _NS.Resolve("notRegisteredName");
+  CPPUNIT_ASSERT(CORBA::is_nil(obj));
+
+  obj = _NS.Resolve("unknownPath/notRegisteredName");
+  CPPUNIT_ASSERT(CORBA::is_nil(obj));
+
+  obj = _NS.Resolve("anUnknown/ComplicatedPath/notRegisteredName");
+  CPPUNIT_ASSERT(CORBA::is_nil(obj));
+}
+
+// ============================================================================
+/*!
+ * Test register and resolve multiple objects, test resolveFirst.
+ * Register a few objects in /nstestfirst/echo_n where n is the object id.
+ * Resolve all the objects.
+ * ResolveFirst /nstestfirst/echo must give /nstestfirst/echo_i, corresponding
+ * to the first object.
+ */
+// ============================================================================
+
+#define NB_OBJS 10
+
+void
+NamingServiceTest::testResolveFirst()
+{
+  CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
+
+  int ref[NB_OBJS];
+
+  for (int i=0; i<NB_OBJS; i++)
+    {
+      NSTEST::echo_var anEchoRef = myFactory->createInstance();
+      ref[i] = anEchoRef->getId();
+      string name = "/nstestfirst/echo_";
+      char anum[10];
+      sprintf(anum,"%d",ref[i]);
+      name += anum;
+      _NS.Register(anEchoRef,name.c_str());
+    }
+
+  for (int i=0; i<NB_OBJS; i++)
+    {
+      string name = "/nstestfirst/echo_";
+      char anum[10];
+      sprintf(anum,"%d",ref[i]);
+      name += anum;
+      obj = _NS.Resolve(name.c_str());
+      CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+      NSTEST::echo_var anEchoRef = NSTEST::echo::_narrow(obj);
+      CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef));
+      CPPUNIT_ASSERT(anEchoRef->getId() == ref[i]);
+    }
+
+  string name = "/nstestfirst/echo";
+  obj = _NS.ResolveFirst(name.c_str());
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::echo_var anEchoRef = NSTEST::echo::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef));
+  CPPUNIT_ASSERT(anEchoRef->getId() == ref[0]);
+}
+
+// ============================================================================
+/*!
+ * Test register and resolve multiple objects, test resolveFirst, relative path
+ * Register a few objects in /nstestfirstrel/echo_n where n is the object id.
+ * Resolve all the objects.
+ * ResolveFirst echo with a relative path /nstestfirstrel must give 
+ * /nstestfirst/echo_i, corresponding to the first object.
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testResolveFirstRelative()
+{
+  CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
+
+  int ref[NB_OBJS];
+
+  for (int i=0; i<NB_OBJS; i++)
+    {
+      NSTEST::echo_var anEchoRef = myFactory->createInstance();
+      ref[i] = anEchoRef->getId();
+      string name = "/nstestfirstrel/echo_";
+      char anum[10];
+      sprintf(anum,"%d",ref[i]);
+      name += anum;
+      _NS.Register(anEchoRef,name.c_str());
+    }
+
+  for (int i=0; i<NB_OBJS; i++)
+    {
+      _NS.Change_Directory("/nstestfirstrel");
+      string name = "echo_";
+      char anum[10];
+      sprintf(anum,"%d",ref[i]);
+      name += anum;
+      obj = _NS.Resolve(name.c_str());
+      CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+      NSTEST::echo_var anEchoRef = NSTEST::echo::_narrow(obj);
+      CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef));
+      CPPUNIT_ASSERT(anEchoRef->getId() == ref[i]);
+    }
+
+  _NS.Change_Directory("/nstestfirstrel");
+  string name = "echo";
+  obj = _NS.ResolveFirst(name.c_str());
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+}
+
+// ============================================================================
+/*!
+ * Test resolveFirst with unknown name
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testResolveFirstUnknown()
+{
+  string name = "/notYeyRegistered";
+  CORBA::Object_var obj= _NS.ResolveFirst(name.c_str());
+  CPPUNIT_ASSERT(CORBA::is_nil(obj));
+
+  name = "/nstestfirst/notYeyRegistered";
+  obj = _NS.ResolveFirst(name.c_str());
+  CPPUNIT_ASSERT(CORBA::is_nil(obj));
+
+  name = "/rrr/sss/ttt/notYeyRegistered";
+  obj = _NS.ResolveFirst(name.c_str());
+  CPPUNIT_ASSERT(CORBA::is_nil(obj));
+}
+
+// ============================================================================
+/*!
+ * Test resolveFirst with unknown name, relative Path
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testResolveFirstUnknownRelative()
+{
+  _NS.Create_Directory("/myContext");
+  _NS.Change_Directory("/myContext");
+
+  string name = "RelnotYeyRegistered";
+  CORBA::Object_var obj = _NS.ResolveFirst(name.c_str());
+  CPPUNIT_ASSERT(CORBA::is_nil(obj));
+
+  name = "Relnstestfirst/notYeyRegistered";
+  obj = _NS.ResolveFirst(name.c_str());
+  CPPUNIT_ASSERT(CORBA::is_nil(obj));
+
+  name = "Relrrr/sss/ttt/notYeyRegistered";
+  obj = _NS.ResolveFirst(name.c_str());
+  CPPUNIT_ASSERT(CORBA::is_nil(obj));
+}
+
+// ============================================================================
+/*!
+ * Test ResolveComponent works as specified
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testResolveComponentOK()
+{
+  CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
+
+  NSTEST::echo_var anEchoRef = myFactory->createInstance();
+  _NS.Register(anEchoRef,
+              "/Containers/theHostName/theContainerName/theComponentName");
+
+  obj = _NS.ResolveComponent("theHostName",
+                            "theContainerName",
+                            "theComponentName");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::echo_var anEchoRefa = NSTEST::echo::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefa));
+  CPPUNIT_ASSERT(anEchoRefa->getId() == anEchoRef->getId());
+
+
+  NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
+  _NS.Register(anEchoRef2,
+              "/Containers/theHostName/theContainerName_2/theComponentName");
+
+  obj = _NS.ResolveComponent("theHostName",
+                            "theContainerName",
+                            "theComponentName",
+                            2);
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::echo_var anEchoRefb = NSTEST::echo::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefb));
+  CPPUNIT_ASSERT(anEchoRefb->getId() == anEchoRef2->getId());
+}
+
+// ============================================================================
+/*!
+ * Test ResolveComponent gives nil pointer if hostname is not given (empty)
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testResolveComponentEmptyHostname()
+{
+  CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
+
+  NSTEST::echo_var anEchoRef = myFactory->createInstance();
+  _NS.Register(anEchoRef,
+              "/Containers/theHostName/theContainerName/theComponentName");
+
+  obj = _NS.ResolveComponent("",
+                            "theContainerName",
+                            "theComponentName");
+  CPPUNIT_ASSERT(CORBA::is_nil(obj));
+}
+
+// ============================================================================
+/*!
+ * Test ResolveComponent gives nil pointer if hostname is unknown
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testResolveComponentUnknownHostname()
+{
+  CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
+
+  NSTEST::echo_var anEchoRef = myFactory->createInstance();
+  _NS.Register(anEchoRef,
+              "/Containers/theHostName/theContainerName/theComponentName");
+
+  obj = _NS.ResolveComponent("anUnknownHostName",
+                            "theContainerName",
+                            "theComponentName");
+  CPPUNIT_ASSERT(CORBA::is_nil(obj));
+}
+
+// ============================================================================
+/*!
+ * Test ResolveComponent when containerName is empty.
+ * check bad hostname gives nil pointer.
+ * If componentName registered on a container from hostname, a component
+ * reference is found (the first one).
+ * Else give nil pointer.
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testResolveComponentEmptyContainerName()
+{
+  CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
+
+  NSTEST::echo_var anEchoRef = myFactory->createInstance();
+  _NS.Register(anEchoRef,
+              "/Containers/theHostName/theContainerName/theComponentName");
+
+  NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
+  _NS.Register(anEchoRef2,
+              "/Containers/theHostName/aContainerName/aComponentName");
+
+  NSTEST::echo_var anEchoRef3 = myFactory->createInstance();
+  _NS.Register(anEchoRef3,
+              "/Containers/theHostName/otherContainerName/theComponentName");
+
+  obj = _NS.ResolveComponent("anUnknownHostName",
+                            "",
+                            "theComponentName");
+  CPPUNIT_ASSERT(CORBA::is_nil(obj));
+
+  obj = _NS.ResolveComponent("theHostName",
+                            "",
+                            "theComponentName");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::echo_var anEchoRefa = NSTEST::echo::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefa));
+  CPPUNIT_ASSERT(anEchoRefa->getId() == anEchoRef->getId());
+}
+
+// ============================================================================
+/*!
+ * Test 
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testResolveComponentUnknownContainerName()
+{
+  CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
+
+  NSTEST::echo_var anEchoRef = myFactory->createInstance();
+  _NS.Register(anEchoRef,
+              "/Containers/theHostName/theContainerName/theComponentName");
+
+  NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
+  _NS.Register(anEchoRef2,
+              "/Containers/theHostName/aContainerName/aComponentName");
+
+  NSTEST::echo_var anEchoRef3 = myFactory->createInstance();
+  _NS.Register(anEchoRef3,
+              "/Containers/theHostName/otherContainerName/theComponentName");
+
+  obj = _NS.ResolveComponent("theHostName",
+                            "anUnknownContainerName",
+                            "theComponentName");
+  CPPUNIT_ASSERT(CORBA::is_nil(obj));
+}
+
+// ============================================================================
+/*!
+ * Test 
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testResolveComponentEmptyComponentName()
+{
+  CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
+
+  NSTEST::echo_var anEchoRef = myFactory->createInstance();
+  _NS.Register(anEchoRef,
+              "/Containers/theHostName/theContainerName/theComponentName");
+
+  NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
+  _NS.Register(anEchoRef2,
+              "/Containers/theHostName/EmptyContainerName/");
+
+  obj = _NS.ResolveComponent("theHostName",
+                            "EmptyContainerName",
+                            "");
+  CPPUNIT_ASSERT(CORBA::is_nil(obj));
+}
+
+// ============================================================================
+/*!
+ * Test 
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testResolveComponentUnknownComponentName()
+{
+  CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
+
+  NSTEST::echo_var anEchoRef = myFactory->createInstance();
+  _NS.Register(anEchoRef,
+              "/Containers/theHostName/theContaine:rName/theComponentName");
+
+  obj = _NS.ResolveComponent("theHostName",
+                            "theContainerName",
+                            "anUnknownComponentName");
+  CPPUNIT_ASSERT(CORBA::is_nil(obj));
+}
+
+// ============================================================================
+/*!
+ * Test with a false number nbproc. 
+ * A positive number not corresponding to a registered component gives nil ref.
+ * A negative number is not taken into account and may give a non nil ref.
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testResolveComponentFalseNbproc()
+{
+  CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
+
+  NSTEST::echo_var anEchoRef = myFactory->createInstance();
+  _NS.Register(anEchoRef,
+              "/Containers/theHostName/theContainerName/theComponentName");
+
+  obj = _NS.ResolveComponent("theHostName",
+                            "theContainerName",
+                            "theComponentName",
+                            25);
+  CPPUNIT_ASSERT(CORBA::is_nil(obj));
+
+  obj = _NS.ResolveComponent("theHostName",
+                            "theContainerName",
+                            "theComponentName",
+                            -25);
+  CPPUNIT_ASSERT(! CORBA::is_nil(obj));
+}
+
+// ============================================================================
+/*!
+ * Test 
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testContainerName()
+{
+  string ref0 = "FactoryServer";
+  string ret = _NS.ContainerName("");
+  CPPUNIT_ASSERT(ret == ref0);
+
+  ref0 = "MyContainerName";
+  ret = _NS.ContainerName(ref0.c_str());
+  CPPUNIT_ASSERT(ret == ref0);
+}
+
+// ============================================================================
+/*!
+ * Test 
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testContainerNameParams()
+{
+  Engines::MachineParameters params;
+  params.container_name = "";
+  params.hostname = "";
+  params.OS = "";
+  params.mem_mb = 0;
+  params.cpu_clock = 0;
+  params.nb_proc_per_node = 0;
+  params.nb_node = 0;
+  params.isMPI = false;
+
+  string ref0 = "FactoryServer";
+  string ret = _NS.ContainerName(params);
+  CPPUNIT_ASSERT(ret == ref0);
+
+  ref0 = "MyContainerName";
+  params.container_name = ref0.c_str();
+  ret = _NS.ContainerName(params);
+  CPPUNIT_ASSERT(ret == ref0);
+}
+
+// ============================================================================
+/*!
+ * Test 
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testBuildContainerNameForNS()
+{
+  string ref0 = "/Containers/theHostName/theContainerName";
+  string ret = _NS.BuildContainerNameForNS("theContainerName","theHostName");
+  CPPUNIT_ASSERT(ret == ref0);
+
+  ref0 = "/Containers/theHostName/FactoryServer";
+  ret = _NS.BuildContainerNameForNS("","theHostName");
+  CPPUNIT_ASSERT(ret == ref0);
+}
+
+// ============================================================================
+/*!
+ * Test 
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testBuildContainerNameForNSParams()
+{
+  Engines::MachineParameters params;
+  params.container_name = "";
+  params.hostname = "";
+  params.OS = "";
+  params.mem_mb = 0;
+  params.cpu_clock = 0;
+  params.nb_proc_per_node = 0;
+  params.nb_node = 0;
+  params.isMPI = false;
+
+  params.container_name = "theContainerName";
+  string ref0 = "/Containers/theHostName/theContainerName";
+  string ret = _NS.BuildContainerNameForNS(params,"theHostName");
+  CPPUNIT_ASSERT(ret == ref0);
+
+  params.container_name = "";
+  ref0 = "/Containers/theHostName/FactoryServer";
+  ret = _NS.BuildContainerNameForNS(params,"theHostName");
+  CPPUNIT_ASSERT(ret == ref0);
+}
+
+// ============================================================================
+/*!
+ * Test 
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testFind()
+{
+  CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
+
+  NSTEST::echo_var anEchoRef = myFactory->createInstance();
+  _NS.Register(anEchoRef,
+              "/Containers/theHostName/theContainerName/theComponentName");
+
+  NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
+  _NS.Register(anEchoRef2,
+              "/Containers/theHostName/aContainerName/aComponentName");
+
+  NSTEST::echo_var anEchoRef3 = myFactory->createInstance();
+  _NS.Register(anEchoRef3,
+              "/Containers/theHostName/otherContainerName/theComponentName");
+
+  NSTEST::echo_var anEchoRef4 = myFactory->createInstance();
+  _NS.Register(anEchoRef4,
+              "/Containers/anHostName/oneContainerName/theComponentName");
+
+  _NS.Change_Directory("/Containers");
+  int occ= _NS.Find("theComponentName");
+  CPPUNIT_ASSERT(occ >= 3); // see previous tests
+
+  _NS.Change_Directory("/Containers");
+  occ= _NS.Find("aComponentName");
+  CPPUNIT_ASSERT(occ == 1);
+
+  _NS.Change_Directory("/Containers");
+  occ= _NS.Find("UnknownCompnentName");
+  CPPUNIT_ASSERT(occ == 0);
+}
+
+// ============================================================================
+/*!
+ * Test 
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testCreateDirectory()
+{
+  CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
+
+  bool ret = _NS.Create_Directory("/aaa/bbb/ccc/ddd/eee");
+  CPPUNIT_ASSERT(ret);
+
+  _NS.Change_Directory("/aaa/bbb/ccc/ddd/eee");
+  NSTEST::echo_var anEchoRef = myFactory->createInstance();
+  int val = anEchoRef->getId();
+  string name = "echo_";
+  char anum[10];
+  sprintf(anum,"%d",val);
+  name += anum;
+  _NS.Register(anEchoRef,name.c_str());
+
+  string dirname = "/aaa/bbb/ccc/ddd/eee/";
+  dirname += name;
+  obj = _NS.Resolve(dirname.c_str());
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::echo_var anEchoRef2 = NSTEST::echo::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef2));
+  CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRef2->getId());
+
+  ret = _NS.Create_Directory("/aaa/bbb/ccc/ddd/eee");
+  CPPUNIT_ASSERT(ret);
+
+  _NS.Change_Directory("/aaa/bbb");
+  ret = _NS.Create_Directory("cccccc/dddddd/eeeeee");
+  _NS.Register(anEchoRef,"echo_abcde");
+
+  CPPUNIT_ASSERT(ret);
+  _NS.Change_Directory("/aaa/bbb/cccccc/dddddd/eeeeee");
+  obj = _NS.Resolve("echo_abcde");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+}
+
+// ============================================================================
+/*!
+ * Test 
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testChangeDirectory()
+{
+  CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
+
+  NSTEST::echo_var anEchoRef = myFactory->createInstance();
+  _NS.Register(anEchoRef,
+              "/Containers/theHostName/theContainerName/theComponentName");
+
+  NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
+  _NS.Register(anEchoRef2,
+              "/Containers/theHostName/aContainerName/aComponentName");
+
+  NSTEST::echo_var anEchoRef3 = myFactory->createInstance();
+  _NS.Register(anEchoRef3,
+              "/Containers/theHostName/otherContainerName/theComponentName");
+
+  NSTEST::echo_var anEchoRef4 = myFactory->createInstance();
+  _NS.Register(anEchoRef4,
+              "/Containers/anHostName/oneContainerName/theComponentName");
+  
+  _NS.Change_Directory("/Containers/theHostName/otherContainerName");
+  obj = _NS.Resolve("theComponentName");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  
+  NSTEST::echo_var anEchoRefa = NSTEST::echo::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefa));
+  CPPUNIT_ASSERT(anEchoRefa->getId() == anEchoRef3->getId());
+}
+
+// ============================================================================
+/*!
+ * Test 
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testCurrentDirectory()
+{
+  string path = "/aaa/bbb/ccc/ddd/eee";
+  bool ret = _NS.Create_Directory(path.c_str());
+  CPPUNIT_ASSERT(ret);
+
+  _NS.Change_Directory(path.c_str());
+  string curdir = _NS.Current_Directory();
+  CPPUNIT_ASSERT(curdir == path);
+}
+
+// ============================================================================
+/*!
+ * Test 
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testList()
+{
+  _NS.Change_Directory("/Containers/theHostName/theContainerName");
+  _NS.list();
+  _NS.Change_Directory("/Containers");
+  _NS.list();
+}
+
+// ============================================================================
+/*!
+ * Test 
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testListDirectory()
+{
+  _NS.Change_Directory("/Containers/theHostName/theContainerName");
+  _NS.list_directory();
+  _NS.Change_Directory("/Containers");
+  _NS.list_directory();
+}
+
+// ============================================================================
+/*!
+ * Test 
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testListDirectoryRecurs()
+{
+  _NS.Change_Directory("/Containers/theHostName/theContainerName");
+  _NS.list_directory_recurs();
+  _NS.Change_Directory("/Containers");
+  _NS.list_directory_recurs();
+  _NS.Change_Directory("/");
+  _NS.list_directory_recurs();
+}
+
+
+// ============================================================================
+/*!
+ * Test 
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testListSubdirs()
+{
+  _NS.Change_Directory("/Containers/theHostName/theContainerName");
+  _NS.list_subdirs();
+  _NS.Change_Directory("/Containers");
+  _NS.list_subdirs();
+  _NS.Change_Directory("/");
+  _NS.list_subdirs();
+}
+// ============================================================================
+/*!
+ * Test 
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testDestroyName()
+{
+  CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
+
+  string path = "/Containers/theHostName/theContainerName/theComponentName";
+
+  NSTEST::echo_var anEchoRef = myFactory->createInstance();
+  _NS.Register(anEchoRef, path.c_str());
+
+  obj=_NS.Resolve(path.c_str());
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+
+  _NS.Destroy_Name(path.c_str());
+  obj=_NS.Resolve(path.c_str());
+  CPPUNIT_ASSERT(CORBA::is_nil(obj));
+}
+
+// ============================================================================
+/*!
+ * Test 
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testDestroyDirectory()
+{
+  CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
+
+  string path = "/Containers/theHostName/theContainerName/theComponentName";
+
+  NSTEST::echo_var anEchoRef = myFactory->createInstance();
+  _NS.Register(anEchoRef, path.c_str());
+
+  _NS.Destroy_Directory("/Containers/theHostName/theContainerName");
+  obj=_NS.Resolve(path.c_str());
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj)); // directory not empty: not destroyed
+
+  _NS.Destroy_Name(path.c_str());
+  _NS.Destroy_Directory("/Containers/theHostName/theContainerName");
+  _NS.Change_Directory("/Containers/theHostName");
+  _NS.list_subdirs();
+}
+
+// ============================================================================
+/*!
+ * Test 
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testDestroyFullDirectory()
+{
+  _NS.Destroy_FullDirectory("/Containers");
+  _NS.Change_Directory("/");
+  _NS.list_subdirs();
+}
+
+// ============================================================================
+/*!
+ * Test 
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testGetIorAddr()
+{
+  char *root = _NS.getIORaddr();
+  CORBA::Object_var obj = _orb->string_to_object(root);
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj)); 
+}
+
+// ============================================================================
+/*!
+ * Test 
+ */
+// ============================================================================
+
+// void
+// NamingServiceTest::()
+// {
+//   CPPUNIT_ASSERT(0);
+// }
+
diff --git a/src/NamingService/Test/NamingServiceTest.hxx b/src/NamingService/Test/NamingServiceTest.hxx
new file mode 100644 (file)
index 0000000..3630c10
--- /dev/null
@@ -0,0 +1,132 @@
+
+#ifndef _NAMINGSERVICETEST_HXX_
+#define _NAMINGSERVICETEST_HXX_
+
+#include <cppunit/extensions/HelperMacros.h>
+#include "SALOME_NamingService.hxx"
+
+#include <SALOMEconfig.h>
+#include CORBA_SERVER_HEADER(nstest)
+
+class NSTEST_echo_i : public virtual POA_NSTEST::echo,
+                     public virtual PortableServer::RefCountServantBase
+{
+public:
+  NSTEST_echo_i();
+  NSTEST_echo_i(CORBA::Long num);
+  ~NSTEST_echo_i();
+  CORBA::Long getId();
+private:
+  int _num;
+};
+
+class NSTEST_aFactory_i : public virtual POA_NSTEST::aFactory,
+                         public virtual PortableServer::RefCountServantBase
+{
+public:
+  NSTEST_aFactory_i();
+  ~NSTEST_aFactory_i();
+  NSTEST::echo_ptr createInstance();
+private:
+  int _num;
+};
+
+class NamingServiceTest : public CppUnit::TestFixture
+{
+  CPPUNIT_TEST_SUITE( NamingServiceTest );
+  CPPUNIT_TEST( testConstructorDefault );
+  CPPUNIT_TEST( testConstructorOrb );
+  CPPUNIT_TEST( testRegisterResolveAbsNoPath );
+  CPPUNIT_TEST( testRegisterResolveRelativeNoPath );
+  CPPUNIT_TEST( testRegisterResolveAbsWithPath );
+  CPPUNIT_TEST( testRegisterResolveRelativeWithPath );
+  CPPUNIT_TEST( testResolveBadName );
+  CPPUNIT_TEST( testResolveBadNameRelative );
+  CPPUNIT_TEST( testResolveFirst );
+  CPPUNIT_TEST( testResolveFirstRelative );
+  CPPUNIT_TEST( testResolveFirstUnknown );
+  CPPUNIT_TEST( testResolveFirstUnknownRelative );
+  CPPUNIT_TEST( testResolveComponentOK );
+  CPPUNIT_TEST( testResolveComponentEmptyHostname );
+  CPPUNIT_TEST( testResolveComponentUnknownHostname );
+  CPPUNIT_TEST( testResolveComponentEmptyContainerName );
+  CPPUNIT_TEST( testResolveComponentUnknownContainerName );
+  CPPUNIT_TEST( testResolveComponentEmptyComponentName );
+  CPPUNIT_TEST( testResolveComponentUnknownComponentName );
+  CPPUNIT_TEST( testResolveComponentFalseNbproc );
+  CPPUNIT_TEST( testContainerName );
+  CPPUNIT_TEST( testContainerNameParams );
+  CPPUNIT_TEST( testBuildContainerNameForNS );
+  CPPUNIT_TEST( testBuildContainerNameForNSParams );
+  CPPUNIT_TEST( testFind );
+  CPPUNIT_TEST( testCreateDirectory );
+  CPPUNIT_TEST( testChangeDirectory );
+  CPPUNIT_TEST( testCurrentDirectory );
+  CPPUNIT_TEST( testList );
+  CPPUNIT_TEST( testListDirectory );
+  CPPUNIT_TEST( testListDirectoryRecurs );
+  CPPUNIT_TEST( testListSubdirs );
+  CPPUNIT_TEST( testDestroyName );
+  CPPUNIT_TEST( testDestroyDirectory );
+  CPPUNIT_TEST( testDestroyFullDirectory );
+  CPPUNIT_TEST( testGetIorAddr );
+//   CPPUNIT_TEST(  );
+//   CPPUNIT_TEST(  );
+//   CPPUNIT_TEST(  );
+
+  CPPUNIT_TEST_SUITE_END();
+
+public:
+
+  void setUp();
+  void tearDown();
+
+  void testConstructorDefault();
+  void testConstructorOrb();
+  void testRegisterResolveAbsNoPath();
+  void testRegisterResolveRelativeNoPath();
+  void testRegisterResolveAbsWithPath();
+  void testRegisterResolveRelativeWithPath();
+  void testResolveBadName();
+  void testResolveBadNameRelative();
+  void testResolveFirst();
+  void testResolveFirstRelative();
+  void testResolveFirstUnknown();
+  void testResolveFirstUnknownRelative();
+  void testResolveComponentOK();
+  void testResolveComponentEmptyHostname();
+  void testResolveComponentUnknownHostname();
+  void testResolveComponentEmptyContainerName();
+  void testResolveComponentUnknownContainerName();
+  void testResolveComponentEmptyComponentName();
+  void testResolveComponentUnknownComponentName();
+  void testResolveComponentFalseNbproc();
+  void testContainerName();
+  void testContainerNameParams();
+  void testBuildContainerNameForNS();
+  void testBuildContainerNameForNSParams();
+  void testFind();
+  void testCreateDirectory();
+  void testChangeDirectory();
+  void testCurrentDirectory();
+  void testList();
+  void testListDirectory();
+  void testListDirectoryRecurs();
+  void testListSubdirs();
+  void testDestroyName();
+  void testDestroyDirectory();
+  void testDestroyFullDirectory();
+  void testGetIorAddr();
+
+protected:
+  CORBA::ORB_var _orb;
+  SALOME_NamingService _NS;
+
+  PortableServer::POA_var _root_poa;
+  PortableServer::POAManager_var _pman;
+  PortableServer::ObjectId_var _myFactoryId;
+  NSTEST_aFactory_i * _myFactory;
+  CORBA::Object_var _factoryRef;
+};
+
+#endif
diff --git a/src/NamingService/Test/TestNamingService.cxx b/src/NamingService/Test/TestNamingService.cxx
new file mode 100644 (file)
index 0000000..5680c4e
--- /dev/null
@@ -0,0 +1,18 @@
+
+// --- include all Unit Test from basics until the present directory
+
+#include "SALOMELocalTraceTest.hxx"
+#include "SALOMETraceCollectorTest.hxx"
+#include "UtilsTest.hxx"
+#include "NamingServiceTest.hxx"
+
+// --- Registers the fixture into the 'registry'
+
+CPPUNIT_TEST_SUITE_REGISTRATION( SALOMELocalTraceTest );
+CPPUNIT_TEST_SUITE_REGISTRATION( SALOMETraceCollectorTest );
+CPPUNIT_TEST_SUITE_REGISTRATION( UtilsTest );
+CPPUNIT_TEST_SUITE_REGISTRATION( NamingServiceTest );
+
+// --- generic Main program from Basic/Test
+
+#include "BasicMainTest.hxx"
diff --git a/src/NamingService/Test/TestNamingService.py b/src/NamingService/Test/TestNamingService.py
new file mode 100644 (file)
index 0000000..153b719
--- /dev/null
@@ -0,0 +1,35 @@
+import sys, os,signal,string,commands
+import runSalome
+import orbmodule
+import TestKiller
+
+# get SALOME environment :
+
+args, modules_list, modules_root_dir = runSalome.get_config()
+runSalome.set_env(args, modules_list, modules_root_dir)
+
+# set environment for trace in logger
+# (with file, servers may be killed before the write to the file...)
+
+#os.environ["SALOME_trace"] = "file:/tmp/traceUnitTest.log"
+#os.environ["SALOME_trace"] = "local"
+os.environ["SALOME_trace"] = "with_logger"
+
+# launch CORBA naming server
+
+clt=orbmodule.client()
+
+# launch CORBA logger server
+
+myServer=runSalome.LoggerServer(args)
+myServer.run()
+clt.waitLogger("Logger")
+
+# execute Unit Test
+
+command = ['TestNamingService']
+ret = os.spawnvp(os.P_WAIT, command[0], command)
+
+# kill Test process
+
+TestKiller.killProcess(runSalome.process_id)
index 88ff54e84b5119fe1efaede0bedb4f96f9e9e582..26f9d2de74d3d1172c60d9d62799eda7afa00ef0 100644 (file)
@@ -461,6 +461,7 @@ SALOME_ResourcesManager::BuildCommandToLaunchLocalContainer
       o << nbproc << " ";
 
       command += o.str();
+      command += "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
 
       if (isPythonContainer(params.container_name))
         command += "pyMPI SALOME_ContainerPy.py ";
index ba880f6aeeb31fed3a7676ef0fad2b9ee506e92d..61ac812273eb35766164fbaea9b9641d8d5cdb2b 100644 (file)
@@ -31,6 +31,7 @@
 
 using namespace std;
 
+//#define _DEVDEBUG_
 #include "FileTraceCollector.hxx"
 
 // Class attributes initialisation, for class method FileTraceCollector::run
@@ -88,6 +89,7 @@ BaseTraceCollector* FileTraceCollector::instance(const char *fileName)
 
 void* FileTraceCollector::run(void *bid)
 {
+  //DEVTRACE("init run");
   _threadId = new pthread_t;
   *_threadId = pthread_self();
   sem_post(&_sem); // unlock instance
@@ -100,6 +102,7 @@ void* FileTraceCollector::run(void *bid)
 
   ofstream traceFile;
   const char *theFileName = _fileName.c_str();
+  DEVTRACE("try to open trace file "<< theFileName);
   traceFile.open(theFileName, ios::out | ios::app);
   if (!traceFile)
     {
@@ -109,7 +112,7 @@ void* FileTraceCollector::run(void *bid)
 
   // --- Loop until there is no more buffer to print,
   //     and no ask for end from destructor.
-
+  DEVTRACE("Begin loop");
   while ((!_threadToClose) || myTraceBuffer->toCollect() )
     {
       if (_threadToClose)
@@ -183,8 +186,8 @@ FileTraceCollector:: ~FileTraceCollector()
          _threadToClose = 0;
        }
       _singleton = 0;
-      ret = pthread_mutex_unlock(&_singletonMutex); // release lock
     }
+  ret = pthread_mutex_unlock(&_singletonMutex); // release lock
 }
 
 // ============================================================================
index 2613d8714c805f48b399a9cdb053e881f7fcc16d..8fd4c5bf2d3bfea754094b37bdf59eddc5e72352 100644 (file)
@@ -33,6 +33,7 @@
 #else
 #endif
 
+//#define _DEVDEBUG_
 #include "LocalTraceBufferPool.hxx"
 #include "BaseTraceCollector.hxx"
 #include "LocalTraceCollector.hxx"
@@ -82,10 +83,12 @@ LocalTraceBufferPool* LocalTraceBufferPool::instance()
       ret = pthread_mutex_lock(&_singletonMutex); // acquire lock to be alone
       if (_singleton == 0)                     // another thread may have got
        {                                      // the lock after the first test
-        LocalTraceBufferPool* myInstance = new LocalTraceBufferPool(); 
+         DEVTRACE("New buffer pool");
+         LocalTraceBufferPool* myInstance = new LocalTraceBufferPool(); 
 
          DESTRUCTOR_OF<LocalTraceBufferPool> *ptrDestroy =
            new DESTRUCTOR_OF<LocalTraceBufferPool> (*myInstance);
+         _singleton = myInstance;
 
          // --- start a trace Collector
 
@@ -140,7 +143,7 @@ LocalTraceBufferPool* LocalTraceBufferPool::instance()
                  exit(1);        // in case assert is deactivated
                }             
            }
-         _singleton = myInstance;
+         DEVTRACE("New buffer pool: end");
        }
       ret = pthread_mutex_unlock(&_singletonMutex); // release lock
     }
@@ -295,8 +298,8 @@ LocalTraceBufferPool::~LocalTraceBufferPool()
       ret=pthread_mutex_destroy(&_incrementMutex);
       DEVTRACE("LocalTraceBufferPool::~LocalTraceBufferPool()-end");
       _singleton = 0;
-      ret = pthread_mutex_unlock(&_singletonMutex); // release lock
     }
+  ret = pthread_mutex_unlock(&_singletonMutex); // release lock
 }
 
 // ============================================================================
index 559216ac9ff8213877f7ff489fd36d10919e4678..edaa246904ae72e6e056d18605f24fc7e7c7391b 100644 (file)
@@ -153,8 +153,8 @@ LocalTraceCollector:: ~LocalTraceCollector()
          _threadToClose = 0;
        }
       _singleton = 0;
-      ret = pthread_mutex_unlock(&_singletonMutex); // release lock
     }
+  ret = pthread_mutex_unlock(&_singletonMutex); // release lock
 }
 
 // ============================================================================
index 6fd76763f1a541152da63b8070ce5d3983bee295..361595a66310fabdd86f4e76dfccf43815d23272 100644 (file)
@@ -192,8 +192,8 @@ SALOMETraceCollector:: ~SALOMETraceCollector()
          _threadToClose = 0;
        }
       _singleton = 0;
-      ret = pthread_mutex_unlock(&_singletonMutex); // release lock
     }
+  ret = pthread_mutex_unlock(&_singletonMutex); // release lock
 }
 
 // ============================================================================
index 451d9d20f912790be42294b205bd19b3aff3b34e..000d291af4a5591b12df5aef0d4d380be20f5c70 100644 (file)
@@ -28,10 +28,10 @@ LIB_CLIENT_IDL = Logger.idl SALOME_MPIObject.idl SALOME_TestMPIComponent.idl SAL
 # Executables targets
 BIN = TestMPIContainer
 BIN_SRC = 
-BIN_CLIENT_IDL = Logger.idl SALOME_MPIObject.idl SALOME_MPIContainer.idl SALOME_TestMPIComponent.idl
+BIN_CLIENT_IDL = Logger.idl SALOME_MPIObject.idl SALOME_MPIContainer.idl SALOME_TestMPIComponent.idl SALOME_Exception.idl
 BIN_SERVER_IDL = 
 
-LDFLAGSFORBIN+= -lSalomeNotification -lSalomeNS -lSalomeLifeCycleCORBA -lSalomeMPIContainer -lSalomeContainer -lRegistry -lOpUtil -lSALOMELocalTrace  -lSalomeResourcesManager ${MPI_LIBS}
+LDFLAGSFORBIN+= -lSalomeNotification -lSalomeNS -lSalomeLifeCycleCORBA -lSalomeMPIContainer -lSalomeContainer -lRegistry -lOpUtil -lSALOMELocalTrace -lSALOMEBasics -lSalomeResourcesManager ${MPI_LIBS}
 
 CXXFLAGS+=${MPI_INCLUDES}
 CXX_DEPEND_FLAG+=${MPI_INCLUDES}
index a0c1540839338ef0594c51192ed4c5a0e9208297..f7651111f0b65b2bb9d7d2c5eb01a9c6f1f6cf28 100644 (file)
@@ -48,7 +48,7 @@ LIB_SRC =
 BIN = UnitTests
 BIN_SRC = 
 BIN_CLIENT_IDL = SALOME_Component.idl SALOME_TestComponent.idl \
-                SALOME_Exception.idl
+                SALOME_Exception.idl nstest.idl
 
 CXXFLAGS += @CPPUNIT_INCLUDES@
 CPPFLAGS += @CPPUNIT_INCLUDES@
@@ -59,7 +59,8 @@ LDFLAGSFORBIN+= \
  -lSALOMELocalTraceTest -lSALOMELocalTrace -lSALOMEBasics \
  -lSALOMETraceCollectorTest \
  -lUtilsTest -lOpUtil \
- -lSalomeNS -lSalomeContainer -lSalomeResourcesManager \
+ -lNamingServiceTest -lSalomeNS \
+ -lSalomeContainer -lSalomeResourcesManager \
  -lRegistry -lSalomeNotification \
  -lLifeCycleCORBATest -lSalomeLifeCycleCORBA \
 
index 987e3049ca619d3d6055ab55d27262a754f3958f..ee91e638eb33fd63e07a144b04d5ba4775c02e4a 100644 (file)
@@ -4,6 +4,7 @@
 #include "SALOMELocalTraceTest.hxx"
 #include "SALOMETraceCollectorTest.hxx"
 #include "UtilsTest.hxx"
+#include "NamingServiceTest.hxx"
 #include "LifeCycleCORBATest.hxx"
 
 // --- Registers the fixture into the 'registry'
@@ -11,6 +12,7 @@
 CPPUNIT_TEST_SUITE_REGISTRATION( SALOMELocalTraceTest );
 CPPUNIT_TEST_SUITE_REGISTRATION( SALOMETraceCollectorTest );
 CPPUNIT_TEST_SUITE_REGISTRATION( UtilsTest );
+CPPUNIT_TEST_SUITE_REGISTRATION( NamingServiceTest );
 CPPUNIT_TEST_SUITE_REGISTRATION( LifeCycleCORBATest );
 
 // --- generic Main program from Basic/Test