+
+ def import_component(self, componentName):
+ MESSAGE( "SALOME_Container_i::import_component" )
+ reason = ""
+ try:
+ if verbose(): print "try import %s" % componentName
+ # try import component
+ module=__import__(componentName)
+ if verbose(): print "import %s is done successfully" % componentName
+ # if import successfully, check that component is loadable
+ if not hasattr(module, componentName):
+ reason = "module %s is not loadable" % componentName
+ print reason
+ pass
+ pass
+ except:
+ import traceback
+ print "cannot import %s" % componentName
+ traceback.print_exc()
+ reason = "cannot import %s" % componentName
+ return reason
+
+ #-------------------------------------------------------------------------
+
+ def load_component_Library(self, componentName):
+ MESSAGE( "SALOME_ContainerPy_i::load_component_Library " + str(componentName) )
+ ret = 0
+ instanceName = componentName + "_inst_" + `self._numInstance`
+ interfaceName = componentName
+ reason = self.import_component(componentName)
+ return reason == "", reason
+
+ #-------------------------------------------------------------------------
+
+ def create_component_instance_env(self, componentName, studyId, env):
+ return self.create_component_instance(componentName, studyId), ""
+
+ def create_component_instance(self, componentName, studyId):
+ MESSAGE( "SALOME_ContainerPy_i::create_component_instance ==> " + str(componentName) + ' ' + str(studyId) )
+ if studyId < 0:
+ MESSAGE( "Study ID is lower than 0!" )
+ return None
+ else:
+ self._numInstance = self._numInstance +1
+ instanceName = componentName + "_inst_" + `self._numInstance`
+ comp_iors=""
+ try:
+ component=__import__(componentName)
+ factory=getattr(component,componentName)
+ comp_i=factory(self._orb,
+ self._poa,
+ self._this(),
+ self._containerName,
+ instanceName,
+ componentName)
+
+ MESSAGE( "SALOME_Container_i::create_component_instance : OK")
+ comp_o = comp_i._this()
+ self._listInstances_map[instanceName] = comp_i
+ except:
+ import traceback
+ traceback.print_exc()
+ MESSAGE( "SALOME_Container_i::create_component_instance : NOT OK")
+ return comp_o
+
+ #-------------------------------------------------------------------------
+
+ def find_component_instance(self, registeredName, studyId):
+ anEngine = None
+ keysList = self._listInstances_map.keys()
+ i = 0
+ while i < len(keysList):
+ instance = keysList[i]
+ if find(instance,registeredName) == 0:
+ anEngine = self._listInstances_map[instance]
+ if studyId == anEngine.getStudyId():
+ return anEngine._this()
+ i = i + 1
+ return anEngine._this()
+
+
+ #-------------------------------------------------------------------------
+
+ def create_python_service_instance(self, CompName):
+ return self.create_component_instance(CompName, 0)
+
+ #-------------------------------------------------------------------------