Salome HOME
Merge from mergeto_V5_1_main_19Jan10
[modules/kernel.git] / src / ResourcesManager / SALOME_ResourcesCatalog_Handler.cxx
index 19f5f410ae42f50689c23962d4ff341eecba739f..2cf3e8b7280fa1cdb4ed78db15b0cbf591c3467c 100755 (executable)
@@ -1,6 +1,6 @@
-//  SALOME ResourcesCatalog : implementation of catalog resources parsing (SALOME_ModuleCatalog.idl)
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  Copyright (C) 2003-2007  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
 //  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
-//
-//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+//  SALOME ResourcesCatalog : implementation of catalog resources parsing (SALOME_ModuleCatalog.idl)
 //  File   : SALOME_ResourcesCatalog_Handler.cxx
 //  Author : Estelle Deville
 //  Module : SALOME
 //$Header$
-
+//
 #include "SALOME_ResourcesCatalog_Handler.hxx"
+#include "Basics_Utils.hxx"
 #include <iostream>
 #include <map>
-#include <qdom.h>
-#include "utilities.h"
 
 using namespace std;
 
@@ -42,29 +40,34 @@ using namespace std;
 //=============================================================================
 
 SALOME_ResourcesCatalog_Handler::
-SALOME_ResourcesCatalog_Handler(MapOfParserResourcesType& listOfResources):
-    _resources_list(listOfResources)
+SALOME_ResourcesCatalog_Handler(MapOfParserResourcesType& resources_list): _resources_list(resources_list)
 {
-  MESSAGE("SALOME_ResourcesCatalog_Handler creation");
   //XML tags initialisation
   test_machine = "machine";
-  test_resources = "resources";
-
+  test_cluster = "cluster";
+  test_name = "name";
   test_hostname = "hostname";
-  test_alias = "alias";
   test_protocol = "protocol";
+  test_cluster_internal_protocol = "iprotocol";
   test_mode = "mode";
+  test_batch = "batch";
+  test_mpi = "mpi";
   test_user_name = "userName";
   test_appli_path = "appliPath";
   test_modules = "modules";
   test_module_name = "moduleName";
-  test_module_path = "modulePath";
-  test_pre_req_file_path = "preReqFilePath";
+  test_components = "component";
+  test_component_name = "name";
   test_os = "OS";
   test_mem_in_mb = "memInMB";
   test_cpu_freq_mhz = "CPUFreqMHz";
   test_nb_of_nodes = "nbOfNodes";
+  test_nb_of_proc = "nbOfProc";
   test_nb_of_proc_per_node = "nbOfProcPerNode";
+  test_batch_queue = "batchQueue";
+  test_user_commands = "userCommands";
+  test_use = "use";
+  test_members = "members";
 }
 
 //=============================================================================
@@ -75,7 +78,7 @@ SALOME_ResourcesCatalog_Handler(MapOfParserResourcesType& listOfResources):
 
 SALOME_ResourcesCatalog_Handler::~SALOME_ResourcesCatalog_Handler()
 {
-  //  MESSAGE("SALOME_ResourcesCatalog_Handler destruction");
+  //  cout << "SALOME_ResourcesCatalog_Handler destruction") << endl;
 }
 
 //=============================================================================
@@ -86,312 +89,679 @@ SALOME_ResourcesCatalog_Handler::~SALOME_ResourcesCatalog_Handler()
 
 const MapOfParserResourcesType&
 SALOME_ResourcesCatalog_Handler::GetResourcesAfterParsing() const
-  {
-    return _resources_list;
-  }
+{
+  return _resources_list;
+}
 
 //=============================================================================
 /*!
- *  Overload handler function startDocument.
- *  Called before an xml file is parsed.
- *  Clears the list of resources.
- *  \return true (if no error detected...)
+ *  Processes XML document and fills the list of resources
  */ 
 //=============================================================================
 
-bool SALOME_ResourcesCatalog_Handler::startDocument()
+void SALOME_ResourcesCatalog_Handler::ProcessXmlDocument(xmlDocPtr theDoc)
 {
-  //  MESSAGE("Begin parse document");
-
-  // --- Empty private elements
-
+  // Empty private elements
   _resources_list.clear();
-  return true;
-}
 
-//=============================================================================
-/*!
- *  Overload handler function startElement.
- *    \param QString argument by reference (not used here ?)
- *    \param QString argument by reference (not used here ?)
- *    \param name                          (not used here ?)
- *    \param atts
- *    \return true if no error was detected
- */ 
-//=============================================================================
+  // Get the document root node
+  xmlNodePtr aCurNode = xmlDocGetRootElement(theDoc);
 
-bool
-SALOME_ResourcesCatalog_Handler::
-startElement( const QString&,
-              const QString&,
-              const QString& name,
-              const QXmlAttributes& attrs )
-{
-  for (int i = 0;i < attrs.count();i++)
+  aCurNode = aCurNode->xmlChildrenNode;
+  // Processing the document nodes
+  while(aCurNode != NULL)
+  {
+    // Cas d'une machine ou d'une machine batch
+    if (!xmlStrcmp(aCurNode->name,(const xmlChar*)test_machine))
+    {
+      _resource.Clear();
+      bool Ok = ProcessMachine(aCurNode, _resource);
+      if (Ok)
+      {
+       // Adding a resource
+       if(_resource.HostName == "localhost")
+       {
+         _resource.HostName = Kernel_Utils::GetHostname();
+         if (_resource.Name == "localhost")
+         {
+           _resource.Name = Kernel_Utils::GetHostname();
+           _resource.DataForSort._Name = Kernel_Utils::GetHostname();
+         }
+       }
+       map<string, ParserResourcesType>::const_iterator iter = _resources_list.find(_resource.Name);
+       if (iter != _resources_list.end())
+         RES_INFOS("Warning resource " << _resource.Name << " already added, keep last resource found !");
+       _resources_list[_resource.Name] = _resource;
+      }
+    }
+    // Cas de la déclaration d'un cluster
+    if (!xmlStrcmp(aCurNode->name,(const xmlChar*)test_cluster))
     {
-      QString qName(attrs.localName(i));
-      std::string content(attrs.value(i).latin1());
+      _resource.Clear();
+      if(ProcessCluster(aCurNode, _resource))
+      {
+       map<string, ParserResourcesType>::const_iterator iter = _resources_list.find(_resource.Name);
+       if (iter != _resources_list.end())
+         RES_INFOS("Warning resource " << _resource.Name << " already added, keep last resource found !");
+       _resources_list[_resource.Name] = _resource;
+      }
+    }
+    aCurNode = aCurNode->next;
+  }
 
-      if ((qName.compare(QString(test_hostname)) == 0))
-        _resource.DataForSort._hostName = content;
+#ifdef _DEBUG_
+  for (map<string, ParserResourcesType>::const_iterator iter = _resources_list.begin();
+       iter != _resources_list.end();
+       iter++)
+  {
+    std::cerr << "************************************************" << std::endl;
+    std::cerr << "Resource " << (*iter).first << " found:" << std::endl;
+    std::cerr << " Name: " << (*iter).second.Name << std::endl;
+    std::cerr << " Hostname: " << (*iter).second.HostName << std::endl;
+    std::cerr << " Username: " << (*iter).second.UserName << std::endl;
+    std::cerr << " Appli path: " <<(*iter).second.AppliPath << std::endl;
+    std::cerr << " OS: " << (*iter).second.OS << std::endl;
+    std::cerr << " Protocol: " << (*iter).second.PrintAccessProtocolType() << std::endl;
+    std::cerr << " Internal Protocol: " <<(*iter).second.PrintClusterInternalProtocol() << std::endl;
+    std::cerr << " Mode: " << (*iter).second.PrintAccessModeType() << std::endl;
+    std::cerr << " Batch Type: " << (*iter).second.PrintBatchType() << std::endl;
+    std::cerr << " MPI Impl: " << (*iter).second.PrintMpiImplType() << std::endl;
+    std::cerr << "************************************************" << std::endl;
+  }
+#endif
+}
 
-      if ((qName.compare(QString(test_alias)) == 0))
-        _resource.Alias = content;
+bool
+SALOME_ResourcesCatalog_Handler::ProcessCluster(xmlNodePtr cluster_descr, ParserResourcesType & resource)
+{
+  // Ajout d'un cluster
+  // hostname, use et nbOfProc sont obligatoires
+  if (xmlHasProp(cluster_descr, (const xmlChar*)test_hostname))
+  {
+    xmlChar* hostname = xmlGetProp(cluster_descr, (const xmlChar*)test_hostname);
+    resource.HostName = (const char*)hostname;
+    xmlFree(hostname);
+  }
+  else
+  {
+    std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! found a cluster without a hostname" << std::endl;
+    std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! this cluster will not be added" << std::endl;
+    return false;
+  }
 
-      if ((qName.compare(QString(test_protocol)) == 0))
-        {
-          switch (content[0])
-            {
-
-            case 'r':
-              _resource.Protocol = rsh;
-              break;
-
-            case 's':
-              _resource.Protocol = ssh;
-              break;
-
-            default:
-              // If it'not in all theses cases, the protocol is affected to rsh
-              _resource.Protocol = rsh;
-              break;
-            }
-        }
+  if (xmlHasProp(cluster_descr, (const xmlChar*)test_name))
+  {
+    xmlChar* name = xmlGetProp(cluster_descr, (const xmlChar*)test_name);
+    resource.Name = (const char*)name;
+    resource.DataForSort._Name = (const char*)name;
+    xmlFree(name);
+  }
+  else
+  {
+    resource.Name = resource.HostName;
+    resource.DataForSort._Name = resource.HostName;
+    std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! No Name found use Hostname for resource: " << _resource.Name << std::endl;
+  }
 
-      if ((qName.compare(QString(test_mode)) == 0))
-        {
-          switch (content[0])
-            {
-
-            case 'i':
-              _resource.Mode = interactive;
-              break;
-
-            case 'b':
-              _resource.Mode = batch;
-              break;
-
-            default:
-              // If it'not in all theses cases, the mode is affected to interactive
-              _resource.Mode = interactive;
-              break;
-            }
-        }
+  if (xmlHasProp(cluster_descr, (const xmlChar*)test_use))
+  {
+    xmlChar* use = xmlGetProp(cluster_descr, (const xmlChar*)test_use);
+    resource.use = (const char*)use;
+    xmlFree(use);
+  }
+  else
+  {
+    std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! found a cluster without a use" << std::endl;
+    std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! this cluster will not be added" << std::endl;
+    return false;
+  }
 
-      if ((qName.compare(QString(test_user_name)) == 0))
-        _resource.UserName = content;
+  if (xmlHasProp(cluster_descr, (const xmlChar*)test_nb_of_proc))
+  {
+    xmlChar* nb_of_proc = xmlGetProp(cluster_descr, (const xmlChar*)test_nb_of_proc);
+    resource.nbOfProc = atoi((const char*)nb_of_proc);
+    xmlFree(nb_of_proc);
+  }
+  else
+  {
+    std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! found a cluster without a nbOfProc" << std::endl;
+    std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! this cluster will not be added" << std::endl;
+    return false;
+  }
 
-      if ((qName.compare(QString(test_appli_path)) == 0))
-        _resource.AppliPath = content;
+  if (xmlHasProp(cluster_descr, (const xmlChar*)test_mpi))
+  {
+    xmlChar* mpi = xmlGetProp(cluster_descr, (const xmlChar*)test_mpi);
+    std::string anMpi = (const char*)mpi;
+    xmlFree(mpi);
+    if (anMpi == "lam")
+      resource.mpi = lam;
+    else if (anMpi == "mpich1")
+      resource.mpi = mpich1;
+    else if (anMpi == "mpich2")
+      resource.mpi = mpich2;
+    else if (anMpi == "openmpi")
+      resource.mpi = openmpi;
+    else if  (anMpi == "slurm")
+      resource.mpi = slurm;
+    else if  (anMpi == "prun")
+      resource.mpi = prun;
+    else
+      resource.mpi = nompi;
+  }
 
-      if ((qName.compare(QString(test_module_name)) == 0))
-        previous_module_name = content;
+  // Parsing des membres du cluster 
+  xmlNodePtr aCurSubNode = cluster_descr->xmlChildrenNode;
+  while(aCurSubNode != NULL)
+  {
+    if (!xmlStrcmp(aCurSubNode->name, (const xmlChar*)test_members))
+    {
+       xmlNodePtr members = aCurSubNode->xmlChildrenNode;
+       while (members != NULL)
+       {
+         // Process members
+         if (!xmlStrcmp(members->name, (const xmlChar*)test_machine))
+         {
+           ParserResourcesClusterMembersType new_member;
+           if (ProcessMember(members, new_member))
+             resource.ClusterMembersList.push_back(new_member);
+         }
+         members = members->next;
+       }
+    }
+    aCurSubNode = aCurSubNode->next;
+  }
 
-      if ((qName.compare(QString(test_module_path)) == 0))
-        previous_module_path = content;
+  // Test: Il faut au moins un membre pour que le cluster soit correct !
+  if (resource.ClusterMembersList.empty())
+  {
+    std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! found a cluster without a member" << std::endl;
+    std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessCluster : !!! Warning !!! this cluster will not be added" << std::endl;
+    return false;
+  }
+  return true;
+}
 
-      if ((qName.compare(QString(test_pre_req_file_path)) == 0))
-        _resource.PreReqFilePath = content;
+bool
+SALOME_ResourcesCatalog_Handler::ProcessMember(xmlNodePtr member_descr, ParserResourcesClusterMembersType & resource)
+{
+  if (xmlHasProp(member_descr, (const xmlChar*)test_hostname))
+  {
+    xmlChar* hostname = xmlGetProp(member_descr, (const xmlChar*)test_hostname);
+    resource.HostName = (const char*)hostname;
+    xmlFree(hostname);
+  }
+  else
+  {
+    std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a hostname" << std::endl;
+    std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
+    return false;
+  }
 
-      if ((qName.compare(QString(test_os)) == 0))
-        _resource.OS = content;
+  if (xmlHasProp(member_descr, (const xmlChar*)test_protocol))
+  {
+    xmlChar* protocol= xmlGetProp(member_descr, (const xmlChar*)test_protocol);
+    switch (protocol[0])
+    {
+      case 'r':
+        resource.Protocol = rsh;
+        break;
+      case 's':
+        resource.Protocol = ssh;
+        break;
+      default:
+        std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine with a bad protocol" << std::endl;
+        std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
+        return false;
+    }
+    xmlFree(protocol);
+  }
+  else
+  {
+    std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a protocol" << std::endl;
+    std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
+    return false;
+  }
 
-      if ((qName.compare(QString(test_mem_in_mb)) == 0))
-        _resource.DataForSort._memInMB = atoi(content.c_str());
+  if (xmlHasProp(member_descr, (const xmlChar*)test_cluster_internal_protocol))
+  {
+    xmlChar* iprotocol= xmlGetProp(member_descr, (const xmlChar*)test_cluster_internal_protocol);
+    switch (iprotocol[0])
+    {
+      case 'r':
+        resource.ClusterInternalProtocol = rsh;
+        break;
+      case 's':
+        resource.ClusterInternalProtocol = ssh;
+        break;
+      default:
+        std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine with a bad protocol" << std::endl;
+        std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
+        return false;
+    }
+    xmlFree(iprotocol);
+  }
+  else
+  {
+    std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a protocol" << std::endl;
+    std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
+    return false;
+  }
 
-      if ((qName.compare(QString(test_cpu_freq_mhz)) == 0))
-        _resource.DataForSort._CPUFreqMHz = atoi(content.c_str());
+  if (xmlHasProp(member_descr, (const xmlChar*)test_user_name))
+  {
+    xmlChar* user_name= xmlGetProp(member_descr, (const xmlChar*)test_user_name);
+    resource.UserName = (const char*)user_name;
+    xmlFree(user_name);
+  }
+  else
+  {
+    std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a user name" << std::endl;
+    std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
+    return false;
+  }
 
-      if ((qName.compare(QString(test_nb_of_nodes)) == 0))
-        _resource.DataForSort._nbOfNodes = atoi(content.c_str());
+  if (xmlHasProp(member_descr, (const xmlChar*)test_nb_of_nodes))
+  {
+    xmlChar* nb_of_nodes = xmlGetProp(member_descr, (const xmlChar*)test_nb_of_nodes);
+    resource.DataForSort._nbOfNodes = atoi((const char*)nb_of_nodes);
+    xmlFree(nb_of_nodes);
+  }
+  else
+  {
+    std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a nbOfNodes" << std::endl;
+    std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
+    return false;
+  }
 
-      if ((qName.compare(QString(test_nb_of_proc_per_node)) == 0))
-        _resource.DataForSort._nbOfProcPerNode = atoi(content.c_str());
-    }
+  if (xmlHasProp(member_descr, (const xmlChar*)test_nb_of_proc_per_node))
+  {
+    xmlChar* nb_of_proc_per_node = xmlGetProp(member_descr, (const xmlChar*)test_nb_of_proc_per_node);
+    resource.DataForSort._nbOfProcPerNode = atoi((const char*)nb_of_proc_per_node);
+    xmlFree(nb_of_proc_per_node);
+  }
+  else
+  {
+    std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a nbOfProcPerNode" << std::endl;
+    std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
+    return false;
+  }
 
+  if (xmlHasProp(member_descr, (const xmlChar*)test_appli_path))
+  {
+    xmlChar* appli_path = xmlGetProp(member_descr, (const xmlChar*)test_appli_path);
+    resource.AppliPath = (const char*)appli_path;
+    xmlFree(appli_path);
+  }
+  else
+  {
+    std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine without a AppliPath" << std::endl;
+    std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl;
+    return false;
+  }
   return true;
 }
 
-//=============================================================================
-/*!
- *  Overload handler function endElement.
- *     \param QString argument by reference  (not used here ?)
- *     \param QString argument by reference  (not used here ?)
- *     \param qName 
- *     \return true (if no error detected ...)
- */ 
-//=============================================================================
-
-bool SALOME_ResourcesCatalog_Handler::
-endElement(const QString&,
-           const QString&,
-           const QString& qName)
+bool
+SALOME_ResourcesCatalog_Handler::ProcessMachine(xmlNodePtr machine_descr, ParserResourcesType & resource)
 {
-  if ((qName.compare(QString(test_modules)) == 0))
-    _resource.ModulesPath[previous_module_name] = previous_module_path;
+  if (xmlHasProp(machine_descr, (const xmlChar*)test_hostname))
+  {
+    xmlChar* hostname = xmlGetProp(machine_descr, (const xmlChar*)test_hostname);
+    resource.HostName = (const char*)hostname;
+    xmlFree(hostname);
+  }
+  else
+  {
+    std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMachine : Warning found a machine without a hostname" << std::endl;
+    std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMachine : Warning this machine will not be added" << std::endl;
+    return false;
+  }
 
-  if ((qName.compare(QString(test_machine)) == 0))
-    _resources_list[_resource.DataForSort._hostName] = _resource;
+  if (xmlHasProp(machine_descr, (const xmlChar*)test_name))
+  {
+    xmlChar* name = xmlGetProp(machine_descr, (const xmlChar*)test_name);
+    resource.Name = (const char*)name;
+    resource.DataForSort._Name = (const char*)name;
+    xmlFree(name);
+  }
+  else
+  {
+    resource.Name = resource.HostName;
+    resource.DataForSort._Name = resource.HostName;
+    std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMachine : !!! Warning !!! No Name found use Hostname for resource: " << _resource.Name << std::endl;
+  }
 
-  return true;
-}
+  if (xmlHasProp(machine_descr, (const xmlChar*)test_batch_queue))
+  {
+    xmlChar* batch_queue = xmlGetProp(machine_descr, (const xmlChar*)test_batch_queue);
+    resource.batchQueue = (const char*)batch_queue;
+    xmlFree(batch_queue);
+  }
+  else
+    resource.batchQueue = "";
 
-//=============================================================================
-/*!
- *  Overload handler function characters.
- *  fills the private attribute string 'content'.
- *     \param chars  
- *     \return true (if no error detected ...)
- */ 
-//=============================================================================
+  if (xmlHasProp(machine_descr, (const xmlChar*)test_user_commands))
+  {
+    xmlChar* user_commands= xmlGetProp(machine_descr, (const xmlChar*)test_user_commands);
+    resource.userCommands = (const char*)user_commands;
+    xmlFree(user_commands);
+  }
+  else
+    resource.userCommands = "";
 
-bool SALOME_ResourcesCatalog_Handler::characters(const QString& chars)
-{
-  content = (const char *)chars ;
-  return true;
-}
+  if (xmlHasProp(machine_descr, (const xmlChar*)test_protocol))
+  {
+    xmlChar* protocol= xmlGetProp(machine_descr, (const xmlChar*)test_protocol);
+    switch ( protocol[0])
+    {
+      case 'r':
+        resource.Protocol = rsh;
+        break;
+      case 's':
+        resource.Protocol = ssh;
+        break;
+      default:
+        // If it'not in all theses cases, the protocol is affected to rsh
+        resource.Protocol = rsh;
+        break;
+    }
+    xmlFree(protocol);
+  }
+  else
+    resource.Protocol = rsh;
 
-//=============================================================================
-/*!
- *  Overload handler function endDocument.
- *  Called after the document has been parsed.
- *     \return true (if no error detected ...)
- */ 
-//=============================================================================
+  if (xmlHasProp(machine_descr, (const xmlChar*)test_cluster_internal_protocol))
+  {
+    xmlChar* iprotocol= xmlGetProp(machine_descr, (const xmlChar*)test_cluster_internal_protocol);
+    switch ( iprotocol[0])
+    {
+      case 'r':
+        resource.ClusterInternalProtocol = rsh;
+        break;
+      case 's':
+        resource.ClusterInternalProtocol = ssh;
+        break;
+      default:
+        // If it'not in all theses cases, the protocol is affected to rsh
+        resource.ClusterInternalProtocol = rsh;
+        break;
+    }
+    xmlFree(iprotocol);
+  }
+  else
+    resource.ClusterInternalProtocol = resource.Protocol;
 
-bool SALOME_ResourcesCatalog_Handler::endDocument()
-{
-//   for (map<string, ParserResourcesType>::const_iterator iter =
-//          _resources_list.begin();
-//        iter != _resources_list.end();
-//        iter++)
-//     {
-//       SCRUTE((*iter).second.Alias);
-//       SCRUTE((*iter).second.UserName);
-//       SCRUTE((*iter).second.AppliPath);
-//       SCRUTE((*iter).second.PreReqFilePath);
-//       SCRUTE((*iter).second.OS);
-//       SCRUTE((*iter).second.Protocol);
-//       SCRUTE((*iter).second.Mode);
-//    }
-  
-//  MESSAGE("This is the end of document");
-  return true;
-}
+  if (xmlHasProp(machine_descr, (const xmlChar*)test_mode))
+  {
+    xmlChar* mode=xmlGetProp(machine_descr, (const xmlChar*)test_mode);
+    switch ( mode[0] )
+    {
+      case 'i':
+        resource.Mode = interactive;
+        break;
+      case 'b':
+        resource.Mode = batch;
+        break;
+      default:
+        // If it'not in all theses cases, the mode is affected to interactive
+        resource.Mode = interactive;
+        break;
+    }
+    xmlFree(mode);
+  }
+  else
+    resource.Mode = interactive;
 
-//=============================================================================
-/*!
- *  Overload handler function errorProtocol.
- *  \return the error message.
- */ 
-//=============================================================================
+  if (xmlHasProp(machine_descr, (const xmlChar*)test_batch))
+  {
+    xmlChar* batch = xmlGetProp(machine_descr, (const xmlChar*)test_batch);
+    std::string aBatch = (const char*)batch;
+    xmlFree(batch);
+    if (aBatch == "pbs")
+      resource.Batch = pbs;
+    else if  (aBatch == "lsf")
+      resource.Batch = lsf;
+    else if  (aBatch == "sge")
+      resource.Batch = sge;
+    else if  (aBatch == "ssh_batch")
+      resource.Batch = ssh_batch;
+    else
+      resource.Batch = none;
+  }
 
-QString SALOME_ResourcesCatalog_Handler::errorProtocol()
-{
-  INFOS(" ------------- error protocol !");
-  return errorProt;
-}
+  if (xmlHasProp(machine_descr, (const xmlChar*)test_mpi))
+  {
+    xmlChar* mpi = xmlGetProp(machine_descr, (const xmlChar*)test_mpi);
+    std::string anMpi = (const char*)mpi;
+    xmlFree(mpi);
+    if (anMpi == "lam")
+      resource.mpi = lam;
+    else if (anMpi == "mpich1")
+      resource.mpi = mpich1;
+    else if (anMpi == "mpich2")
+      resource.mpi = mpich2;
+    else if (anMpi == "openmpi")
+      resource.mpi = openmpi;
+    else if  (anMpi == "slurm")
+      resource.mpi = slurm;
+    else if  (anMpi == "prun")
+      resource.mpi = prun;
+    else
+      resource.mpi = nompi;
+  }
 
-//=============================================================================
-/*!
- *  Overload handler function fatalError.
- *  Fills the private string errorProt with details on error.
- *     \param exception from parser
- *     \return boolean (meaning ?)
- */
-//=============================================================================
+  if (xmlHasProp(machine_descr, (const xmlChar*)test_user_name))
+  {
+    xmlChar* user_name= xmlGetProp(machine_descr, (const xmlChar*)test_user_name);
+    resource.UserName = (const char*)user_name;
+    xmlFree(user_name);
+  }
 
-bool
-SALOME_ResourcesCatalog_Handler::fatalError
-(const QXmlParseException& exception)
-{
-  INFOS(" ------------- fatal error !");
-  errorProt += QString( "fatal parsing error: %1 in line %2, column %3\n" )
-               .arg( exception.message() )
-               .arg( exception.lineNumber() )
-               .arg( exception.columnNumber() );
+  if (xmlHasProp(machine_descr, (const xmlChar*)test_appli_path))
+  {
+    xmlChar* appli_path = xmlGetProp(machine_descr, (const xmlChar*)test_appli_path);
+    resource.AppliPath = (const char*)appli_path;
+    xmlFree(appli_path);
+  }
+
+  if (xmlHasProp(machine_descr, (const xmlChar*)test_os))
+  {
+    xmlChar* os = xmlGetProp(machine_descr, (const xmlChar*)test_os);
+    resource.OS = (const char*)os;
+    xmlFree(os);
+  }
+
+  if (xmlHasProp(machine_descr, (const xmlChar*)test_mem_in_mb))
+  {
+    xmlChar* mem_in_mb = xmlGetProp(machine_descr, (const xmlChar*)test_mem_in_mb);
+    resource.DataForSort._memInMB = atoi((const char*)mem_in_mb);
+    xmlFree(mem_in_mb);
+  }
 
-  return QXmlDefaultHandler::fatalError( exception );
+  if (xmlHasProp(machine_descr, (const xmlChar*)test_cpu_freq_mhz))
+  {
+    xmlChar* cpu_freq_mhz = xmlGetProp(machine_descr, (const xmlChar*)test_cpu_freq_mhz);
+    resource.DataForSort._CPUFreqMHz = atoi((const char*)cpu_freq_mhz);
+    xmlFree(cpu_freq_mhz);
+  }
+
+  if (xmlHasProp(machine_descr, (const xmlChar*)test_nb_of_nodes))
+  {
+    xmlChar* nb_of_nodes = xmlGetProp(machine_descr, (const xmlChar*)test_nb_of_nodes);
+    resource.DataForSort._nbOfNodes = atoi((const char*)nb_of_nodes);
+    xmlFree(nb_of_nodes);
+  }
+
+  if (xmlHasProp(machine_descr, (const xmlChar*)test_nb_of_proc_per_node))
+  {
+    xmlChar* nb_of_proc_per_node = xmlGetProp(machine_descr, (const xmlChar*)test_nb_of_proc_per_node);
+    resource.DataForSort._nbOfProcPerNode = atoi((const char*)nb_of_proc_per_node);
+    xmlFree(nb_of_proc_per_node);
+  }
+
+  // Process children nodes
+  xmlNodePtr aCurSubNode = machine_descr->xmlChildrenNode;
+  while(aCurSubNode != NULL)
+  {
+    // Process components
+    if ( !xmlStrcmp(aCurSubNode->name, (const xmlChar*)test_components) )
+    {
+      //If a component is given, it is in a module with the same name
+      //except if the module name is given
+      if (xmlHasProp(aCurSubNode, (const xmlChar*)test_component_name)) 
+      {
+        xmlChar* component_name = xmlGetProp(aCurSubNode, (const xmlChar*)test_component_name);
+        std::string aComponentName = (const char*)component_name;
+        _resource.ComponentsList.push_back(aComponentName);
+        if (xmlHasProp(aCurSubNode, (const xmlChar*)test_module_name)) 
+        {
+          xmlChar* module_name = xmlGetProp(aCurSubNode, (const xmlChar*)test_module_name);
+          std::string aModuleName = (const char*)module_name;
+          _resource.ModulesList.push_back(aModuleName);
+          xmlFree(module_name);
+        }
+        else
+          _resource.ModulesList.push_back(aComponentName);
+        xmlFree(component_name);
+      }
+    }
+    // Process modules
+    else if ( !xmlStrcmp(aCurSubNode->name, (const xmlChar*)test_modules) )
+    {
+      // If a module is given, we create an entry in componentsList and modulesList
+      // with the same name (module == component)
+      if (xmlHasProp(aCurSubNode, (const xmlChar*)test_module_name)) 
+      {
+        xmlChar* component_name = xmlGetProp(aCurSubNode, (const xmlChar*)test_module_name);
+        std::string aComponentName = (const char*)component_name;
+        _resource.ComponentsList.push_back(aComponentName);
+        _resource.ModulesList.push_back(aComponentName);
+        xmlFree(component_name);
+      }
+    }
+    aCurSubNode = aCurSubNode->next;
+  }
+  return true;
 }
 
 //=============================================================================
 /*!
  *  Fill the document tree in xml file, used to write in an xml file.
- *  \param doc document to fill.
+ *  \param theDoc document to fill.
  */ 
 //=============================================================================
 
-void SALOME_ResourcesCatalog_Handler::PrepareDocToXmlFile(QDomDocument& doc)
+void SALOME_ResourcesCatalog_Handler::PrepareDocToXmlFile(xmlDocPtr theDoc)
 {
-  QDomElement root = doc.createElement("resources");
-  doc.appendChild(root);
+  // Node pointers
+  xmlNodePtr root_node = NULL, node = NULL, node1 = NULL;
+  char string_buf[80];
+
+  root_node = xmlNewNode(NULL, BAD_CAST "resources");
+  xmlDocSetRootElement(theDoc, root_node);
+    
+  std::map<std::string, ParserResourcesType>::iterator iter = _resources_list.begin();
+  for (; iter != _resources_list.end(); iter++)
+  {
+    node = xmlNewChild(root_node, NULL, BAD_CAST test_machine, NULL);
+    xmlNewProp(node, BAD_CAST test_name, BAD_CAST (*iter).second.Name.c_str());
+    xmlNewProp(node, BAD_CAST test_hostname, BAD_CAST (*iter).second.HostName.c_str());
+    xmlNewProp(node, BAD_CAST test_batch_queue, BAD_CAST (*iter).second.batchQueue.c_str());
+    xmlNewProp(node, BAD_CAST test_user_commands, BAD_CAST (*iter).second.userCommands.c_str());
 
-  for (map<string, ParserResourcesType>::iterator iter =
-         _resources_list.begin();
-       iter != _resources_list.end();
-       iter++)
+    switch ((*iter).second.Protocol)
     {
-      QDomElement eltRoot = doc.createElement(test_machine);
-      root.appendChild( eltRoot );
-      eltRoot.setAttribute((char *)test_hostname, (*iter).first.c_str());
-      eltRoot.setAttribute((char *)test_alias, (*iter).second.Alias.c_str());
-
-      switch ((*iter).second.Protocol)
-        {
-
-        case rsh:
-          eltRoot.setAttribute((char *)test_protocol, "rsh");
-          break;
-
-        case ssh:
-          eltRoot.setAttribute((char *)test_protocol, "ssh");
-          break;
-
-        default:
-          eltRoot.setAttribute((char *)test_protocol, "rsh");
-        }
-
-      switch ((*iter).second.Mode)
-        {
+      case rsh:
+        xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "rsh");
+        break;
+      case ssh:
+        xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "ssh");
+        break;
+      default:
+        xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "rsh");
+    }
 
-        case interactive:
-          eltRoot.setAttribute((char *)test_mode, "interactive");
-          break;
+    switch ((*iter).second.ClusterInternalProtocol)
+    {
+      case rsh:
+        xmlNewProp(node, BAD_CAST test_cluster_internal_protocol, BAD_CAST "rsh");
+        break;
+      case ssh:
+        xmlNewProp(node, BAD_CAST test_cluster_internal_protocol, BAD_CAST "ssh");
+        break;
+      default:
+        xmlNewProp(node, BAD_CAST test_cluster_internal_protocol, BAD_CAST "rsh");
+    }
 
-        case batch:
-          eltRoot.setAttribute((char *)test_mode, "batch");
-          break;
+    switch ((*iter).second.Mode)
+    {
+      case interactive:
+        xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "interactive");
+        break;
+      case batch:
+        xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "batch");
+        break;
+      default:
+        xmlNewProp(node, BAD_CAST test_mode, BAD_CAST "interactive");
+    }
 
-        default:
-          eltRoot.setAttribute((char *)test_mode, "interactive");
-        }
+    switch ((*iter).second.Batch)
+    {
+      case pbs:
+        xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "pbs");
+        break;
+      case lsf:
+        xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "lsf");
+        break;
+      case sge:
+        xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "sge");
+        break;
+      case ssh_batch:
+        xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "ssh_batch");
+        break;
+      default:
+        xmlNewProp(node, BAD_CAST test_batch, BAD_CAST "");
+    }
 
-      eltRoot.setAttribute((char *)test_user_name,
-                           (*iter).second.UserName.c_str());
+    switch ((*iter).second.mpi)
+    {
+      case lam:
+        xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "lam");
+        break;
+      case mpich1:
+        xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "mpich1");
+        break;
+      case mpich2:
+        xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "mpich2");
+        break;
+      case openmpi:
+        xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "openmpi");
+        break;
+      case slurm:
+        xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "slurm");
+        break;
+      case prun:
+        xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "prun");
+        break;
+      default:
+        xmlNewProp(node, BAD_CAST test_mpi, BAD_CAST "");
+    }
 
-      for (map<string, string>::const_iterator iter2 =
-             (*iter).second.ModulesPath.begin();
-           iter2 != (*iter).second.ModulesPath.end();
-           iter2++)
-        {
-          QDomElement rootForModulesPaths = doc.createElement(test_modules);
-          rootForModulesPaths.setAttribute(test_module_name,
-                                           (*iter2).first.c_str());
-          rootForModulesPaths.setAttribute(test_module_path,
-                                           (*iter2).second.c_str());
-          eltRoot.appendChild(rootForModulesPaths);
-        }
+    xmlNewProp(node, BAD_CAST test_user_name, BAD_CAST (*iter).second.UserName.c_str());
 
-      eltRoot.setAttribute(test_pre_req_file_path,
-                           (*iter).second.PreReqFilePath.c_str());
-      eltRoot.setAttribute(test_os, (*iter).second.OS.c_str());
-      eltRoot.setAttribute(test_mem_in_mb,
-                           (*iter).second.DataForSort._memInMB);
-      eltRoot.setAttribute(test_cpu_freq_mhz,
-                           (*iter).second.DataForSort._CPUFreqMHz);
-      eltRoot.setAttribute(test_nb_of_nodes,
-                           (*iter).second.DataForSort._nbOfNodes);
-      eltRoot.setAttribute(test_nb_of_proc_per_node,
-                           (*iter).second.DataForSort._nbOfProcPerNode);
+    std::vector<std::string>::const_iterator iter2 = (*iter).second.ComponentsList.begin();
+    for(;iter2 != (*iter).second.ComponentsList.end(); iter2++)
+    {
+      node1 = xmlNewChild(node, NULL, BAD_CAST test_components, NULL);
+      xmlNewProp(node1, BAD_CAST test_component_name, BAD_CAST (*iter2).c_str());
     }
+
+    xmlNewProp(node, BAD_CAST test_os, BAD_CAST (*iter).second.OS.c_str());
+    xmlNewProp(node, BAD_CAST test_mem_in_mb, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._memInMB));
+    xmlNewProp(node, BAD_CAST test_cpu_freq_mhz, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._CPUFreqMHz));
+    xmlNewProp(node, BAD_CAST test_nb_of_nodes, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._nbOfNodes));
+    xmlNewProp(node, BAD_CAST test_nb_of_proc_per_node, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._nbOfProcPerNode));
+  }
 }