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_Acomponent_impl.cxx
25 // Author : Estelle Deville
29 #include "SALOME_ModuleCatalog_Acomponent_impl.hxx"
32 //----------------------------------------------------------------------
33 // Function : SALOME_ModuleCatalog_AcomponentImpl
34 // Purpose : Constructor
35 // Affect the component name, type,icone, a bool to define
36 // if it's multistudy or not.
37 // Affect too the constraint and the interfaces of the component
38 // and the pathes prefixes for all computers
39 //----------------------------------------------------------------------
40 SALOME_ModuleCatalog_AcomponentImpl::SALOME_ModuleCatalog_AcomponentImpl(
43 const char* constraint,
44 SALOME_ModuleCatalog::ComponentType componenttype,
45 CORBA::Boolean componentmultistudy,
47 SALOME_ModuleCatalog::ListOfDefInterface list_interfaces,
48 ListOfPathPrefix pathes)
50 MESSAGE("Component creation")
51 // Affect component name
52 _component_name = new char[strlen(name)+1];
53 strcpy(_component_name, name);
55 // Affect component user name
56 _component_user_name = new char[strlen(username)+1];
57 strcpy(_component_user_name, username);
60 _constraint =new char[strlen(constraint)+1];
61 strcpy(_constraint, constraint);
63 // Affect component type
64 _componenttype = componenttype;
66 // Affect component multistudy
67 _componentmultistudy = componentmultistudy;
70 _icone =new char[strlen(icone)+1];
71 strcpy(_icone, icone);
74 _list_interfaces.length(list_interfaces.length());
75 _list_interfaces = list_interfaces;
77 // affect path prefixes
78 _pathes.resize(pathes.size());
82 //----------------------------------------------------------------------
83 // Function : ~SALOME_ModuleCatalog_AcomponentImpl
84 // Purpose : Destructor
85 //----------------------------------------------------------------------
86 SALOME_ModuleCatalog_AcomponentImpl::~SALOME_ModuleCatalog_AcomponentImpl()
88 MESSAGE("Component destruction")
90 delete [] _component_name;
91 delete [] _component_user_name;
92 delete [] _constraint;
95 //----------------------------------------------------------------------
96 // Function : GetInterfaceList
97 // Purpose : get a list of the interfaces name of a component
98 //----------------------------------------------------------------------
99 SALOME_ModuleCatalog::ListOfInterfaces*
100 SALOME_ModuleCatalog_AcomponentImpl::GetInterfaceList()
102 SALOME_ModuleCatalog::ListOfInterfaces_var _list = new SALOME_ModuleCatalog::ListOfInterfaces;
104 // All the interfaces are defined in _list_interfaces affected at the
105 // component creation
106 unsigned int _length_interfaces =_list_interfaces.length();
108 _list->length(_length_interfaces);
110 // Parse all the interfaces to get their name
111 for (unsigned int ind = 0; ind < _length_interfaces; ind++)
113 _list[ind] = CORBA::string_dup(_list_interfaces[ind].interfacename);
114 MESSAGE("The component " << _component_name << " contains " << _list[ind] << " as interface")
117 return _list._retn();
120 //----------------------------------------------------------------------
121 // Function : GetInterface
122 // Purpose : get one interface of a component
123 //----------------------------------------------------------------------
124 SALOME_ModuleCatalog::DefinitionInterface*
125 SALOME_ModuleCatalog_AcomponentImpl::GetInterface(const char* interfacename)
126 throw(SALOME_ModuleCatalog::NotFound)
128 SALOME_ModuleCatalog::DefinitionInterface_var _interface = new SALOME_ModuleCatalog::DefinitionInterface;
129 SALOME_ModuleCatalog::Service_var _service = new SALOME_ModuleCatalog::Service;
130 // Variables initialisation
131 _interface->interfaceservicelist.length(0);
135 // looking for the specified interface
136 for (unsigned int ind = 0; ind < _list_interfaces.length(); ind++)
138 if (strcmp(interfacename, _list_interfaces[ind].interfacename) == 0)
143 // Affect the name of the interface
144 _interface->interfacename = interfacename;
146 // Affect each service of the wanted interface
147 for (unsigned int ind1 = 0; ind1 < _list_interfaces[ind].interfaceservicelist.length() ; ind1++)
149 _interface->interfaceservicelist.length(_length+1);
150 _service = _duplicate_service(_list_interfaces[ind].interfaceservicelist[ind1]);
151 _interface->interfaceservicelist[_length] = _service;
161 // The interface was not found, the exception should be thrown
162 char * message = new char[100];
163 strcpy(message, "The interface ");
164 strcat(message,interfacename);
165 strcat(message, " of the component ");
166 strcat(message,_component_name);
167 strcat(message, " was not found") ;
168 MESSAGE("The interface " << interfacename << " of the component " << _component_name << " was not found")
169 throw SALOME_ModuleCatalog::NotFound(message);
173 return _interface._retn();
178 //----------------------------------------------------------------------
179 // Function : GetServiceList
180 // Purpose : get a list of the services name of an interface
182 //----------------------------------------------------------------------
183 SALOME_ModuleCatalog::ListOfServices*
184 SALOME_ModuleCatalog_AcomponentImpl::GetServiceList(const char* interfacename)
185 throw(SALOME_ModuleCatalog::NotFound)
187 SALOME_ModuleCatalog::ListOfServices_var _list = new SALOME_ModuleCatalog::ListOfServices;
189 // Variables initialisation
193 // looking for the specified interface
194 for (unsigned int ind = 0; ind < _list_interfaces.length(); ind++)
196 if (strcmp(interfacename, _list_interfaces[ind].interfacename) == 0)
200 // Get the list of services name for this interface
201 unsigned int _length_services = _list_interfaces[ind].interfaceservicelist.length();
202 _list->length(_length_services);
203 for (unsigned int ind1 = 0; ind1 < _length_services ; ind1++)
205 _list[ind1] = CORBA::string_dup(_list_interfaces[ind].interfaceservicelist[ind1].ServiceName);
206 MESSAGE("The interface " << interfacename << " of the component " << _component_name << " contains " << _list[ind1] << " as a service")
213 // The interface was not found, the exception should be thrown
214 char * message = new char[100];
215 strcpy(message, "The interface ");
216 strcat(message,interfacename);
217 strcat(message, " of the component ");
218 strcat(message,_component_name);
219 strcat(message, " was not found") ;
220 MESSAGE("The interface " << interfacename << " of the component " << _component_name << " was not found")
221 throw SALOME_ModuleCatalog::NotFound(message);
225 return _list._retn();
229 //----------------------------------------------------------------------
230 // Function : GetService
231 // Purpose : get one service of an interface of a component
232 //----------------------------------------------------------------------
233 SALOME_ModuleCatalog::Service*
234 SALOME_ModuleCatalog_AcomponentImpl::GetService(const char* interfacename,
235 const char* servicename)
236 throw(SALOME_ModuleCatalog::NotFound)
238 SALOME_ModuleCatalog::Service_var _service = new SALOME_ModuleCatalog::Service;
239 // Varaibles initialisation
242 // looking for the specified interface
243 for (unsigned int ind = 0; ind < _list_interfaces.length(); ind++)
245 if (strcmp(interfacename, _list_interfaces[ind].interfacename) == 0)
248 // looking for the specified service
249 for (unsigned int ind1 = 0; ind1 < _list_interfaces[ind].interfaceservicelist.length() ; ind1++)
251 if (strcmp(servicename, _list_interfaces[ind].interfaceservicelist[ind1].ServiceName) == 0)
254 // Affect the service to be returned
256 _service = _duplicate_service(_list_interfaces[ind].interfaceservicelist[ind1]);
265 // The service was not found, the exception should be thrown
266 char * message = new char[100];
267 strcpy(message, "The service ");
268 strcat(message, servicename);
269 strcat(message," of the interface ");
270 strcat(message,interfacename);
271 strcat(message, " of the component ");
272 strcat(message,_component_name);
273 strcat(message, " was not found") ;
274 MESSAGE("The service " << servicename << " of the interface " << interfacename << " of the component " << _component_name << " was not found")
275 throw SALOME_ModuleCatalog::NotFound(message);
279 return _service._retn();
282 //----------------------------------------------------------------------
283 // Function : GetDefaultService
284 // Purpose : get the default service of the interface
285 //----------------------------------------------------------------------
286 SALOME_ModuleCatalog::Service*
287 SALOME_ModuleCatalog_AcomponentImpl::GetDefaultService(const char* interfacename)
288 throw(SALOME_ModuleCatalog::NotFound)
290 SALOME_ModuleCatalog::Service_var _service = new SALOME_ModuleCatalog::Service;
292 // Variables initialisation
295 // looking for the specified interface
296 for (unsigned int ind = 0; ind < _list_interfaces.length(); ind++)
298 if (strcmp(interfacename, _list_interfaces[ind].interfacename) == 0)
301 // looking for the defautl service of the wanted interface
302 for (unsigned int ind1 = 0; ind1 < _list_interfaces[ind].interfaceservicelist.length() ; ind1++)
304 if (_list_interfaces[ind].interfaceservicelist[ind1].Servicebydefault)
307 // affect the service to be returned
309 _service = _duplicate_service(_list_interfaces[ind].interfaceservicelist[ind1]);
318 // The service was not found, the exception should be thrown
319 char * message = new char[100];
320 strcpy(message, "The default service of the interface ");
321 strcat(message,interfacename);
322 strcat(message, " of the component ");
323 strcat(message,_component_name);
324 strcat(message, " was not found") ;
325 MESSAGE("The default service of the interface " << interfacename << " of the component " << _component_name << " was not found")
326 throw SALOME_ModuleCatalog::NotFound(message);
330 return _service._retn();
333 //----------------------------------------------------------------------
334 // Function : GetPathPrefix
335 // Purpose : get the PathPrefix of a computer
336 //----------------------------------------------------------------------
338 SALOME_ModuleCatalog_AcomponentImpl::GetPathPrefix(const char* machinename)
339 throw(SALOME_ModuleCatalog::NotFound)
341 MESSAGE("Begin of GetPathPrefix")
342 // Variables initialisation
346 // Parse all the path prefixes
347 // looking for the wanted computer
348 for (unsigned int ind = 0 ; ind < _pathes.size() ; ind++)
350 for (unsigned int ind1 = 0 ; ind1 < _pathes[ind].ListOfComputer.size() ; ind1++)
352 if (strcmp(machinename, _pathes[ind].ListOfComputer[ind1].c_str()) == 0)
356 // affect the path to be returned
357 const char* _temp = _pathes[ind].path.c_str() ;
358 _path = new char[strlen(_temp)+1];
366 // The computer was not found, the exception should be thrown
367 char * message = new char[100];
368 strcpy(message, "The computer ");
369 strcat(message,machinename);
370 strcat(message, " was not found in the catalog associated to the component ") ;
371 strcat(message,_component_name);
372 MESSAGE("The computer " << machinename << " was not found in the catalog associated to the component " << _component_name)
373 throw SALOME_ModuleCatalog::NotFound(message);
380 //----------------------------------------------------------------------
381 // Function : constraint
382 // Purpose : obtain the constraint affected to a component
383 //----------------------------------------------------------------------
384 char* SALOME_ModuleCatalog_AcomponentImpl::constraint()
386 return CORBA::string_dup(_constraint);
389 //----------------------------------------------------------------------
390 // Function : componentname
391 // Purpose : obtain the componentname
392 //----------------------------------------------------------------------
393 char* SALOME_ModuleCatalog_AcomponentImpl::componentname()
395 return CORBA::string_dup(_component_name);
398 //----------------------------------------------------------------------
399 // Function : componentusername
400 // Purpose : obtain the componentusername
401 //----------------------------------------------------------------------
402 char* SALOME_ModuleCatalog_AcomponentImpl::componentusername()
404 return CORBA::string_dup(_component_user_name);
407 //----------------------------------------------------------------------
408 // Function : multistudy
409 // Purpose : define if a component can be multistudy or not
410 //----------------------------------------------------------------------
411 CORBA::Boolean SALOME_ModuleCatalog_AcomponentImpl::multistudy()
413 return _componentmultistudy ;
416 //----------------------------------------------------------------------
417 // Function : component_type
418 // Purpose : define the type of the component
419 //----------------------------------------------------------------------
420 SALOME_ModuleCatalog::ComponentType
421 SALOME_ModuleCatalog_AcomponentImpl::component_type()
423 return _componenttype;
426 //----------------------------------------------------------------------
428 // Purpose : obtain the icone affected to a component (for IAPP)
429 //----------------------------------------------------------------------
430 char* SALOME_ModuleCatalog_AcomponentImpl::component_icone()
432 return CORBA::string_dup(_icone);
435 //----------------------------------------------------------------------
436 // Function : _duplicate_service
437 // Purpose : duplicate a service
438 //----------------------------------------------------------------------
439 SALOME_ModuleCatalog::Service_var
440 SALOME_ModuleCatalog_AcomponentImpl::_duplicate_service(SALOME_ModuleCatalog::Service service)
442 SALOME_ModuleCatalog::Service_var _service = new SALOME_ModuleCatalog::Service;
445 _service->ServiceName = CORBA::string_dup(service.ServiceName);
446 // service by default
447 _service->Servicebydefault = service.Servicebydefault;
449 // in Parameters service
450 unsigned int _length_in_param = service.ServiceinParameter.length();
451 for(unsigned int ind = 0; ind < _length_in_param; ind++)
453 _service->ServiceinParameter.length(_length_in_param);
455 _service->ServiceinParameter[ind].Parametertype = CORBA::string_dup(service.ServiceinParameter[ind].Parametertype);
457 _service->ServiceinParameter[ind].Parametername = CORBA::string_dup(service.ServiceinParameter[ind].Parametername);
460 // out Parameters service
461 unsigned int _length_out_param = service.ServiceoutParameter.length();
462 for(unsigned int ind = 0; ind < _length_out_param; ind++)
464 _service->ServiceoutParameter.length(_length_out_param);
465 // out Parameter type
466 _service->ServiceoutParameter[ind].Parametertype = CORBA::string_dup(service.ServiceoutParameter[ind].Parametertype);
467 // out Parameter name
468 _service->ServiceoutParameter[ind].Parametername = CORBA::string_dup(service.ServiceoutParameter[ind].Parametername);