18 import omniORB.CORBA
as CORBA
86 self.
_nameServer =
"corbaloc::" + name_server +
"/NameService" 91 print "CorbaNaming: Failed to narrow the root naming context." 93 except CORBA.ORB.InvalidName:
94 print "Service required is invalid [does not exist]." 129 self.
_nameServer =
"corbaloc::" + name_server +
"/NameService" 131 self.
_rootContext = obj._narrow(CosNaming.NamingContext)
184 def bind(self, name_list, obj, force=None):
189 self._rootContext.bind(name_list, obj)
190 except CosNaming.NamingContext.NotFound:
195 except CosNaming.NamingContext.CannotProceed, err:
200 except CosNaming.NamingContext.AlreadyBound:
201 self._rootContext.rebind(name_list, obj)
229 self.
bind(self.
toName(string_name), obj, force)
268 length = len(name_list)
270 for i
in range(length):
273 cxt.bind(self.
subName(name_list, i, i), obj)
274 except CosNaming.NamingContext.AlreadyBound:
275 cxt.rebind(self.
subName(name_list, i, i), obj)
281 raise CosNaming.NamingContext.CannotProceed(cxt, self.
subName(name_list, i))
309 def rebind(self, name_list, obj, force=True):
314 self._rootContext.rebind(name_list, obj)
316 except CosNaming.NamingContext.NotFound:
322 except CosNaming.NamingContext.CannotProceed, err:
385 length = len(name_list)
386 for i
in range(length):
388 context.rebind(self.
subName(name_list, i, i), obj)
393 context = context.bind_new_context(self.
subName(name_list, i, i))
394 except CosNaming.NamingContext.AlreadyBound:
395 obj_ = context.resolve(self.
subName(name_list, i, i))
396 context = obj_._narrow(CosNaming.NamingContext)
398 raise CosNaming.NamingContext.CannotProceed(context, self.
subName(name_list, i))
427 if isinstance(name, basestring):
430 self.
bind(name, name_cxt, force)
481 if isinstance(name, basestring):
484 self.
rebind(name, name_cxt, force)
538 if isinstance(name, basestring):
544 obj = self._rootContext.resolve(name_)
546 except CosNaming.NamingContext.NotFound, ex:
578 if isinstance(name, basestring):
583 self._rootContext.unbind(name_)
603 return self._rootContext.new_context()
636 if isinstance(name, basestring):
642 return self._rootContext.bind_new_context(name_)
643 except CosNaming.NamingContext.NotFound:
648 except CosNaming.NamingContext.CannotProceed, err:
716 for i
in range(len(bl)):
717 if bl[i].binding_type == CosNaming.ncontext:
718 obj = context.resolve(bl[i].binding_name)
719 next_context = obj._narrow(CosNaming.NamingContext)
722 context.unbind(bl[i].binding_name)
723 next_context.destroy()
724 elif bl[i].binding_type == CosNaming.nobject:
725 context.unbind(bl[i].binding_name)
733 if not (CORBA.is_nil(bi)):
768 def list(self, name_cxt, how_many, rbl, rbi):
769 bl, bi = name_cxt.list(how_many)
798 if len(name_list) == 0:
799 raise CosNaming.NamingContext.InvalidName
826 raise CosNaming.NamingContext.InvalidName
832 nc_length = self.
split(string_name,
"/", name_comps)
833 if not (nc_length > 0):
834 raise CosNaming.NamingContext.InvalidName
836 name_list = [CosNaming.NameComponent(
"",
"")
for i
in range(nc_length)]
838 for i
in range(nc_length):
839 pos = string.rfind(name_comps[i][0:],
".")
841 name_list[i].id = name_comps[i]
842 name_list[i].kind =
"" 844 name_list[i].id = name_comps[i][0:pos]
845 name_list[i].kind = name_comps[i][(pos+1):]
869 return self._rootContext.to_url(addr, string_name)
921 context.bind_context(name_list, obj)
923 except CosNaming.NamingContext.AlreadyBound:
924 obj = context.resolve(name_list)
926 return CORBA.Object._nil
951 if new_context
is None:
954 new_cxt = new_context
957 return obj._narrow(CosNaming.NamingContext)
1009 nc = obj._narrow(CosNaming.NamingContext)
1010 if CORBA.is_nil(nc):
1054 if end
is None or end < 0:
1055 end = len(name_list) - 1
1057 sub_len = end - (begin -1)
1062 for i
in range(sub_len):
1063 sub_name.append(name_list[begin + i])
1088 for i
in range(len(name_list)):
1089 for id_
in name_list[i].id:
1090 if id_ ==
"/" or id_ ==
"." or id_ ==
"\\":
1091 string_name[0] +=
"\\" 1092 string_name[0] += id_
1094 if name_list[i].id ==
"" or name_list[i].kind !=
"":
1095 string_name[0] +=
"." 1097 for kind_
in name_list[i].kind:
1098 if kind_ ==
"/" or kind_ ==
"." or kind_ ==
"\\":
1099 string_name[0] +=
"\\" 1100 string_name[0] += kind_
1102 string_name[0] +=
"/" 1125 for i
in range(len(name_list)):
1126 for id_
in name_list[i].id:
1127 if id_ ==
"/" or id_ ==
"." or id_ ==
"\\":
1130 if name_list[i].id ==
"" or name_list[i].kind ==
"":
1133 for kind_
in name_list[i].kind:
1134 if kind_ ==
"/" or kind_ ==
"." or kind_ ==
"\\":
1159 def split(self, input, delimiter, results):
1160 delim_size = len(delimiter)
1161 found_pos = begin_pos = pre_pos = substr_size = 0
1163 if input[0:delim_size] == delimiter:
1164 begin_pos = pre_pos = delim_size
1167 found_pos = string.find(input[begin_pos:],delimiter)
1170 results.append(input[pre_pos:])
1173 if found_pos > 0
and input[found_pos - 1] ==
"\\":
1174 begin_pos += found_pos + delim_size
1176 substr_size = found_pos + (begin_pos - pre_pos)
1178 results.append(input[pre_pos:(pre_pos+substr_size)])
1179 begin_pos += found_pos + delim_size
def nameToString(self, name_list, string_name, slen)
Get string representation of name component.
def bindNewContext(self, name, force=True)
def bindByString(self, string_name, obj, force=True)
def toUrl(self, addr, string_name)
Get URL representation from given addr and string_name.
def unbind(self, name)
void unbind(const CosNaming::Name& name) throw(NotFound, CannotProceed, InvalidName); ...
def nameIsNamingContext(self, name_list)
Whether the given name component is NamingContext.
def subName(self, name_list, begin, end=None)
Get subset of given name component.
def bindContext(self, name, name_cxt, force=True)
def bindOrResolveContext(self, context, name_list, new_context=None)
Bind of resolve the given name component.
def getRootContext(self)
Get the root context.
def getNameServer(self)
Get the name of naming server.
def clearAll(self)
Destroy all binding.
def rebindContext(self, name, name_cxt, force=True)
def objIsNamingContext(self, obj)
Whether the object is NamingContext.
def toName(self, sname)
Get NameComponent from gien string name representation.
def toString(self, name_list)
Get string representation of given NameComponent.
def rebind(self, name_list, obj, force=True)
def split(self, input, delimiter, results)
Split of string.
def list(self, name_cxt, how_many, rbl, rbi)
def init(self, name_server)
def __init__(self, orb, name_server=None)
Consructor.
def rebindContextRecursive(self, context, name_list, name_cxt)
def destroy(self, context)
def resolveStr(self, string_name)
Resolve from name of string representation and get object.
def bind(self, name_list, obj, force=None)
def bindContextRecursive(self, context, name_list, name_cxt)
def rebindByString(self, string_name, obj, force=True)
def getNameLength(self, name_list)
Get string length of the name component's string representation.
def __del__(self)
destructor
def bindRecursive(self, context, name_list, obj)
def bindOrResolve(self, context, name_list, obj)
Bind of resolve the given name component.
def destroyRecursive(self, context)
Destroy the naming context recursively.
CORBA Naming Service helper class.
def rebindRecursive(self, context, name_list, obj)