2 # Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 # SALOME NamingService : wrapping NamingService services
24 # File : SALOME_NamingServicePy.py
25 # Author : Estelle Deville, CEA
31 from omniORB import CORBA
36 from SALOME_utilities import *
37 #=============================================================================
39 class SALOME_NamingServicePy_i(object):
45 #-------------------------------------------------------------------------
47 def __init__(self, orb):
48 #MESSAGE ( "SALOME_NamingServicePy_i::__init__" )
50 # initialize root context and current context
53 while steps > 0 and ok == 0:
55 obj =self._orb.resolve_initial_references("NameService")
56 self._root_context =obj._narrow(CosNaming.NamingContext)
57 self._current_context = self._root_context
60 if self._root_context is None :
61 #MESSAGE ( "Name Service Reference is invalid" )
63 MESSAGE(" Name service not found")
66 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
67 MESSAGE(" Name service not found")
70 if steps == 0 and self._root_context is None:
71 MESSAGE ( "Name Service Reference is invalid" )
74 #-------------------------------------------------------------------------
76 def Register(self,ObjRef, Path):
77 """ ns.Register(object,pathname )
79 register a CORBA object under a pathname
82 MESSAGE ( "SALOME_NamingServicePy_i::Register" )
84 path_list = list(Path)
86 self._current_context = self._root_context
87 #delete first '/' before split
90 result_resolve_path = string.split(Path,'/')
91 if len(result_resolve_path)>1:
92 # A directory is treated (not only an object name)
93 # We had to test if the directory where ObjRef should be recorded
95 # If not, the new context has to be created
97 for i in range(len(result_resolve_path)-1):
98 _context_name.append(CosNaming.NameComponent(result_resolve_path[i],"dir"))
101 obj = self._current_context.resolve(_context_name)
102 self._current_context = obj._narrow(CosNaming.NamingContext)
103 except CosNaming.NamingContext.NotFound, ex:
105 except CosNaming.NamingContext.InvalidName, ex:
106 MESSAGE ( "Register : CosNaming.NamingContext.InvalidName" )
107 except CosNaming.NamingContext.CannotProceed, ex:
108 MESSAGE ( "Register : CosNaming.NamingContext.CannotProceed" )
109 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
110 MESSAGE ( "Register : CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE" )
113 # at least one context of the complete path is not created, we had
114 # to create it or them
116 for i in range(len(result_resolve_path)-1):
117 _context_name = [CosNaming.NameComponent(result_resolve_path[i],"dir")]
120 obj = self._current_context.resolve(_context_name)
121 self._current_context = obj._narrow(CosNaming.NamingContext)
122 except CosNaming.NamingContext.NotFound, ex:
123 #This context is not created. It will be done
124 self._current_context = self._current_context.bind_new_context(_context_name)
126 #The current directory is now the directory where the object should
129 _context_name = [CosNaming.NameComponent(result_resolve_path[len(result_resolve_path)-1],"object")]
131 self._current_context.bind(_context_name,ObjRef)
132 except CosNaming.NamingContext.NotFound, ex:
133 MESSAGE ( "Register : CosNaming.NamingContext.NotFound" )
134 except CosNaming.NamingContext.InvalidName, ex:
135 MESSAGE ( "Register : CosNaming.NamingContext.InvalidName" )
136 except CosNaming.NamingContext.CannotProceed, ex:
137 MESSAGE ( "Register : CosNaming.NamingContext.CannotProceed" )
138 except CosNaming.NamingContext.AlreadyBound, ex:
139 MESSAGE ( "Register : CosNaming.NamingContext.AlreadyBound, object will be rebind" )
140 self._current_context.rebind(_context_name,ObjRef)
141 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
142 MESSAGE ( "Register : CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE" )
144 #-------------------------------------------------------------------------
146 def Resolve(self, Path):
147 """ ns.Resolve(pathname) -> object
149 find a CORBA object (ior) by its pathname
151 #MESSAGE ( "SALOME_NamingServicePy_i::Resolve" )
152 path_list = list(Path)
153 if path_list[0]=='/':
154 self._current_context = self._root_context
155 #delete first '/' before split
158 result_resolve_path = string.split(Path,'/')
160 for i in range(len(result_resolve_path)-1):
161 _context_name.append(CosNaming.NameComponent(result_resolve_path[i],"dir"))
162 _context_name.append(CosNaming.NameComponent(result_resolve_path[len(result_resolve_path)-1],"object"))
164 self._obj = self._current_context.resolve(_context_name)
165 except CosNaming.NamingContext.NotFound, ex:
166 MESSAGE ( "Resolve : CosNaming.NamingContext.NotFound" )
168 except CosNaming.NamingContext.InvalidName, ex:
169 MESSAGE ( "Resolve : CosNaming.NamingContext.InvalidName" )
171 except CosNaming.NamingContext.CannotProceed, ex:
172 MESSAGE ( "Resolve : CosNaming.NamingContext.CannotProceed" )
174 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
175 MESSAGE ( "Resolve : CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE" )
180 #-------------------------------------------------------------------------
182 def Create_Directory(self,ObjRef, Path):
183 MESSAGE ( "SALOME_NamingServicePy_i::Create_Directory" )
185 path_list = list(Path)
186 if path_list[0]=='/':
187 self._current_context = self._root_context
188 #delete first '/' before split
191 result_resolve_path = string.split(Path,'/')
193 for i in range(len(result_resolve_path)):
194 _context_name[CosNaming.NameComponent(result_resolve_path[i],"dir")]
196 obj = self._current_context.resolve(_context_name)
197 self._current_context = obj._narrow(CosNaming.NamingContext)
198 except CosNaming.NamingContext.NotFound, ex:
199 self._current_context = self._current_context.bind_new_context(_context_name)
200 except CosNaming.NamingContext.InvalidName, ex:
201 MESSAGE ( "Create_Directory : CosNaming.NamingContext.InvalidName" )
202 except CosNaming.NamingContext.CannotProceed, ex:
203 MESSAGE ( "Create_Directory : CosNaming.NamingContext.CannotProceed" )
204 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
205 MESSAGE ( "Create_Directory : CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE" )
207 def Destroy_Name(self,Path):
208 resolve_path=string.split(Path,'/')
209 if resolve_path[0] == '': del resolve_path[0]
210 dir_path=resolve_path[:-1]
213 context_name.append(CosNaming.NameComponent(e,"dir"))
214 context_name.append(CosNaming.NameComponent(resolve_path[-1],"object"))
217 self._root_context.unbind(context_name)
218 except CosNaming.NamingContext.NotFound, ex:
220 except CORBA.Exception,ex:
223 def Destroy_FullDirectory(self,Path):
225 for e in string.split(Path,'/'):
227 context_name.append(CosNaming.NameComponent(e,"dir"))
230 context=self._root_context.resolve(context_name)
231 except CosNaming.NamingContext.NotFound, ex:
233 except CORBA.Exception,ex:
236 bl,bi=context.list(0)
240 for s in b.binding_name :
241 if s.kind == "object":
243 elif s.kind == "dir":
248 self._root_context.unbind(context_name)