3 #=============================================================================
4 # File : SALOME_NamingServicePy.py
5 # Created : lun oct 15 14:55 CEST 2001
6 # Author : Estelle Deville, CEA
10 #=============================================================================
13 from omniORB import CORBA
17 from SALOME_utilities import *
18 #=============================================================================
20 class SALOME_NamingServicePy_i:
26 #-------------------------------------------------------------------------
28 def __init__(self, orb):
29 MESSAGE ( "SALOME_NamingServicePy_i::__init__" )
31 # initialize root context and current context
32 obj =self._orb.resolve_initial_references("NameService")
33 self._root_context =obj._narrow(CosNaming.NamingContext)
34 self._current_context = self._root_context
37 if self._root_context is None :
38 MESSAGE ( "Name Service Reference is invalid" )
41 #-------------------------------------------------------------------------
42 def Register(self,ObjRef, Path):
43 MESSAGE ( "SALOME_NamingServicePy_i::Register" )
45 path_list = list(Path)
47 self._current_context = self._root_context
48 #delete first '/' before split
51 result_resolve_path = split(Path,'/')
52 if len(result_resolve_path)>1:
53 # A directory is treated (not only an object name)
54 # We had to test if the directory where ObjRef should be recorded
56 # If not, the new context has to be created
58 for i in range(len(result_resolve_path)-1):
59 _context_name.append(CosNaming.NameComponent(result_resolve_path[i],"dir"))
62 obj = self._current_context.resolve(_context_name)
63 self._current_context = obj._narrow(CosNaming.NamingContext)
64 except CosNaming.NamingContext.NotFound, ex:
66 except CosNaming.NamingContext.InvalidName, ex:
67 MESSAGE ( "Register : CosNaming.NamingContext.InvalidName" )
68 except CosNaming.NamingContext.CannotProceed, ex:
69 MESSAGE ( "Register : CosNaming.NamingContext.CannotProceed" )
70 except CORBA.COMM_FAILURE, ex:
71 MESSAGE ( "Register : CORBA.COMM_FAILURE" )
74 # at least one context of the complete path is not created, we had
75 # to create it or them
77 for i in range(len(result_resolve_path)-1):
78 _context_name = [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:
84 #This context is not created. It will be done
85 self._current_context = self._current_context.bind_new_context(_context_name)
87 #The current directory is now the directory where the object should
90 _context_name = [CosNaming.NameComponent(result_resolve_path[len(result_resolve_path)-1],"object")]
92 self._current_context.bind(_context_name,ObjRef)
93 except CosNaming.NamingContext.NotFound, ex:
94 MESSAGE ( "Register : CosNaming.NamingContext.NotFound" )
95 except CosNaming.NamingContext.InvalidName, ex:
96 MESSAGE ( "Register : CosNaming.NamingContext.InvalidName" )
97 except CosNaming.NamingContext.CannotProceed, ex:
98 MESSAGE ( "Register : CosNaming.NamingContext.CannotProceed" )
99 except CosNaming.NamingContext.AlreadyBound, ex:
100 MESSAGE ( "Register : CosNaming.NamingContext.AlreadyBound, object will be rebind" )
101 self._current_context.rebind(_context_name,ObjRef)
102 except CORBA.COMM_FAILURE, ex:
103 MESSAGE ( "Register : CORBA.COMM_FAILURE" )
106 #-------------------------------------------------------------------------
107 def Resolve(self, Path):
108 MESSAGE ( "SALOME_NamingServicePy_i::Resolve" )
109 path_list = list(Path)
110 if path_list[0]=='/':
111 self._current_context = self._root_context
112 #delete first '/' before split
115 result_resolve_path = split(Path,'/')
117 for i in range(len(result_resolve_path)-1):
118 _context_name.append(CosNaming.NameComponent(result_resolve_path[i],"dir"))
119 _context_name.append(CosNaming.NameComponent(result_resolve_path[len(result_resolve_path)-1],"object"))
121 self._obj = self._current_context.resolve(_context_name)
122 except CosNaming.NamingContext.NotFound, ex:
123 MESSAGE ( "Resolve : CosNaming.NamingContext.NotFound" )
125 except CosNaming.NamingContext.InvalidName, ex:
126 MESSAGE ( "Resolve : CosNaming.NamingContext.InvalidName" )
128 except CosNaming.NamingContext.CannotProceed, ex:
129 MESSAGE ( "Resolve : CosNaming.NamingContext.CannotProceed" )
131 except CORBA.COMM_FAILURE, ex:
132 MESSAGE ( "Resolve : CORBA.COMM_FAILURE" )
138 #-------------------------------------------------------------------------
139 def Create_Directory(self,ObjRef, Path):
140 MESSAGE ( "SALOME_NamingServicePy_i::Create_Directory" )
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)):
151 _context_name[CosNaming.NameComponent(result_resolve_path[i],"dir")]
153 obj = self._current_context.resolve(_context_name)
154 self._current_context = obj._narrow(CosNaming.NamingContext)
155 except CosNaming.NamingContext.NotFound, ex:
156 self._current_context = self._current_context.bind_new_context(_context_name)
157 except CosNaming.NamingContext.InvalidName, ex:
158 MESSAGE ( "Create_Directory : CosNaming.NamingContext.InvalidName" )
159 except CosNaming.NamingContext.CannotProceed, ex:
160 MESSAGE ( "Create_Directory : CosNaming.NamingContext.CannotProceed" )
161 except CORBA.COMM_FAILURE, ex:
162 MESSAGE ( "Create_Directory : CORBA.COMM_FAILURE" )