Back to index

salome-kernel  6.5.0
SALOME_ModuleCatalog_impl.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SALOME ModuleCatalog : implementation of ModuleCatalog server which parsers xml description of modules
00024 //  File   : SALOME_ModuleCatalog_impl.cxx
00025 //  Author : Estelle Deville
00026 //  Module : SALOME
00027 //  $Header: /home/server/cvs/KERNEL/KERNEL_SRC/src/ModuleCatalog/SALOME_ModuleCatalog_impl.cxx,v 1.13.2.2.10.2.12.1 2012-04-12 14:05:17 vsr Exp $
00028 //
00029 #include "SALOME_ModuleCatalog_impl.hxx"
00030 #include "SALOME_ModuleCatalog_Acomponent_impl.hxx"
00031 #include <libxml/parser.h>
00032 #include <fstream>
00033 #include <map>
00034 #include "utilities.h"
00035 
00036 #ifdef WIN32
00037 # include <process.h>
00038 #endif
00039 
00040 #ifdef _DEBUG_
00041 static int MYDEBUG = 0;
00042 #else
00043 static int MYDEBUG = 0;
00044 #endif
00045 
00046 static const char* SEPARATOR     = "::";
00047 static const char* OLD_SEPARATOR = ":";
00048 
00049 
00050 std::list<std::string> splitStringToList(const std::string& theString, const std::string& theSeparator)
00051 {
00052   std::list<std::string> aList;
00053 
00054   int sepLen = theSeparator.length();
00055   int startPos = 0, sepPos = theString.find(theSeparator, startPos);
00056 
00057   while (1)
00058     {
00059       std::string anItem ;
00060       if(sepPos != std::string::npos)
00061         anItem = theString.substr(startPos, sepPos - startPos);
00062       else
00063         anItem = theString.substr(startPos);
00064       if (anItem.length() > 0)
00065         aList.push_back(anItem);
00066       if(sepPos == std::string::npos)
00067         break;
00068       startPos = sepPos + sepLen;
00069       sepPos = theString.find(theSeparator, startPos);
00070     }
00071 
00072   return aList;
00073 }
00074 
00075 //----------------------------------------------------------------------
00076 // Function : SALOME_ModuleCatalogImpl
00077 // Purpose  : Constructor 
00078 //----------------------------------------------------------------------
00079 SALOME_ModuleCatalogImpl::SALOME_ModuleCatalogImpl(int argc, char** argv, CORBA::ORB_ptr orb) : _orb(orb)
00080 {
00081   if(MYDEBUG) MESSAGE("Catalog creation");
00082   /* Init libxml */
00083   xmlInitParser();
00084 
00085   // Conversion rules for component types
00086   ComponentTypeConvert[GEOM]
00087     = SALOME_ModuleCatalog::GEOM;
00088   ComponentTypeConvert[MESH]
00089     = SALOME_ModuleCatalog::MESH;
00090   ComponentTypeConvert[Med]
00091     = SALOME_ModuleCatalog::Med;
00092   ComponentTypeConvert[SOLVER]
00093     = SALOME_ModuleCatalog::SOLVER;
00094   ComponentTypeConvert[DATA]
00095     = SALOME_ModuleCatalog::DATA;
00096   ComponentTypeConvert[VISU]
00097     = SALOME_ModuleCatalog::VISU;
00098   ComponentTypeConvert[SUPERV]
00099     = SALOME_ModuleCatalog::SUPERV;
00100   ComponentTypeConvert[OTHER]
00101     = SALOME_ModuleCatalog::OTHER;
00102 
00103   // Conversion rules for datastream parameters dependency
00104   DataStreamDepConvert["UNDEFINED"] 
00105     = SALOME_ModuleCatalog::DATASTREAM_UNDEFINED;
00106   DataStreamDepConvert["T"]
00107     = SALOME_ModuleCatalog::DATASTREAM_TEMPORAL;
00108   DataStreamDepConvert["I"] 
00109     = SALOME_ModuleCatalog::DATASTREAM_ITERATIVE;
00110 
00111   // Empty used variables
00112   _general_module_list.resize(0);
00113   _general_path_list.resize(0);
00114 
00115   _personal_module_list.resize(0);
00116   _personal_path_list.resize(0);
00117 
00118   // Parse the arguments given at server run
00119   if (!_parseArguments(argc, argv,&_general_path,&_personal_path))
00120     if(MYDEBUG) MESSAGE( "Error while argument parsing" );
00121 
00122   // Test existency of files
00123   if (_general_path == NULL)
00124   {
00125     if(MYDEBUG) MESSAGE( "Error the general catalog should be indicated" );
00126   }
00127   else
00128   {
00129     // Affect the _general_module_list and _general_path_list members
00130     // with the common catalog
00131 
00132     std::list<std::string> dirList;
00133 
00134 #ifdef WIN32
00135     dirList = splitStringToList(_general_path, SEPARATOR);
00136 #else
00137     //check for new format
00138     bool isNew = (std::string( _general_path ).find(SEPARATOR) != std::string::npos);
00139     if ( isNew ) {
00140       //using new format
00141       dirList = splitStringToList(_general_path, SEPARATOR);
00142     } else {
00143       //support old format
00144       dirList = splitStringToList(_general_path, OLD_SEPARATOR);
00145     }
00146 #endif
00147 
00148     for (std::list<std::string>::iterator iter = dirList.begin(); iter != dirList.end(); iter++)
00149     {
00150       std::string aPath = (*iter);
00151       //remove inverted commas from filename
00152       while (aPath.find('\"') != std::string::npos)
00153         aPath.erase(aPath.find('\"'), 1);
00154 
00155       _parse_xml_file(aPath.c_str(), 
00156                       _general_module_list, 
00157                       _general_path_list,
00158                       _typeMap,
00159                       _typeList);
00160     }
00161 
00162     // Verification of _general_path_list content
00163     if (!_verify_path_prefix(_general_path_list)) {
00164       if(MYDEBUG) MESSAGE( "Error while parsing the general path list, "
00165                            "differents paths are associated to the same computer," 
00166                            "the first one will be choosen");
00167     } else {
00168       if(MYDEBUG) MESSAGE("General path list OK");
00169     }
00170 
00171     if (_personal_path != NULL) {
00172       // Initialize the _personal_module_list and 
00173       // _personal_path_list members with the personal catalog files
00174       _parse_xml_file(_personal_path,
00175                       _personal_module_list, 
00176                       _personal_path_list,
00177                       _typeMap,
00178                       _typeList);
00179       
00180       // Verification of _general_path_list content
00181       if(!_verify_path_prefix(_personal_path_list)){
00182         if(MYDEBUG) MESSAGE("Error while parsing the personal path list, "
00183                             "differents paths are associated to the same computer, "
00184                             "the first one will be choosen" );
00185       }else {
00186         if(MYDEBUG) MESSAGE("Personal path list OK");
00187       }
00188     }else 
00189       if(MYDEBUG) MESSAGE("No personal catalog indicated or error while "
00190                           "opening the personal catalog");
00191   }
00192 }
00193 
00194 //----------------------------------------------------------------------
00195 // Function : ~SALOME_ModuleCatalogImpl
00196 // Purpose  : Destructor 
00197 //----------------------------------------------------------------------
00198 SALOME_ModuleCatalogImpl::~SALOME_ModuleCatalogImpl()
00199 {
00200   if(MYDEBUG) MESSAGE("Catalog Destruction");
00201 }
00202 
00203 
00205 
00208 SALOME_ModuleCatalog::ListOfTypeDefinition* SALOME_ModuleCatalogImpl::GetTypes()
00209 {
00210   SALOME_ModuleCatalog::ListOfTypeDefinition_var type_list = new SALOME_ModuleCatalog::ListOfTypeDefinition();
00211   type_list->length(_typeList.size());
00212 
00213   for (unsigned int ind = 0 ; ind < _typeList.size() ; ind++)
00214     {
00215       //no real need to call string_dup, omniorb calls it on operator= (const char *) but it is safer
00216       type_list[ind].name=CORBA::string_dup(_typeList[ind].name.c_str());
00217       type_list[ind].kind=SALOME_ModuleCatalog::NONE;
00218       if(_typeList[ind].kind=="double")
00219         type_list[ind].kind=SALOME_ModuleCatalog::Dble;
00220       else if(_typeList[ind].kind=="int")
00221         type_list[ind].kind=SALOME_ModuleCatalog::Int;
00222       else if(_typeList[ind].kind=="bool")
00223         type_list[ind].kind=SALOME_ModuleCatalog::Bool;
00224       else if(_typeList[ind].kind=="string")
00225         type_list[ind].kind=SALOME_ModuleCatalog::Str;
00226       else if(_typeList[ind].kind=="objref")
00227         {
00228           type_list[ind].kind=SALOME_ModuleCatalog::Objref;
00229           type_list[ind].id=CORBA::string_dup(_typeList[ind].id.c_str());
00230           //bases
00231           type_list[ind].bases.length(_typeList[ind].bases.size());
00232           std::vector<std::string>::const_iterator miter;
00233           miter=_typeList[ind].bases.begin();
00234           int n_memb=0;
00235           while(miter != _typeList[ind].bases.end())
00236             {
00237               type_list[ind].bases[n_memb]=CORBA::string_dup(miter->c_str());
00238               miter++;
00239               n_memb++;
00240             }
00241         }
00242       else if(_typeList[ind].kind=="sequence")
00243         {
00244           type_list[ind].kind=SALOME_ModuleCatalog::Seq;
00245           type_list[ind].content=CORBA::string_dup(_typeList[ind].content.c_str());
00246         }
00247       else if(_typeList[ind].kind=="array")
00248         {
00249           type_list[ind].kind=SALOME_ModuleCatalog::Array;
00250           type_list[ind].content=CORBA::string_dup(_typeList[ind].content.c_str());
00251         }
00252       else if(_typeList[ind].kind=="struct")
00253         {
00254           type_list[ind].kind=SALOME_ModuleCatalog::Struc;
00255           //members
00256           type_list[ind].members.length(_typeList[ind].members.size());
00257 
00258           std::vector< std::pair<std::string,std::string> >::const_iterator miter;
00259           miter=_typeList[ind].members.begin();
00260           int n_memb=0;
00261           while(miter != _typeList[ind].members.end())
00262             {
00263               type_list[ind].members[n_memb].name=CORBA::string_dup(miter->first.c_str());
00264               type_list[ind].members[n_memb].type=CORBA::string_dup(miter->second.c_str());
00265               n_memb++;
00266               miter++;
00267             }
00268         }
00269     }
00270   return type_list._retn();
00271 }
00272 
00273 //----------------------------------------------------------------------
00274 // Function : GetComputerList
00275 // Purpose  : get a computer list
00276 //----------------------------------------------------------------------
00277 SALOME_ModuleCatalog::ListOfComputers* 
00278 SALOME_ModuleCatalogImpl::GetComputerList()
00279 {
00280   SALOME_ModuleCatalog::ListOfComputers_var _list_computers = 
00281     new SALOME_ModuleCatalog::ListOfComputers;
00282   return _list_computers._retn();
00283 }
00284 
00285 //----------------------------------------------------------------------
00286 // Function : GetPathPrefix
00287 // Purpose  : get the PathPrefix of a computer
00288 //----------------------------------------------------------------------
00289 char * 
00290 SALOME_ModuleCatalogImpl::GetPathPrefix(const char* machinename) {
00291   if(MYDEBUG) MESSAGE("Begin of GetPathPrefix");
00292   // Variables initialisation
00293   char* _path = NULL;
00294   bool _find = false ;
00295 
00296   // Parse all the path prefixes
00297   // looking for the wanted computer
00298   for (unsigned int ind = 0 ; ind < _personal_path_list.size() ; ind++)
00299     {
00300       for (unsigned int ind1 = 0 ; ind1 < _personal_path_list[ind].listOfComputer.size() ; ind1++)    
00301         {
00302           if (strcmp(machinename, _personal_path_list[ind].listOfComputer[ind1].c_str()) == 0)
00303             {
00304               _find = true ;
00305               // Wanted computer
00306               // affect the path to be returned
00307                 const char* _temp = _personal_path_list[ind].path.c_str() ;
00308                   _path = new char[strlen(_temp)+1];
00309               strcpy(_path,_temp);
00310             }
00311         }
00312     }
00313 
00314   if (!_find)
00315     {
00316     for (unsigned int ind = 0 ; ind < _general_path_list.size() ; ind++)
00317       {
00318         for (unsigned int ind1 = 0 ; ind1 < _general_path_list[ind].listOfComputer.size() ; ind1++)    
00319           {
00320             if (strcmp(machinename, _general_path_list[ind].listOfComputer[ind1].c_str()) == 0)
00321               {
00322                 _find = true ;
00323                 // Wanted computer
00324                 // affect the path to be returned
00325                   const char* _temp = _general_path_list[ind].path.c_str() ;
00326                     _path = new char[strlen(_temp)+1];
00327                 strcpy(_path,_temp);
00328               }
00329           }
00330       }
00331     }
00332 
00333   return _path;
00334 }
00335 
00336 //----------------------------------------------------------------------
00337 // Function : GetComponentList
00338 // Purpose  : get a component list
00339 //            If a component is defined in the personal catalog and 
00340 //            in the general catalog (same name), the component defined
00341 //            in the personal catalog is used
00342 //----------------------------------------------------------------------
00343 SALOME_ModuleCatalog::ListOfComponents* 
00344 SALOME_ModuleCatalogImpl::GetComponentList()
00345 {
00346   if(MYDEBUG) MESSAGE("Begin of GetComponentList");
00347   SALOME_ModuleCatalog::ListOfComponents_var _list_components = 
00348     new SALOME_ModuleCatalog::ListOfComponents;
00349 
00350   _list_components->length(_personal_module_list.size());
00351 
00352   // All the components defined in the personal catalog are taken
00353   for(unsigned int ind=0; ind < _personal_module_list.size();ind++){
00354     _list_components[ind]=(_personal_module_list[ind].name).c_str();
00355     if(MYDEBUG) SCRUTE(_list_components[ind]) ;
00356   }
00357 
00358   int indice = _personal_module_list.size() ;
00359   bool _find = false;
00360   
00361   // The components in the general catalog are taken only if they're
00362   // not defined in the personal catalog
00363   for(unsigned int ind=0; ind < _general_module_list.size();ind++){
00364     _find = false;
00365     for(unsigned int ind1=0; ind1 < _personal_module_list.size();ind1++){
00366       // searching if the component is already defined in 
00367       // the personal catalog
00368       if ((_general_module_list[ind].name.compare(_personal_module_list[ind1].name)) == 0)
00369         _find = true;
00370     }
00371     if(!_find){
00372       if(MYDEBUG) MESSAGE("A new component " << _general_module_list[ind].name 
00373                           << " has to be to added in the list");
00374       _list_components->length(indice+1);
00375       // The component is not already defined => has to be taken
00376       _list_components[indice]=(_general_module_list[ind].name).c_str();   
00377       if(MYDEBUG) SCRUTE(_list_components[indice]) ;
00378       
00379       indice++;
00380     }else{
00381       if(MYDEBUG) MESSAGE("The component " <<_general_module_list[ind].name 
00382                           << " was already defined in the personal catalog") ;
00383     }
00384   }
00385   
00386   if(MYDEBUG) MESSAGE ( "End of GetComponentList" );
00387   return _list_components._retn();
00388 }
00389 
00390 
00391 //----------------------------------------------------------------------
00392 // Function : GetComponentIconeList
00393 // Purpose  : get a component list of component name and component icone
00394 //            If a component is defined in the personal catalog and 
00395 //            in the general catalog (same name), the component defined
00396 //            in the personal catalog is used
00397 //----------------------------------------------------------------------
00398 SALOME_ModuleCatalog::ListOfIAPP_Affich* 
00399 SALOME_ModuleCatalogImpl::GetComponentIconeList()
00400 {
00401   if(MYDEBUG) MESSAGE("Begin of GetComponentIconeList");
00402 
00403   SALOME_ModuleCatalog::ListOfIAPP_Affich_var _list_components_icone = 
00404     new SALOME_ModuleCatalog::ListOfIAPP_Affich;
00405 
00406   _list_components_icone->length(_personal_module_list.size());
00407 
00408   // All the components defined in the personal catalog are taken
00409   for(unsigned int ind=0; ind < _personal_module_list.size();ind++){
00410     _list_components_icone[ind].modulename=(_personal_module_list[ind].name).c_str();
00411     _list_components_icone[ind].moduleusername=(_personal_module_list[ind].username).c_str();
00412     _list_components_icone[ind].moduleicone=(_personal_module_list[ind].icon).c_str();
00413     _list_components_icone[ind].moduleversion=(_personal_module_list[ind].version).c_str();
00414     _list_components_icone[ind].modulecomment=(_personal_module_list[ind].comment).c_str();
00415     //if(MYDEBUG) SCRUTE(_list_components_icone[ind].modulename); 
00416     //if(MYDEBUG) SCRUTE(_list_components_icone[ind].moduleicone);
00417   }
00418   
00419   int indice = _personal_module_list.size() ;
00420   bool _find = false;
00421   
00422   // The components in the general catalog are taken only if they're
00423   // not defined in the personal catalog
00424   for(unsigned int ind=0; ind < _general_module_list.size();ind++){
00425     _find = false;
00426     for(unsigned int ind1=0; ind1 < _personal_module_list.size();ind1++){
00427       // searching if the component is aleready defined in 
00428       // the personal catalog
00429       if((_general_module_list[ind].name.compare(_personal_module_list[ind1].name)) == 0)
00430         _find = true;
00431     }
00432     if(!_find){
00433       //          if(MYDEBUG) MESSAGE("A new component " << _general_module_list[ind].name << " has to be to added in the list");
00434       _list_components_icone->length(indice+1);
00435       // The component is not already defined => has to be taken
00436       _list_components_icone[indice].modulename=_general_module_list[ind].name.c_str();  
00437       _list_components_icone[indice].moduleusername=_general_module_list[ind].username.c_str();  
00438       _list_components_icone[indice].moduleicone=_general_module_list[ind].icon.c_str(); 
00439       _list_components_icone[indice].moduleversion=_general_module_list[ind].version.c_str();
00440       _list_components_icone[indice].modulecomment=_general_module_list[ind].comment.c_str();
00441       //if(MYDEBUG) SCRUTE(_list_components_icone[indice].modulename) ;
00442       //if(MYDEBUG) SCRUTE(_list_components_icone[indice].moduleicone);
00443       
00444       indice++;
00445     }
00446     // else 
00447     //if(MYDEBUG) MESSAGE("The component " <<_general_module_list[ind].name << " was already defined in the personal catalog"); 
00448   }
00449   
00450   return _list_components_icone._retn() ;
00451 }
00452 
00453 //----------------------------------------------------------------------
00454 // Function : GetTypedComponentList
00455 // Purpose  : get a component list of a wanted type
00456 //            If a component is defined in the personal catalog and 
00457 //            in the general catalog (same name), the component defined
00458 //            in the personal catalog is used
00459 //----------------------------------------------------------------------
00460 SALOME_ModuleCatalog::ListOfComponents* 
00461 SALOME_ModuleCatalogImpl::GetTypedComponentList(SALOME_ModuleCatalog::ComponentType component_type)
00462 {
00463   if(MYDEBUG) MESSAGE("Begin of GetTypedComponentList");
00464   SALOME_ModuleCatalog::ListOfComponents_var _list_typed_component = 
00465     new SALOME_ModuleCatalog::ListOfComponents;
00466   int _j = 0;
00467 
00468   _list_typed_component->length(0);
00469   // Transform SALOME_ModuleCatalog::ComponentType in ParserComponentType
00470   ParserComponentType _temp_component_type;
00471   switch(component_type){
00472   case SALOME_ModuleCatalog::GEOM:
00473     _temp_component_type = GEOM ;
00474     break;
00475   case SALOME_ModuleCatalog::MESH:
00476     _temp_component_type = MESH;
00477     break;   
00478   case SALOME_ModuleCatalog::Med:
00479     _temp_component_type = Med;
00480     break;    
00481   case SALOME_ModuleCatalog::SOLVER:   
00482     _temp_component_type = SOLVER;
00483     break;
00484   case SALOME_ModuleCatalog::DATA:
00485     _temp_component_type = DATA;
00486     break;
00487   case SALOME_ModuleCatalog::VISU:
00488     _temp_component_type = VISU;
00489     break;  
00490   case SALOME_ModuleCatalog::SUPERV:
00491     _temp_component_type = SUPERV;
00492     break;
00493   case SALOME_ModuleCatalog::OTHER:
00494     _temp_component_type = OTHER;
00495     break;
00496   }
00497 
00498   // All the components in the personal catalog are taken
00499   for (unsigned int ind=0; ind < _personal_module_list.size();ind++)
00500     {
00501       if  (_personal_module_list[ind].type == _temp_component_type)
00502         {
00503           _list_typed_component->length(_j + 1); 
00504            _list_typed_component[_j] = _personal_module_list[ind].name.c_str();
00505           //if(MYDEBUG) SCRUTE(_list_typed_component[_j]);
00506           _j++;
00507         }
00508     }
00509 
00510   int indice = _list_typed_component->length() ;
00511   bool _find = false;
00512   
00513   // The components in the general catalog are taken only if they're
00514   // not defined in the personal catalog
00515   for (unsigned int ind=0; ind < _general_module_list.size();ind++)
00516     {
00517       _find = false;
00518 
00519       if(_general_module_list[ind].type == _temp_component_type)
00520         {
00521           for (unsigned int ind1=0; ind1 < _personal_module_list.size();ind1++)
00522             {
00523               // searching if the component is aleready defined in 
00524               // the personal catalog
00525               if ((_general_module_list[ind].name.compare(_personal_module_list[ind1].name)) == 0)
00526                 _find = true;
00527             }
00528           if (!_find)
00529             {
00530               //if(MYDEBUG) MESSAGE("A new component " << _general_module_list[ind].name << " has to be to added in the list");
00531               _list_typed_component->length(indice+1);
00532               // The component is not already defined => has to be taken
00533               _list_typed_component[indice]=(_general_module_list[ind].name).c_str();   
00534               //if(MYDEBUG) SCRUTE(_list_typed_component[indice]) ;
00535 
00536               indice++;
00537             }
00538           //else 
00539             //if(MYDEBUG) MESSAGE("The component " <<_general_module_list[ind].name << " was already defined in the personal catalog") ;
00540         }
00541     }
00542 
00543 
00544   return _list_typed_component._retn();
00545 }
00546 
00547 //----------------------------------------------------------------------
00548 // Function : GetComponent
00549 // Purpose  : get a component 
00550 //            If a component is defined in the personal catalog and 
00551 //            in the general catalog (same name), the component defined
00552 //            in the personal catalog is used
00553 //----------------------------------------------------------------------
00554 SALOME_ModuleCatalog::Acomponent_ptr 
00555 SALOME_ModuleCatalogImpl::GetComponent(const char* name)
00556 {
00557   // Looking for component named "componentname" in the personal catalog
00558   // If found, get name, interfaces and constraint
00559   // If not found, looking for component named "componentname" in
00560   // the general catalog
00561   // If found, get name, interfaces and constraint
00562   // If not found, NULL pointer is returned
00563 
00564   std::string s(name);
00565   ParserComponent *C_parser = NULL;
00566   //ParserPathPrefixes *pp = NULL;
00567 
00568   SALOME_ModuleCatalog::Acomponent_ptr compo
00569     = SALOME_ModuleCatalog::Acomponent::_nil();
00570   C_parser = findComponent(s);
00571   if (C_parser) {
00572     
00573     //    DebugParserComponent(*C_parser);
00574 
00575     SALOME_ModuleCatalog::ComponentDef C_corba;
00576     duplicate(C_corba, *C_parser);
00577 
00578     
00579     SALOME_ModuleCatalog_AcomponentImpl * aComponentImpl = 
00580       new SALOME_ModuleCatalog_AcomponentImpl(C_corba);
00581     
00582     compo = aComponentImpl->_this();
00583   }
00584   else {
00585     // Not found in the personal catalog and in the general catalog
00586     // return NULL object
00587     if(MYDEBUG) MESSAGE("Component with name  " << name 
00588                         << " not found in catalog");
00589   }
00590   
00591   return compo;
00592 }
00593 
00594 SALOME_ModuleCatalog::ComponentDef *
00595 SALOME_ModuleCatalogImpl::GetComponentInfo(const char *name)
00596 {
00597   std::string s(name);
00598 
00599   ParserComponent * C_parser = findComponent(s);
00600   
00601   if (C_parser) {
00602     
00603     SALOME_ModuleCatalog::ComponentDef * C_corba 
00604       = new SALOME_ModuleCatalog::ComponentDef; 
00605     duplicate(*C_corba, *C_parser);
00606     return C_corba;
00607   }
00608 
00609   return NULL;
00610 }
00611 
00612 CORBA::Long SALOME_ModuleCatalogImpl::getPID()
00613 { 
00614   return 
00615 #ifndef WIN32
00616     (CORBA::Long)getpid();
00617 #else
00618     (CORBA::Long)_getpid();
00619 #endif
00620 }
00621 
00622 void SALOME_ModuleCatalogImpl::ShutdownWithExit()
00623 {
00624   exit( EXIT_SUCCESS );
00625 }
00626 
00627 ParserComponent *
00628 SALOME_ModuleCatalogImpl::findComponent(const std::string & name)
00629 {
00630   ParserComponent * C_parser = NULL;
00631 
00632   if (!C_parser)
00633     for (unsigned int ind=0; ind < _personal_module_list.size();ind++)
00634       {
00635         if (name.compare(_personal_module_list[ind].name) == 0)
00636           {
00637             if(MYDEBUG) MESSAGE("Component named " << name 
00638                                 << " found in the personal catalog");
00639             C_parser = &(_personal_module_list[ind]);
00640             break;
00641           }
00642       }
00643 
00644   if (!C_parser)
00645     for (unsigned int ind=0; ind < _general_module_list.size();ind++)
00646       {
00647         if (name.compare(_general_module_list[ind].name) == 0)
00648           {
00649             //      if(MYDEBUG) MESSAGE("Component named " << name 
00650             //                  << " found in the general catalog");
00651             C_parser = &(_general_module_list[ind]);
00652             break;
00653           }
00654       }
00655 
00656   return C_parser;
00657 }
00658 
00659 //----------------------------------------------------------------------
00660 // Function : _parse_xml_file
00661 // Purpose  : parse one module catalog 
00662 //----------------------------------------------------------------------
00663 void 
00664 SALOME_ModuleCatalogImpl::_parse_xml_file(const char* file, 
00665                                           ParserComponents& modulelist, 
00666                                           ParserPathPrefixes& pathList,
00667                                           ParserTypes& typeMap,
00668                                           TypeList& typeList)
00669 {
00670   if(MYDEBUG) BEGIN_OF("_parse_xml_file");
00671   if(MYDEBUG) SCRUTE(file);
00672 
00673   //Local path and module list for the file to parse
00674   ParserPathPrefixes  _pathList;
00675   ParserComponents    _moduleList;
00676  
00677   SALOME_ModuleCatalog_Handler* handler = new SALOME_ModuleCatalog_Handler(_pathList,_moduleList,typeMap,typeList);
00678 
00679   FILE* aFile = fopen(file, "r");
00680 
00681   if (aFile != NULL)
00682     {
00683       xmlDocPtr aDoc = xmlReadFile(file, NULL, 0);
00684       
00685       if (aDoc != NULL) 
00686         handler->ProcessXmlDocument(aDoc);
00687       else
00688         MESSAGE("ModuleCatalog: could not parse file "<<file);
00689 
00690       xmlFreeDoc(aDoc);
00691       fclose(aFile);
00692     }
00693   else
00694     MESSAGE("ModuleCatalog: file "<<file<<" is not readable.");
00695   
00696   delete handler;
00697   
00698   unsigned int i, j;
00699 
00700   for ( i = 0; i < _moduleList.size(); i++) {
00701     for (j=0; j<modulelist.size(); j++) {
00702       if (modulelist[j].name == _moduleList[i].name)
00703         break;
00704     }
00705     if (j < modulelist.size())
00706       modulelist[j] = _moduleList[i];
00707     else
00708       modulelist.push_back(_moduleList[i]);
00709   }
00710 
00711   for ( i=0; i < _pathList.size(); i++)
00712     pathList.push_back(_pathList[i]) ;
00713 
00714   for (j=0; j<modulelist.size(); j++)
00715     modulelist[j].prefixes = pathList;
00716 }
00717 
00718 void 
00719 SALOME_ModuleCatalogImpl::ImportXmlCatalogFile(const char* file)
00720 {
00721   _parse_xml_file(file, _personal_module_list, _personal_path_list,_typeMap,_typeList);
00722 }
00723 
00724 
00725 //
00726 //  Duplicate functions create a Corba structure (component,
00727 //  interface, service, parameter) from the corresponding C++ 
00728 //  parser structure
00729 //
00730 
00731 //----------------------------------------------------------------------
00732 // Function : duplicate
00733 // Purpose  : create a component from the catalog parsing
00734 //----------------------------------------------------------------------
00735 void SALOME_ModuleCatalogImpl::duplicate
00736 (SALOME_ModuleCatalog::ComponentDef & C_corba, 
00737  const ParserComponent & C_parser)
00738 {
00739   C_corba.name = CORBA::string_dup(C_parser.name.c_str());
00740   C_corba.username = CORBA::string_dup(C_parser.username.c_str());
00741   C_corba.multistudy = C_parser.multistudy;
00742   C_corba.icon = CORBA::string_dup(C_parser.icon.c_str());
00743   C_corba.type = ComponentTypeConvert[C_parser.type];
00744   if(C_parser.implementationType == "EXE")
00745     C_corba.implementationType=SALOME_ModuleCatalog::EXE;
00746   else if(C_parser.implementationType == "CEXE")
00747     C_corba.implementationType=SALOME_ModuleCatalog::CEXE;
00748   else if(C_parser.implementationType == "PY")
00749     C_corba.implementationType=SALOME_ModuleCatalog::PY;
00750   else
00751     C_corba.implementationType=SALOME_ModuleCatalog::SO;
00752   C_corba.implname = CORBA::string_dup(C_parser.implementationName.c_str());
00753 
00754   unsigned int _length = C_parser.interfaces.size();
00755   C_corba.interfaces.length(_length);
00756   
00757   for (unsigned int ind = 0; ind < _length; ind++)
00758     duplicate(C_corba.interfaces[ind], C_parser.interfaces[ind]);
00759 }
00760 
00761 
00762 //----------------------------------------------------------------------
00763 // Function : duplicate
00764 // Purpose  : create an interface from the catalog parsing
00765 //----------------------------------------------------------------------
00766 void SALOME_ModuleCatalogImpl::duplicate
00767 (SALOME_ModuleCatalog::DefinitionInterface & I_corba,
00768  const ParserInterface & I_parser)
00769 {
00770   //duplicate interface name
00771   I_corba.interfacename = CORBA::string_dup(I_parser.name.c_str());
00772   
00773   // duplicate service list
00774   unsigned int _length = I_parser.services.size();
00775   //  if(MYDEBUG) SCRUTE(_length);
00776   //  I_corba.interfaceservicelist 
00777   //  = new SALOME_ModuleCatalog::ListOfInterfaceService;
00778   I_corba.interfaceservicelist.length(_length);
00779   
00780   for (unsigned int ind1 = 0; ind1 < _length ; ind1 ++)
00781     duplicate(I_corba.interfaceservicelist[ind1],
00782               I_parser.services[ind1]);
00783 }
00784 
00785 //----------------------------------------------------------------------
00786 // Function : duplicate
00787 // Purpose  : create a service from the catalog parsing
00788 //----------------------------------------------------------------------
00789 void SALOME_ModuleCatalogImpl::duplicate
00790 (SALOME_ModuleCatalog::Service & S_corba,
00791  const ParserService & S_parser)
00792 {
00793   // duplicate service name
00794   S_corba.ServiceName = CORBA::string_dup(S_parser.name.c_str());
00795   
00796   // duplicate service by default
00797   S_corba.Servicebydefault = S_parser.byDefault;
00798 
00799   S_corba.TypeOfNode = S_parser.typeOfNode;
00800 
00801   unsigned int _length;
00802 
00803   // duplicate in Parameters
00804   _length = S_parser.inParameters.size();
00805   S_corba.ServiceinParameter.length(_length);
00806 
00807   for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
00808     duplicate(S_corba.ServiceinParameter[ind2],
00809               S_parser.inParameters[ind2]);
00810   
00811   // duplicate out Parameters
00812   _length = S_parser.outParameters.size();
00813   S_corba.ServiceoutParameter.length(_length);
00814 
00815   for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
00816     duplicate(S_corba.ServiceoutParameter[ind2],
00817               S_parser.outParameters[ind2]);
00818   
00819   // duplicate in DataStreamParameters
00820   _length = S_parser.inDataStreamParameters.size();
00821   S_corba.ServiceinDataStreamParameter.length(_length);
00822 
00823   for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
00824     duplicate(S_corba.ServiceinDataStreamParameter[ind2],
00825               S_parser.inDataStreamParameters[ind2]);
00826   
00827   // duplicate out DataStreamParameters
00828   _length = S_parser.outDataStreamParameters.size();
00829   //  if(MYDEBUG) SCRUTE(_length);
00830   S_corba.ServiceoutDataStreamParameter.length(_length);
00831 
00832   for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
00833     duplicate(S_corba.ServiceoutDataStreamParameter[ind2],
00834               S_parser.outDataStreamParameters[ind2]);
00835 }
00836 
00837 //----------------------------------------------------------------------
00838 // Function : duplicate
00839 // Purpose  : create a service parameter from the catalog parsing
00840 //----------------------------------------------------------------------
00841 void SALOME_ModuleCatalogImpl::duplicate
00842 (SALOME_ModuleCatalog::ServicesParameter & P_corba,
00843  const ParserParameter & P_parser)
00844 {
00845   // duplicate parameter name
00846   P_corba.Parametername = CORBA::string_dup(P_parser.name.c_str());
00847   
00848   // duplicate parameter type
00849   P_corba.Parametertype = CORBA::string_dup(P_parser.type.c_str());
00850 }
00851 
00852 
00853 //----------------------------------------------------------------------
00854 // Function : duplicate
00855 // Purpose  : create a service datastream parameter from the catalog parsing
00856 //----------------------------------------------------------------------
00857 void SALOME_ModuleCatalogImpl::duplicate
00858 (SALOME_ModuleCatalog::ServicesDataStreamParameter & P_corba,
00859  const ParserDataStreamParameter & P_parser)
00860 {
00861   std::map < std::string, 
00862     SALOME_ModuleCatalog::DataStreamDependency >::const_iterator it_dep;
00863 
00864   // duplicate parameter name
00865   P_corba.Parametername = CORBA::string_dup(P_parser.name.c_str());
00866   
00867   // duplicate parameter type
00868 
00869   // doesn't work ??? 
00870   //   it_type = DataStreamTypeConvert.find(P_parser.type);
00871   //   P_corba.Parametertype
00872   //     = (it_type == DataStreamTypeConvert.end()) 
00873   //     ? it_type->second : SALOME_ModuleCatalog::DATASTREAM_UNKNOWN;
00874 
00875   P_corba.Parametertype = CORBA::string_dup(P_parser.type.c_str());
00876 
00877   // duplicate parameter dependency
00878   
00879   if(MYDEBUG) SCRUTE(P_parser.dependency);
00880   P_corba.Parameterdependency = SALOME_ModuleCatalog::DATASTREAM_UNDEFINED;
00881   for (it_dep = DataStreamDepConvert.begin(); 
00882        it_dep != DataStreamDepConvert.end(); 
00883        it_dep++)
00884     if (P_parser.dependency.compare(it_dep->first) == 0) {
00885       P_corba.Parameterdependency = it_dep->second;
00886       break;
00887     }
00888 
00889   if(MYDEBUG) SCRUTE(P_corba.Parameterdependency);
00890 }
00891 
00892 //----------------------------------------------------------------------
00893 // Function : duplicate
00894 // Purpose  : create the path prefix structures from the catalog parsing
00895 //----------------------------------------------------------------------
00896 void
00897 SALOME_ModuleCatalogImpl::duplicate(ParserPathPrefixes &L_out, 
00898                                     const ParserPathPrefixes &L_in)
00899 {
00900   L_out = L_in;
00901 }
00902 
00903 
00904 //----------------------------------------------------------------------
00905 // Function : _verify_path_prefix
00906 // Purpose  : verify the path prefix structures from the catalog parsing
00907 //            Verify that there only one path prefix associated to a 
00908 //            particular computer
00909 //----------------------------------------------------------------------
00910 bool
00911 SALOME_ModuleCatalogImpl::_verify_path_prefix(ParserPathPrefixes & pathList)
00912 {
00913   bool _return_value = true;
00914   std::vector<std::string> _machine_list;
00915 
00916   // Fill a list of all computers indicated in the path list
00917   for (unsigned int ind = 0; ind < pathList.size(); ind++)
00918     { 
00919       for (unsigned int ind1 = 0 ; ind1 < pathList[ind].listOfComputer.size(); ind1++)
00920         {
00921           _machine_list.push_back(pathList[ind].listOfComputer[ind1]);
00922         }
00923     }
00924 
00925   // Parse if a computer name is twice in the list of computers
00926   for (unsigned int ind = 0; ind < _machine_list.size(); ind++)
00927     {
00928      for (unsigned int ind1 = ind+1 ; ind1 < _machine_list.size(); ind1++)
00929        {
00930          if(_machine_list[ind].compare(_machine_list[ind1]) == 0)
00931            {
00932              if(MYDEBUG) MESSAGE( "The computer " << _machine_list[ind] << " is indicated more than once in the path list");
00933              _return_value = false; 
00934            }
00935        }
00936     }
00937   return _return_value;
00938 }
00939 
00940 
00941 //----------------------------------------------------------------------
00942 // Function : _parseArguments
00943 // Purpose  : parse arguments to get general and personal catalog files
00944 //----------------------------------------------------------------------
00945 bool
00946 SALOME_ModuleCatalogImpl::_parseArguments(int argc, char **argv, 
00947                                           char **_general, 
00948                                           char** _personal)
00949 {
00950   bool _return_value = true;
00951   *_general = NULL;
00952   *_personal = NULL ;
00953   for (int ind = 0; ind < argc ; ind++)
00954     {
00955 
00956       if (strcmp(argv[ind],"-help") == 0)
00957         {
00958           INFOS( "Usage: " << argv[0] 
00959                  << " -common 'path to general catalog' "
00960                  " -personal 'path to personal catalog' "
00961                  " -ORBInitRef NameService=corbaname::localhost");
00962             _return_value = false ;
00963         }
00964 
00965       if (strcmp(argv[ind],"-common") == 0)
00966         {
00967           if (ind + 1 < argc)
00968             {
00969               // General catalog file
00970               *_general = argv[ind + 1] ;
00971             }
00972         }
00973       else if (strcmp(argv[ind],"-personal") == 0)
00974         {
00975           if (ind + 1 < argc)
00976             {
00977               // Personal catalog file
00978               *_personal = argv[ind + 1] ;
00979             }
00980         }
00981     }
00982   return _return_value;
00983 }