Salome HOME
To avoid compilation pb on RedHat 8.0.
[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
144   aCurNode = aCurNode->xmlChildrenNode;
145
146   // Processing the document nodes
147   while(aCurNode != NULL)
148     {
149       // Process path prefix list (tag test_path_prefix_list)
150       if ( !xmlStrcmp(aCurNode->name,(const xmlChar*)test_path_prefix_list) )
151         {
152           xmlNodePtr aCurSubNode = aCurNode->xmlChildrenNode;
153           while(aCurSubNode != NULL)
154             {
155               // Forming a PathPrefix structure (tag test_path_prefix)
156               if ( xmlStrcmp(aCurSubNode->name, (const xmlChar*)test_path_prefix) ) {
157                 aCurSubNode = aCurSubNode->next;
158                 continue;
159               }
160               
161               xmlNodePtr aCurSubSubNode = aCurSubNode->xmlChildrenNode;
162               while(aCurSubSubNode != NULL)
163                 {
164                   // Tag test_path_prefix_name
165                   if ( !xmlStrcmp(aCurSubSubNode->name, (const xmlChar*)test_path_prefix_name) )
166                     _pathPrefix.path = (const char*)aCurSubSubNode->content;
167
168                   // Tag test_computer_list
169                   if ( !xmlStrcmp(aCurSubSubNode->name, (const xmlChar*)test_computer_list) ) {
170                     xmlNodePtr aComputerNode = aCurSubSubNode->xmlChildrenNode;
171                     while (aComputerNode != NULL) {
172                       // Tag test_computer_name
173                       if ( !xmlStrcmp(aComputerNode->name, (const xmlChar*) test_computer_name) )
174                         _pathPrefix.listOfComputer.push_back((const char*)aComputerNode->content);
175                       
176                       aComputerNode = aComputerNode->next;
177                     }
178                   }
179                   
180                   aCurSubSubNode = aCurSubSubNode->next;
181                 }
182               
183               _pathList.push_back(_pathPrefix);
184               _pathPrefix.listOfComputer.resize(0);
185               
186               aCurSubNode = aCurSubNode->next;
187             }
188         }
189
190       //@ Process list of components (tag test_component_list)
191       if ( !xmlStrcmp(aCurNode->name,(const xmlChar*)test_component_list) )
192         {
193           xmlNodePtr aComponentNode = aCurNode->xmlChildrenNode;
194           while(aComponentNode != NULL)
195             {
196               // Do not process tags differ from test_component here
197               if ( xmlStrcmp(aComponentNode->name, (const xmlChar*)test_component) ) {
198                 aComponentNode = aComponentNode->next;
199                 continue;
200               }
201               
202               // Component identification
203
204               // Empty temporary structures
205               _aModule.name = "";
206               _aModule.constraint = "";
207               _aModule.icon="";       
208               _aModule.interfaces.resize(0);
209               
210               xmlNodePtr aComponentSubNode = aComponentNode->xmlChildrenNode;
211               while(aComponentSubNode != NULL) {
212                 
213                 std::string aContent = (const char*)aComponentSubNode->content;
214
215                 // Tag test_component_name
216                 if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_name) )
217                   _aModule.name = aContent;
218
219                 // Tag test_component_username
220                 if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_username) )
221                   _aModule.username = aContent;
222
223                 // Tag test_component_type
224                 if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_type) ) {
225                   std::string aType = aContent;
226
227                   if ((aType.compare("MESH") == 0) ||
228                       (aType.compare("Mesh") == 0) ||
229                       (aType.compare("mesh") == 0))
230                     _aModule.type = MESH ;
231                   else if((aType.compare("MED") == 0) ||
232                           (aType.compare("Med") == 0) ||
233                           (aType.compare("med") == 0))
234                     _aModule.type = Med ;
235                   else if((aType.compare("GEOM") == 0) ||
236                           (aType.compare("Geom") == 0) ||
237                           (aType.compare("geom") == 0))
238                     _aModule.type = GEOM ;
239                   else if((aType.compare("SOLVER") == 0) ||
240                           (aType.compare("Solver") == 0) ||
241                           (aType.compare("solver") == 0))
242                     _aModule.type = SOLVER ;
243                   else if((aType.compare("SUPERV") == 0) ||
244                           (aType.compare("Superv") == 0) ||
245                           (aType.compare("Supervision") == 0) ||
246                           (aType.compare("superv") == 0))
247                     _aModule.type = SUPERV ;
248                   else if((aType.compare("DATA") == 0) ||
249                           (aType.compare("Data") == 0) ||
250                           (aType.compare("data") == 0))
251                     _aModule.type = DATA ; 
252                   else if((aType.compare("VISU") == 0) ||
253                           (aType.compare("Visu") == 0) ||
254                           (aType.compare("visu") == 0))
255                     _aModule.type = VISU ; 
256                   else if((aType.compare("OTHER") == 0) ||
257                           (aType.compare("Other") == 0) ||
258                           (aType.compare("other") == 0))                
259                     _aModule.type = OTHER ;
260                   else
261                     // If it'not in all theses cases, the type is affected to OTHER
262                     _aModule.type = OTHER ;
263                 }
264                 
265                 // Tag test_component_multistudy
266                 if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_multistudy) )
267                   _aModule.multistudy = atoi( aContent.c_str() );
268
269                 // Tag test_component_impltype
270                 if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_impltype) )
271                   _aModule.implementationType = atoi(aContent.c_str());
272
273                 // Tag test_component_icon
274                 if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_icon) )
275                   _aModule.icon = aContent;
276
277                 // Tag test_component_version
278                 if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_version) )
279                   _aModule.version = aContent;
280
281                 // Tag test_component_comment
282                 if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_comment) )
283                   _aModule.comment = aContent;
284
285                 // Tag test_constraint
286                 if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_constraint) )
287                   _aModule.constraint = aContent;
288                 
289                 // Process tag test_interface_list:
290                 if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_interface_list) ) {
291
292                   // Form an interface list for the component
293                   xmlNodePtr aSubNode = aComponentSubNode->xmlChildrenNode;
294                   while(aSubNode != NULL) {
295                     // Tag test_interface_name
296                     if ( !xmlStrcmp(aSubNode->name, (const xmlChar*)test_interface_name) )
297                       _aInterface.name = (const char*)aSubNode->content;
298                     
299                     // Tag test_service_list
300                     if ( !xmlStrcmp(aSubNode->name, (const xmlChar*)test_service_list) ) {
301                       // Form a service list for the interface
302                       xmlNodePtr aCompServiceNode = aSubNode->xmlChildrenNode;
303                       while(aCompServiceNode != NULL) {
304                         // Tag test_service
305                         if ( !xmlStrcmp(aCompServiceNode->name, (const xmlChar*)test_interface_name) ) {
306                           xmlNodePtr aCompServiceSubNode = aCompServiceNode->xmlChildrenNode;
307                           while(aCompServiceSubNode != NULL) {
308                             // Tag test_service_name
309                             if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_service_name) )
310                               _aService.name = (const char*)aCompServiceSubNode->content;
311
312                             // Tag test_defaultservice
313                             if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_defaultservice) )
314                               _aService.byDefault = (const char*)aCompServiceSubNode->content;
315
316                             // Tag test_typeofnode
317                             if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_typeofnode) )
318                               _aService.typeOfNode = (const char*)aCompServiceSubNode->content;
319
320                             // Tag test_inParameter_list
321                             if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_inParameter_list) ) {
322                               xmlNodePtr aParamNode = aCompServiceSubNode->xmlChildrenNode;
323                               while(aParamNode != NULL) {
324                                 
325                                 // Tag test_inParameter
326                                 if (xmlStrcmp(aParamNode->name, (const xmlChar*)test_inParameter)) {
327                                   aParamNode = aParamNode->next;
328                                   continue;
329                                 }
330                                 
331                                 xmlNodePtr aParamItemNode = aParamNode->xmlChildrenNode;
332                                 while(aParamItemNode != NULL) {
333
334                                   // Tag test_inParameter_name
335                                   if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_inParameter_name) )
336                                     _inParam.name = (const char*)aParamItemNode->content;
337
338                                   // Tag test_inParameter_type
339                                   if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_inParameter_type) )
340                                     _inParam.type = (const char*)aParamItemNode->content;
341                                   
342                                   aParamItemNode = aParamItemNode->next;
343                                 }
344                                 
345                                 _inParamList.push_back(_inParam) ; 
346         
347                                 // Empty temporary structures
348                                 _inParam.type = "";
349                                 _inParam.name = "";
350
351                                 aParamNode = aParamNode->next;
352                               }
353                               
354                               _aService.inParameters = _inParamList;
355                               _inParamList.resize(0);
356                             }
357
358                             // Tag test_outParameter_list
359                             if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_outParameter_list) ) {
360                               xmlNodePtr aParamNode = aCompServiceSubNode->xmlChildrenNode;
361                               while(aParamNode != NULL) {
362                                 
363                                 // Tag test_outParameter
364                                 if (xmlStrcmp(aParamNode->name, (const xmlChar*)test_outParameter)) {
365                                   aParamNode = aParamNode->next;
366                                   continue;
367                                 }
368                                 
369                                 xmlNodePtr aParamItemNode = aParamNode->xmlChildrenNode;
370                                 while(aParamItemNode != NULL) {
371
372                                   // Tag test_outParameter_name
373                                   if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_outParameter_name) )
374                                     _outParam.name = (const char*)aParamItemNode->content;
375
376                                   // Tag test_outParameter_type
377                                   if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_outParameter_type) )
378                                     _outParam.type = (const char*)aParamItemNode->content;
379                                   
380                                   aParamItemNode = aParamItemNode->next;
381                                 }
382                                 
383                                 _outParamList.push_back(_outParam) ; 
384         
385                                 // Empty temporary structures
386                                 _outParam.type = "";
387                                 _outParam.name = "";
388
389                                 aParamNode = aParamNode->next;
390                               }
391                               
392                               _aService.outParameters = _outParamList;
393                               _outParamList.resize(0);
394                             }
395
396                             //@ Tag test_inDataStreamParameter_list
397                             if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_inDataStreamParameter_list) ) {
398                               xmlNodePtr aParamNode = aCompServiceSubNode->xmlChildrenNode;
399                               while(aParamNode != NULL) {
400                                 
401                                 // Tag test_inDataStreamParameter
402                                 if (xmlStrcmp(aParamNode->name, (const xmlChar*)test_inDataStreamParameter)) {
403                                   aParamNode = aParamNode->next;
404                                   continue;
405                                 }
406                                 
407                                 xmlNodePtr aParamItemNode = aParamNode->xmlChildrenNode;
408                                 while(aParamItemNode != NULL) {
409
410                                   // Tag test_inDataStreamParameter_name
411                                   if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_inDataStreamParameter_name) )
412                                     _inDataStreamParam.name = (const char*)aParamItemNode->content;
413
414                                   // Tag test_inDataStreamParameter_type
415                                   if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_inDataStreamParameter_type) )
416                                     _inDataStreamParam.type = (const char*)aParamItemNode->content;
417
418                                   // Tag test_inDataStreamParameter_dependency
419                                   if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_inDataStreamParameter_dependency) )
420                                     _inDataStreamParam.dependency = (const char*)aParamItemNode->content;
421                                   
422                                   aParamItemNode = aParamItemNode->next;
423                                 }
424                                 
425                                 _inDataStreamParamList.push_back(_inDataStreamParam) ; 
426         
427                                 // Empty temporary structures
428                                 _inDataStreamParam.type = "";
429                                 _inDataStreamParam.name = "";
430                                 _inDataStreamParam.dependency = "";
431
432                                 aParamNode = aParamNode->next;
433                               }
434                               
435                               _aService.inDataStreamParameters = _inDataStreamParamList;
436                               _inDataStreamParamList.resize(0);
437                             }
438                             
439                             // Tag test_outDataStreamParameter_list
440                             if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_outDataStreamParameter_list) ) {
441                               xmlNodePtr aParamNode = aCompServiceSubNode->xmlChildrenNode;
442                               while(aParamNode != NULL) {
443                                 
444                                 // Tag test_outDataStreamParameter
445                                 if (xmlStrcmp(aParamNode->name, (const xmlChar*)test_outDataStreamParameter)) {
446                                   aParamNode = aParamNode->next;
447                                   continue;
448                                 }
449                                 
450                                 xmlNodePtr aParamItemNode = aParamNode->xmlChildrenNode;
451                                 while(aParamItemNode != NULL) {
452
453                                   // Tag test_outDataStreamParameter_name
454                                   if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_outDataStreamParameter_name) )
455                                     _outDataStreamParam.name = (const char*)aParamItemNode->content;
456
457                                   // Tag test_outDataStreamParameter_type
458                                   if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_outDataStreamParameter_type) )
459                                     _outDataStreamParam.type = (const char*)aParamItemNode->content;
460
461                                   // Tag test_outDataStreamParameter_dependency
462                                   if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_outDataStreamParameter_dependency) )
463                                     _outDataStreamParam.dependency = (const char*)aParamItemNode->content;
464                                   
465                                   aParamItemNode = aParamItemNode->next;
466                                 }
467                                 
468                                 _outDataStreamParamList.push_back(_outDataStreamParam) ; 
469         
470                                 // Empty temporary structures
471                                 _outDataStreamParam.type = "";
472                                 _outDataStreamParam.name = "";
473                                 _outDataStreamParam.dependency = "";
474
475                                 aParamNode = aParamNode->next;
476                               }
477                               
478                               _aService.outDataStreamParameters = _outDataStreamParamList;
479                               _outDataStreamParamList.resize(0);
480                             }
481                             
482                             aCompServiceSubNode = aCompServiceSubNode->next;
483                           }
484
485
486                           // Put formed service into the list
487                           _serviceList.push_back(_aService);
488
489                           // Empty temporary structures
490                           _aService.name = "";
491                           _aService.typeOfNode = 1;
492                           _aService.inParameters.resize(0);
493                           _aService.outParameters.resize(0);
494                           _aService.inDataStreamParameters.resize(0);
495                           _aService.outDataStreamParameters.resize(0);
496                         }
497                         
498                         aCompServiceNode = aCompServiceNode->next;
499                       }
500                       
501                       _aInterface.services = _serviceList ;
502                       
503                       // Empty temporary structures
504                       _serviceList.resize(0);
505                       _interfaceList.push_back(_aInterface);  
506                       _aInterface.name ="";    
507                       _aInterface.services.resize(0);
508                     }
509                     
510                     aSubNode = aSubNode->next;
511                   }
512                   
513                   _aModule.interfaces = _interfaceList ;
514                   _interfaceList.resize(0);
515                 }
516                 
517
518                 aComponentSubNode = aComponentSubNode->next;
519               }
520             
521               
522               aComponentNode = aComponentNode->next;
523             }
524         }
525
526       
527       aCurNode = aCurNode->next;
528     }
529 }