Salome HOME
NRI : Remove dependence with VISU.
[modules/kernel.git] / src / ModuleCatalog / SALOME_ModuleCatalog_Handler.cxx
1 using namespace std;
2 // File: SALOME_ModuleCatalog_Handler.cxx
3 // Created: Tue June 27 2001
4 // Author: Estelle Deville
5 // Project: SALOME
6 // Copyright : CEA/DEN/DMSS/LGLS
7 // $Header$
8
9 #define WRITE_CATA_COMPONENT
10 #include "SALOME_ModuleCatalog_Handler.hxx"
11
12 //----------------------------------------------------------------------
13 // Function : SALOME_ModuleCatalog_Handler
14 // Purpose  : Constructor
15 //----------------------------------------------------------------------
16 SALOME_ModuleCatalog_Handler::SALOME_ModuleCatalog_Handler()
17 {
18   MESSAGE("SALOME_ModuleCatalog_Handler creation")
19   // XML Tags initialisation
20   // Used in the function endElement
21   test_path_prefix_name = "path-prefix-name";
22   test_computer_name = "computer-name" ;
23   test_path_prefix = "path-prefix" ;
24
25   test_component_name = "component-name";
26   test_component_username = "component-username";
27   test_component_type = "component-type" ;
28   test_component_multistudy="component-multistudy";
29   test_component_icone="component-icone" ;
30
31   test_interface_name = "component-interface-name" ;
32   
33   test_service_name = "service-name";
34   test_defaultservice = "service-by-default";
35
36   test_inParameter_type="inParameter-type";
37   test_inParameter_name="inParameter-name";
38   test_inParameter="inParameter";
39   test_inParameter_list="inParameter-list";
40
41   test_outParameter_type="outParameter-type";
42   test_outParameter_name="outParameter-name";
43   test_outParameter="outParameter";
44   test_outParameter_list="outParameter-list";
45
46   test_service= "component-service";
47   test_service_list="component-service-list";
48   test_interface_list="component-interface-list";
49
50   test_constraint="constraint";
51
52   test_component="component";
53 }
54
55 //----------------------------------------------------------------------
56 // Function : ~SALOME_ModuleCatalog_Handler
57 // Purpose  : Destructor
58 //----------------------------------------------------------------------
59 SALOME_ModuleCatalog_Handler::~SALOME_ModuleCatalog_Handler()
60 {
61   MESSAGE("SALOME_ModuleCatalog_Handler destruction")
62 }
63
64 //----------------------------------------------------------------------
65 // Function : startDocument
66 // Purpose  : overload handler function
67 //----------------------------------------------------------------------
68 bool SALOME_ModuleCatalog_Handler::startDocument()
69 {
70   MESSAGE("Begin parse document")
71   // Empty the private elements
72   _pathlist.resize(0);
73   _path_prefix.ListOfComputer.resize(0);
74   _servicelist.resize(0);
75   _interfacelist.resize(0);
76   _modulelist.resize(0);
77   _inparamlist.resize(0);
78   _outparamlist.resize(0);
79   return true;
80 }
81
82 //----------------------------------------------------------------------
83 // Function : startElement
84 // Purpose  : overload handler function
85 //----------------------------------------------------------------------
86 bool SALOME_ModuleCatalog_Handler::startElement(const QString&, 
87                                                 const QString &,
88                                                 const QString& qName, 
89                                                 const QXmlAttributes& atts)
90 {
91   return true;
92
93
94 //----------------------------------------------------------------------
95 // Function : endElement
96 // Purpose  : overload handler function
97 //----------------------------------------------------------------------
98 bool SALOME_ModuleCatalog_Handler::endElement(const QString&, 
99                                               const QString &,
100                                               const QString& qName)
101 {
102   // Path prefix
103
104   // tag test_path_prefix_name
105   if((qName.compare(QString(test_path_prefix_name))==0))
106     _path_prefix.path = content;
107   // tag test_computer_name
108   if((qName.compare(QString(test_computer_name))==0)) 
109     _path_prefix.ListOfComputer.push_back(content);
110    
111   // tag test_path_prefix
112   if((qName.compare(QString(test_path_prefix))==0))
113     {
114       _pathlist.push_back(_path_prefix);
115       _path_prefix.ListOfComputer.resize(0);
116     }
117
118   // Component identification
119
120   // tag test_component_name
121   if((qName.compare(QString(test_component_name))==0)) 
122     _amodule.Parsercomponentname = content ;
123   // tag test_component_username
124   if((qName.compare(QString(test_component_username))==0)) 
125     _amodule.Parsercomponentusername = content ;
126   // tag test_component_type
127    if((qName.compare(QString(test_component_type))==0)) 
128      {
129        if ((content.compare("MESH") == 0) ||
130            (content.compare("Mesh") == 0) ||
131            (content.compare("mesh") == 0))
132          _amodule.Parsercomponenttype = MESH ;
133        else if((content.compare("MED") == 0) ||
134                (content.compare("Med") == 0) ||
135                (content.compare("med") == 0))
136          _amodule.Parsercomponenttype = Med ;
137        else if((content.compare("GEOM") == 0) ||
138                (content.compare("Geom") == 0) ||
139                (content.compare("geom") == 0))
140          _amodule.Parsercomponenttype = GEOM ;
141        else if((content.compare("SOLVER") == 0) ||
142                (content.compare("Solver") == 0) ||
143                (content.compare("solver") == 0))
144          _amodule.Parsercomponenttype = SOLVER ;
145        else if((content.compare("SUPERV") == 0) ||
146                (content.compare("Superv") == 0) ||
147                (content.compare("Supervision") == 0) ||
148                (content.compare("superv") == 0))
149          _amodule.Parsercomponenttype = SUPERV ;
150        else if((content.compare("DATA") == 0) ||
151                (content.compare("Data") == 0) ||
152                (content.compare("data") == 0))
153          _amodule.Parsercomponenttype = DATA ; 
154        else if((content.compare("VISU") == 0) ||
155                (content.compare("Visu") == 0) ||
156                (content.compare("visu") == 0))
157          _amodule.Parsercomponenttype = VISU ; 
158        else if((content.compare("OTHER") == 0) ||
159                (content.compare("Other") == 0) ||
160                (content.compare("other") == 0))                
161          _amodule.Parsercomponenttype = OTHER ;
162        else
163          // If it'not in all theses cases, the type is affected to OTHER
164          _amodule.Parsercomponenttype = OTHER ;
165      }
166
167    // tag test_component_multistudy
168   if((qName.compare(QString(test_component_multistudy))==0)) 
169     _amodule.Parsercomponentmultistudy = atoi(content.c_str()) ;
170
171   // tag test_component_icone
172   if((qName.compare(QString(test_component_icone))==0)) 
173     _amodule.Parsercomponenticone = content ;
174
175    // interface identification
176
177    // tag test_interface_name
178    if((qName.compare(QString(test_interface_name))==0)) 
179        _aInterface.Parserinterfacename = content ;
180
181    // Service identification
182
183    // tag test_service_name
184    if((qName.compare(QString(test_service_name))==0))
185      _aService.ParserServiceName = content ;
186      
187    //tag test_defaultservice
188    if((qName.compare(QString(test_defaultservice))==0))
189      _aService.ParserServicebydefault = atoi(content.c_str()) ;
190
191    // Parameter in
192
193    // tag test_inParameter_type
194    if((qName.compare(QString(test_inParameter_type))==0))
195      _inparam.ParserParamtype = content ;
196    //tag test_inParameter_name
197    if((qName.compare(QString(test_inParameter_name))==0))
198      _inparam.ParserParamname = content ; 
199
200    //tag test_inParameter
201   if((qName.compare(QString(test_inParameter))==0))
202     {
203       _inparamlist.push_back(_inparam) ; 
204
205       // Empty temporary structures
206       _inparam.ParserParamtype = "";
207       _inparam.ParserParamname = "";
208     }
209   
210    //tag test_inParameter_list
211    if((qName.compare(QString(test_inParameter_list))==0))
212      {
213        _aService.ParserServiceinParameter = _inparamlist;
214        _inparamlist.resize(0);
215      }
216
217    // Parameter out
218
219    // tag test_outParameter_type
220    if((qName.compare(QString(test_outParameter_type))==0))
221      _outparam.ParserParamtype = content ;
222    //tag test_outParameter_name
223    if((qName.compare(QString(test_outParameter_name))==0))
224      _outparam.ParserParamname = content ; 
225    
226    //tag test_outParameter
227   if((qName.compare(QString(test_outParameter))==0))
228     {
229       _outparamlist.push_back(_outparam) ; 
230      
231       // Empty temporary structures
232       _outparam.ParserParamtype = "";
233       _outparam.ParserParamname = "";
234     }
235    //tag test_outParameter_list
236    if((qName.compare(QString(test_outParameter_list))==0)) 
237      {
238        _aService.ParserServiceoutParameter=_outparamlist;
239        _outparamlist.resize(0);
240      }
241      
242
243    // tag   test_service
244    if((qName.compare(QString(test_service))==0))
245      {
246        _servicelist.push_back(_aService);
247
248        // Empty temporary structures
249        _aService.ParserServiceName = "";
250        _aService.ParserServiceinParameter.resize(0);
251        _aService.ParserServiceoutParameter.resize(0);
252      }
253
254    // tag   test_service_list
255    if((qName.compare(QString(test_service_list))==0))
256      {
257        _aInterface.Parserinterfaceservicelist = _servicelist ;
258
259        // Empty temporary structures
260        _servicelist.resize(0); 
261        _interfacelist.push_back(_aInterface);  
262        _aInterface.Parserinterfacename ="";    
263        _aInterface.Parserinterfaceservicelist.resize(0);
264
265      }
266
267    //tag test_interface_list
268    if((qName.compare(QString(test_interface_list))==0))
269      {
270        _amodule.ParserListInterface = _interfacelist ;
271        _interfacelist.resize(0);
272      }
273
274    //tag test_constraint
275    if((qName.compare(QString(test_constraint))==0))
276      _amodule.Parserconstraint = content ;
277
278    // tag test_component
279    if((qName.compare(QString(test_component))==0))
280      {
281        _modulelist.push_back(_amodule) ;
282        
283        // Empty temporary structures
284        _amodule.Parsercomponentname = "";
285        _amodule.Parserconstraint = "";
286        _amodule.Parsercomponenticone="";       
287        _amodule.ParserListInterface.resize(0);
288      }
289     
290   return true;
291 }
292   
293 //----------------------------------------------------------------------
294 // Function : characters
295 // Purpose  : overload handler function
296 //----------------------------------------------------------------------
297 bool SALOME_ModuleCatalog_Handler::characters(const QString& chars)
298 {
299   content = chars ;
300   return true;
301 }
302
303 //----------------------------------------------------------------------
304 // Function : endDocument
305 // Purpose  : overload handler function
306 //            Print all informations find in the catalog 
307 //            (only in DEBUG mode!!)
308 //----------------------------------------------------------------------  
309 bool SALOME_ModuleCatalog_Handler::endDocument()
310 {
311   //_pathlist
312   for (unsigned int ind = 0; ind < _pathlist.size(); ind++)
313     {
314       MESSAGE("Path :"<<_pathlist[ind].path)
315       for (unsigned int i = 0; i < _pathlist[ind].ListOfComputer.size(); i++)
316           MESSAGE("Computer name :" << _pathlist[ind].ListOfComputer[i])
317     }
318
319    // _modulelist
320   for (unsigned int ind = 0; ind < _modulelist.size(); ind++)
321     {
322       MESSAGE("Component name : " << _modulelist[ind].Parsercomponentname);
323       //      MESSAGE("Component type : " <<_modulelist[ind].Parsercomponenttype);
324 //       MESSAGE("Component constraint : " << _modulelist[ind].Parserconstraint);
325 //       MESSAGE("Component icone : " << _modulelist[ind].Parsercomponenticone);
326 //       for (unsigned int i = 0; i < _modulelist[ind].ParserListInterface.size(); i++)
327 //      {
328 //        MESSAGE("Component interface name : " << _modulelist[ind].ParserListInterface[i].Parserinterfacename);
329 //        for (unsigned int j=0; j< _modulelist[ind].ParserListInterface[i].Parserinterfaceservicelist.size(); j++)
330 //          {
331 //            MESSAGE("Service name : " << _modulelist[ind].ParserListInterface[i].Parserinterfaceservicelist[j].ParserServiceName);
332 //            MESSAGE("Service default : " << _modulelist[ind].ParserListInterface[i].Parserinterfaceservicelist[j].ParserServicebydefault);
333 //            for (unsigned int k=0; k< _modulelist[ind].ParserListInterface[i].Parserinterfaceservicelist[j].ParserServiceinParameter.size() ; k++)
334 //              {
335 //                MESSAGE("Service Parameter in name : " <<_modulelist[ind].ParserListInterface[i].Parserinterfaceservicelist[j].ParserServiceinParameter[k].ParserParamname);
336 //                MESSAGE("Service Parameter in type : " << _modulelist[ind].ParserListInterface[i].Parserinterfaceservicelist[j].ParserServiceinParameter[k].ParserParamtype);
337 //              }
338 //            for (unsigned int k=0; k< _modulelist[ind].ParserListInterface[i].Parserinterfaceservicelist[j].ParserServiceoutParameter.size() ; k++)
339 //              {
340 //                MESSAGE("Service Parameter out name : " << _modulelist[ind].ParserListInterface[i].Parserinterfaceservicelist[j].ParserServiceoutParameter[k].ParserParamname);
341 //                MESSAGE("Service Parameter out type : " << _modulelist[ind].ParserListInterface[i].Parserinterfaceservicelist[j].ParserServiceoutParameter[k].ParserParamtype);
342 //              }
343 //          }  
344        }
345 //     }
346   //MESSAGE("Document parsed");
347   return true;
348 }
349  
350 //----------------------------------------------------------------------
351 // Function : errorProtocol
352 // Purpose  : overload handler function
353 //----------------------------------------------------------------------  
354 QString SALOME_ModuleCatalog_Handler::errorProtocol()
355 {
356   return errorProt ;
357 }
358
359
360 //----------------------------------------------------------------------
361 // Function : fatalError
362 // Purpose  : overload handler function
363 //----------------------------------------------------------------------  
364 bool SALOME_ModuleCatalog_Handler::fatalError(const QXmlParseException& exception)
365 {
366     errorProt += QString( "fatal parsing error: %1 in line %2, column %3\n" )
367     .arg( exception.message() )
368     .arg( exception.lineNumber() )
369     .arg( exception.columnNumber() );
370
371   return QXmlDefaultHandler::fatalError( exception );
372 }