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);
144 aCurNode = aCurNode->xmlChildrenNode;
146 // Processing the document nodes
147 while(aCurNode != NULL)
149 // Process path prefix list (tag test_path_prefix_list)
150 if ( !xmlStrcmp(aCurNode->name,(const xmlChar*)test_path_prefix_list) )
152 xmlNodePtr aCurSubNode = aCurNode->xmlChildrenNode;
153 while(aCurSubNode != NULL)
155 // Forming a PathPrefix structure (tag test_path_prefix)
156 if ( xmlStrcmp(aCurSubNode->name, (const xmlChar*)test_path_prefix) ) {
157 aCurSubNode = aCurSubNode->next;
161 xmlNodePtr aCurSubSubNode = aCurSubNode->xmlChildrenNode;
162 while(aCurSubSubNode != NULL)
164 // Tag test_path_prefix_name
165 if ( !xmlStrcmp(aCurSubSubNode->name, (const xmlChar*)test_path_prefix_name) )
166 _pathPrefix.path = (const char*)aCurSubSubNode->content;
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);
176 aComputerNode = aComputerNode->next;
180 aCurSubSubNode = aCurSubSubNode->next;
183 _pathList.push_back(_pathPrefix);
184 _pathPrefix.listOfComputer.resize(0);
186 aCurSubNode = aCurSubNode->next;
190 //@ Process list of components (tag test_component_list)
191 if ( !xmlStrcmp(aCurNode->name,(const xmlChar*)test_component_list) )
193 xmlNodePtr aComponentNode = aCurNode->xmlChildrenNode;
194 while(aComponentNode != NULL)
196 // Do not process tags differ from test_component here
197 if ( xmlStrcmp(aComponentNode->name, (const xmlChar*)test_component) ) {
198 aComponentNode = aComponentNode->next;
202 // Component identification
204 // Empty temporary structures
206 _aModule.constraint = "";
208 _aModule.interfaces.resize(0);
210 xmlNodePtr aComponentSubNode = aComponentNode->xmlChildrenNode;
211 while(aComponentSubNode != NULL) {
213 std::string aContent = (const char*)aComponentSubNode->content;
215 // Tag test_component_name
216 if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_name) )
217 _aModule.name = aContent;
219 // Tag test_component_username
220 if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_username) )
221 _aModule.username = aContent;
223 // Tag test_component_type
224 if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_type) ) {
225 std::string aType = aContent;
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 ;
261 // If it'not in all theses cases, the type is affected to OTHER
262 _aModule.type = OTHER ;
265 // Tag test_component_multistudy
266 if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_multistudy) )
267 _aModule.multistudy = atoi( aContent.c_str() );
269 // Tag test_component_impltype
270 if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_impltype) )
271 _aModule.implementationType = atoi(aContent.c_str());
273 // Tag test_component_icon
274 if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_icon) )
275 _aModule.icon = aContent;
277 // Tag test_component_version
278 if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_version) )
279 _aModule.version = aContent;
281 // Tag test_component_comment
282 if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_comment) )
283 _aModule.comment = aContent;
285 // Tag test_constraint
286 if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_constraint) )
287 _aModule.constraint = aContent;
289 // Process tag test_interface_list:
290 if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_interface_list) ) {
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;
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) {
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;
312 // Tag test_defaultservice
313 if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_defaultservice) )
314 _aService.byDefault = (const char*)aCompServiceSubNode->content;
316 // Tag test_typeofnode
317 if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_typeofnode) )
318 _aService.typeOfNode = (const char*)aCompServiceSubNode->content;
320 // Tag test_inParameter_list
321 if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_inParameter_list) ) {
322 xmlNodePtr aParamNode = aCompServiceSubNode->xmlChildrenNode;
323 while(aParamNode != NULL) {
325 // Tag test_inParameter
326 if (xmlStrcmp(aParamNode->name, (const xmlChar*)test_inParameter)) {
327 aParamNode = aParamNode->next;
331 xmlNodePtr aParamItemNode = aParamNode->xmlChildrenNode;
332 while(aParamItemNode != NULL) {
334 // Tag test_inParameter_name
335 if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_inParameter_name) )
336 _inParam.name = (const char*)aParamItemNode->content;
338 // Tag test_inParameter_type
339 if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_inParameter_type) )
340 _inParam.type = (const char*)aParamItemNode->content;
342 aParamItemNode = aParamItemNode->next;
345 _inParamList.push_back(_inParam) ;
347 // Empty temporary structures
351 aParamNode = aParamNode->next;
354 _aService.inParameters = _inParamList;
355 _inParamList.resize(0);
358 // Tag test_outParameter_list
359 if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_outParameter_list) ) {
360 xmlNodePtr aParamNode = aCompServiceSubNode->xmlChildrenNode;
361 while(aParamNode != NULL) {
363 // Tag test_outParameter
364 if (xmlStrcmp(aParamNode->name, (const xmlChar*)test_outParameter)) {
365 aParamNode = aParamNode->next;
369 xmlNodePtr aParamItemNode = aParamNode->xmlChildrenNode;
370 while(aParamItemNode != NULL) {
372 // Tag test_outParameter_name
373 if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_outParameter_name) )
374 _outParam.name = (const char*)aParamItemNode->content;
376 // Tag test_outParameter_type
377 if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_outParameter_type) )
378 _outParam.type = (const char*)aParamItemNode->content;
380 aParamItemNode = aParamItemNode->next;
383 _outParamList.push_back(_outParam) ;
385 // Empty temporary structures
389 aParamNode = aParamNode->next;
392 _aService.outParameters = _outParamList;
393 _outParamList.resize(0);
396 //@ Tag test_inDataStreamParameter_list
397 if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_inDataStreamParameter_list) ) {
398 xmlNodePtr aParamNode = aCompServiceSubNode->xmlChildrenNode;
399 while(aParamNode != NULL) {
401 // Tag test_inDataStreamParameter
402 if (xmlStrcmp(aParamNode->name, (const xmlChar*)test_inDataStreamParameter)) {
403 aParamNode = aParamNode->next;
407 xmlNodePtr aParamItemNode = aParamNode->xmlChildrenNode;
408 while(aParamItemNode != NULL) {
410 // Tag test_inDataStreamParameter_name
411 if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_inDataStreamParameter_name) )
412 _inDataStreamParam.name = (const char*)aParamItemNode->content;
414 // Tag test_inDataStreamParameter_type
415 if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_inDataStreamParameter_type) )
416 _inDataStreamParam.type = (const char*)aParamItemNode->content;
418 // Tag test_inDataStreamParameter_dependency
419 if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_inDataStreamParameter_dependency) )
420 _inDataStreamParam.dependency = (const char*)aParamItemNode->content;
422 aParamItemNode = aParamItemNode->next;
425 _inDataStreamParamList.push_back(_inDataStreamParam) ;
427 // Empty temporary structures
428 _inDataStreamParam.type = "";
429 _inDataStreamParam.name = "";
430 _inDataStreamParam.dependency = "";
432 aParamNode = aParamNode->next;
435 _aService.inDataStreamParameters = _inDataStreamParamList;
436 _inDataStreamParamList.resize(0);
439 // Tag test_outDataStreamParameter_list
440 if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_outDataStreamParameter_list) ) {
441 xmlNodePtr aParamNode = aCompServiceSubNode->xmlChildrenNode;
442 while(aParamNode != NULL) {
444 // Tag test_outDataStreamParameter
445 if (xmlStrcmp(aParamNode->name, (const xmlChar*)test_outDataStreamParameter)) {
446 aParamNode = aParamNode->next;
450 xmlNodePtr aParamItemNode = aParamNode->xmlChildrenNode;
451 while(aParamItemNode != NULL) {
453 // Tag test_outDataStreamParameter_name
454 if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_outDataStreamParameter_name) )
455 _outDataStreamParam.name = (const char*)aParamItemNode->content;
457 // Tag test_outDataStreamParameter_type
458 if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_outDataStreamParameter_type) )
459 _outDataStreamParam.type = (const char*)aParamItemNode->content;
461 // Tag test_outDataStreamParameter_dependency
462 if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_outDataStreamParameter_dependency) )
463 _outDataStreamParam.dependency = (const char*)aParamItemNode->content;
465 aParamItemNode = aParamItemNode->next;
468 _outDataStreamParamList.push_back(_outDataStreamParam) ;
470 // Empty temporary structures
471 _outDataStreamParam.type = "";
472 _outDataStreamParam.name = "";
473 _outDataStreamParam.dependency = "";
475 aParamNode = aParamNode->next;
478 _aService.outDataStreamParameters = _outDataStreamParamList;
479 _outDataStreamParamList.resize(0);
482 aCompServiceSubNode = aCompServiceSubNode->next;
486 // Put formed service into the list
487 _serviceList.push_back(_aService);
489 // Empty temporary structures
491 _aService.typeOfNode = 1;
492 _aService.inParameters.resize(0);
493 _aService.outParameters.resize(0);
494 _aService.inDataStreamParameters.resize(0);
495 _aService.outDataStreamParameters.resize(0);
498 aCompServiceNode = aCompServiceNode->next;
501 _aInterface.services = _serviceList ;
503 // Empty temporary structures
504 _serviceList.resize(0);
505 _interfaceList.push_back(_aInterface);
506 _aInterface.name ="";
507 _aInterface.services.resize(0);
510 aSubNode = aSubNode->next;
513 _aModule.interfaces = _interfaceList ;
514 _interfaceList.resize(0);
518 aComponentSubNode = aComponentSubNode->next;
522 aComponentNode = aComponentNode->next;
527 aCurNode = aCurNode->next;