Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[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_username = "component-username";
48   test_component_type = "component-type" ;
49   test_component_multistudy="component-multistudy";
50   test_component_icone="component-icone" ;
51
52   test_interface_name = "component-interface-name" ;
53   
54   test_service_name = "service-name";
55   test_defaultservice = "service-by-default";
56
57   test_inParameter_type="inParameter-type";
58   test_inParameter_name="inParameter-name";
59   test_inParameter="inParameter";
60   test_inParameter_list="inParameter-list";
61
62   test_outParameter_type="outParameter-type";
63   test_outParameter_name="outParameter-name";
64   test_outParameter="outParameter";
65   test_outParameter_list="outParameter-list";
66
67   test_service= "component-service";
68   test_service_list="component-service-list";
69   test_interface_list="component-interface-list";
70
71   test_constraint="constraint";
72
73   test_component="component";
74 }
75
76 //----------------------------------------------------------------------
77 // Function : ~SALOME_ModuleCatalog_Handler
78 // Purpose  : Destructor
79 //----------------------------------------------------------------------
80 SALOME_ModuleCatalog_Handler::~SALOME_ModuleCatalog_Handler()
81 {
82   MESSAGE("SALOME_ModuleCatalog_Handler destruction")
83 }
84
85 //----------------------------------------------------------------------
86 // Function : startDocument
87 // Purpose  : overload handler function
88 //----------------------------------------------------------------------
89 bool SALOME_ModuleCatalog_Handler::startDocument()
90 {
91   MESSAGE("Begin parse document")
92   // Empty the private elements
93   _pathlist.resize(0);
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);
100   return true;
101 }
102
103 //----------------------------------------------------------------------
104 // Function : startElement
105 // Purpose  : overload handler function
106 //----------------------------------------------------------------------
107 bool SALOME_ModuleCatalog_Handler::startElement(const QString&, 
108                                                 const QString &,
109                                                 const QString& qName, 
110                                                 const QXmlAttributes& atts)
111 {
112   return true;
113
114
115 //----------------------------------------------------------------------
116 // Function : endElement
117 // Purpose  : overload handler function
118 //----------------------------------------------------------------------
119 bool SALOME_ModuleCatalog_Handler::endElement(const QString&, 
120                                               const QString &,
121                                               const QString& qName)
122 {
123   // Path prefix
124
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);
131    
132   // tag test_path_prefix
133   if((qName.compare(QString(test_path_prefix))==0))
134     {
135       _pathlist.push_back(_path_prefix);
136       _path_prefix.ListOfComputer.resize(0);
137     }
138
139   // Component identification
140
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)) 
149      {
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 ;
183        else
184          // If it'not in all theses cases, the type is affected to OTHER
185          _amodule.Parsercomponenttype = OTHER ;
186      }
187
188    // tag test_component_multistudy
189   if((qName.compare(QString(test_component_multistudy))==0)) 
190     _amodule.Parsercomponentmultistudy = atoi(content.c_str()) ;
191
192   // tag test_component_icone
193   if((qName.compare(QString(test_component_icone))==0)) 
194     _amodule.Parsercomponenticone = content ;
195
196    // interface identification
197
198    // tag test_interface_name
199    if((qName.compare(QString(test_interface_name))==0)) 
200        _aInterface.Parserinterfacename = content ;
201
202    // Service identification
203
204    // tag test_service_name
205    if((qName.compare(QString(test_service_name))==0))
206      _aService.ParserServiceName = content ;
207      
208    //tag test_defaultservice
209    if((qName.compare(QString(test_defaultservice))==0))
210      _aService.ParserServicebydefault = atoi(content.c_str()) ;
211
212    // Parameter in
213
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 ; 
220
221    //tag test_inParameter
222   if((qName.compare(QString(test_inParameter))==0))
223     {
224       _inparamlist.push_back(_inparam) ; 
225
226       // Empty temporary structures
227       _inparam.ParserParamtype = "";
228       _inparam.ParserParamname = "";
229     }
230   
231    //tag test_inParameter_list
232    if((qName.compare(QString(test_inParameter_list))==0))
233      {
234        _aService.ParserServiceinParameter = _inparamlist;
235        _inparamlist.resize(0);
236      }
237
238    // Parameter out
239
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 ; 
246    
247    //tag test_outParameter
248   if((qName.compare(QString(test_outParameter))==0))
249     {
250       _outparamlist.push_back(_outparam) ; 
251      
252       // Empty temporary structures
253       _outparam.ParserParamtype = "";
254       _outparam.ParserParamname = "";
255     }
256    //tag test_outParameter_list
257    if((qName.compare(QString(test_outParameter_list))==0)) 
258      {
259        _aService.ParserServiceoutParameter=_outparamlist;
260        _outparamlist.resize(0);
261      }
262      
263
264    // tag   test_service
265    if((qName.compare(QString(test_service))==0))
266      {
267        _servicelist.push_back(_aService);
268
269        // Empty temporary structures
270        _aService.ParserServiceName = "";
271        _aService.ParserServiceinParameter.resize(0);
272        _aService.ParserServiceoutParameter.resize(0);
273      }
274
275    // tag   test_service_list
276    if((qName.compare(QString(test_service_list))==0))
277      {
278        _aInterface.Parserinterfaceservicelist = _servicelist ;
279
280        // Empty temporary structures
281        _servicelist.resize(0); 
282        _interfacelist.push_back(_aInterface);  
283        _aInterface.Parserinterfacename ="";    
284        _aInterface.Parserinterfaceservicelist.resize(0);
285
286      }
287
288    //tag test_interface_list
289    if((qName.compare(QString(test_interface_list))==0))
290      {
291        _amodule.ParserListInterface = _interfacelist ;
292        _interfacelist.resize(0);
293      }
294
295    //tag test_constraint
296    if((qName.compare(QString(test_constraint))==0))
297      _amodule.Parserconstraint = content ;
298
299    // tag test_component
300    if((qName.compare(QString(test_component))==0))
301      {
302        _modulelist.push_back(_amodule) ;
303        
304        // Empty temporary structures
305        _amodule.Parsercomponentname = "";
306        _amodule.Parserconstraint = "";
307        _amodule.Parsercomponenticone="";       
308        _amodule.ParserListInterface.resize(0);
309      }
310     
311   return true;
312 }
313   
314 //----------------------------------------------------------------------
315 // Function : characters
316 // Purpose  : overload handler function
317 //----------------------------------------------------------------------
318 bool SALOME_ModuleCatalog_Handler::characters(const QString& chars)
319 {
320   content = (const char*)chars ;
321   return true;
322 }
323
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()
331 {
332   //_pathlist
333   for (unsigned int ind = 0; ind < _pathlist.size(); ind++)
334     {
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])
338     }
339
340    // _modulelist
341   for (unsigned int ind = 0; ind < _modulelist.size(); ind++)
342     {
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++)
348 //      {
349 //        MESSAGE("Component interface name : " << _modulelist[ind].ParserListInterface[i].Parserinterfacename);
350 //        for (unsigned int j=0; j< _modulelist[ind].ParserListInterface[i].Parserinterfaceservicelist.size(); j++)
351 //          {
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++)
355 //              {
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);
358 //              }
359 //            for (unsigned int k=0; k< _modulelist[ind].ParserListInterface[i].Parserinterfaceservicelist[j].ParserServiceoutParameter.size() ; k++)
360 //              {
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);
363 //              }
364 //          }  
365        }
366 //     }
367   //MESSAGE("Document parsed");
368   return true;
369 }
370  
371 //----------------------------------------------------------------------
372 // Function : errorProtocol
373 // Purpose  : overload handler function
374 //----------------------------------------------------------------------  
375 QString SALOME_ModuleCatalog_Handler::errorProtocol()
376 {
377   return errorProt ;
378 }
379
380
381 //----------------------------------------------------------------------
382 // Function : fatalError
383 // Purpose  : overload handler function
384 //----------------------------------------------------------------------  
385 bool SALOME_ModuleCatalog_Handler::fatalError(const QXmlParseException& exception)
386 {
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() );
391
392   return QXmlDefaultHandler::fatalError( exception );
393 }