Salome HOME
sources v1.2
[modules/kernel.git] / src / ModuleCatalog / SALOME_ModuleCatalog_Handler.cxx
1 //  SALOME ModuleCatalog : implementation of ModuleCatalog server which parsers xml description of modules
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SALOME_ModuleCatalog_Handler.cxx
25 //  Author : Estelle Deville
26 //  Module : SALOME
27 //  $Header$
28
29 using namespace std;
30 #define WRITE_CATA_COMPONENT
31 #include "SALOME_ModuleCatalog_Handler.hxx"
32
33 //----------------------------------------------------------------------
34 // Function : SALOME_ModuleCatalog_Handler
35 // Purpose  : Constructor
36 //----------------------------------------------------------------------
37 SALOME_ModuleCatalog_Handler::SALOME_ModuleCatalog_Handler()
38 {
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" ;
45
46   test_component_name = "component-name";
47   test_component_type = "component-type" ;
48   test_component_multistudy="component-multistudy";
49   test_component_icone="component-icone" ;
50
51   test_interface_name = "component-interface-name" ;
52   
53   test_service_name = "service-name";
54   test_defaultservice = "service-by-default";
55
56   test_inParameter_type="inParameter-type";
57   test_inParameter_name="inParameter-name";
58   test_inParameter="inParameter";
59   test_inParameter_list="inParameter-list";
60
61   test_outParameter_type="outParameter-type";
62   test_outParameter_name="outParameter-name";
63   test_outParameter="outParameter";
64   test_outParameter_list="outParameter-list";
65
66   test_service= "component-service";
67   test_service_list="component-service-list";
68   test_interface_list="component-interface-list";
69
70   test_constraint="constraint";
71
72   test_component="component";
73 }
74
75 //----------------------------------------------------------------------
76 // Function : ~SALOME_ModuleCatalog_Handler
77 // Purpose  : Destructor
78 //----------------------------------------------------------------------
79 SALOME_ModuleCatalog_Handler::~SALOME_ModuleCatalog_Handler()
80 {
81   MESSAGE("SALOME_ModuleCatalog_Handler destruction")
82 }
83
84 //----------------------------------------------------------------------
85 // Function : startDocument
86 // Purpose  : overload handler function
87 //----------------------------------------------------------------------
88 bool SALOME_ModuleCatalog_Handler::startDocument()
89 {
90   MESSAGE("Begin parse document")
91   // Empty the private elements
92   _pathlist.resize(0);
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);
99   return true;
100 }
101
102 //----------------------------------------------------------------------
103 // Function : startElement
104 // Purpose  : overload handler function
105 //----------------------------------------------------------------------
106 bool SALOME_ModuleCatalog_Handler::startElement(const QString&, 
107                                                 const QString &,
108                                                 const QString& qName, 
109                                                 const QXmlAttributes& atts)
110 {
111   return true;
112
113
114 //----------------------------------------------------------------------
115 // Function : endElement
116 // Purpose  : overload handler function
117 //----------------------------------------------------------------------
118 bool SALOME_ModuleCatalog_Handler::endElement(const QString&, 
119                                               const QString &,
120                                               const QString& qName)
121 {
122   // Path prefix
123
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);
130    
131   // tag test_path_prefix
132   if((qName.compare(QString(test_path_prefix))==0))
133     {
134       _pathlist.push_back(_path_prefix);
135       _path_prefix.ListOfComputer.resize(0);
136     }
137
138   // Component identification
139
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)) 
145      {
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 ;
179        else
180          // If it'not in all theses cases, the type is affected to OTHER
181          _amodule.Parsercomponenttype = OTHER ;
182      }
183
184    // tag test_component_multistudy
185   if((qName.compare(QString(test_component_multistudy))==0)) 
186     _amodule.Parsercomponentmultistudy = atoi(content.c_str()) ;
187
188   // tag test_component_icone
189   if((qName.compare(QString(test_component_icone))==0)) 
190     _amodule.Parsercomponenticone = content ;
191
192    // interface identification
193
194    // tag test_interface_name
195    if((qName.compare(QString(test_interface_name))==0)) 
196        _aInterface.Parserinterfacename = content ;
197
198    // Service identification
199
200    // tag test_service_name
201    if((qName.compare(QString(test_service_name))==0))
202      _aService.ParserServiceName = content ;
203      
204    //tag test_defaultservice
205    if((qName.compare(QString(test_defaultservice))==0))
206      _aService.ParserServicebydefault = atoi(content.c_str()) ;
207
208    // Parameter in
209
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 ; 
216
217    //tag test_inParameter
218   if((qName.compare(QString(test_inParameter))==0))
219     {
220       _inparamlist.push_back(_inparam) ; 
221
222       // Empty temporary structures
223       _inparam.ParserParamtype = "";
224       _inparam.ParserParamname = "";
225     }
226   
227    //tag test_inParameter_list
228    if((qName.compare(QString(test_inParameter_list))==0))
229      {
230        _aService.ParserServiceinParameter = _inparamlist;
231        _inparamlist.resize(0);
232      }
233
234    // Parameter out
235
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 ; 
242    
243    //tag test_outParameter
244   if((qName.compare(QString(test_outParameter))==0))
245     {
246       _outparamlist.push_back(_outparam) ; 
247      
248       // Empty temporary structures
249       _outparam.ParserParamtype = "";
250       _outparam.ParserParamname = "";
251     }
252    //tag test_outParameter_list
253    if((qName.compare(QString(test_outParameter_list))==0)) 
254      {
255        _aService.ParserServiceoutParameter=_outparamlist;
256        _outparamlist.resize(0);
257      }
258      
259
260    // tag   test_service
261    if((qName.compare(QString(test_service))==0))
262      {
263        _servicelist.push_back(_aService);
264
265        // Empty temporary structures
266        _aService.ParserServiceName = "";
267        _aService.ParserServiceinParameter.resize(0);
268        _aService.ParserServiceoutParameter.resize(0);
269      }
270
271    // tag   test_service_list
272    if((qName.compare(QString(test_service_list))==0))
273      {
274        _aInterface.Parserinterfaceservicelist = _servicelist ;
275
276        // Empty temporary structures
277        _servicelist.resize(0); 
278        _interfacelist.push_back(_aInterface);  
279        _aInterface.Parserinterfacename ="";    
280        _aInterface.Parserinterfaceservicelist.resize(0);
281
282      }
283
284    //tag test_interface_list
285    if((qName.compare(QString(test_interface_list))==0))
286      {
287        _amodule.ParserListInterface = _interfacelist ;
288        _interfacelist.resize(0);
289      }
290
291    //tag test_constraint
292    if((qName.compare(QString(test_constraint))==0))
293      _amodule.Parserconstraint = content ;
294
295    // tag test_component
296    if((qName.compare(QString(test_component))==0))
297      {
298        _modulelist.push_back(_amodule) ;
299        
300        // Empty temporary structures
301        _amodule.Parsercomponentname = "";
302        _amodule.Parserconstraint = "";
303        _amodule.Parsercomponenticone="";       
304        _amodule.ParserListInterface.resize(0);
305      }
306     
307   return true;
308 }
309   
310 //----------------------------------------------------------------------
311 // Function : characters
312 // Purpose  : overload handler function
313 //----------------------------------------------------------------------
314 bool SALOME_ModuleCatalog_Handler::characters(const QString& chars)
315 {
316   content = (const char*)chars ;
317   return true;
318 }
319
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()
327 {
328   //_pathlist
329   for (unsigned int ind = 0; ind < _pathlist.size(); ind++)
330     {
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])
334     }
335
336    // _modulelist
337   for (unsigned int ind = 0; ind < _modulelist.size(); ind++)
338     {
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++)
344 //      {
345 //        MESSAGE("Component interface name : " << _modulelist[ind].ParserListInterface[i].Parserinterfacename);
346 //        for (unsigned int j=0; j< _modulelist[ind].ParserListInterface[i].Parserinterfaceservicelist.size(); j++)
347 //          {
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++)
351 //              {
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);
354 //              }
355 //            for (unsigned int k=0; k< _modulelist[ind].ParserListInterface[i].Parserinterfaceservicelist[j].ParserServiceoutParameter.size() ; k++)
356 //              {
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);
359 //              }
360 //          }  
361        }
362 //     }
363   //MESSAGE("Document parsed");
364   return true;
365 }
366  
367 //----------------------------------------------------------------------
368 // Function : errorProtocol
369 // Purpose  : overload handler function
370 //----------------------------------------------------------------------  
371 QString SALOME_ModuleCatalog_Handler::errorProtocol()
372 {
373   return errorProt ;
374 }
375
376
377 //----------------------------------------------------------------------
378 // Function : fatalError
379 // Purpose  : overload handler function
380 //----------------------------------------------------------------------  
381 bool SALOME_ModuleCatalog_Handler::fatalError(const QXmlParseException& exception)
382 {
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() );
387
388   return QXmlDefaultHandler::fatalError( exception );
389 }