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