Salome HOME
Fix pb. with loading of last module (in list).
[modules/kernel.git] / src / ModuleCatalog / SALOME_ModuleCatalog_Handler.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_Handler.cxx
25 //  Author : Estelle Deville
26 //  Module : SALOME
27 //  $Header$ 
28
29 #define WRITE_CATA_COMPONENT
30
31 #include "SALOME_ModuleCatalog_Handler.hxx"
32 #include "SALOME_ModuleCatalog_Parser_IO.hxx"
33 #include "utilities.h"
34
35 #include <sstream>
36 using namespace std;
37
38 #ifdef _DEBUG_
39 static int MYDEBUG = 0;
40 #else
41 static int MYDEBUG = 0;
42 #endif
43
44 //----------------------------------------------------------------------
45 // Function : SALOME_ModuleCatalog_Handler
46 // Purpose  : Constructor
47 //----------------------------------------------------------------------
48 SALOME_ModuleCatalog_Handler::SALOME_ModuleCatalog_Handler()
49 {
50   if(MYDEBUG) BEGIN_OF("SALOME_ModuleCatalog_Handler");
51
52   // XML Tags initialisation
53   // Used in the function endElement
54   test_path_prefix_name     = "path-prefix-name";
55   test_computer_name        = "computer-name" ;
56   test_computer_list        = "computer-list" ;
57   test_path_prefix          = "path-prefix" ;
58   test_path_prefix_list     = "path-prefix-list" ;
59
60   test_component_name       = "component-name";
61   test_component_username   = "component-username";
62   test_component_type       = "component-type" ;
63   test_component_multistudy = "component-multistudy";
64   test_component_icon       = "component-icone" ;
65   test_component_impltype   = "component-impltype";
66   test_component_version    = "component-version";
67   test_component_comment    = "component-comment";
68
69   test_interface_name       = "component-interface-name" ;
70   
71   test_service_name         = "service-name";
72   test_defaultservice       = "service-by-default";
73
74   test_typeofnode           = "type-of-node";
75
76   test_inParameter_type     = "inParameter-type";
77   test_inParameter_name     = "inParameter-name";
78   test_inParameter          = "inParameter";
79   test_inParameter_list     = "inParameter-list";
80
81   test_outParameter_type    = "outParameter-type";
82   test_outParameter_name    = "outParameter-name";
83   test_outParameter         = "outParameter";
84   test_outParameter_list    = "outParameter-list";
85
86   test_inDataStreamParameter_type = "inParameter-type";
87   test_inDataStreamParameter_name = "inParameter-name";
88   test_inDataStreamParameter_dependency = "inParameter-dependency";
89   test_inDataStreamParameter = "inParameter";
90   test_inDataStreamParameter_list = "DataStream-list";
91
92   test_outDataStreamParameter_type = "outParameter-type";
93   test_outDataStreamParameter_name = "outParameter-name";
94   test_outDataStreamParameter_dependency = "outParameter-dependency";
95   test_outDataStreamParameter = "outParameter";
96   test_outDataStreamParameter_list = "DataStream-list";
97
98   test_service =  "component-service";
99   test_service_list = "component-service-list";
100   test_interface_list = "component-interface-list";
101
102   test_constraint = "constraint";
103
104   test_component_list = "component-list";
105   test_component="component";
106
107   if(MYDEBUG) END_OF("SALOME_ModuleCatalog_Handler");
108 }
109
110 //----------------------------------------------------------------------
111 // Function : ~SALOME_ModuleCatalog_Handler
112 // Purpose  : Destructor
113 //----------------------------------------------------------------------
114 SALOME_ModuleCatalog_Handler::~SALOME_ModuleCatalog_Handler()
115 {
116   if(MYDEBUG) BEGIN_OF("~SALOME_ModuleCatalog_Handler()")
117   if(MYDEBUG) END_OF("~SALOME_ModuleCatalog_Handler()")
118 }
119
120
121 //=============================================================================
122 /*!
123  *  Processes XML document and fills the list of modules
124  */ 
125 //=============================================================================
126
127 void SALOME_ModuleCatalog_Handler::ProcessXmlDocument(xmlDocPtr theDoc)
128 {
129   if(MYDEBUG) MESSAGE("Begin parse document");
130   // Empty the private elements
131   _pathList.resize(0);
132   _pathPrefix.listOfComputer.resize(0);
133   _serviceList.resize(0);
134   _interfaceList.resize(0);
135   _moduleList.resize(0);
136   _inDataStreamParamList.resize(0);
137   _outDataStreamParamList.resize(0);
138   _inParamList.resize(0);
139   _outParamList.resize(0);
140
141   // Get the document root node
142   xmlNodePtr aCurNode = xmlDocGetRootElement(theDoc);
143   aCurNode = aCurNode->xmlChildrenNode;
144   
145   // Processing the document nodes
146   while(aCurNode != NULL)
147   {
148     // Process path prefix list (tag test_path_prefix_list)
149     if ( !xmlStrcmp(aCurNode->name,(const xmlChar*)test_path_prefix_list) )
150     {
151       xmlNodePtr aCurSubNode = aCurNode->xmlChildrenNode;
152       while(aCurSubNode != NULL)
153       {
154         // Forming a PathPrefix structure (tag test_path_prefix)
155         if ( xmlStrcmp(aCurSubNode->name, (const xmlChar*)test_path_prefix) ) {
156           aCurSubNode = aCurSubNode->next;
157           continue;
158         }
159
160         xmlNodePtr aCurSubSubNode = aCurSubNode->xmlChildrenNode;
161         while(aCurSubSubNode != NULL)
162         {
163           // Tag test_path_prefix_name
164           if ( !xmlStrcmp(aCurSubSubNode->name, (const xmlChar*)test_path_prefix_name) ) {
165             xmlChar* aPath = xmlNodeGetContent(aCurSubSubNode);
166             if (aPath != NULL) {
167               _pathPrefix.path = (const char*)aPath;
168               xmlFree(aPath);
169             }
170           }
171
172           // Tag test_computer_list
173           if ( !xmlStrcmp(aCurSubSubNode->name, (const xmlChar*)test_computer_list) ) {
174             xmlNodePtr aComputerNode = aCurSubSubNode->xmlChildrenNode;
175             while (aComputerNode != NULL) {
176               // Tag test_computer_name
177               if ( !xmlStrcmp(aComputerNode->name, (const xmlChar*) test_computer_name) ) {
178                 xmlChar* aCompName = xmlNodeGetContent(aComputerNode);
179                 if (aCompName != NULL) {
180                   _pathPrefix.listOfComputer.push_back((const char*)aCompName);
181                   xmlFree(aCompName);
182                 }
183               }
184
185               aComputerNode = aComputerNode->next;
186             }
187           }
188
189           aCurSubSubNode = aCurSubSubNode->next;
190         }
191
192         _pathList.push_back(_pathPrefix);
193         _pathPrefix.listOfComputer.resize(0);
194
195         aCurSubNode = aCurSubNode->next;
196       }
197     }
198
199     //@ Process list of components (tag test_component_list)
200     if ( !xmlStrcmp(aCurNode->name,(const xmlChar*)test_component_list) )
201     {
202       xmlNodePtr aComponentNode = aCurNode->xmlChildrenNode;
203       while (aComponentNode != NULL)
204       {
205         // Do not process tags differ from test_component here
206         if ( xmlStrcmp(aComponentNode->name, (const xmlChar*)test_component) ) {
207           aComponentNode = aComponentNode->next;
208           continue;
209         }
210
211         // Component identification
212
213         // Empty temporary structures
214         _aModule.name = "";
215         _aModule.constraint = "";
216         _aModule.icon="";       
217         _aModule.interfaces.resize(0);
218
219         xmlNodePtr aComponentSubNode = aComponentNode->xmlChildrenNode;
220         while(aComponentSubNode != NULL)
221         {
222           xmlChar* aNodeContent = xmlNodeGetContent(aComponentSubNode);
223
224           if (aNodeContent == NULL) {
225             aComponentSubNode = aComponentSubNode->next;
226             continue;
227           }
228
229           std::string aContent = (const char*)aNodeContent;
230
231           // Tag test_component_name
232           if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_name) )
233             _aModule.name = aContent;
234
235           // Tag test_component_username
236           if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_username) )
237             _aModule.username = aContent;
238
239           // Tag test_component_type
240           if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_type) ) {
241             std::string aType = aContent;
242
243             if ((aType.compare("MESH") == 0) ||
244                 (aType.compare("Mesh") == 0) ||
245                 (aType.compare("mesh") == 0))
246               _aModule.type = MESH ;
247             else if((aType.compare("MED") == 0) ||
248                     (aType.compare("Med") == 0) ||
249                     (aType.compare("med") == 0))
250               _aModule.type = Med ;
251             else if((aType.compare("GEOM") == 0) ||
252                     (aType.compare("Geom") == 0) ||
253                     (aType.compare("geom") == 0))
254               _aModule.type = GEOM ;
255             else if((aType.compare("SOLVER") == 0) ||
256                     (aType.compare("Solver") == 0) ||
257                     (aType.compare("solver") == 0))
258               _aModule.type = SOLVER ;
259             else if((aType.compare("SUPERV") == 0) ||
260                     (aType.compare("Superv") == 0) ||
261                     (aType.compare("Supervision") == 0) ||
262                     (aType.compare("superv") == 0))
263               _aModule.type = SUPERV ;
264             else if((aType.compare("DATA") == 0) ||
265                     (aType.compare("Data") == 0) ||
266                     (aType.compare("data") == 0))
267               _aModule.type = DATA ; 
268             else if((aType.compare("VISU") == 0) ||
269                     (aType.compare("Visu") == 0) ||
270                     (aType.compare("visu") == 0))
271               _aModule.type = VISU ; 
272             else if((aType.compare("OTHER") == 0) ||
273                     (aType.compare("Other") == 0) ||
274                     (aType.compare("other") == 0))                
275               _aModule.type = OTHER ;
276             else
277               // If it'not in all theses cases, the type is affected to OTHER
278               _aModule.type = OTHER ;
279           }
280
281           // Tag test_component_multistudy
282           if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_multistudy) )
283             _aModule.multistudy = atoi( aContent.c_str() );
284
285           // Tag test_component_impltype
286           if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_impltype) )
287             _aModule.implementationType = atoi(aContent.c_str());
288
289           // Tag test_component_icon
290           if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_icon) )
291             _aModule.icon = aContent;
292
293           // Tag test_component_version
294           if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_version) )
295             _aModule.version = aContent;
296
297           // Tag test_component_comment
298           if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_comment) )
299             _aModule.comment = aContent;
300
301           // Tag test_constraint
302           if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_constraint) )
303             _aModule.constraint = aContent;
304
305           xmlFree(aNodeContent);
306
307           // Process tag test_interface_list:
308           if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_interface_list) ) {
309
310             // Form an interface list for the component
311             xmlNodePtr aSubNode = aComponentSubNode->xmlChildrenNode;
312             while(aSubNode != NULL) {
313               // Tag test_interface_name
314               if ( !xmlStrcmp(aSubNode->name, (const xmlChar*)test_interface_name) ) {
315                 xmlChar* anInterfaceName = xmlNodeGetContent(aSubNode);
316                 if (anInterfaceName != NULL) {
317                   _aInterface.name = (const char*)anInterfaceName;
318                   xmlFree(anInterfaceName);
319                 }
320               }
321
322               // Tag test_service_list
323               if ( !xmlStrcmp(aSubNode->name, (const xmlChar*)test_service_list) ) {
324                 // Form a service list for the interface
325                 xmlNodePtr aCompServiceNode = aSubNode->xmlChildrenNode;
326                 while(aCompServiceNode != NULL) {
327                   // Tag test_service
328                   if ( !xmlStrcmp(aCompServiceNode->name, (const xmlChar*)test_interface_name) ) {
329                     xmlNodePtr aCompServiceSubNode = aCompServiceNode->xmlChildrenNode;
330                     while(aCompServiceSubNode != NULL)
331                     {
332                       xmlChar* aCompServiceData = xmlNodeGetContent(aCompServiceSubNode);
333
334                       if ( aCompServiceData != NULL)
335                       {
336                         // Tag test_service_name
337                         if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_service_name) )
338                           _aService.name = (const char*)aCompServiceData;
339
340                         // Tag test_defaultservice
341                         if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_defaultservice) )
342                           _aService.byDefault = (const char*)aCompServiceData;
343
344                         // Tag test_typeofnode
345                         if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_typeofnode) )
346                           _aService.typeOfNode = (const char*)aCompServiceData;
347
348                         xmlFree(aCompServiceData);
349                       }
350
351                       // Tag test_inParameter_list
352                       if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_inParameter_list) ) {
353                         xmlNodePtr aParamNode = aCompServiceSubNode->xmlChildrenNode;
354                         while (aParamNode != NULL)
355                         {
356                           // Tag test_inParameter
357                           if (xmlStrcmp(aParamNode->name, (const xmlChar*)test_inParameter)) {
358                             aParamNode = aParamNode->next;
359                             continue;
360                           }
361
362                           xmlNodePtr aParamItemNode = aParamNode->xmlChildrenNode;
363                           while (aParamItemNode != NULL)
364                           {
365                             xmlChar* aParamData = xmlNodeGetContent(aParamItemNode);
366
367                             if (aParamData != NULL)
368                             {
369                               // Tag test_inParameter_name
370                               if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_inParameter_name) )
371                                 _inParam.name = (const char*)aParamData;
372
373                               // Tag test_inParameter_type
374                               if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_inParameter_type) )
375                                 _inParam.type = (const char*)aParamData;
376
377                               xmlFree(aParamData);
378                             }
379
380                             aParamItemNode = aParamItemNode->next;
381                           }
382
383                           _inParamList.push_back(_inParam) ; 
384
385                           // Empty temporary structures
386                           _inParam.type = "";
387                           _inParam.name = "";
388
389                           aParamNode = aParamNode->next;
390                         }
391
392                         _aService.inParameters = _inParamList;
393                         _inParamList.resize(0);
394                       }
395
396                       // Tag test_outParameter_list
397                       if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_outParameter_list) ) {
398                         xmlNodePtr aParamNode = aCompServiceSubNode->xmlChildrenNode;
399                         while (aParamNode != NULL)
400                         {
401                           // Tag test_outParameter
402                           if (xmlStrcmp(aParamNode->name, (const xmlChar*)test_outParameter)) {
403                             aParamNode = aParamNode->next;
404                             continue;
405                           }
406
407                           xmlNodePtr aParamItemNode = aParamNode->xmlChildrenNode;
408                           while (aParamItemNode != NULL)
409                           {
410                             xmlChar* anOutParamData = xmlNodeGetContent(aParamItemNode);
411
412                             if (anOutParamData != NULL)
413                             {
414                               // Tag test_outParameter_name
415                               if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_outParameter_name) )
416                                 _outParam.name = (const char*)anOutParamData;
417
418                               // Tag test_outParameter_type
419                               if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_outParameter_type) )
420                                 _outParam.type = (const char*)anOutParamData;
421
422                               xmlFree(anOutParamData);
423                             }
424
425                             aParamItemNode = aParamItemNode->next;
426                           }
427
428                           _outParamList.push_back(_outParam) ; 
429
430                           // Empty temporary structures
431                           _outParam.type = "";
432                           _outParam.name = "";
433
434                           aParamNode = aParamNode->next;
435                         }
436
437                         _aService.outParameters = _outParamList;
438                         _outParamList.resize(0);
439                       }
440
441                       //@ Tag test_inDataStreamParameter_list
442                       if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_inDataStreamParameter_list) )
443                       {
444                         xmlNodePtr aParamNode = aCompServiceSubNode->xmlChildrenNode;
445                         while (aParamNode != NULL)
446                         {
447                           // Tag test_inDataStreamParameter
448                           if (xmlStrcmp(aParamNode->name, (const xmlChar*)test_inDataStreamParameter)) {
449                             aParamNode = aParamNode->next;
450                             continue;
451                           }
452
453                           xmlNodePtr aParamItemNode = aParamNode->xmlChildrenNode;
454                           while (aParamItemNode != NULL)
455                           {
456                             xmlChar* inDataStreamParamData = xmlNodeGetContent(aParamItemNode);
457
458                             if (inDataStreamParamData != NULL)
459                             {
460                               // Tag test_inDataStreamParameter_name
461                               if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_inDataStreamParameter_name) )
462                                 _inDataStreamParam.name = (const char*)inDataStreamParamData;
463
464                               // Tag test_inDataStreamParameter_type
465                               if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_inDataStreamParameter_type) )
466                                 _inDataStreamParam.type = (const char*)inDataStreamParamData;
467
468                               // Tag test_inDataStreamParameter_dependency
469                               if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_inDataStreamParameter_dependency) )
470                                 _inDataStreamParam.dependency = (const char*)inDataStreamParamData;
471
472                               xmlFree(inDataStreamParamData);
473                             }
474
475                             aParamItemNode = aParamItemNode->next;
476                           }
477
478                           _inDataStreamParamList.push_back(_inDataStreamParam) ; 
479
480                           // Empty temporary structures
481                           _inDataStreamParam.type = "";
482                           _inDataStreamParam.name = "";
483                           _inDataStreamParam.dependency = "";
484
485                           aParamNode = aParamNode->next;
486                         }
487
488                         _aService.inDataStreamParameters = _inDataStreamParamList;
489                         _inDataStreamParamList.resize(0);
490                       }
491
492                       // Tag test_outDataStreamParameter_list
493                       if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_outDataStreamParameter_list) )
494                       {
495                         xmlNodePtr aParamNode = aCompServiceSubNode->xmlChildrenNode;
496                         while (aParamNode != NULL)
497                         {
498                           // Tag test_outDataStreamParameter
499                           if (xmlStrcmp(aParamNode->name, (const xmlChar*)test_outDataStreamParameter)) {
500                             aParamNode = aParamNode->next;
501                             continue;
502                           }
503
504                           xmlNodePtr aParamItemNode = aParamNode->xmlChildrenNode;
505                           while (aParamItemNode != NULL)
506                           {
507                             xmlChar* outDataStreamParamData = xmlNodeGetContent(aParamItemNode);
508
509                             if (outDataStreamParamData != NULL)
510                             {
511                               // Tag test_outDataStreamParameter_name
512                               if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_outDataStreamParameter_name) )
513                                 _outDataStreamParam.name = (const char*)outDataStreamParamData;
514                               
515                               // Tag test_outDataStreamParameter_type
516                               if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_outDataStreamParameter_type) )
517                                 _outDataStreamParam.type = (const char*)outDataStreamParamData;
518                               
519                               // Tag test_outDataStreamParameter_dependency
520                               if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_outDataStreamParameter_dependency) )
521                                 _outDataStreamParam.dependency = (const char*)outDataStreamParamData;
522                               
523                               xmlFree(outDataStreamParamData);
524                             }
525
526                             aParamItemNode = aParamItemNode->next;
527                           }
528                           
529                           _outDataStreamParamList.push_back(_outDataStreamParam) ; 
530                           
531                           // Empty temporary structures
532                           _outDataStreamParam.type = "";
533                           _outDataStreamParam.name = "";
534                           _outDataStreamParam.dependency = "";
535
536                           aParamNode = aParamNode->next;
537                         }
538                         
539                         _aService.outDataStreamParameters = _outDataStreamParamList;
540                         _outDataStreamParamList.resize(0);
541                       }
542                       
543                       aCompServiceSubNode = aCompServiceSubNode->next;
544                     }
545
546                     // Put formed service into the list
547                     _serviceList.push_back(_aService);
548
549                     // Empty temporary structures
550                     _aService.name = "";
551                     _aService.typeOfNode = 1;
552                     _aService.inParameters.resize(0);
553                     _aService.outParameters.resize(0);
554                     _aService.inDataStreamParameters.resize(0);
555                     _aService.outDataStreamParameters.resize(0);
556                   }
557                   
558                   aCompServiceNode = aCompServiceNode->next;
559                 }
560                 
561                 _aInterface.services = _serviceList ;
562                 
563                 // Empty temporary structures
564                 _serviceList.resize(0);
565                 _interfaceList.push_back(_aInterface);  
566                 _aInterface.name ="";    
567                 _aInterface.services.resize(0);
568               }
569               
570               aSubNode = aSubNode->next;
571             }
572             
573             _aModule.interfaces = _interfaceList ;
574             _interfaceList.resize(0);
575           }
576
577           aComponentSubNode = aComponentSubNode->next;
578         }
579
580         _moduleList.push_back(_aModule);
581
582         aComponentNode = aComponentNode->next;
583       }
584     }
585
586     aCurNode = aCurNode->next;
587   }
588 }