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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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:
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.COMM_FAILURE, ex:
68 MESSAGE(" Name service not found")
72 MESSAGE ( "Name Service Reference is invalid" )
74 #-------------------------------------------------------------------------
75 def Register(self,ObjRef, Path):
76 MESSAGE ( "SALOME_NamingServicePy_i::Register" )
78 path_list = list(Path)
80 self._current_context = self._root_context
81 #delete first '/' before split
84 result_resolve_path = split(Path,'/')
85 if len(result_resolve_path)>1:
86 # A directory is treated (not only an object name)
87 # We had to test if the directory where ObjRef should be recorded
89 # If not, the new context has to be created
91 for i in range(len(result_resolve_path)-1):
92 _context_name.append(CosNaming.NameComponent(result_resolve_path[i],"dir"))
95 obj = self._current_context.resolve(_context_name)
96 self._current_context = obj._narrow(CosNaming.NamingContext)
97 except CosNaming.NamingContext.NotFound, ex:
99 except CosNaming.NamingContext.InvalidName, ex:
100 MESSAGE ( "Register : CosNaming.NamingContext.InvalidName" )
101 except CosNaming.NamingContext.CannotProceed, ex:
102 MESSAGE ( "Register : CosNaming.NamingContext.CannotProceed" )
103 except CORBA.COMM_FAILURE, ex:
104 MESSAGE ( "Register : CORBA.COMM_FAILURE" )
107 # at least one context of the complete path is not created, we had
108 # to create it or them
110 for i in range(len(result_resolve_path)-1):
111 _context_name = [CosNaming.NameComponent(result_resolve_path[i],"dir")]
114 obj = self._current_context.resolve(_context_name)
115 self._current_context = obj._narrow(CosNaming.NamingContext)
116 except CosNaming.NamingContext.NotFound, ex:
117 #This context is not created. It will be done
118 self._current_context = self._current_context.bind_new_context(_context_name)
120 #The current directory is now the directory where the object should
123 _context_name = [CosNaming.NameComponent(result_resolve_path[len(result_resolve_path)-1],"object")]
125 self._current_context.bind(_context_name,ObjRef)
126 except CosNaming.NamingContext.NotFound, ex:
127 MESSAGE ( "Register : CosNaming.NamingContext.NotFound" )
128 except CosNaming.NamingContext.InvalidName, ex:
129 MESSAGE ( "Register : CosNaming.NamingContext.InvalidName" )
130 except CosNaming.NamingContext.CannotProceed, ex:
131 MESSAGE ( "Register : CosNaming.NamingContext.CannotProceed" )
132 except CosNaming.NamingContext.AlreadyBound, ex:
133 MESSAGE ( "Register : CosNaming.NamingContext.AlreadyBound, object will be rebind" )
134 self._current_context.rebind(_context_name,ObjRef)
135 except CORBA.COMM_FAILURE, ex:
136 MESSAGE ( "Register : CORBA.COMM_FAILURE" )
139 #-------------------------------------------------------------------------
140 def Resolve(self, Path):
141 #MESSAGE ( "SALOME_NamingServicePy_i::Resolve" )
142 path_list = list(Path)
143 if path_list[0]=='/':
144 self._current_context = self._root_context
145 #delete first '/' before split
148 result_resolve_path = split(Path,'/')
150 for i in range(len(result_resolve_path)-1):
151 _context_name.append(CosNaming.NameComponent(result_resolve_path[i],"dir"))
152 _context_name.append(CosNaming.NameComponent(result_resolve_path[len(result_resolve_path)-1],"object"))
154 self._obj = self._current_context.resolve(_context_name)
155 except CosNaming.NamingContext.NotFound, ex:
156 MESSAGE ( "Resolve : CosNaming.NamingContext.NotFound" )
158 except CosNaming.NamingContext.InvalidName, ex:
159 MESSAGE ( "Resolve : CosNaming.NamingContext.InvalidName" )
161 except CosNaming.NamingContext.CannotProceed, ex:
162 MESSAGE ( "Resolve : CosNaming.NamingContext.CannotProceed" )
164 except CORBA.COMM_FAILURE, ex:
165 MESSAGE ( "Resolve : CORBA.COMM_FAILURE" )
171 #-------------------------------------------------------------------------
172 def Create_Directory(self,ObjRef, Path):
173 MESSAGE ( "SALOME_NamingServicePy_i::Create_Directory" )
175 path_list = list(Path)
176 if path_list[0]=='/':
177 self._current_context = self._root_context
178 #delete first '/' before split
181 result_resolve_path = split(Path,'/')
183 for i in range(len(result_resolve_path)):
184 _context_name[CosNaming.NameComponent(result_resolve_path[i],"dir")]
186 obj = self._current_context.resolve(_context_name)
187 self._current_context = obj._narrow(CosNaming.NamingContext)
188 except CosNaming.NamingContext.NotFound, ex:
189 self._current_context = self._current_context.bind_new_context(_context_name)
190 except CosNaming.NamingContext.InvalidName, ex:
191 MESSAGE ( "Create_Directory : CosNaming.NamingContext.InvalidName" )
192 except CosNaming.NamingContext.CannotProceed, ex:
193 MESSAGE ( "Create_Directory : CosNaming.NamingContext.CannotProceed" )
194 except CORBA.COMM_FAILURE, ex:
195 MESSAGE ( "Create_Directory : CORBA.COMM_FAILURE" )