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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SALOME_ModuleCatalog_Handler.cxx
25 // Author : Estelle Deville
30 #define WRITE_CATA_COMPONENT
31 #include "SALOME_ModuleCatalog_Handler.hxx"
33 //----------------------------------------------------------------------
34 // Function : SALOME_ModuleCatalog_Handler
35 // Purpose : Constructor
36 //----------------------------------------------------------------------
37 SALOME_ModuleCatalog_Handler::SALOME_ModuleCatalog_Handler()
39 MESSAGE("SALOME_ModuleCatalog_Handler creation")
40 // XML Tags initialisation
41 // Used in the function endElement
42 test_path_prefix_name = "path-prefix-name";
43 test_computer_name = "computer-name" ;
44 test_path_prefix = "path-prefix" ;
46 test_component_name = "component-name";
47 test_component_username = "component-username";
48 test_component_type = "component-type" ;
49 test_component_multistudy="component-multistudy";
50 test_component_icone="component-icone" ;
52 test_interface_name = "component-interface-name" ;
54 test_service_name = "service-name";
55 test_defaultservice = "service-by-default";
57 test_inParameter_type="inParameter-type";
58 test_inParameter_name="inParameter-name";
59 test_inParameter="inParameter";
60 test_inParameter_list="inParameter-list";
62 test_outParameter_type="outParameter-type";
63 test_outParameter_name="outParameter-name";
64 test_outParameter="outParameter";
65 test_outParameter_list="outParameter-list";
67 test_service= "component-service";
68 test_service_list="component-service-list";
69 test_interface_list="component-interface-list";
71 test_constraint="constraint";
73 test_component="component";
76 //----------------------------------------------------------------------
77 // Function : ~SALOME_ModuleCatalog_Handler
78 // Purpose : Destructor
79 //----------------------------------------------------------------------
80 SALOME_ModuleCatalog_Handler::~SALOME_ModuleCatalog_Handler()
82 MESSAGE("SALOME_ModuleCatalog_Handler destruction")
85 //----------------------------------------------------------------------
86 // Function : startDocument
87 // Purpose : overload handler function
88 //----------------------------------------------------------------------
89 bool SALOME_ModuleCatalog_Handler::startDocument()
91 MESSAGE("Begin parse document")
92 // Empty the private elements
94 _path_prefix.ListOfComputer.resize(0);
95 _servicelist.resize(0);
96 _interfacelist.resize(0);
97 _modulelist.resize(0);
98 _inparamlist.resize(0);
99 _outparamlist.resize(0);
103 //----------------------------------------------------------------------
104 // Function : startElement
105 // Purpose : overload handler function
106 //----------------------------------------------------------------------
107 bool SALOME_ModuleCatalog_Handler::startElement(const QString&,
109 const QString& qName,
110 const QXmlAttributes& atts)
115 //----------------------------------------------------------------------
116 // Function : endElement
117 // Purpose : overload handler function
118 //----------------------------------------------------------------------
119 bool SALOME_ModuleCatalog_Handler::endElement(const QString&,
121 const QString& qName)
125 // tag test_path_prefix_name
126 if((qName.compare(QString(test_path_prefix_name))==0))
127 _path_prefix.path = content;
128 // tag test_computer_name
129 if((qName.compare(QString(test_computer_name))==0))
130 _path_prefix.ListOfComputer.push_back(content);
132 // tag test_path_prefix
133 if((qName.compare(QString(test_path_prefix))==0))
135 _pathlist.push_back(_path_prefix);
136 _path_prefix.ListOfComputer.resize(0);
139 // Component identification
141 // tag test_component_name
142 if((qName.compare(QString(test_component_name))==0))
143 _amodule.Parsercomponentname = content ;
144 // tag test_component_username
145 if((qName.compare(QString(test_component_username))==0))
146 _amodule.Parsercomponentusername = content ;
147 // tag test_component_type
148 if((qName.compare(QString(test_component_type))==0))
150 if ((content.compare("MESH") == 0) ||
151 (content.compare("Mesh") == 0) ||
152 (content.compare("mesh") == 0))
153 _amodule.Parsercomponenttype = MESH ;
154 else if((content.compare("MED") == 0) ||
155 (content.compare("Med") == 0) ||
156 (content.compare("med") == 0))
157 _amodule.Parsercomponenttype = Med ;
158 else if((content.compare("GEOM") == 0) ||
159 (content.compare("Geom") == 0) ||
160 (content.compare("geom") == 0))
161 _amodule.Parsercomponenttype = GEOM ;
162 else if((content.compare("SOLVER") == 0) ||
163 (content.compare("Solver") == 0) ||
164 (content.compare("solver") == 0))
165 _amodule.Parsercomponenttype = SOLVER ;
166 else if((content.compare("SUPERV") == 0) ||
167 (content.compare("Superv") == 0) ||
168 (content.compare("Supervision") == 0) ||
169 (content.compare("superv") == 0))
170 _amodule.Parsercomponenttype = SUPERV ;
171 else if((content.compare("DATA") == 0) ||
172 (content.compare("Data") == 0) ||
173 (content.compare("data") == 0))
174 _amodule.Parsercomponenttype = DATA ;
175 else if((content.compare("VISU") == 0) ||
176 (content.compare("Visu") == 0) ||
177 (content.compare("visu") == 0))
178 _amodule.Parsercomponenttype = VISU ;
179 else if((content.compare("OTHER") == 0) ||
180 (content.compare("Other") == 0) ||
181 (content.compare("other") == 0))
182 _amodule.Parsercomponenttype = OTHER ;
184 // If it'not in all theses cases, the type is affected to OTHER
185 _amodule.Parsercomponenttype = OTHER ;
188 // tag test_component_multistudy
189 if((qName.compare(QString(test_component_multistudy))==0))
190 _amodule.Parsercomponentmultistudy = atoi(content.c_str()) ;
192 // tag test_component_icone
193 if((qName.compare(QString(test_component_icone))==0))
194 _amodule.Parsercomponenticone = content ;
196 // interface identification
198 // tag test_interface_name
199 if((qName.compare(QString(test_interface_name))==0))
200 _aInterface.Parserinterfacename = content ;
202 // Service identification
204 // tag test_service_name
205 if((qName.compare(QString(test_service_name))==0))
206 _aService.ParserServiceName = content ;
208 //tag test_defaultservice
209 if((qName.compare(QString(test_defaultservice))==0))
210 _aService.ParserServicebydefault = atoi(content.c_str()) ;
214 // tag test_inParameter_type
215 if((qName.compare(QString(test_inParameter_type))==0))
216 _inparam.ParserParamtype = content ;
217 //tag test_inParameter_name
218 if((qName.compare(QString(test_inParameter_name))==0))
219 _inparam.ParserParamname = content ;
221 //tag test_inParameter
222 if((qName.compare(QString(test_inParameter))==0))
224 _inparamlist.push_back(_inparam) ;
226 // Empty temporary structures
227 _inparam.ParserParamtype = "";
228 _inparam.ParserParamname = "";
231 //tag test_inParameter_list
232 if((qName.compare(QString(test_inParameter_list))==0))
234 _aService.ParserServiceinParameter = _inparamlist;
235 _inparamlist.resize(0);
240 // tag test_outParameter_type
241 if((qName.compare(QString(test_outParameter_type))==0))
242 _outparam.ParserParamtype = content ;
243 //tag test_outParameter_name
244 if((qName.compare(QString(test_outParameter_name))==0))
245 _outparam.ParserParamname = content ;
247 //tag test_outParameter
248 if((qName.compare(QString(test_outParameter))==0))
250 _outparamlist.push_back(_outparam) ;
252 // Empty temporary structures
253 _outparam.ParserParamtype = "";
254 _outparam.ParserParamname = "";
256 //tag test_outParameter_list
257 if((qName.compare(QString(test_outParameter_list))==0))
259 _aService.ParserServiceoutParameter=_outparamlist;
260 _outparamlist.resize(0);
265 if((qName.compare(QString(test_service))==0))
267 _servicelist.push_back(_aService);
269 // Empty temporary structures
270 _aService.ParserServiceName = "";
271 _aService.ParserServiceinParameter.resize(0);
272 _aService.ParserServiceoutParameter.resize(0);
275 // tag test_service_list
276 if((qName.compare(QString(test_service_list))==0))
278 _aInterface.Parserinterfaceservicelist = _servicelist ;
280 // Empty temporary structures
281 _servicelist.resize(0);
282 _interfacelist.push_back(_aInterface);
283 _aInterface.Parserinterfacename ="";
284 _aInterface.Parserinterfaceservicelist.resize(0);
288 //tag test_interface_list
289 if((qName.compare(QString(test_interface_list))==0))
291 _amodule.ParserListInterface = _interfacelist ;
292 _interfacelist.resize(0);
295 //tag test_constraint
296 if((qName.compare(QString(test_constraint))==0))
297 _amodule.Parserconstraint = content ;
299 // tag test_component
300 if((qName.compare(QString(test_component))==0))
302 _modulelist.push_back(_amodule) ;
304 // Empty temporary structures
305 _amodule.Parsercomponentname = "";
306 _amodule.Parserconstraint = "";
307 _amodule.Parsercomponenticone="";
308 _amodule.ParserListInterface.resize(0);
314 //----------------------------------------------------------------------
315 // Function : characters
316 // Purpose : overload handler function
317 //----------------------------------------------------------------------
318 bool SALOME_ModuleCatalog_Handler::characters(const QString& chars)
320 content = (const char*)chars ;
324 //----------------------------------------------------------------------
325 // Function : endDocument
326 // Purpose : overload handler function
327 // Print all informations find in the catalog
328 // (only in DEBUG mode!!)
329 //----------------------------------------------------------------------
330 bool SALOME_ModuleCatalog_Handler::endDocument()
333 for (unsigned int ind = 0; ind < _pathlist.size(); ind++)
335 MESSAGE("Path :"<<_pathlist[ind].path)
336 for (unsigned int i = 0; i < _pathlist[ind].ListOfComputer.size(); i++)
337 MESSAGE("Computer name :" << _pathlist[ind].ListOfComputer[i])
341 for (unsigned int ind = 0; ind < _modulelist.size(); ind++)
343 MESSAGE("Component name : " << _modulelist[ind].Parsercomponentname);
344 // MESSAGE("Component type : " <<_modulelist[ind].Parsercomponenttype);
345 // MESSAGE("Component constraint : " << _modulelist[ind].Parserconstraint);
346 // MESSAGE("Component icone : " << _modulelist[ind].Parsercomponenticone);
347 // for (unsigned int i = 0; i < _modulelist[ind].ParserListInterface.size(); i++)
349 // MESSAGE("Component interface name : " << _modulelist[ind].ParserListInterface[i].Parserinterfacename);
350 // for (unsigned int j=0; j< _modulelist[ind].ParserListInterface[i].Parserinterfaceservicelist.size(); j++)
352 // MESSAGE("Service name : " << _modulelist[ind].ParserListInterface[i].Parserinterfaceservicelist[j].ParserServiceName);
353 // MESSAGE("Service default : " << _modulelist[ind].ParserListInterface[i].Parserinterfaceservicelist[j].ParserServicebydefault);
354 // for (unsigned int k=0; k< _modulelist[ind].ParserListInterface[i].Parserinterfaceservicelist[j].ParserServiceinParameter.size() ; k++)
356 // MESSAGE("Service Parameter in name : " <<_modulelist[ind].ParserListInterface[i].Parserinterfaceservicelist[j].ParserServiceinParameter[k].ParserParamname);
357 // MESSAGE("Service Parameter in type : " << _modulelist[ind].ParserListInterface[i].Parserinterfaceservicelist[j].ParserServiceinParameter[k].ParserParamtype);
359 // for (unsigned int k=0; k< _modulelist[ind].ParserListInterface[i].Parserinterfaceservicelist[j].ParserServiceoutParameter.size() ; k++)
361 // MESSAGE("Service Parameter out name : " << _modulelist[ind].ParserListInterface[i].Parserinterfaceservicelist[j].ParserServiceoutParameter[k].ParserParamname);
362 // MESSAGE("Service Parameter out type : " << _modulelist[ind].ParserListInterface[i].Parserinterfaceservicelist[j].ParserServiceoutParameter[k].ParserParamtype);
367 //MESSAGE("Document parsed");
371 //----------------------------------------------------------------------
372 // Function : errorProtocol
373 // Purpose : overload handler function
374 //----------------------------------------------------------------------
375 QString SALOME_ModuleCatalog_Handler::errorProtocol()
381 //----------------------------------------------------------------------
382 // Function : fatalError
383 // Purpose : overload handler function
384 //----------------------------------------------------------------------
385 bool SALOME_ModuleCatalog_Handler::fatalError(const QXmlParseException& exception)
387 errorProt += QString( "fatal parsing error: %1 in line %2, column %3\n" )
388 .arg( exception.message() )
389 .arg( exception.lineNumber() )
390 .arg( exception.columnNumber() );
392 return QXmlDefaultHandler::fatalError( exception );