19 import omniORB.CORBA
as CORBA
87 self.
_nameServer =
"corbaloc::" + name_server +
"/NameService" 92 print "CorbaNaming: Failed to narrow the root naming context." 94 except CORBA.ORB.InvalidName:
95 print "Service required is invalid [does not exist]." 130 self.
_nameServer =
"corbaloc::" + name_server +
"/NameService" 132 self.
_rootContext = obj._narrow(CosNaming.NamingContext)
185 def bind(self, name_list, obj, force=None):
190 self._rootContext.bind(name_list, obj)
191 except CosNaming.NamingContext.NotFound:
196 except CosNaming.NamingContext.CannotProceed, err:
201 except CosNaming.NamingContext.AlreadyBound:
202 self._rootContext.rebind(name_list, obj)
230 self.
bind(self.
toName(string_name), obj, force)
269 length = len(name_list)
271 for i
in range(length):
274 cxt.bind(self.
subName(name_list, i, i), obj)
275 except CosNaming.NamingContext.AlreadyBound:
276 cxt.rebind(self.
subName(name_list, i, i), obj)
282 raise CosNaming.NamingContext.CannotProceed(cxt, self.
subName(name_list, i))
310 def rebind(self, name_list, obj, force=True):
315 self._rootContext.rebind(name_list, obj)
317 except CosNaming.NamingContext.NotFound:
323 except CosNaming.NamingContext.CannotProceed, err:
386 length = len(name_list)
387 for i
in range(length):
389 context.rebind(self.
subName(name_list, i, i), obj)
394 context = context.bind_new_context(self.
subName(name_list, i, i))
395 except CosNaming.NamingContext.AlreadyBound:
396 obj_ = context.resolve(self.
subName(name_list, i, i))
397 context = obj_._narrow(CosNaming.NamingContext)
399 raise CosNaming.NamingContext.CannotProceed(context, self.
subName(name_list, i))
428 if isinstance(name, basestring):
431 self.
bind(name, name_cxt, force)
482 if isinstance(name, basestring):
485 self.
rebind(name, name_cxt, force)
539 if isinstance(name, basestring):
545 obj = self._rootContext.resolve(name_)
547 except CosNaming.NamingContext.NotFound, ex:
579 if isinstance(name, basestring):
584 self._rootContext.unbind(name_)
604 return self._rootContext.new_context()
637 if isinstance(name, basestring):
643 return self._rootContext.bind_new_context(name_)
644 except CosNaming.NamingContext.NotFound:
649 except CosNaming.NamingContext.CannotProceed, err:
717 for i
in range(len(bl)):
718 if bl[i].binding_type == CosNaming.ncontext:
719 obj = context.resolve(bl[i].binding_name)
720 next_context = obj._narrow(CosNaming.NamingContext)
723 context.unbind(bl[i].binding_name)
724 next_context.destroy()
725 elif bl[i].binding_type == CosNaming.nobject:
726 context.unbind(bl[i].binding_name)
734 if not (CORBA.is_nil(bi)):
769 def list(self, name_cxt, how_many, rbl, rbi):
770 bl, bi = name_cxt.list(how_many)
799 if len(name_list) == 0:
800 raise CosNaming.NamingContext.InvalidName
827 raise CosNaming.NamingContext.InvalidName
833 nc_length = self.
split(string_name,
"/", name_comps)
834 if not (nc_length > 0):
835 raise CosNaming.NamingContext.InvalidName
837 name_list = [CosNaming.NameComponent(
"",
"")
for i
in range(nc_length)]
839 for i
in range(nc_length):
840 pos = string.rfind(name_comps[i][0:],
".")
842 name_list[i].id = name_comps[i]
843 name_list[i].kind =
"" 845 name_list[i].id = name_comps[i][0:pos]
846 name_list[i].kind = name_comps[i][(pos+1):]
870 return self._rootContext.to_url(addr, string_name)
922 context.bind_context(name_list, obj)
924 except CosNaming.NamingContext.AlreadyBound:
925 obj = context.resolve(name_list)
927 return CORBA.Object._nil
952 if new_context
is None:
955 new_cxt = new_context
958 return obj._narrow(CosNaming.NamingContext)
1010 nc = obj._narrow(CosNaming.NamingContext)
1011 if CORBA.is_nil(nc):
1055 if end
is None or end < 0:
1056 end = len(name_list) - 1
1058 sub_len = end - (begin -1)
1063 for i
in range(sub_len):
1064 sub_name.append(name_list[begin + i])
1089 for i
in range(len(name_list)):
1090 for id_
in name_list[i].id:
1091 if id_ ==
"/" or id_ ==
"." or id_ ==
"\\":
1092 string_name[0] +=
"\\" 1093 string_name[0] += id_
1095 if name_list[i].id ==
"" or name_list[i].kind !=
"":
1096 string_name[0] +=
"." 1098 for kind_
in name_list[i].kind:
1099 if kind_ ==
"/" or kind_ ==
"." or kind_ ==
"\\":
1100 string_name[0] +=
"\\" 1101 string_name[0] += kind_
1103 string_name[0] +=
"/" 1126 for i
in range(len(name_list)):
1127 for id_
in name_list[i].id:
1128 if id_ ==
"/" or id_ ==
"." or id_ ==
"\\":
1131 if name_list[i].id ==
"" or name_list[i].kind ==
"":
1134 for kind_
in name_list[i].kind:
1135 if kind_ ==
"/" or kind_ ==
"." or kind_ ==
"\\":
1160 def split(self, input, delimiter, results):
1161 delim_size = len(delimiter)
1162 found_pos = begin_pos = pre_pos = substr_size = 0
1164 if input[0:delim_size] == delimiter:
1165 begin_pos = pre_pos = delim_size
1168 found_pos = string.find(input[begin_pos:],delimiter)
1171 results.append(input[pre_pos:])
1174 if found_pos > 0
and input[found_pos - 1] ==
"\\":
1175 begin_pos += found_pos + delim_size
1177 substr_size = found_pos + (begin_pos - pre_pos)
1179 results.append(input[pre_pos:(pre_pos+substr_size)])
1180 begin_pos += found_pos + delim_size
def toString(self, name_list)
Get string representation of given NameComponent.
def getRootContext(self)
Get the root context.
def __del__(self)
destructor
def bindOrResolveContext(self, context, name_list, new_context=None)
Bind of resolve the given name component.
def nameIsNamingContext(self, name_list)
Whether the given name component is NamingContext.
def __init__(self, orb, name_server=None)
Consructor.
def toName(self, sname)
Get NameComponent from gien string name representation.
def split(self, input, delimiter, results)
Split of string.
def unbind(self, name)
void unbind(const CosNaming::Name& name) throw(NotFound, CannotProceed, InvalidName); ...
def subName(self, name_list, begin, end=None)
Get subset of given name component.
def objIsNamingContext(self, obj)
Whether the object is NamingContext.
def getNameLength(self, name_list)
Get string length of the name component's string representation.
def resolveStr(self, string_name)
Resolve from name of string representation and get object.
def bindRecursive(self, context, name_list, obj)
CORBA Naming Service helper class.
def rebindContextRecursive(self, context, name_list, name_cxt)
def bind(self, name_list, obj, force=None)
def bindContextRecursive(self, context, name_list, name_cxt)
def list(self, name_cxt, how_many, rbl, rbi)
def init(self, name_server)
def bindByString(self, string_name, obj, force=True)
def rebindContext(self, name, name_cxt, force=True)
def bindNewContext(self, name, force=True)
def bindOrResolve(self, context, name_list, obj)
Bind of resolve the given name component.
def destroy(self, context)
def toUrl(self, addr, string_name)
Get URL representation from given addr and string_name.
def rebind(self, name_list, obj, force=True)
def getNameServer(self)
Get the name of naming server.
def clearAll(self)
Destroy all binding.
def rebindRecursive(self, context, name_list, obj)
def nameToString(self, name_list, string_name, slen)
Get string representation of name component.
def rebindByString(self, string_name, obj, force=True)
def destroyRecursive(self, context)
Destroy the naming context recursively.
def bindContext(self, name, name_cxt, force=True)