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
32 from omniORB import CORBA
36 from SALOME_utilities import *
37 #=============================================================================
39 class SALOME_NamingServicePy_i:
45 #-------------------------------------------------------------------------
47 def __init__(self, orb):
48 MESSAGE ( "SALOME_NamingServicePy_i::__init__" )
50 # initialize root context and current context
51 obj =self._orb.resolve_initial_references("NameService")
52 self._root_context =obj._narrow(CosNaming.NamingContext)
53 self._current_context = self._root_context
56 if self._root_context is None :
57 MESSAGE ( "Name Service Reference is invalid" )
60 #-------------------------------------------------------------------------
61 def Register(self,ObjRef, Path):
62 MESSAGE ( "SALOME_NamingServicePy_i::Register" )
64 path_list = list(Path)
66 self._current_context = self._root_context
67 #delete first '/' before split
70 result_resolve_path = split(Path,'/')
71 if len(result_resolve_path)>1:
72 # A directory is treated (not only an object name)
73 # We had to test if the directory where ObjRef should be recorded
75 # If not, the new context has to be created
77 for i in range(len(result_resolve_path)-1):
78 _context_name.append(CosNaming.NameComponent(result_resolve_path[i],"dir"))
81 obj = self._current_context.resolve(_context_name)
82 self._current_context = obj._narrow(CosNaming.NamingContext)
83 except CosNaming.NamingContext.NotFound, ex:
85 except CosNaming.NamingContext.InvalidName, ex:
86 MESSAGE ( "Register : CosNaming.NamingContext.InvalidName" )
87 except CosNaming.NamingContext.CannotProceed, ex:
88 MESSAGE ( "Register : CosNaming.NamingContext.CannotProceed" )
89 except CORBA.COMM_FAILURE, ex:
90 MESSAGE ( "Register : CORBA.COMM_FAILURE" )
93 # at least one context of the complete path is not created, we had
94 # to create it or them
96 for i in range(len(result_resolve_path)-1):
97 _context_name = [CosNaming.NameComponent(result_resolve_path[i],"dir")]
100 obj = self._current_context.resolve(_context_name)
101 self._current_context = obj._narrow(CosNaming.NamingContext)
102 except CosNaming.NamingContext.NotFound, ex:
103 #This context is not created. It will be done
104 self._current_context = self._current_context.bind_new_context(_context_name)
106 #The current directory is now the directory where the object should
109 _context_name = [CosNaming.NameComponent(result_resolve_path[len(result_resolve_path)-1],"object")]
111 self._current_context.bind(_context_name,ObjRef)
112 except CosNaming.NamingContext.NotFound, ex:
113 MESSAGE ( "Register : CosNaming.NamingContext.NotFound" )
114 except CosNaming.NamingContext.InvalidName, ex:
115 MESSAGE ( "Register : CosNaming.NamingContext.InvalidName" )
116 except CosNaming.NamingContext.CannotProceed, ex:
117 MESSAGE ( "Register : CosNaming.NamingContext.CannotProceed" )
118 except CosNaming.NamingContext.AlreadyBound, ex:
119 MESSAGE ( "Register : CosNaming.NamingContext.AlreadyBound, object will be rebind" )
120 self._current_context.rebind(_context_name,ObjRef)
121 except CORBA.COMM_FAILURE, ex:
122 MESSAGE ( "Register : CORBA.COMM_FAILURE" )
125 #-------------------------------------------------------------------------
126 def Resolve(self, Path):
127 MESSAGE ( "SALOME_NamingServicePy_i::Resolve" )
128 path_list = list(Path)
129 if path_list[0]=='/':
130 self._current_context = self._root_context
131 #delete first '/' before split
134 result_resolve_path = split(Path,'/')
136 for i in range(len(result_resolve_path)-1):
137 _context_name.append(CosNaming.NameComponent(result_resolve_path[i],"dir"))
138 _context_name.append(CosNaming.NameComponent(result_resolve_path[len(result_resolve_path)-1],"object"))
140 self._obj = self._current_context.resolve(_context_name)
141 except CosNaming.NamingContext.NotFound, ex:
142 MESSAGE ( "Resolve : CosNaming.NamingContext.NotFound" )
144 except CosNaming.NamingContext.InvalidName, ex:
145 MESSAGE ( "Resolve : CosNaming.NamingContext.InvalidName" )
147 except CosNaming.NamingContext.CannotProceed, ex:
148 MESSAGE ( "Resolve : CosNaming.NamingContext.CannotProceed" )
150 except CORBA.COMM_FAILURE, ex:
151 MESSAGE ( "Resolve : CORBA.COMM_FAILURE" )
157 #-------------------------------------------------------------------------
158 def Create_Directory(self,ObjRef, Path):
159 MESSAGE ( "SALOME_NamingServicePy_i::Create_Directory" )
161 path_list = list(Path)
162 if path_list[0]=='/':
163 self._current_context = self._root_context
164 #delete first '/' before split
167 result_resolve_path = split(Path,'/')
169 for i in range(len(result_resolve_path)):
170 _context_name[CosNaming.NameComponent(result_resolve_path[i],"dir")]
172 obj = self._current_context.resolve(_context_name)
173 self._current_context = obj._narrow(CosNaming.NamingContext)
174 except CosNaming.NamingContext.NotFound, ex:
175 self._current_context = self._current_context.bind_new_context(_context_name)
176 except CosNaming.NamingContext.InvalidName, ex:
177 MESSAGE ( "Create_Directory : CosNaming.NamingContext.InvalidName" )
178 except CosNaming.NamingContext.CannotProceed, ex:
179 MESSAGE ( "Create_Directory : CosNaming.NamingContext.CannotProceed" )
180 except CORBA.COMM_FAILURE, ex:
181 MESSAGE ( "Create_Directory : CORBA.COMM_FAILURE" )