1 // SALOME ModuleCatalog : implementation of ModuleCatalog server which parsers xml description of modules
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SALOME_ModuleCatalog_Handler.cxx
25 // Author : Estelle Deville
29 #define WRITE_CATA_COMPONENT
31 #include "SALOME_ModuleCatalog_Handler.hxx"
32 #include "SALOME_ModuleCatalog_Parser_IO.hxx"
33 #include "utilities.h"
39 static int MYDEBUG = 0;
41 static int MYDEBUG = 0;
44 //----------------------------------------------------------------------
45 // Function : SALOME_ModuleCatalog_Handler
46 // Purpose : Constructor
47 //----------------------------------------------------------------------
48 SALOME_ModuleCatalog_Handler::SALOME_ModuleCatalog_Handler()
50 if(MYDEBUG) BEGIN_OF("SALOME_ModuleCatalog_Handler");
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" ;
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";
69 test_interface_name = "component-interface-name" ;
71 test_service_name = "service-name";
72 test_defaultservice = "service-by-default";
74 test_typeofnode = "type-of-node";
76 test_inParameter_type = "inParameter-type";
77 test_inParameter_name = "inParameter-name";
78 test_inParameter = "inParameter";
79 test_inParameter_list = "inParameter-list";
81 test_outParameter_type = "outParameter-type";
82 test_outParameter_name = "outParameter-name";
83 test_outParameter = "outParameter";
84 test_outParameter_list = "outParameter-list";
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";
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";
98 test_service = "component-service";
99 test_service_list = "component-service-list";
100 test_interface_list = "component-interface-list";
102 test_constraint = "constraint";
104 test_component_list = "component-list";
105 test_component="component";
107 if(MYDEBUG) END_OF("SALOME_ModuleCatalog_Handler");
110 //----------------------------------------------------------------------
111 // Function : ~SALOME_ModuleCatalog_Handler
112 // Purpose : Destructor
113 //----------------------------------------------------------------------
114 SALOME_ModuleCatalog_Handler::~SALOME_ModuleCatalog_Handler()
116 if(MYDEBUG) BEGIN_OF("~SALOME_ModuleCatalog_Handler()")
117 if(MYDEBUG) END_OF("~SALOME_ModuleCatalog_Handler()")
121 //=============================================================================
123 * Processes XML document and fills the list of modules
125 //=============================================================================
127 void SALOME_ModuleCatalog_Handler::ProcessXmlDocument(xmlDocPtr theDoc)
129 if(MYDEBUG) MESSAGE("Begin parse document");
130 // Empty the private elements
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);
141 // Get the document root node
142 xmlNodePtr aCurNode = xmlDocGetRootElement(theDoc);
143 aCurNode = aCurNode->xmlChildrenNode;
145 // Processing the document nodes
146 while(aCurNode != NULL)
148 // Process path prefix list (tag test_path_prefix_list)
149 if ( !xmlStrcmp(aCurNode->name,(const xmlChar*)test_path_prefix_list) )
151 xmlNodePtr aCurSubNode = aCurNode->xmlChildrenNode;
152 while(aCurSubNode != NULL)
154 // Forming a PathPrefix structure (tag test_path_prefix)
155 if ( xmlStrcmp(aCurSubNode->name, (const xmlChar*)test_path_prefix) ) {
156 aCurSubNode = aCurSubNode->next;
160 xmlNodePtr aCurSubSubNode = aCurSubNode->xmlChildrenNode;
161 while(aCurSubSubNode != NULL)
163 // Tag test_path_prefix_name
164 if ( !xmlStrcmp(aCurSubSubNode->name, (const xmlChar*)test_path_prefix_name) ) {
165 xmlChar* aPath = xmlNodeGetContent(aCurSubSubNode);
167 _pathPrefix.path = (const char*)aPath;
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);
185 aComputerNode = aComputerNode->next;
189 aCurSubSubNode = aCurSubSubNode->next;
192 _pathList.push_back(_pathPrefix);
193 _pathPrefix.listOfComputer.resize(0);
195 aCurSubNode = aCurSubNode->next;
199 //@ Process list of components (tag test_component_list)
200 if ( !xmlStrcmp(aCurNode->name,(const xmlChar*)test_component_list) )
202 xmlNodePtr aComponentNode = aCurNode->xmlChildrenNode;
203 while (aComponentNode != NULL)
205 // Do not process tags differ from test_component here
206 if ( xmlStrcmp(aComponentNode->name, (const xmlChar*)test_component) ) {
207 aComponentNode = aComponentNode->next;
211 // Component identification
213 // Empty temporary structures
215 _aModule.constraint = "";
217 _aModule.interfaces.resize(0);
219 xmlNodePtr aComponentSubNode = aComponentNode->xmlChildrenNode;
220 while(aComponentSubNode != NULL)
222 xmlChar* aNodeContent = xmlNodeGetContent(aComponentSubNode);
224 if (aNodeContent == NULL) {
225 aComponentSubNode = aComponentSubNode->next;
229 std::string aContent = (const char*)aNodeContent;
231 // Tag test_component_name
232 if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_name) )
233 _aModule.name = aContent;
235 // Tag test_component_username
236 if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_username) )
237 _aModule.username = aContent;
239 // Tag test_component_type
240 if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_type) ) {
241 std::string aType = aContent;
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 ;
277 // If it'not in all theses cases, the type is affected to OTHER
278 _aModule.type = OTHER ;
281 // Tag test_component_multistudy
282 if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_multistudy) )
283 _aModule.multistudy = atoi( aContent.c_str() );
285 // Tag test_component_impltype
286 if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_impltype) )
287 _aModule.implementationType = atoi(aContent.c_str());
289 // Tag test_component_icon
290 if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_icon) )
291 _aModule.icon = aContent;
293 // Tag test_component_version
294 if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_version) )
295 _aModule.version = aContent;
297 // Tag test_component_comment
298 if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_comment) )
299 _aModule.comment = aContent;
301 // Tag test_constraint
302 if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_constraint) )
303 _aModule.constraint = aContent;
305 xmlFree(aNodeContent);
307 // Process tag test_interface_list:
308 if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_interface_list) ) {
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);
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) {
328 if ( !xmlStrcmp(aCompServiceNode->name, (const xmlChar*)test_interface_name) ) {
329 xmlNodePtr aCompServiceSubNode = aCompServiceNode->xmlChildrenNode;
330 while(aCompServiceSubNode != NULL)
332 xmlChar* aCompServiceData = xmlNodeGetContent(aCompServiceSubNode);
334 if ( aCompServiceData != NULL)
336 // Tag test_service_name
337 if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_service_name) )
338 _aService.name = (const char*)aCompServiceData;
340 // Tag test_defaultservice
341 if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_defaultservice) )
342 _aService.byDefault = (const char*)aCompServiceData;
344 // Tag test_typeofnode
345 if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_typeofnode) )
346 _aService.typeOfNode = (const char*)aCompServiceData;
348 xmlFree(aCompServiceData);
351 // Tag test_inParameter_list
352 if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_inParameter_list) ) {
353 xmlNodePtr aParamNode = aCompServiceSubNode->xmlChildrenNode;
354 while (aParamNode != NULL)
356 // Tag test_inParameter
357 if (xmlStrcmp(aParamNode->name, (const xmlChar*)test_inParameter)) {
358 aParamNode = aParamNode->next;
362 xmlNodePtr aParamItemNode = aParamNode->xmlChildrenNode;
363 while (aParamItemNode != NULL)
365 xmlChar* aParamData = xmlNodeGetContent(aParamItemNode);
367 if (aParamData != NULL)
369 // Tag test_inParameter_name
370 if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_inParameter_name) )
371 _inParam.name = (const char*)aParamData;
373 // Tag test_inParameter_type
374 if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_inParameter_type) )
375 _inParam.type = (const char*)aParamData;
380 aParamItemNode = aParamItemNode->next;
383 _inParamList.push_back(_inParam) ;
385 // Empty temporary structures
389 aParamNode = aParamNode->next;
392 _aService.inParameters = _inParamList;
393 _inParamList.resize(0);
396 // Tag test_outParameter_list
397 if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_outParameter_list) ) {
398 xmlNodePtr aParamNode = aCompServiceSubNode->xmlChildrenNode;
399 while (aParamNode != NULL)
401 // Tag test_outParameter
402 if (xmlStrcmp(aParamNode->name, (const xmlChar*)test_outParameter)) {
403 aParamNode = aParamNode->next;
407 xmlNodePtr aParamItemNode = aParamNode->xmlChildrenNode;
408 while (aParamItemNode != NULL)
410 xmlChar* anOutParamData = xmlNodeGetContent(aParamItemNode);
412 if (anOutParamData != NULL)
414 // Tag test_outParameter_name
415 if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_outParameter_name) )
416 _outParam.name = (const char*)anOutParamData;
418 // Tag test_outParameter_type
419 if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_outParameter_type) )
420 _outParam.type = (const char*)anOutParamData;
422 xmlFree(anOutParamData);
425 aParamItemNode = aParamItemNode->next;
428 _outParamList.push_back(_outParam) ;
430 // Empty temporary structures
434 aParamNode = aParamNode->next;
437 _aService.outParameters = _outParamList;
438 _outParamList.resize(0);
441 //@ Tag test_inDataStreamParameter_list
442 if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_inDataStreamParameter_list) )
444 xmlNodePtr aParamNode = aCompServiceSubNode->xmlChildrenNode;
445 while (aParamNode != NULL)
447 // Tag test_inDataStreamParameter
448 if (xmlStrcmp(aParamNode->name, (const xmlChar*)test_inDataStreamParameter)) {
449 aParamNode = aParamNode->next;
453 xmlNodePtr aParamItemNode = aParamNode->xmlChildrenNode;
454 while (aParamItemNode != NULL)
456 xmlChar* inDataStreamParamData = xmlNodeGetContent(aParamItemNode);
458 if (inDataStreamParamData != NULL)
460 // Tag test_inDataStreamParameter_name
461 if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_inDataStreamParameter_name) )
462 _inDataStreamParam.name = (const char*)inDataStreamParamData;
464 // Tag test_inDataStreamParameter_type
465 if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_inDataStreamParameter_type) )
466 _inDataStreamParam.type = (const char*)inDataStreamParamData;
468 // Tag test_inDataStreamParameter_dependency
469 if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_inDataStreamParameter_dependency) )
470 _inDataStreamParam.dependency = (const char*)inDataStreamParamData;
472 xmlFree(inDataStreamParamData);
475 aParamItemNode = aParamItemNode->next;
478 _inDataStreamParamList.push_back(_inDataStreamParam) ;
480 // Empty temporary structures
481 _inDataStreamParam.type = "";
482 _inDataStreamParam.name = "";
483 _inDataStreamParam.dependency = "";
485 aParamNode = aParamNode->next;
488 _aService.inDataStreamParameters = _inDataStreamParamList;
489 _inDataStreamParamList.resize(0);
492 // Tag test_outDataStreamParameter_list
493 if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_outDataStreamParameter_list) )
495 xmlNodePtr aParamNode = aCompServiceSubNode->xmlChildrenNode;
496 while (aParamNode != NULL)
498 // Tag test_outDataStreamParameter
499 if (xmlStrcmp(aParamNode->name, (const xmlChar*)test_outDataStreamParameter)) {
500 aParamNode = aParamNode->next;
504 xmlNodePtr aParamItemNode = aParamNode->xmlChildrenNode;
505 while (aParamItemNode != NULL)
507 xmlChar* outDataStreamParamData = xmlNodeGetContent(aParamItemNode);
509 if (outDataStreamParamData != NULL)
511 // Tag test_outDataStreamParameter_name
512 if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_outDataStreamParameter_name) )
513 _outDataStreamParam.name = (const char*)outDataStreamParamData;
515 // Tag test_outDataStreamParameter_type
516 if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_outDataStreamParameter_type) )
517 _outDataStreamParam.type = (const char*)outDataStreamParamData;
519 // Tag test_outDataStreamParameter_dependency
520 if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_outDataStreamParameter_dependency) )
521 _outDataStreamParam.dependency = (const char*)outDataStreamParamData;
523 xmlFree(outDataStreamParamData);
526 aParamItemNode = aParamItemNode->next;
529 _outDataStreamParamList.push_back(_outDataStreamParam) ;
531 // Empty temporary structures
532 _outDataStreamParam.type = "";
533 _outDataStreamParam.name = "";
534 _outDataStreamParam.dependency = "";
536 aParamNode = aParamNode->next;
539 _aService.outDataStreamParameters = _outDataStreamParamList;
540 _outDataStreamParamList.resize(0);
543 aCompServiceSubNode = aCompServiceSubNode->next;
546 // Put formed service into the list
547 _serviceList.push_back(_aService);
549 // Empty temporary structures
551 _aService.typeOfNode = 1;
552 _aService.inParameters.resize(0);
553 _aService.outParameters.resize(0);
554 _aService.inDataStreamParameters.resize(0);
555 _aService.outDataStreamParameters.resize(0);
558 aCompServiceNode = aCompServiceNode->next;
561 _aInterface.services = _serviceList ;
563 // Empty temporary structures
564 _serviceList.resize(0);
565 _interfaceList.push_back(_aInterface);
566 _aInterface.name ="";
567 _aInterface.services.resize(0);
570 aSubNode = aSubNode->next;
573 _aModule.interfaces = _interfaceList ;
574 _interfaceList.resize(0);
577 aComponentSubNode = aComponentSubNode->next;
580 _moduleList.push_back(_aModule);
582 aComponentNode = aComponentNode->next;
586 aCurNode = aCurNode->next;