Salome HOME
Porting KERNEL on new XML reader.
[modules/kernel.git] / src / Container / SALOME_Container.py
1 #! /usr/bin/env python
2 #
3 #  SALOME Container : implementation of container and engine for Kernel
4 #
5 #  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
6 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
7
8 #  This library is free software; you can redistribute it and/or 
9 #  modify it under the terms of the GNU Lesser General Public 
10 #  License as published by the Free Software Foundation; either 
11 #  version 2.1 of the License. 
12
13 #  This library is distributed in the hope that it will be useful, 
14 #  but WITHOUT ANY WARRANTY; without even the implied warranty of 
15 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
16 #  Lesser General Public License for more details. 
17
18 #  You should have received a copy of the GNU Lesser General Public 
19 #  License along with this library; if not, write to the Free Software 
20 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
21
22 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #
24 #
25 #
26 #  File   : SALOME_Container.py
27 #  Author : Paul RASCLE, EDF
28 #  Module : SALOME
29 #  $Header$
30
31 import os
32 import sys
33 import string
34 from omniORB import CORBA, PortableServer
35 # import SALOMEDS before other SALOME modules
36 # (if not, incomplete import done by SALOME module: no load of SALOMEDS_attributes)
37 import SALOMEDS 
38 import Engines, Engines__POA
39 reload(Engines)
40 reload(Engines__POA)
41 from SALOME_NamingServicePy import *
42 from SALOME_ComponentPy import *
43
44 from SALOME_utilities import *
45 from Utils_Identity import getShortHostName
46 from launchConfigureParser import verbose
47
48 #=============================================================================
49
50 #define an implementation of the container interface
51
52 class SALOME_Container_i:
53     _orb = None
54     _poa = None
55     _containerName = ""
56     _naming_service = None
57
58     #-------------------------------------------------------------------------
59
60     def __init__(self ,containerName, containerIORStr):
61         MESSAGE( "SALOME_Container_i::__init__" )
62         self._orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
63         self._poa = self._orb.resolve_initial_references("RootPOA")
64         self._containerName = containerName
65         if verbose(): print "SALOME_Container.SALOME_Container_i : _containerName ",self._containerName
66         #self._naming_service = SALOME_NamingServicePy_i(self._orb)
67         self._container = self._orb.string_to_object(containerIORStr)
68
69     #-------------------------------------------------------------------------
70
71     def import_component(self, componentName):
72         MESSAGE( "SALOME_Container_i::import_component" )
73         ret=0
74         try:
75             print "try import ",componentName
76             __import__(componentName)
77             print "import ",componentName," successful"
78             ret=1
79         except:
80             import traceback
81             traceback.print_exc()
82             print "import ",componentName," not possible"
83         return ret
84         
85     #-------------------------------------------------------------------------
86
87     def create_component_instance(self, componentName, instanceName, studyId):
88         MESSAGE( "SALOME_Container_i::create_component_instance" )
89         comp_iors=""
90         try:
91             component=__import__(componentName)
92             factory=getattr(component,componentName)
93             comp_i=factory(self._orb,
94                            self._poa,
95                            self._container,
96                            self._containerName,
97                            instanceName,
98                            componentName)
99
100             MESSAGE( "SALOME_Container_i::create_component_instance : OK")
101             comp_o = comp_i._this()
102             comp_iors = self._orb.object_to_string(comp_o)
103         except:
104             import traceback
105             traceback.print_exc()
106             MESSAGE( "SALOME_Container_i::create_component_instance : NOT OK")
107         return comp_iors 
108         
109