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_type = "component-type" ;
48 test_component_multistudy="component-multistudy";
49 test_component_icone="component-icone" ;
51 test_interface_name = "component-interface-name" ;
53 test_service_name = "service-name";
54 test_defaultservice = "service-by-default";
56 test_inParameter_type="inParameter-type";
57 test_inParameter_name="inParameter-name";
58 test_inParameter="inParameter";
59 test_inParameter_list="inParameter-list";
61 test_outParameter_type="outParameter-type";
62 test_outParameter_name="outParameter-name";
63 test_outParameter="outParameter";
64 test_outParameter_list="outParameter-list";
66 test_service= "component-service";
67 test_service_list="component-service-list";
68 test_interface_list="component-interface-list";
70 test_constraint="constraint";
72 test_component="component";
75 //----------------------------------------------------------------------
76 // Function : ~SALOME_ModuleCatalog_Handler
77 // Purpose : Destructor
78 //----------------------------------------------------------------------
79 SALOME_ModuleCatalog_Handler::~SALOME_ModuleCatalog_Handler()
81 MESSAGE("SALOME_ModuleCatalog_Handler destruction")
84 //----------------------------------------------------------------------
85 // Function : startDocument
86 // Purpose : overload handler function
87 //----------------------------------------------------------------------
88 bool SALOME_ModuleCatalog_Handler::startDocument()
90 MESSAGE("Begin parse document")
91 // Empty the private elements
93 _path_prefix.ListOfComputer.resize(0);
94 _servicelist.resize(0);
95 _interfacelist.resize(0);
96 _modulelist.resize(0);
97 _inparamlist.resize(0);
98 _outparamlist.resize(0);
102 //----------------------------------------------------------------------
103 // Function : startElement
104 // Purpose : overload handler function
105 //----------------------------------------------------------------------
106 bool SALOME_ModuleCatalog_Handler::startElement(const QString&,
108 const QString& qName,
109 const QXmlAttributes& atts)
114 //----------------------------------------------------------------------
115 // Function : endElement
116 // Purpose : overload handler function
117 //----------------------------------------------------------------------
118 bool SALOME_ModuleCatalog_Handler::endElement(const QString&,
120 const QString& qName)
124 // tag test_path_prefix_name
125 if((qName.compare(QString(test_path_prefix_name))==0))
126 _path_prefix.path = content;
127 // tag test_computer_name
128 if((qName.compare(QString(test_computer_name))==0))
129 _path_prefix.ListOfComputer.push_back(content);
131 // tag test_path_prefix
132 if((qName.compare(QString(test_path_prefix))==0))
134 _pathlist.push_back(_path_prefix);
135 _path_prefix.ListOfComputer.resize(0);
138 // Component identification
140 // tag test_component_name
141 if((qName.compare(QString(test_component_name))==0))
142 _amodule.Parsercomponentname = content ;
143 // tag test_component_type
144 if((qName.compare(QString(test_component_type))==0))
146 if ((content.compare("MESH") == 0) ||
147 (content.compare("Mesh") == 0) ||
148 (content.compare("mesh") == 0))
149 _amodule.Parsercomponenttype = MESH ;
150 else if((content.compare("MED") == 0) ||
151 (content.compare("Med") == 0) ||
152 (content.compare("med") == 0))
153 _amodule.Parsercomponenttype = Med ;
154 else if((content.compare("GEOM") == 0) ||
155 (content.compare("Geom") == 0) ||
156 (content.compare("geom") == 0))
157 _amodule.Parsercomponenttype = GEOM ;
158 else if((content.compare("SOLVER") == 0) ||
159 (content.compare("Solver") == 0) ||
160 (content.compare("solver") == 0))
161 _amodule.Parsercomponenttype = SOLVER ;
162 else if((content.compare("SUPERV") == 0) ||
163 (content.compare("Superv") == 0) ||
164 (content.compare("Supervision") == 0) ||
165 (content.compare("superv") == 0))
166 _amodule.Parsercomponenttype = SUPERV ;
167 else if((content.compare("DATA") == 0) ||
168 (content.compare("Data") == 0) ||
169 (content.compare("data") == 0))
170 _amodule.Parsercomponenttype = DATA ;
171 else if((content.compare("VISU") == 0) ||
172 (content.compare("Visu") == 0) ||
173 (content.compare("visu") == 0))
174 _amodule.Parsercomponenttype = VISU ;
175 else if((content.compare("OTHER") == 0) ||
176 (content.compare("Other") == 0) ||
177 (content.compare("other") == 0))
178 _amodule.Parsercomponenttype = OTHER ;
180 // If it'not in all theses cases, the type is affected to OTHER
181 _amodule.Parsercomponenttype = OTHER ;
184 // tag test_component_multistudy
185 if((qName.compare(QString(test_component_multistudy))==0))
186 _amodule.Parsercomponentmultistudy = atoi(content.c_str()) ;
188 // tag test_component_icone
189 if((qName.compare(QString(test_component_icone))==0))
190 _amodule.Parsercomponenticone = content ;
192 // interface identification
194 // tag test_interface_name
195 if((qName.compare(QString(test_interface_name))==0))
196 _aInterface.Parserinterfacename = content ;
198 // Service identification
200 // tag test_service_name
201 if((qName.compare(QString(test_service_name))==0))
202 _aService.ParserServiceName = content ;
204 //tag test_defaultservice
205 if((qName.compare(QString(test_defaultservice))==0))
206 _aService.ParserServicebydefault = atoi(content.c_str()) ;
210 // tag test_inParameter_type
211 if((qName.compare(QString(test_inParameter_type))==0))
212 _inparam.ParserParamtype = content ;
213 //tag test_inParameter_name
214 if((qName.compare(QString(test_inParameter_name))==0))
215 _inparam.ParserParamname = content ;
217 //tag test_inParameter
218 if((qName.compare(QString(test_inParameter))==0))
220 _inparamlist.push_back(_inparam) ;
222 // Empty temporary structures
223 _inparam.ParserParamtype = "";
224 _inparam.ParserParamname = "";
227 //tag test_inParameter_list
228 if((qName.compare(QString(test_inParameter_list))==0))
230 _aService.ParserServiceinParameter = _inparamlist;
231 _inparamlist.resize(0);
236 // tag test_outParameter_type
237 if((qName.compare(QString(test_outParameter_type))==0))
238 _outparam.ParserParamtype = content ;
239 //tag test_outParameter_name
240 if((qName.compare(QString(test_outParameter_name))==0))
241 _outparam.ParserParamname = content ;
243 //tag test_outParameter
244 if((qName.compare(QString(test_outParameter))==0))
246 _outparamlist.push_back(_outparam) ;
248 // Empty temporary structures
249 _outparam.ParserParamtype = "";
250 _outparam.ParserParamname = "";
252 //tag test_outParameter_list
253 if((qName.compare(QString(test_outParameter_list))==0))
255 _aService.ParserServiceoutParameter=_outparamlist;
256 _outparamlist.resize(0);
261 if((qName.compare(QString(test_service))==0))
263 _servicelist.push_back(_aService);
265 // Empty temporary structures
266 _aService.ParserServiceName = "";
267 _aService.ParserServiceinParameter.resize(0);
268 _aService.ParserServiceoutParameter.resize(0);
271 // tag test_service_list
272 if((qName.compare(QString(test_service_list))==0))
274 _aInterface.Parserinterfaceservicelist = _servicelist ;
276 // Empty temporary structures
277 _servicelist.resize(0);
278 _interfacelist.push_back(_aInterface);
279 _aInterface.Parserinterfacename ="";
280 _aInterface.Parserinterfaceservicelist.resize(0);
284 //tag test_interface_list
285 if((qName.compare(QString(test_interface_list))==0))
287 _amodule.ParserListInterface = _interfacelist ;
288 _interfacelist.resize(0);
291 //tag test_constraint
292 if((qName.compare(QString(test_constraint))==0))
293 _amodule.Parserconstraint = content ;
295 // tag test_component
296 if((qName.compare(QString(test_component))==0))
298 _modulelist.push_back(_amodule) ;
300 // Empty temporary structures
301 _amodule.Parsercomponentname = "";
302 _amodule.Parserconstraint = "";
303 _amodule.Parsercomponenticone="";
304 _amodule.ParserListInterface.resize(0);
310 //----------------------------------------------------------------------
311 // Function : characters
312 // Purpose : overload handler function
313 //----------------------------------------------------------------------
314 bool SALOME_ModuleCatalog_Handler::characters(const QString& chars)
316 content = (const char*)chars ;
320 //----------------------------------------------------------------------
321 // Function : endDocument
322 // Purpose : overload handler function
323 // Print all informations find in the catalog
324 // (only in DEBUG mode!!)
325 //----------------------------------------------------------------------
326 bool SALOME_ModuleCatalog_Handler::endDocument()
329 for (unsigned int ind = 0; ind < _pathlist.size(); ind++)
331 MESSAGE("Path :"<<_pathlist[ind].path)
332 for (unsigned int i = 0; i < _pathlist[ind].ListOfComputer.size(); i++)
333 MESSAGE("Computer name :" << _pathlist[ind].ListOfComputer[i])
337 for (unsigned int ind = 0; ind < _modulelist.size(); ind++)
339 MESSAGE("Component name : " << _modulelist[ind].Parsercomponentname);
340 // MESSAGE("Component type : " <<_modulelist[ind].Parsercomponenttype);
341 // MESSAGE("Component constraint : " << _modulelist[ind].Parserconstraint);
342 // MESSAGE("Component icone : " << _modulelist[ind].Parsercomponenticone);
343 // for (unsigned int i = 0; i < _modulelist[ind].ParserListInterface.size(); i++)
345 // MESSAGE("Component interface name : " << _modulelist[ind].ParserListInterface[i].Parserinterfacename);
346 // for (unsigned int j=0; j< _modulelist[ind].ParserListInterface[i].Parserinterfaceservicelist.size(); j++)
348 // MESSAGE("Service name : " << _modulelist[ind].ParserListInterface[i].Parserinterfaceservicelist[j].ParserServiceName);
349 // MESSAGE("Service default : " << _modulelist[ind].ParserListInterface[i].Parserinterfaceservicelist[j].ParserServicebydefault);
350 // for (unsigned int k=0; k< _modulelist[ind].ParserListInterface[i].Parserinterfaceservicelist[j].ParserServiceinParameter.size() ; k++)
352 // MESSAGE("Service Parameter in name : " <<_modulelist[ind].ParserListInterface[i].Parserinterfaceservicelist[j].ParserServiceinParameter[k].ParserParamname);
353 // MESSAGE("Service Parameter in type : " << _modulelist[ind].ParserListInterface[i].Parserinterfaceservicelist[j].ParserServiceinParameter[k].ParserParamtype);
355 // for (unsigned int k=0; k< _modulelist[ind].ParserListInterface[i].Parserinterfaceservicelist[j].ParserServiceoutParameter.size() ; k++)
357 // MESSAGE("Service Parameter out name : " << _modulelist[ind].ParserListInterface[i].Parserinterfaceservicelist[j].ParserServiceoutParameter[k].ParserParamname);
358 // MESSAGE("Service Parameter out type : " << _modulelist[ind].ParserListInterface[i].Parserinterfaceservicelist[j].ParserServiceoutParameter[k].ParserParamtype);
363 //MESSAGE("Document parsed");
367 //----------------------------------------------------------------------
368 // Function : errorProtocol
369 // Purpose : overload handler function
370 //----------------------------------------------------------------------
371 QString SALOME_ModuleCatalog_Handler::errorProtocol()
377 //----------------------------------------------------------------------
378 // Function : fatalError
379 // Purpose : overload handler function
380 //----------------------------------------------------------------------
381 bool SALOME_ModuleCatalog_Handler::fatalError(const QXmlParseException& exception)
383 errorProt += QString( "fatal parsing error: %1 in line %2, column %3\n" )
384 .arg( exception.message() )
385 .arg( exception.lineNumber() )
386 .arg( exception.columnNumber() );
388 return QXmlDefaultHandler::fatalError( exception );