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_path_prefix = "path-prefix" ;
58 test_component_name = "component-name";
59 test_component_username = "component-username";
60 test_component_type = "component-type" ;
61 test_component_multistudy = "component-multistudy";
62 test_component_icon = "component-icone" ;
63 test_component_impltype = "component-impltype";
64 test_component_version = "component-version";
65 test_component_comment = "component-comment";
67 test_interface_name = "component-interface-name" ;
69 test_service_name = "service-name";
70 test_defaultservice = "service-by-default";
72 test_typeofnode = "type-of-node";
74 test_inParameter_type = "inParameter-type";
75 test_inParameter_name = "inParameter-name";
76 test_inParameter = "inParameter";
77 test_inParameter_list = "inParameter-list";
79 test_outParameter_type = "outParameter-type";
80 test_outParameter_name = "outParameter-name";
81 test_outParameter = "outParameter";
82 test_outParameter_list = "outParameter-list";
84 test_inDataStreamParameter_type = "inParameter-type";
85 test_inDataStreamParameter_name = "inParameter-name";
86 test_inDataStreamParameter_dependency = "inParameter-dependency";
87 test_inDataStreamParameter = "inParameter";
88 test_inDataStreamParameter_list = "DataStream-list";
90 test_outDataStreamParameter_type = "outParameter-type";
91 test_outDataStreamParameter_name = "outParameter-name";
92 test_outDataStreamParameter_dependency = "outParameter-dependency";
93 test_outDataStreamParameter = "outParameter";
94 test_outDataStreamParameter_list = "DataStream-list";
96 test_service = "component-service";
97 test_service_list = "component-service-list";
98 test_interface_list = "component-interface-list";
100 test_constraint = "constraint";
102 test_component="component";
104 if(MYDEBUG) END_OF("SALOME_ModuleCatalog_Handler");
107 //----------------------------------------------------------------------
108 // Function : ~SALOME_ModuleCatalog_Handler
109 // Purpose : Destructor
110 //----------------------------------------------------------------------
111 SALOME_ModuleCatalog_Handler::~SALOME_ModuleCatalog_Handler()
113 if(MYDEBUG) BEGIN_OF("~SALOME_ModuleCatalog_Handler()")
114 if(MYDEBUG) END_OF("~SALOME_ModuleCatalog_Handler()")
117 //----------------------------------------------------------------------
118 // Function : startDocument
119 // Purpose : overload handler function
120 //----------------------------------------------------------------------
121 bool SALOME_ModuleCatalog_Handler::startDocument()
123 if(MYDEBUG) MESSAGE("Begin parse document");
124 // Empty the private elements
126 _pathPrefix.listOfComputer.resize(0);
127 _serviceList.resize(0);
128 _interfaceList.resize(0);
129 _moduleList.resize(0);
130 _inDataStreamParamList.resize(0);
131 _outDataStreamParamList.resize(0);
132 _inParamList.resize(0);
133 _outParamList.resize(0);
137 //----------------------------------------------------------------------
138 // Function : startElement
139 // Purpose : overload handler function
140 //----------------------------------------------------------------------
141 bool SALOME_ModuleCatalog_Handler::startElement(const QString&,
143 const QString& qName,
144 const QXmlAttributes& atts)
146 _xml_pile.push(qName);
151 //----------------------------------------------------------------------
152 // Function : endElement
153 // Purpose : overload handler function
154 //----------------------------------------------------------------------
155 bool SALOME_ModuleCatalog_Handler::endElement(const QString&,
157 const QString& qName)
159 QString parent, grandparent;
161 if (!_xml_pile.empty()) {
162 parent = _xml_pile.top();
164 if (!_xml_pile.empty()) grandparent = _xml_pile.top();
165 _xml_pile.push(parent);
170 // tag test_path_prefix_name
171 if((qName.compare(test_path_prefix_name)==0)) {
172 _pathPrefix.path = content;
176 // tag test_computer_name
177 if((qName.compare(test_computer_name)==0)) {
178 _pathPrefix.listOfComputer.push_back(content);
182 // tag test_path_prefix
183 if((qName.compare(test_path_prefix)==0)) {
184 _pathList.push_back(_pathPrefix);
185 _pathPrefix.listOfComputer.resize(0);
189 // Component identification
191 // tag test_component_name
192 if((qName.compare(test_component_name)==0)) {
193 _aModule.name = content ;
197 // tag test_component_username
198 if((qName.compare(test_component_username)==0)) {
199 _aModule.username = content ;
203 // tag test_component_type
204 if((qName.compare(test_component_type)==0))
206 if ((content.compare("MESH") == 0) ||
207 (content.compare("Mesh") == 0) ||
208 (content.compare("mesh") == 0))
209 _aModule.type = MESH ;
210 else if((content.compare("MED") == 0) ||
211 (content.compare("Med") == 0) ||
212 (content.compare("med") == 0))
213 _aModule.type = Med ;
214 else if((content.compare("GEOM") == 0) ||
215 (content.compare("Geom") == 0) ||
216 (content.compare("geom") == 0))
217 _aModule.type = GEOM ;
218 else if((content.compare("SOLVER") == 0) ||
219 (content.compare("Solver") == 0) ||
220 (content.compare("solver") == 0))
221 _aModule.type = SOLVER ;
222 else if((content.compare("SUPERV") == 0) ||
223 (content.compare("Superv") == 0) ||
224 (content.compare("Supervision") == 0) ||
225 (content.compare("superv") == 0))
226 _aModule.type = SUPERV ;
227 else if((content.compare("DATA") == 0) ||
228 (content.compare("Data") == 0) ||
229 (content.compare("data") == 0))
230 _aModule.type = DATA ;
231 else if((content.compare("VISU") == 0) ||
232 (content.compare("Visu") == 0) ||
233 (content.compare("visu") == 0))
234 _aModule.type = VISU ;
235 else if((content.compare("OTHER") == 0) ||
236 (content.compare("Other") == 0) ||
237 (content.compare("other") == 0))
238 _aModule.type = OTHER ;
240 // If it'not in all theses cases, the type is affected to OTHER
241 _aModule.type = OTHER ;
245 // tag test_component_multistudy
246 if((qName.compare(test_component_multistudy)==0)) {
247 _aModule.multistudy = atoi(content.c_str()) ;
251 // tag test_component_impltype
252 if((qName.compare(QString(test_component_impltype))==0))
253 _aModule.implementationType = atoi(content.c_str()) ;
255 // tag test_component_icon
256 if((qName.compare(test_component_icon)==0)) {
257 _aModule.icon = content ;
261 // tag test_component_version
262 if((qName.compare(test_component_version)==0)) {
263 _aModule.version = content ;
267 // tag test_component_comment
268 if((qName.compare(test_component_comment)==0)) {
269 _aModule.comment = content ;
273 // interface identification
275 // tag test_interface_name
276 if ((qName.compare(test_interface_name)==0)) {
277 _aInterface.name = content ;
281 // Service identification
283 // tag test_service_name
284 if ((qName.compare(test_service_name)==0)) {
285 _aService.name = content ;
289 //tag test_defaultservice
290 if ((qName.compare(test_defaultservice)==0)) {
291 _aService.byDefault = atoi(content.c_str()) ;
295 //tag test_typeofnode
296 if((qName.compare(QString(test_typeofnode))==0))
297 _aService.typeOfNode = atoi(content.c_str()) ;
301 // tag test_inDataStreamParameter_type
302 if ((qName.compare(test_inDataStreamParameter_type)==0)) {
303 if (grandparent.compare(test_inDataStreamParameter_list) == 0)
304 _inDataStreamParam.type = content ;
306 _inParam.type = content ;
310 // tag test_inParameter_type
311 if ((qName.compare(test_inParameter_type)==0)) {
312 if (grandparent.compare(test_inDataStreamParameter_list) == 0)
313 _inDataStreamParam.type = content ;
315 _inParam.type = content ;
319 //tag test_inDataStreamParameter_name
320 if ((qName.compare(test_inDataStreamParameter_name)==0)) {
321 if (grandparent.compare(test_inDataStreamParameter_list) == 0)
322 _inDataStreamParam.name = content ;
324 _inParam.name = content ;
328 //tag test_inParameter_name
329 if ((qName.compare(test_inParameter_name)==0)) {
330 if(MYDEBUG) SCRUTE(parent);
331 if(MYDEBUG) SCRUTE(grandparent);
332 if (grandparent.compare(test_inDataStreamParameter_list) == 0)
333 _inDataStreamParam.name = content ;
335 _inParam.name = content ;
339 //tag test_inDataStreamParameter_dependency
340 if ((qName.compare(test_inDataStreamParameter_dependency)==0)) {
341 _inDataStreamParam.dependency = content ;
345 //tag test_inParameter
346 if ((qName.compare(test_inParameter)==0))
348 if (parent.compare(test_inParameter_list)==0) {
350 if(MYDEBUG) MESSAGE("add inParameter : " << _inParam.name);
351 _inParamList.push_back(_inParam) ;
353 // Empty temporary structures
357 else if ((qName.compare(test_inDataStreamParameter)==0)) {
359 if(MYDEBUG) MESSAGE("add inDataStreamParameter : " << _inDataStreamParam.name);
360 _inDataStreamParamList.push_back(_inDataStreamParam) ;
362 // Empty temporary structures
363 _inDataStreamParam.type = "";
364 _inDataStreamParam.name = "";
365 _inDataStreamParam.dependency = "";
370 //tag test_inParameter_list
371 if((qName.compare(test_inParameter_list)==0))
373 if(MYDEBUG) SCRUTE(_inParamList.size());
374 _aService.inParameters = _inParamList;
375 _inParamList.resize(0);
379 //tag test_inDataStreamParameter_list
380 if((qName.compare(test_inDataStreamParameter_list)==0))
382 if(MYDEBUG) SCRUTE(_inDataStreamParamList.size());
383 _aService.inDataStreamParameters = _inDataStreamParamList;
384 _inDataStreamParamList.resize(0);
386 //tag test_outDataStreamParameter_list
387 if((qName.compare(test_outDataStreamParameter_list)==0))
389 if(MYDEBUG) SCRUTE(_outDataStreamParamList.size());
390 _aService.outDataStreamParameters = _outDataStreamParamList;
391 _outDataStreamParamList.resize(0);
398 if(MYDEBUG) SCRUTE(qName);
400 // tag test_outParameter_type
401 if ((qName.compare(test_outParameter_type)==0)) {
402 if (grandparent.compare(test_outDataStreamParameter_list) == 0)
403 _outDataStreamParam.type = content ;
405 _outParam.type = content ;
409 // tag test_outDataStreamParameter_type
410 if ((qName.compare(test_outDataStreamParameter_type)==0)) {
411 if (grandparent.compare(test_outDataStreamParameter_list) == 0)
412 _outDataStreamParam.type = content ;
414 _outParam.type = content ;
418 //tag test_outParameter_name
419 if ((qName.compare(test_outParameter_name)==0)) {
420 if (grandparent.compare(test_outDataStreamParameter_list) == 0)
421 _outDataStreamParam.name = content ;
423 _outParam.name = content ;
427 //tag test_outDataStreamParameter_name
428 if ((qName.compare(test_outDataStreamParameter_name)==0)) {
429 if(MYDEBUG) SCRUTE(grandparent);
430 if(MYDEBUG) SCRUTE(test_outDataStreamParameter_list);
431 if (grandparent.compare(test_outDataStreamParameter_list) == 0)
432 _outDataStreamParam.name = content ;
434 _outParam.name = content ;
438 //tag test_outParameter_dependency
439 if ((qName.compare(test_outDataStreamParameter_dependency)==0)) {
440 _outDataStreamParam.dependency = content ;
444 //tag test_outParameter
445 if ((qName.compare(test_outParameter)==0))
447 if (parent.compare(test_outParameter_list)==0) {
449 if(MYDEBUG) MESSAGE("add outParameter : " << _outParam.name);
450 _outParamList.push_back(_outParam) ;
452 // Empty temporary structures
456 else if ((qName.compare(test_outDataStreamParameter)==0)) {
458 if(MYDEBUG) MESSAGE("add outDataStreamParameter : " << _outDataStreamParam.name);
459 _outDataStreamParamList.push_back(_outDataStreamParam) ;
461 // Empty temporary structures
462 _outDataStreamParam.type = "";
463 _outDataStreamParam.name = "";
464 _outDataStreamParam.dependency = "";
469 //tag test_outParameter_list
470 if((qName.compare(test_outParameter_list)==0))
472 if(MYDEBUG) SCRUTE(_outParamList.size());
473 _aService.outParameters = _outParamList;
474 _outParamList.resize(0);
479 if((qName.compare(test_service)==0))
481 _serviceList.push_back(_aService);
483 // Empty temporary structures
485 _aService.typeOfNode = 1;
486 _aService.inParameters.resize(0);
487 _aService.outParameters.resize(0);
488 _aService.inDataStreamParameters.resize(0);
489 _aService.outDataStreamParameters.resize(0);
492 // tag test_service_list
493 if((qName.compare(test_service_list)==0))
495 _aInterface.services = _serviceList ;
497 // Empty temporary structures
498 _serviceList.resize(0);
499 _interfaceList.push_back(_aInterface);
500 _aInterface.name ="";
501 _aInterface.services.resize(0);
505 //tag test_interface_list
506 if((qName.compare(test_interface_list)==0))
508 _aModule.interfaces = _interfaceList ;
509 _interfaceList.resize(0);
512 //tag test_constraint
513 if((qName.compare(test_constraint)==0))
514 _aModule.constraint = content ;
516 // tag test_component
517 if((qName.compare(test_component)==0))
519 _moduleList.push_back(_aModule) ;
521 // Empty temporary structures
523 _aModule.constraint = "";
525 _aModule.interfaces.resize(0);
531 //----------------------------------------------------------------------
532 // Function : characters
533 // Purpose : overload handler function
534 //----------------------------------------------------------------------
535 bool SALOME_ModuleCatalog_Handler::characters(const QString& chars)
537 content = (const char*)chars ;
541 //----------------------------------------------------------------------
542 // Function : endDocument
543 // Purpose : overload handler function
544 // Print all informations find in the catalog
545 // (only in DEBUG mode!!)
546 //----------------------------------------------------------------------
548 bool SALOME_ModuleCatalog_Handler::endDocument()
550 // ofstream f("/tmp/logs/xxx.log", std::ofstream::app);
551 // f << "---------------------------------------------------------" << std::endl;
552 if(MYDEBUG) BEGIN_OF("endDocument");
554 for (unsigned int ind = 0; ind < _pathList.size(); ind++)
556 if(MYDEBUG) MESSAGE("Path :"<<_pathList[ind].path);
557 for (unsigned int i = 0; i < _pathList[ind].listOfComputer.size(); i++)
558 if(MYDEBUG) MESSAGE("Computer name :" << _pathList[ind].listOfComputer[i]);
562 // if(MYDEBUG) SCRUTE(_moduleList.size());
563 // for (unsigned int ind = 0; ind < _moduleList.size(); ind++)
565 // f << _moduleList[ind] << std::endl;
568 if(MYDEBUG) MESSAGE("Document parsed");
569 if(MYDEBUG) END_OF("endDocument");
573 //----------------------------------------------------------------------
574 // Function : errorProtocol
575 // Purpose : overload handler function
576 //----------------------------------------------------------------------
577 QString SALOME_ModuleCatalog_Handler::errorProtocol()
583 //----------------------------------------------------------------------
584 // Function : fatalError
585 // Purpose : overload handler function
586 //----------------------------------------------------------------------
587 bool SALOME_ModuleCatalog_Handler::fatalError(const QXmlParseException& exception)
589 errorProt += QString( "fatal parsing error: %1 in line %2, column %3\n" )
590 .arg( exception.message() )
591 .arg( exception.lineNumber() )
592 .arg( exception.columnNumber() );
594 return QXmlDefaultHandler::fatalError( exception );