Salome HOME
ENV: Windows porting.
[modules/kernel.git] / src / ModuleCatalog / SALOME_ModuleCatalog_impl.cxx
1 //  SALOME ModuleCatalog : implementation of ModuleCatalog server which parsers xml description of modules
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SALOME_ModuleCatalog_impl.cxx
25 //  Author : Estelle Deville
26 //  Module : SALOME
27 //  $Header$
28 //
29 #include "SALOME_ModuleCatalog_impl.hxx"
30 #include "SALOME_ModuleCatalog_Acomponent_impl.hxx"
31 #include <fstream>
32 #include <map>
33
34 #include <qstringlist.h>
35 #include <qfileinfo.h>
36 using namespace std;
37
38 #ifdef _DEBUG_
39 static int MYDEBUG = 0;
40 #else
41 static int MYDEBUG = 0;
42 #endif
43
44 static const char* SEPARATOR    = ":";
45
46 //----------------------------------------------------------------------
47 // Function : SALOME_ModuleCatalogImpl
48 // Purpose  : Constructor 
49 //----------------------------------------------------------------------
50 SALOME_ModuleCatalogImpl::SALOME_ModuleCatalogImpl(int argc, char** argv, CORBA::ORB_ptr orb) : _orb(orb)
51 {
52   if(MYDEBUG) MESSAGE("Catalog creation");
53
54   // Conversion rules for component types
55   ComponentTypeConvert[GEOM]
56     = SALOME_ModuleCatalog::GEOM;
57   ComponentTypeConvert[MESH]
58     = SALOME_ModuleCatalog::MESH;
59   ComponentTypeConvert[Med]
60     = SALOME_ModuleCatalog::Med;
61   ComponentTypeConvert[SOLVER]
62     = SALOME_ModuleCatalog::SOLVER;
63   ComponentTypeConvert[DATA]
64     = SALOME_ModuleCatalog::DATA;
65   ComponentTypeConvert[VISU]
66     = SALOME_ModuleCatalog::VISU;
67   ComponentTypeConvert[SUPERV]
68     = SALOME_ModuleCatalog::SUPERV;
69   ComponentTypeConvert[OTHER]
70     = SALOME_ModuleCatalog::OTHER;
71
72   // Conversion rules for datastream parameters type and dependency
73   DataStreamTypeConvert["UNKNOWN"] 
74     = SALOME_ModuleCatalog::DATASTREAM_UNKNOWN;
75   DataStreamTypeConvert["INTEGER"] 
76     = SALOME_ModuleCatalog::DATASTREAM_INTEGER;
77   DataStreamTypeConvert["FLOAT"]   
78     = SALOME_ModuleCatalog::DATASTREAM_FLOAT;
79   DataStreamTypeConvert["DOUBLE"]  
80     = SALOME_ModuleCatalog::DATASTREAM_DOUBLE;
81   DataStreamTypeConvert["STRING"]  
82     = SALOME_ModuleCatalog::DATASTREAM_STRING;
83   DataStreamTypeConvert["BOOLEAN"] 
84     = SALOME_ModuleCatalog::DATASTREAM_BOOLEAN;
85
86   DataStreamDepConvert["UNDEFINED"] 
87     = SALOME_ModuleCatalog::DATASTREAM_UNDEFINED;
88   DataStreamDepConvert["T"]
89     = SALOME_ModuleCatalog::DATASTREAM_TEMPORAL;
90   DataStreamDepConvert["I"] 
91     = SALOME_ModuleCatalog::DATASTREAM_ITERATIVE;
92
93   // Empty used variables
94   _general_module_list.resize(0);
95   _general_path_list.resize(0);
96
97   _personal_module_list.resize(0);
98   _personal_path_list.resize(0);
99
100   // Parse the arguments given at server run
101   if (!_parseArguments(argc, argv,&_general_path,&_personal_path))
102     if(MYDEBUG) MESSAGE( "Error while argument parsing" );
103
104   // Test existency of files
105   if (_general_path == NULL){
106     if(MYDEBUG) MESSAGE( "Error the general catalog should be indicated" );
107   }else{
108     // Affect the _general_module_list and _general_path_list members
109     // with the common catalog
110     
111     QStringList dirList 
112       = QStringList::split( SEPARATOR, _general_path, 
113                             false ); // skip empty entries
114     
115     for ( int i = 0; i < dirList.count(); i++ ) {
116       QFileInfo fileInfo( dirList[ i ] );
117       if ( fileInfo.isFile() && fileInfo.exists() ) {
118         _parse_xml_file(fileInfo.filePath(), 
119                         _general_module_list, 
120                         _general_path_list);
121       }
122     }
123     
124     // Verification of _general_path_list content
125     if(!_verify_path_prefix(_general_path_list)){
126       if(MYDEBUG) MESSAGE( "Error while parsing the general path list, "
127                            "differents paths are associated to the same computer," 
128                            "the first one will be choosen");
129     }else{
130       if(MYDEBUG) MESSAGE("General path list OK");
131     }
132     
133     if(_personal_path != NULL){
134       // Initialize the _personal_module_list and 
135       // _personal_path_list members with the personal catalog files
136       _parse_xml_file(_personal_path,
137                       _personal_module_list, 
138                       _personal_path_list);
139       
140       // Verification of _general_path_list content
141       if(!_verify_path_prefix(_personal_path_list)){
142         if(MYDEBUG) MESSAGE("Error while parsing the personal path list, "
143                             "differents paths are associated to the same computer, "
144                             "the first one will be choosen" );
145       }else {
146         if(MYDEBUG) MESSAGE("Personal path list OK");
147       }
148     }else 
149       if(MYDEBUG) MESSAGE("No personal catalog indicated or error while "
150                           "opening the personal catalog");
151   }
152 }
153
154 //----------------------------------------------------------------------
155 // Function : ~SALOME_ModuleCatalogImpl
156 // Purpose  : Destructor 
157 //----------------------------------------------------------------------
158 SALOME_ModuleCatalogImpl::~SALOME_ModuleCatalogImpl()
159 {
160   if(MYDEBUG) MESSAGE("Catalog Destruction");
161 }
162
163
164 //----------------------------------------------------------------------
165 // Function : GetComputerList
166 // Purpose  : get a computer list
167 //----------------------------------------------------------------------
168 SALOME_ModuleCatalog::ListOfComputers* 
169 SALOME_ModuleCatalogImpl::GetComputerList()
170 {
171   SALOME_ModuleCatalog::ListOfComputers_var _list_computers = 
172     new SALOME_ModuleCatalog::ListOfComputers;
173   return _list_computers._retn();
174 }
175
176 //----------------------------------------------------------------------
177 // Function : GetPathPrefix
178 // Purpose  : get the PathPrefix of a computer
179 //----------------------------------------------------------------------
180 char * 
181 SALOME_ModuleCatalogImpl::GetPathPrefix(const char* machinename) {
182   if(MYDEBUG) MESSAGE("Begin of GetPathPrefix");
183   // Variables initialisation
184   char* _path = NULL;
185   bool _find = false ;
186
187   // Parse all the path prefixes
188   // looking for the wanted computer
189   for (unsigned int ind = 0 ; ind < _personal_path_list.size() ; ind++)
190     {
191       for (unsigned int ind1 = 0 ; ind1 < _personal_path_list[ind].listOfComputer.size() ; ind1++)    
192         {
193           if (strcmp(machinename, _personal_path_list[ind].listOfComputer[ind1].c_str()) == 0)
194             {
195               _find = true ;
196               // Wanted computer
197               // affect the path to be returned
198                 const char* _temp = _personal_path_list[ind].path.c_str() ;
199                   _path = new char[strlen(_temp)+1];
200               strcpy(_path,_temp);
201             }
202         }
203     }
204
205   if (!_find)
206     {
207     for (unsigned int ind = 0 ; ind < _general_path_list.size() ; ind++)
208       {
209         for (unsigned int ind1 = 0 ; ind1 < _general_path_list[ind].listOfComputer.size() ; ind1++)    
210           {
211             if (strcmp(machinename, _general_path_list[ind].listOfComputer[ind1].c_str()) == 0)
212               {
213                 _find = true ;
214                 // Wanted computer
215                 // affect the path to be returned
216                   const char* _temp = _general_path_list[ind].path.c_str() ;
217                     _path = new char[strlen(_temp)+1];
218                 strcpy(_path,_temp);
219               }
220           }
221       }
222     }
223
224   return _path;
225 }
226
227 //----------------------------------------------------------------------
228 // Function : GetComponentList
229 // Purpose  : get a component list
230 //            If a component is defined in the personal catalog and 
231 //            in the general catalog (same name), the component defined
232 //            in the personal catalog is used
233 //----------------------------------------------------------------------
234 SALOME_ModuleCatalog::ListOfComponents* 
235 SALOME_ModuleCatalogImpl::GetComponentList()
236 {
237   if(MYDEBUG) MESSAGE("Begin of GetComponentList");
238   SALOME_ModuleCatalog::ListOfComponents_var _list_components = 
239     new SALOME_ModuleCatalog::ListOfComponents;
240
241   _list_components->length(_personal_module_list.size());
242
243   // All the components defined in the personal catalog are taken
244   for(unsigned int ind=0; ind < _personal_module_list.size();ind++){
245     _list_components[ind]=(_personal_module_list[ind].name).c_str();
246     if(MYDEBUG) SCRUTE(_list_components[ind]) ;
247   }
248
249   int indice = _personal_module_list.size() ;
250   bool _find = false;
251   
252   // The components in the general catalog are taken only if they're
253   // not defined in the personal catalog
254 #ifndef WNT
255   for(unsigned int ind=0; ind < _general_module_list.size();ind++){
256 #else
257   for(ind=0; ind < _general_module_list.size();ind++){
258 #endif
259     _find = false;
260     for(unsigned int ind1=0; ind1 < _personal_module_list.size();ind1++){
261       // searching if the component is already defined in 
262       // the personal catalog
263       if ((_general_module_list[ind].name.compare(_personal_module_list[ind1].name)) == 0)
264         _find = true;
265     }
266     if(!_find){
267       if(MYDEBUG) MESSAGE("A new component " << _general_module_list[ind].name 
268                           << " has to be to added in the list");
269       _list_components->length(indice+1);
270       // The component is not already defined => has to be taken
271       _list_components[indice]=(_general_module_list[ind].name).c_str();   
272       if(MYDEBUG) SCRUTE(_list_components[indice]) ;
273       
274       indice++;
275     }else{
276       if(MYDEBUG) MESSAGE("The component " <<_general_module_list[ind].name 
277                           << " was already defined in the personal catalog") ;
278     }
279   }
280   
281   if(MYDEBUG) MESSAGE ( "End of GetComponentList" );
282   return _list_components._retn();
283 }
284
285
286 //----------------------------------------------------------------------
287 // Function : GetComponentIconeList
288 // Purpose  : get a component list of component name and component icone
289 //            If a component is defined in the personal catalog and 
290 //            in the general catalog (same name), the component defined
291 //            in the personal catalog is used
292 //----------------------------------------------------------------------
293 SALOME_ModuleCatalog::ListOfIAPP_Affich* 
294 SALOME_ModuleCatalogImpl::GetComponentIconeList()
295 {
296   if(MYDEBUG) MESSAGE("Begin of GetComponentIconeList");
297
298   SALOME_ModuleCatalog::ListOfIAPP_Affich_var _list_components_icone = 
299     new SALOME_ModuleCatalog::ListOfIAPP_Affich;
300
301   _list_components_icone->length(_personal_module_list.size());
302
303   // All the components defined in the personal catalog are taken
304   for(unsigned int ind=0; ind < _personal_module_list.size();ind++){
305     _list_components_icone[ind].modulename=(_personal_module_list[ind].name).c_str();
306     _list_components_icone[ind].moduleusername=(_personal_module_list[ind].username).c_str();
307     _list_components_icone[ind].moduleicone=(_personal_module_list[ind].icon).c_str();
308     _list_components_icone[ind].moduleversion=(_personal_module_list[ind].version).c_str();
309     _list_components_icone[ind].modulecomment=(_personal_module_list[ind].comment).c_str();
310     //if(MYDEBUG) SCRUTE(_list_components_icone[ind].modulename); 
311     //if(MYDEBUG) SCRUTE(_list_components_icone[ind].moduleicone);
312   }
313   
314   int indice = _personal_module_list.size() ;
315   bool _find = false;
316   
317   // The components in the general catalog are taken only if they're
318   // not defined in the personal catalog
319 #ifndef WNT
320   for(unsigned int ind=0; ind < _general_module_list.size();ind++){
321 #else
322   for(ind=0; ind < _general_module_list.size();ind++){
323 #endif
324     _find = false;
325     for(unsigned int ind1=0; ind1 < _personal_module_list.size();ind1++){
326       // searching if the component is aleready defined in 
327       // the personal catalog
328       if((_general_module_list[ind].name.compare(_personal_module_list[ind1].name)) == 0)
329         _find = true;
330     }
331     if(!_find){
332       //          if(MYDEBUG) MESSAGE("A new component " << _general_module_list[ind].name << " has to be to added in the list");
333       _list_components_icone->length(indice+1);
334       // The component is not already defined => has to be taken
335       _list_components_icone[indice].modulename=_general_module_list[ind].name.c_str();  
336       _list_components_icone[indice].moduleusername=_general_module_list[ind].username.c_str();  
337       _list_components_icone[indice].moduleicone=_general_module_list[ind].icon.c_str(); 
338       _list_components_icone[indice].moduleversion=_general_module_list[ind].version.c_str();
339       _list_components_icone[indice].modulecomment=_general_module_list[ind].comment.c_str();
340       //if(MYDEBUG) SCRUTE(_list_components_icone[indice].modulename) ;
341       //if(MYDEBUG) SCRUTE(_list_components_icone[indice].moduleicone);
342       
343       indice++;
344     }
345     // else 
346     //if(MYDEBUG) MESSAGE("The component " <<_general_module_list[ind].name << " was already defined in the personal catalog"); 
347   }
348   
349   return _list_components_icone._retn() ;
350 }
351
352 //----------------------------------------------------------------------
353 // Function : GetTypedComponentList
354 // Purpose  : get a component list of a wanted type
355 //            If a component is defined in the personal catalog and 
356 //            in the general catalog (same name), the component defined
357 //            in the personal catalog is used
358 //----------------------------------------------------------------------
359 SALOME_ModuleCatalog::ListOfComponents* 
360 SALOME_ModuleCatalogImpl::GetTypedComponentList(SALOME_ModuleCatalog::ComponentType component_type)
361 {
362   if(MYDEBUG) MESSAGE("Begin of GetTypedComponentList");
363   SALOME_ModuleCatalog::ListOfComponents_var _list_typed_component = 
364     new SALOME_ModuleCatalog::ListOfComponents;
365   int _j = 0;
366
367   _list_typed_component->length(0);
368   // Transform SALOME_ModuleCatalog::ComponentType in ParserComponentType
369   ParserComponentType _temp_component_type;
370   switch(component_type){
371   case SALOME_ModuleCatalog::GEOM:
372     _temp_component_type = GEOM ;
373     break;
374   case SALOME_ModuleCatalog::MESH:
375     _temp_component_type = MESH;
376     break;   
377   case SALOME_ModuleCatalog::Med:
378     _temp_component_type = Med;
379     break;    
380   case SALOME_ModuleCatalog::SOLVER:   
381     _temp_component_type = SOLVER;
382     break;
383   case SALOME_ModuleCatalog::DATA:
384     _temp_component_type = DATA;
385     break;
386   case SALOME_ModuleCatalog::VISU:
387     _temp_component_type = VISU;
388     break;  
389   case SALOME_ModuleCatalog::SUPERV:
390     _temp_component_type = SUPERV;
391     break;
392   case SALOME_ModuleCatalog::OTHER:
393     _temp_component_type = OTHER;
394     break;
395   }
396
397   // All the components in the personal catalog are taken
398   for (unsigned int ind=0; ind < _personal_module_list.size();ind++)
399     {
400       if  (_personal_module_list[ind].type == _temp_component_type)
401         {
402           _list_typed_component->length(_j + 1); 
403           _list_typed_component[_j] = (_moduleList[ind].name).c_str();
404           //if(MYDEBUG) SCRUTE(_list_typed_component[_j]);
405           _j++;
406         }
407     }
408
409   int indice = _list_typed_component->length() ;
410   bool _find = false;
411   
412   // The components in the general catalog are taken only if they're
413   // not defined in the personal catalog
414 #ifndef WNT
415   for (unsigned int ind=0; ind < _general_module_list.size();ind++)
416 #else
417   for (ind=0; ind < _general_module_list.size();ind++)
418 #endif
419     {
420       _find = false;
421
422       if(_general_module_list[ind].type == _temp_component_type)
423         {
424           for (unsigned int ind1=0; ind1 < _personal_module_list.size();ind1++)
425             {
426               // searching if the component is aleready defined in 
427               // the personal catalog
428               if ((_general_module_list[ind].name.compare(_personal_module_list[ind1].name)) == 0)
429                 _find = true;
430             }
431           if (!_find)
432             {
433               //if(MYDEBUG) MESSAGE("A new component " << _general_module_list[ind].name << " has to be to added in the list");
434               _list_typed_component->length(indice+1);
435               // The component is not already defined => has to be taken
436               _list_typed_component[indice]=(_general_module_list[ind].name).c_str();   
437               //if(MYDEBUG) SCRUTE(_list_typed_component[indice]) ;
438
439               indice++;
440             }
441           //else 
442             //if(MYDEBUG) MESSAGE("The component " <<_general_module_list[ind].name << " was already defined in the personal catalog") ;
443         }
444     }
445
446
447   return _list_typed_component._retn();
448 }
449
450 //----------------------------------------------------------------------
451 // Function : GetComponent
452 // Purpose  : get a component 
453 //            If a component is defined in the personal catalog and 
454 //            in the general catalog (same name), the component defined
455 //            in the personal catalog is used
456 //----------------------------------------------------------------------
457 SALOME_ModuleCatalog::Acomponent_ptr 
458 SALOME_ModuleCatalogImpl::GetComponent(const char* name)
459 {
460   // Looking for component named "componentname" in the personal catalog
461   // If found, get name, interfaces and constraint
462   // If not found, looking for component named "componentname" in
463   // the general catalog
464   // If found, get name, interfaces and constraint
465   // If not found, NULL pointer is returned
466
467   std::string s(name);
468   ParserComponent *C_parser = NULL;
469   ParserPathPrefixes *pp = NULL;
470
471   SALOME_ModuleCatalog::Acomponent_ptr compo = NULL;
472   
473   C_parser = findComponent(s);
474   if (C_parser) {
475     
476 //    DebugParserComponent(*C_parser);
477
478     SALOME_ModuleCatalog::Component C_corba;
479     duplicate(C_corba, *C_parser);
480
481     
482     SALOME_ModuleCatalog_AcomponentImpl * aComponentImpl = 
483       new SALOME_ModuleCatalog_AcomponentImpl(C_corba);
484     
485     compo = aComponentImpl->_this();
486   }
487   else {
488     // Not found in the personal catalog and in the general catalog
489     // return NULL object
490     if(MYDEBUG) MESSAGE("Component with name  " << name 
491                         << " not found in catalog");
492     compo = NULL;
493   }
494   
495   return compo;
496 }
497
498 SALOME_ModuleCatalog::Component *
499 SALOME_ModuleCatalogImpl::GetComponentInfo(const char *name)
500 {
501   std::string s(name);
502
503   ParserComponent * C_parser = findComponent(s);
504   
505   if (C_parser) {
506     
507     SALOME_ModuleCatalog::Component * C_corba 
508       = new SALOME_ModuleCatalog::Component; 
509     duplicate(*C_corba, *C_parser);
510     return C_corba;
511   }
512
513   return NULL;
514 }
515
516 ParserComponent *
517 SALOME_ModuleCatalogImpl::findComponent(const string & name)
518 {
519   ParserComponent * C_parser = NULL;
520
521   if (!C_parser)
522     for (unsigned int ind=0; ind < _personal_module_list.size();ind++)
523       if (name.compare(_personal_module_list[ind].name) == 0)
524         {
525           if(MYDEBUG) MESSAGE("Component named " << name 
526                               << " found in the personal catalog");
527           C_parser = &(_personal_module_list[ind]);
528           break;
529         }
530
531   if (!C_parser)
532     for (unsigned int ind=0; ind < _general_module_list.size();ind++)
533       {
534         if (name.compare(_general_module_list[ind].name) == 0)
535           {
536             if(MYDEBUG) MESSAGE("Component named " << name 
537                                 << " found in the general catalog");
538             C_parser = &(_general_module_list[ind]);
539             break;
540           }
541       }
542
543   return C_parser;
544 }
545
546 //----------------------------------------------------------------------
547 // Function : _parse_xml_file
548 // Purpose  : parse one module catalog 
549 //----------------------------------------------------------------------
550 void 
551 SALOME_ModuleCatalogImpl::_parse_xml_file(const char* file, 
552                                           ParserComponents& modulelist, 
553                                           ParserPathPrefixes& pathList)
554 {
555   if(MYDEBUG) BEGIN_OF("_parse_xml_file");
556   if(MYDEBUG) SCRUTE(file);
557
558   SALOME_ModuleCatalog_Handler* handler = new SALOME_ModuleCatalog_Handler();
559   QFile xmlFile(file);
560
561   QXmlInputSource source(xmlFile);
562
563   QXmlSimpleReader reader;
564   reader.setContentHandler( handler );
565   reader.setErrorHandler( handler );
566   reader.parse( source );
567   xmlFile.close();
568
569   unsigned int i, j;
570
571   for ( i = 0; i < _moduleList.size(); i++) {
572     for (j=0; j<modulelist.size(); j++) {
573       if (modulelist[j].name == _moduleList[i].name)
574         break;
575     }
576     if (j < modulelist.size())
577       modulelist[j] = _moduleList[i];
578     else
579       modulelist.push_back(_moduleList[i]);
580   }
581
582   for ( i=0; i < _pathList.size(); i++)
583     pathList.push_back(_pathList[i]) ;
584
585   for (j=0; j<modulelist.size(); j++)
586     modulelist[j].prefixes = pathList;
587 }
588
589 void 
590 SALOME_ModuleCatalogImpl::ImportXmlCatalogFile(const char* file)
591 {
592   _parse_xml_file(file, _personal_module_list, _personal_path_list);
593 }
594
595
596 //
597 //  Duplicate functions create a Corba structure (component,
598 //  interface, service, parameter) from the corresponding C++ 
599 //  parser structure
600 //
601
602 //----------------------------------------------------------------------
603 // Function : duplicate
604 // Purpose  : create a component from the catalog parsing
605 //----------------------------------------------------------------------
606 void SALOME_ModuleCatalogImpl::duplicate
607 (SALOME_ModuleCatalog::Component & C_corba, 
608  const ParserComponent & C_parser)
609 {
610   C_corba.name = CORBA::string_dup(C_parser.name.c_str());
611   C_corba.username = CORBA::string_dup(C_parser.username.c_str());
612   C_corba.multistudy = C_parser.multistudy;
613   C_corba.icon = CORBA::string_dup(C_parser.icon.c_str());
614   C_corba.type = ComponentTypeConvert[C_parser.type];
615   C_corba.implementationType = C_parser.implementationType;
616
617   unsigned int _length = C_parser.interfaces.size();
618   C_corba.interfaces.length(_length);
619   
620   for (unsigned int ind = 0; ind < _length; ind++)
621     duplicate(C_corba.interfaces[ind], C_parser.interfaces[ind]);
622 }
623
624
625 //----------------------------------------------------------------------
626 // Function : duplicate
627 // Purpose  : create an interface from the catalog parsing
628 //----------------------------------------------------------------------
629 void SALOME_ModuleCatalogImpl::duplicate
630 (SALOME_ModuleCatalog::DefinitionInterface & I_corba,
631  const ParserInterface & I_parser)
632 {
633   //duplicate interface name
634   I_corba.interfacename = CORBA::string_dup(I_parser.name.c_str());
635   
636   // duplicate service list
637   unsigned int _length = I_parser.services.size();
638   if(MYDEBUG) SCRUTE(_length);
639   //  I_corba.interfaceservicelist 
640   //  = new SALOME_ModuleCatalog::ListOfInterfaceService;
641   I_corba.interfaceservicelist.length(_length);
642   
643   for (unsigned int ind1 = 0; ind1 < _length ; ind1 ++)
644     duplicate(I_corba.interfaceservicelist[ind1],
645               I_parser.services[ind1]);
646 }
647
648 //----------------------------------------------------------------------
649 // Function : duplicate
650 // Purpose  : create a service from the catalog parsing
651 //----------------------------------------------------------------------
652 void SALOME_ModuleCatalogImpl::duplicate
653 (SALOME_ModuleCatalog::Service & S_corba,
654  const ParserService & S_parser)
655 {
656   // duplicate service name
657   S_corba.ServiceName = CORBA::string_dup(S_parser.name.c_str());
658   
659   // duplicate service by default
660   S_corba.Servicebydefault = S_parser.byDefault;
661
662   S_corba.TypeOfNode = S_parser.typeOfNode;
663
664   unsigned int _length;
665
666   // duplicate in Parameters
667   _length = S_parser.inParameters.size();
668   S_corba.ServiceinParameter.length(_length);
669
670   for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
671     duplicate(S_corba.ServiceinParameter[ind2],
672               S_parser.inParameters[ind2]);
673   
674   // duplicate out Parameters
675   _length = S_parser.outParameters.size();
676   S_corba.ServiceoutParameter.length(_length);
677
678 #ifndef WNT
679   for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
680 #else
681   for (ind2 = 0; ind2 < _length ; ind2 ++)
682 #endif
683     duplicate(S_corba.ServiceoutParameter[ind2],
684               S_parser.outParameters[ind2]);
685   
686   // duplicate in DataStreamParameters
687   _length = S_parser.inDataStreamParameters.size();
688   S_corba.ServiceinDataStreamParameter.length(_length);
689
690 #ifndef WNT
691   for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
692 #else
693   for (ind2 = 0; ind2 < _length ; ind2 ++)
694 #endif
695     duplicate(S_corba.ServiceinDataStreamParameter[ind2],
696               S_parser.inDataStreamParameters[ind2]);
697   
698   // duplicate out DataStreamParameters
699   _length = S_parser.outDataStreamParameters.size();
700   if(MYDEBUG) SCRUTE(_length);
701   S_corba.ServiceoutDataStreamParameter.length(_length);
702
703 #ifndef WNT
704   for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
705 #else
706   for (ind2 = 0; ind2 < _length ; ind2 ++)
707 #endif
708     duplicate(S_corba.ServiceoutDataStreamParameter[ind2],
709               S_parser.outDataStreamParameters[ind2]);
710 }
711
712 //----------------------------------------------------------------------
713 // Function : duplicate
714 // Purpose  : create a service parameter from the catalog parsing
715 //----------------------------------------------------------------------
716 void SALOME_ModuleCatalogImpl::duplicate
717 (SALOME_ModuleCatalog::ServicesParameter & P_corba,
718  const ParserParameter & P_parser)
719 {
720   // duplicate parameter name
721   P_corba.Parametername = CORBA::string_dup(P_parser.name.c_str());
722   
723   // duplicate parameter type
724   P_corba.Parametertype = CORBA::string_dup(P_parser.type.c_str());
725 }
726
727
728 //----------------------------------------------------------------------
729 // Function : duplicate
730 // Purpose  : create a service datastream parameter from the catalog parsing
731 //----------------------------------------------------------------------
732 void SALOME_ModuleCatalogImpl::duplicate
733 (SALOME_ModuleCatalog::ServicesDataStreamParameter & P_corba,
734  const ParserDataStreamParameter & P_parser)
735 {
736   std::map < std::string, 
737     SALOME_ModuleCatalog::DataStreamType >::const_iterator it_type;
738
739   std::map < std::string, 
740     SALOME_ModuleCatalog::DataStreamDependency >::const_iterator it_dep;
741
742   // duplicate parameter name
743   P_corba.Parametername = CORBA::string_dup(P_parser.name.c_str());
744   
745   // doesn't work ??? 
746   //   it_type = DataStreamTypeConvert.find(P_parser.type);
747   //   P_corba.Parametertype
748   //     = (it_type == DataStreamTypeConvert.end()) 
749   //     ? it_type->second : SALOME_ModuleCatalog::DATASTREAM_UNKNOWN;
750
751   if(MYDEBUG) SCRUTE(P_parser.type);
752   P_corba.Parametertype = SALOME_ModuleCatalog::DATASTREAM_UNKNOWN;
753   for (it_type = DataStreamTypeConvert.begin(); 
754        it_type != DataStreamTypeConvert.end(); 
755        it_type++)
756     if (P_parser.type.compare(it_type->first) == 0) {
757       P_corba.Parametertype = it_type->second;
758       break;
759     }
760   if(MYDEBUG) SCRUTE(P_corba.Parametertype);
761
762   // duplicate parameter type
763
764   // doesn't work ??? 
765   //   it_type = DataStreamTypeConvert.find(P_parser.type);
766   //   P_corba.Parametertype
767   //     = (it_type == DataStreamTypeConvert.end()) 
768   //     ? it_type->second : SALOME_ModuleCatalog::DATASTREAM_UNKNOWN;
769   
770   if(MYDEBUG) SCRUTE(P_parser.dependency);
771   P_corba.Parameterdependency = SALOME_ModuleCatalog::DATASTREAM_UNDEFINED;
772   for (it_dep = DataStreamDepConvert.begin(); 
773        it_dep != DataStreamDepConvert.end(); 
774        it_dep++)
775     if (P_parser.dependency.compare(it_dep->first) == 0) {
776       P_corba.Parameterdependency = it_dep->second;
777       break;
778     }
779
780   if(MYDEBUG) SCRUTE(P_corba.Parameterdependency);
781 }
782
783 //----------------------------------------------------------------------
784 // Function : duplicate
785 // Purpose  : create the path prefix structures from the catalog parsing
786 //----------------------------------------------------------------------
787 void
788 SALOME_ModuleCatalogImpl::duplicate(ParserPathPrefixes &L_out, 
789                                     const ParserPathPrefixes &L_in)
790 {
791   L_out = L_in;
792 }
793
794
795 //----------------------------------------------------------------------
796 // Function : _verify_path_prefix
797 // Purpose  : verify the path prefix structures from the catalog parsing
798 //            Verify that there only one path prefix associated to a 
799 //            particular computer
800 //----------------------------------------------------------------------
801 bool
802 SALOME_ModuleCatalogImpl::_verify_path_prefix(ParserPathPrefixes & pathList)
803 {
804   bool _return_value = true;
805   vector<string> _machine_list;
806
807   // Fill a list of all computers indicated in the path list
808   for (unsigned int ind = 0; ind < pathList.size(); ind++)
809     { 
810       for (unsigned int ind1 = 0 ; ind1 < pathList[ind].listOfComputer.size(); ind1++)
811         {
812           _machine_list.push_back(pathList[ind].listOfComputer[ind1]);
813         }
814     }
815
816   // Parse if a computer name is twice in the list of computers
817 #ifndef WNT
818   for (unsigned int ind = 0; ind < _machine_list.size(); ind++)
819 #else
820   for (ind = 0; ind < _machine_list.size(); ind++)
821 #endif
822     {
823      for (unsigned int ind1 = ind+1 ; ind1 < _machine_list.size(); ind1++)
824        {
825          if(_machine_list[ind].compare(_machine_list[ind1]) == 0)
826            {
827              if(MYDEBUG) MESSAGE( "The computer " << _machine_list[ind] << " is indicated more than once in the path list");
828              _return_value = false; 
829            }
830        }
831     }
832   return _return_value;
833 }
834
835
836 //----------------------------------------------------------------------
837 // Function : _parseArguments
838 // Purpose  : parse arguments to get general and personal catalog files
839 //----------------------------------------------------------------------
840 bool
841 SALOME_ModuleCatalogImpl::_parseArguments(int argc, char **argv, 
842                                           char **_general, 
843                                           char** _personal)
844 {
845   bool _return_value = true;
846   *_general = NULL;
847   *_personal = NULL ;
848   for (int ind = 0; ind < argc ; ind++)
849     {
850
851       if (strcmp(argv[ind],"-help") == 0)
852         {
853           INFOS( "Usage: " << argv[0] 
854                  << " -common 'path to general catalog' "
855                  " -personal 'path to personal catalog' "
856                  " -ORBInitRef NameService=corbaname::localhost");
857             _return_value = false ;
858         }
859
860       if (strcmp(argv[ind],"-common") == 0)
861         {
862           if (ind + 1 < argc)
863             {
864               // General catalog file
865               *_general = argv[ind + 1] ;
866             }
867         }
868       else if (strcmp(argv[ind],"-personal") == 0)
869         {
870           if (ind + 1 < argc)
871             {
872               // Personal catalog file
873               *_personal = argv[ind + 1] ;
874             }
875         }
876     }
877   return _return_value;
878 }
879
880