3 # SALOME NamingService : wrapping NamingService services
5 # Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
6 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
22 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
26 # File : SALOME_NamingServicePy.py
27 # Author : Estelle Deville, CEA
33 from omniORB import CORBA
37 from SALOME_utilities import *
38 #=============================================================================
40 class SALOME_NamingServicePy_i(object):
46 #-------------------------------------------------------------------------
48 def __init__(self, orb):
49 #MESSAGE ( "SALOME_NamingServicePy_i::__init__" )
51 # initialize root context and current context
54 while steps > 0 and ok == 0:
56 obj =self._orb.resolve_initial_references("NameService")
57 self._root_context =obj._narrow(CosNaming.NamingContext)
58 self._current_context = self._root_context
61 if self._root_context is None :
62 #MESSAGE ( "Name Service Reference is invalid" )
64 MESSAGE(" Name service not found")
67 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
68 MESSAGE(" Name service not found")
71 if steps == 0 and self._root_context is None:
72 MESSAGE ( "Name Service Reference is invalid" )
75 #-------------------------------------------------------------------------
77 def Register(self,ObjRef, Path):
78 """ ns.Register(object,pathname )
80 register a CORBA object under a pathname
83 MESSAGE ( "SALOME_NamingServicePy_i::Register" )
85 path_list = list(Path)
87 self._current_context = self._root_context
88 #delete first '/' before split
91 result_resolve_path = split(Path,'/')
92 if len(result_resolve_path)>1:
93 # A directory is treated (not only an object name)
94 # We had to test if the directory where ObjRef should be recorded
96 # If not, the new context has to be created
98 for i in range(len(result_resolve_path)-1):
99 _context_name.append(CosNaming.NameComponent(result_resolve_path[i],"dir"))
102 obj = self._current_context.resolve(_context_name)
103 self._current_context = obj._narrow(CosNaming.NamingContext)
104 except CosNaming.NamingContext.NotFound, ex:
106 except CosNaming.NamingContext.InvalidName, ex:
107 MESSAGE ( "Register : CosNaming.NamingContext.InvalidName" )
108 except CosNaming.NamingContext.CannotProceed, ex:
109 MESSAGE ( "Register : CosNaming.NamingContext.CannotProceed" )
110 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
111 MESSAGE ( "Register : CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE" )
114 # at least one context of the complete path is not created, we had
115 # to create it or them
117 for i in range(len(result_resolve_path)-1):
118 _context_name = [CosNaming.NameComponent(result_resolve_path[i],"dir")]
121 obj = self._current_context.resolve(_context_name)
122 self._current_context = obj._narrow(CosNaming.NamingContext)
123 except CosNaming.NamingContext.NotFound, ex:
124 #This context is not created. It will be done
125 self._current_context = self._current_context.bind_new_context(_context_name)
127 #The current directory is now the directory where the object should
130 _context_name = [CosNaming.NameComponent(result_resolve_path[len(result_resolve_path)-1],"object")]
132 self._current_context.bind(_context_name,ObjRef)
133 except CosNaming.NamingContext.NotFound, ex:
134 MESSAGE ( "Register : CosNaming.NamingContext.NotFound" )
135 except CosNaming.NamingContext.InvalidName, ex:
136 MESSAGE ( "Register : CosNaming.NamingContext.InvalidName" )
137 except CosNaming.NamingContext.CannotProceed, ex:
138 MESSAGE ( "Register : CosNaming.NamingContext.CannotProceed" )
139 except CosNaming.NamingContext.AlreadyBound, ex:
140 MESSAGE ( "Register : CosNaming.NamingContext.AlreadyBound, object will be rebind" )
141 self._current_context.rebind(_context_name,ObjRef)
142 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
143 MESSAGE ( "Register : CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE" )
145 #-------------------------------------------------------------------------
147 def Resolve(self, Path):
148 """ ns.Resolve(pathname) -> object
150 find a CORBA object (ior) by its pathname
152 #MESSAGE ( "SALOME_NamingServicePy_i::Resolve" )
153 path_list = list(Path)
154 if path_list[0]=='/':
155 self._current_context = self._root_context
156 #delete first '/' before split
159 result_resolve_path = split(Path,'/')
161 for i in range(len(result_resolve_path)-1):
162 _context_name.append(CosNaming.NameComponent(result_resolve_path[i],"dir"))
163 _context_name.append(CosNaming.NameComponent(result_resolve_path[len(result_resolve_path)-1],"object"))
165 self._obj = self._current_context.resolve(_context_name)
166 except CosNaming.NamingContext.NotFound, ex:
167 MESSAGE ( "Resolve : CosNaming.NamingContext.NotFound" )
169 except CosNaming.NamingContext.InvalidName, ex:
170 MESSAGE ( "Resolve : CosNaming.NamingContext.InvalidName" )
172 except CosNaming.NamingContext.CannotProceed, ex:
173 MESSAGE ( "Resolve : CosNaming.NamingContext.CannotProceed" )
175 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
176 MESSAGE ( "Resolve : CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE" )
181 #-------------------------------------------------------------------------
183 def Create_Directory(self,ObjRef, Path):
184 MESSAGE ( "SALOME_NamingServicePy_i::Create_Directory" )
186 path_list = list(Path)
187 if path_list[0]=='/':
188 self._current_context = self._root_context
189 #delete first '/' before split
192 result_resolve_path = split(Path,'/')
194 for i in range(len(result_resolve_path)):
195 _context_name[CosNaming.NameComponent(result_resolve_path[i],"dir")]
197 obj = self._current_context.resolve(_context_name)
198 self._current_context = obj._narrow(CosNaming.NamingContext)
199 except CosNaming.NamingContext.NotFound, ex:
200 self._current_context = self._current_context.bind_new_context(_context_name)
201 except CosNaming.NamingContext.InvalidName, ex:
202 MESSAGE ( "Create_Directory : CosNaming.NamingContext.InvalidName" )
203 except CosNaming.NamingContext.CannotProceed, ex:
204 MESSAGE ( "Create_Directory : CosNaming.NamingContext.CannotProceed" )
205 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
206 MESSAGE ( "Create_Directory : CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE" )