CorbaNaming.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: euc-jp -*-
00003 
00004 
00005 ##
00006 # \file CorbaNaming.py
00007 # \brief CORBA naming service helper class
00008 # \author Noriaki Ando <n-ando@aist.go.jp> and Shinji Kurihara
00009 #
00010 # Copyright (C) 2006-2008
00011 #     Noriaki Ando
00012 #     Task-intelligence Research Group,
00013 #     Intelligent Systems Research Institute,
00014 #     National Institute of
00015 #         Advanced Industrial Science and Technology (AIST), Japan
00016 #     All rights reserved.
00017 
00018 import omniORB.CORBA as CORBA
00019 import CosNaming
00020 import string
00021 
00022 ##
00023 # @if jp
00024 # @class CorbaNaming
00025 # @brief CORBA Naming Service �إ�ѡ����饹
00026 #
00027 # ���Υ��饹�ϡ�CosNaming::NamingContext ���Ф����åѡ����饹�Ǥ��롣
00028 # CosNaming::NamingContext �����ĥ��ڥ졼�����Ȥۤ�Ʊ����ǽ��
00029 # ���ڥ졼�������󶡤���ȤȤ�ˡ��͡��ॳ��ݡ��ͥ�� CosNaming::Name
00030 # �������ʸ����ˤ��̾��ɽ��������դ��륪�ڥ졼�������󶡤��롣
00031 #
00032 # ���֥������Ȥ������������뤤������ľ��� CORBA �͡��ॵ���Ф���³��
00033 # �ʸ塢���Υ͡��ॵ���ФΥ롼�ȥ���ƥ����Ȥ��Ф��Ƽ�Υ��ڥ졼�����
00034 # ��������롣
00035 # �������ؤΥ͡��ߥ󥰥���ƥ����Ȥκ����䥪�֥������ȤΥХ���ɤˤ����ơ�
00036 # ����Υ���ƥ����Ȥ�¸�ߤ��ʤ����Ǥ⡢����Ū�˥���ƥ����Ȥ�Х����
00037 # ����Ū�Υ���ƥ����Ȥ䥪�֥������ȤΥХ���ɤ�Ԥ����Ȥ�Ǥ��롣
00038 #
00039 # @since 0.4.0
00040 #
00041 # @else
00042 # @class CorbaNaming
00043 # @brief CORBA Naming Service helper class
00044 #
00045 # This class is a wrapper class of CosNaming::NamingContext.
00046 # Almost the same operations which CosNaming::NamingContext has are
00047 # provided, and some operation allows string naming representation of
00048 # context and object instead of CosNaming::Name.
00049 #
00050 # The object of the class would connect to a CORBA naming server at
00051 # the instantiation or immediately after instantiation.
00052 # After that the object invokes operations to the root context of it.
00053 # This class realizes forced binding to deep NamingContext, without binding
00054 # intermediate NamingContexts explicitly.
00055 #
00056 # @since 0.4.0
00057 #
00058 # @endif
00059 class CorbaNaming:
00060   """
00061   """
00062 
00063 
00064 
00065   ##
00066   # @if jp
00067   #
00068   # @brief ���󥹥ȥ饯��
00069   #
00070   # @param self
00071   # @param orb ORB
00072   # @param name_server �͡��ॵ���Ф�̾��(�ǥե������:None)
00073   #
00074   # @else
00075   #
00076   # @brief Consructor
00077   #
00078   # @endif
00079   def __init__(self, orb, name_server=None):
00080     self._orb = orb
00081     self._nameServer = ""
00082     self._rootContext = CosNaming.NamingContext._nil
00083     self._blLength = 100
00084 
00085     if name_server:
00086       self._nameServer = "corbaloc::" + name_server + "/NameService"
00087       try:
00088         obj = orb.string_to_object(self._nameServer)
00089         self._rootContext = obj._narrow(CosNaming.NamingContext)
00090         if CORBA.is_nil(self._rootContext):
00091           print "CorbaNaming: Failed to narrow the root naming context."
00092 
00093       except CORBA.ORB.InvalidName:
00094         print "Service required is invalid [does not exist]."
00095 
00096     return
00097   
00098 
00099   ##
00100   # @if jp
00101   #
00102   # @brief �ǥ��ȥ饯��
00103   # 
00104   # @param self
00105   # 
00106   # @else
00107   # 
00108   # @brief destructor
00109   # 
00110   # @endif
00111   def __del__(self):
00112     return
00113 
00114 
00115   ##
00116   # @if jp
00117   #
00118   # @brief �͡��ߥ󥰥����ӥ��ν����
00119   # 
00120   # ���ꤵ�줿�͡��ॵ���о�Υ͡��ߥ󥰥����ӥ����������ޤ���
00121   # 
00122   # @param self
00123   # @param name_server �͡��ॵ���Ф�̾��
00124   # 
00125   # @else
00126   # 
00127   # @endif
00128   def init(self, name_server):
00129     self._nameServer = "corbaloc::" + name_server + "/NameService"
00130     obj = self._orb.string_to_object(self._nameServer)
00131     self._rootContext = obj._narrow(CosNaming.NamingContext)
00132     if CORBA.is_nil(self._rootContext):
00133       raise MemoryError
00134 
00135     return
00136 
00137 
00138   ##
00139   # @if jp
00140   #
00141   # @brief Object �� bind ����
00142   #
00143   # CosNaming::bind() �Ȥۤ�Ʊ����Ư���򤹤뤬�����Ϳ����줿�͡��ॵ���Ф�
00144   # �롼�ȥ���ƥ����Ȥ��Ф���bind()���ƤӽФ���������ۤʤ롣
00145   #
00146   # Name <name> �� Object <obj> ������ NamingContext ��˥Х���ɤ��롣
00147   # c_n �� n ���ܤ� NameComponent �򤢤�魯�Ȥ���ȡ�
00148   # name �� n �Ĥ� NameComponent ��������Ȥ����ʲ��Τ褦�˰����롣
00149   #
00150   # cxt->bind(<c_1, c_2, ... c_n>, obj) �ϰʲ�������Ʊ���Ǥ��롣
00151   # cxt->resolve(<c_1, ... c_(n-1)>)->bind(<c_n>, obj)
00152   #
00153   # ���ʤ����1���ܤ���n-1���ܤΥ���ƥ����Ȥ��褷��n-1���ܤΥ���ƥ�����
00154   # ��� name <n> �Ȥ��ơ�obj �� bind ���롣
00155   # ̾�����˻��ä��� <c_1, ... c_(n-1)> �� NemingContext �ϡ�
00156   # bindContext() �� rebindContext() �Ǵ��˥Х���ɺѤߤǤʤ���Фʤ�ʤ���
00157   # �⤷ <c_1, ... c_(n-1)> �� NamingContext ��¸�ߤ��ʤ����ˤϡ�
00158   # NotFound �㳰��ȯ�����롣
00159   #
00160   # �������������Х���ɥե饰 force �� true �λ��ϡ�<c_1, ... c_(n-1)>
00161   # ��¸�ߤ��ʤ����ˤ⡢�Ƶ�Ū�˥���ƥ����Ȥ�Х���ɤ��ʤ��顢
00162   # �ǽ�Ū�� obj ��̾�� name <c_n> �˥Х���ɤ��롣
00163   #
00164   # ������ξ��Ǥ⡢n-1���ܤΥ���ƥ����Ⱦ�� name<n> �Υ��֥�������
00165   # (Object ���뤤�� ����ƥ�����) ���Х���ɤ���Ƥ����
00166   # AlreadyBound �㳰��ȯ�����롣
00167   #
00168   # @param self
00169   # @param name_list ���֥������Ȥ��դ���̾���� NameComponent
00170   # @param obj ��Ϣ�դ����� Object
00171   # @param force true�ξ�硢����Υ���ƥ����Ȥ���Ū�˥Х���ɤ���
00172   #              (�ǥե������:None)
00173   #
00174   # @exception NotFound ����� <c_1, c_2, ..., c_(n-1)> ��¸�ߤ��ʤ���
00175   # @exception CannotProceed ���餫����ͳ�ǽ������³�Ǥ��ʤ���
00176   # @exception InvalidName ���� name_list ��̾����������
00177   # @exception AlreadyBound name <c_n> �� Object �����Ǥ˥Х���ɤ���Ƥ��롣
00178   #
00179   # @else
00180   #
00181   # @brief
00182   #
00183   # @endif
00184   def bind(self, name_list, obj, force=None):
00185     if force is None :
00186       force = True
00187 
00188     try:
00189       self._rootContext.bind(name_list, obj)
00190     except CosNaming.NamingContext.NotFound:
00191       if force:
00192         self.bindRecursive(self._rootContext, name_list, obj)
00193       else:
00194         raise
00195     except CosNaming.NamingContext.CannotProceed, err:
00196       if force:
00197         self.bindRecursive(err.cxt, err.rest_of_name, obj)
00198       else:
00199         raise
00200     except CosNaming.NamingContext.AlreadyBound:
00201       self._rootContext.rebind(name_list, obj)
00202 
00203 
00204   ##
00205   # @if jp
00206   #
00207   # @brief Object �� bind ����
00208   #
00209   # Object �� bind ����ݤ�Ϳ����̾����ʸ����ɽ���Ǥ��뤳�Ȱʳ��ϡ�bind()
00210   # ��Ʊ���Ǥ��롣bind(toName(string_name), obj) ��������
00211   #
00212   # @param self
00213   # @param string_name ���֥������Ȥ��դ���̾����ʸ����ɽ��
00214   # @param obj ��Ϣ�դ����륪�֥�������
00215   # @param force true�ξ�硢����Υ���ƥ����Ȥ���Ū�˥Х���ɤ���
00216   #              (�ǥե������:true)
00217   #
00218   # @exception NotFound ����� <c_1, c_2, ..., c_(n-1)> ��¸�ߤ��ʤ���
00219   # @exception CannotProceed ���餫����ͳ�ǽ������³�Ǥ��ʤ���
00220   # @exception InvalidName ���� string_name ��̾����������
00221   # @exception AlreadyBound name <n> �� Object �����Ǥ˥Х���ɤ���Ƥ��롣
00222   #
00223   # @else
00224   #
00225   # @brief
00226   #
00227   # @endif
00228   def bindByString(self, string_name, obj, force=True):
00229     self.bind(self.toName(string_name), obj, force)
00230 
00231 
00232   ##
00233   # @if jp
00234   #
00235   # @brief ����Υ���ƥ����Ȥ� bind ���ʤ��� Object �� bind ����
00236   #
00237   # context ��Ϳ����줿 NamingContext ���Ф��ơ�name �ǻ��ꤵ�줿
00238   # �͡��ॳ��ݡ��ͥ�� <c_1, ... c_(n-1)> �� NamingContext �Ȥ���
00239   # ��褷�ʤ��顢̾�� <c_n> ���Ф��� obj �� bind ���롣
00240   # �⤷��<c_1, ... c_(n-1)> ���б����� NamingContext ���ʤ����ˤ�
00241   # ������ NamingContext ��Х���ɤ��롣
00242   #
00243   # �ǽ�Ū�� <c_1, c_2, ..., c_(n-1)> ���б����� NamingContext ������
00244   # �ޤ��ϲ�褵�줿��ǡ�CosNaming::bind(<c_n>, object) ���ƤӽФ���롣
00245   # ���ΤȤ������Ǥ˥Х���ǥ��󥰤�¸�ߤ���� AlreadyBound�㳰��ȯ�����롣
00246   #
00247   # ����Υ���ƥ����Ȥ��褹������ǡ���褷�褦�Ȥ��륳��ƥ����Ȥ�
00248   # Ʊ��̾���� NamingContext �ǤϤʤ� Binding ��¸�ߤ����硢
00249   # CannotProceed �㳰��ȯ������������ߤ��롣
00250   #
00251   # @param self
00252   # @param context bind �򳫻Ϥ��롡NamingContext
00253   # @param name_list ���֥������Ȥ��դ���̾���Υ͡��ॳ��ݡ��ͥ��
00254   # @param obj ��Ϣ�դ����륪�֥�������
00255   #
00256   # @exception CannotProceed <c_1, ..., c_(n-1)> ������� NamingContext 
00257   #            �Τ����ҤȤĤ������Ǥ� NamingContext �ʳ��� object �˥Х����
00258   #            ����Ƥ��ꡢ�������³�Ǥ��ʤ���
00259   # @exception InvalidName ̾�� name_list ������
00260   # @exception AlreadyBound name <c_n> �ˤ��Ǥ˲��餫�� object ���Х����
00261   #            ����Ƥ��롣
00262   # @else
00263   #
00264   # @brief
00265   #
00266   # @endif
00267   def bindRecursive(self, context, name_list, obj):
00268     length = len(name_list)
00269     cxt = context
00270     for i in range(length):
00271       if i == length -1:
00272         try:
00273           cxt.bind(self.subName(name_list, i, i), obj)
00274         except CosNaming.NamingContext.AlreadyBound:
00275           cxt.rebind(self.subName(name_list, i, i), obj)
00276         return
00277       else:
00278         if self.objIsNamingContext(cxt):
00279           cxt = self.bindOrResolveContext(cxt,self.subName(name_list, i, i))
00280         else:
00281           raise CosNaming.NamingContext.CannotProceed(cxt, self.subName(name_list, i))
00282     return
00283 
00284 
00285   ##
00286   # @if jp
00287   #
00288   # @brief Object �� rebind ����
00289   #
00290   # name_list �ǻ��ꤵ�줿 Binding �����Ǥ�¸�ߤ����������� bind() ��Ʊ��
00291   # �Ǥ��롣�Х���ǥ��󥰤����Ǥ�¸�ߤ�����ˤϡ��������Х���ǥ��󥰤�
00292   # �֤��������롣
00293   #
00294   # @param self
00295   # @param name_list ���֥������Ȥ��դ���̾���� NameComponent
00296   # @param obj ��Ϣ�դ����륪�֥�������
00297   # @param force true�ξ�硢����Υ���ƥ����Ȥ���Ū�˥Х���ɤ���
00298   #              (�ǥե������:true)
00299   #
00300   # @exception NotFound ����� <c_1, c_2, ..., c_(n-1)> ��¸�ߤ��ʤ���
00301   # @exception CannotProceed ���餫����ͳ�ǽ������³�Ǥ��ʤ���
00302   # @exception InvalidName ̾�� name_list ������
00303   #
00304   # @else
00305   #
00306   # @brief
00307   #
00308   # @endif
00309   def rebind(self, name_list, obj, force=True):
00310     if force is None:
00311       force = True
00312       
00313     try:
00314       self._rootContext.rebind(name_list, obj)
00315 
00316     except CosNaming.NamingContext.NotFound:
00317       if force:
00318         self.rebindRecursive(self._rootContext, name_list, obj)
00319       else:
00320         raise
00321 
00322     except CosNaming.NamingContext.CannotProceed, err:
00323       if force:
00324         self.rebindRecursive(err.cxt, err,rest_of_name, obj)
00325       else:
00326         raise
00327       
00328     return
00329 
00330 
00331   ##
00332   # @if jp
00333   #
00334   # @brief Object �� rebind ����
00335   #
00336   # Object �� rebind ����ݤ�Ϳ����̾����ʸ����ɽ���Ǥ��뤳�Ȱʳ��� rebind()
00337   # ��Ʊ���Ǥ��롣rebind(toName(string_name), obj) ��������
00338   #
00339   # @param self
00340   # @param string_name ���֥������Ȥ��դ���̾����ʸ����ɽ��
00341   # @param obj ��Ϣ�դ����륪�֥�������
00342   # @param force true�ξ�硢����Υ���ƥ����Ȥ���Ū�˥Х���ɤ���
00343   #              (�ǥե������:true)
00344   #
00345   # @exception NotFound ����� <c_1, c_2, ..., c_(n-1)> ��¸�ߤ��ʤ���
00346   # @exception CannotProceed ���餫����ͳ�ǽ������³�Ǥ��ʤ���
00347   # @exception InvalidName ���� string_name ��̾����������
00348   #
00349   # @else
00350   #
00351   # @brief
00352   #
00353   # @endif
00354   def rebindByString(self, string_name, obj, force=True):
00355     self.rebind(self.toName(string_name), obj, force)
00356 
00357     return
00358 
00359 
00360   ##
00361   # @if jp
00362   #
00363   # @brief ����Υ���ƥ����Ȥ� bind ���ʤ��� Object �� rebind ����
00364   #
00365   # name_list <c_n> �ǻ��ꤵ�줿 NamingContext �⤷���� Object �����Ǥ�¸�ߤ���
00366   # ��������� bindRecursive() ��Ʊ���Ǥ��롣
00367   #
00368   # name_list <c_n> �ǻ��ꤵ�줿�Х���ǥ��󥰤����Ǥ�¸�ߤ�����ˤϡ�
00369   # �������Х���ǥ��󥰤��֤��������롣
00370   #
00371   # @param self
00372   # @param context bind �򳫻Ϥ��롡NamingContext
00373   # @param name_list ���֥������Ȥ��դ���̾���� NameComponent
00374   # @param obj ��Ϣ�դ����륪�֥�������
00375   #
00376   # @exception CannotProceed ����Υ���ƥ����Ȥ����Ǥ��ʤ���
00377   # @exception InvalidName Ϳ����줿 name_list ��������
00378   #
00379   # @else
00380   #
00381   # @brief
00382   #
00383   # @endif
00384   def rebindRecursive(self, context, name_list, obj):
00385     length = len(name_list)
00386     for i in range(length):
00387       if i == length - 1:
00388         context.rebind(self.subName(name_list, i, i), obj)
00389         return
00390       else:
00391         if self.objIsNamingContext(context):
00392           try:
00393             context = context.bind_new_context(self.subName(name_list, i, i))
00394           except CosNaming.NamingContext.AlreadyBound:
00395             obj_ = context.resolve(self.subName(name_list, i, i))
00396             context = obj_._narrow(CosNaming.NamingContext)
00397         else:
00398           raise CosNaming.NamingContext.CannotProceed(context, self.subName(name_list, i))
00399     return
00400 
00401 
00402   ##
00403   # @if jp
00404   #
00405   # @brief NamingContext �� bind ����
00406   #
00407   # bind �оݤȤ��ƻ��ꤵ�줿���� name ��ʸ����ξ��� bindByString() �ȡ�
00408   # ����ʳ��ξ��� bind() ��Ʊ���Ǥ��롣
00409   #
00410   # @param self
00411   # @param name ���֥������Ȥ��դ���̾��
00412   # @param name_cxt ��Ϣ�դ����� NamingContext
00413   # @param force true�ξ�硢����Υ���ƥ����Ȥ���Ū�˥Х���ɤ���
00414   #              (�ǥե������:True)
00415   #
00416   # @exception NotFound ����� <c_1, c_2, ..., c_(n-1)> ��¸�ߤ��ʤ���
00417   # @exception CannotProceed ���餫����ͳ�ǽ������³�Ǥ��ʤ���
00418   # @exception InvalidName ���� name ��̾����������
00419   # @exception AlreadyBound name <c_n> �� Object �����Ǥ˥Х���ɤ���Ƥ��롣
00420   #
00421   # @else
00422   #
00423   # @brief
00424   #
00425   # @endif
00426   def bindContext(self, name, name_cxt, force=True):
00427     if isinstance(name, basestring):
00428       self.bind(self.toName(name), name_cxt, force)
00429     else:
00430       self.bind(name, name_cxt, force)
00431     return
00432 
00433 
00434   ##
00435   # @if jp
00436   #
00437   # @brief NamingContext �� bind ����
00438   #
00439   # bind ����륪�֥������Ȥ� NamingContext �Ǥ��뤳�Ȥ������
00440   # bindRecursive() ��Ʊ���Ǥ��롣
00441   #
00442   # @param self
00443   # @param context bind �򳫻Ϥ��롡NamingContext
00444   # @param name_list ���֥������Ȥ��դ���̾���Υ͡��ॳ��ݡ��ͥ��
00445   # @param name_cxt ��Ϣ�դ����� NamingContext
00446   #
00447   # @else
00448   #
00449   # @brief
00450   #
00451   # @endif
00452   def bindContextRecursive(self, context, name_list, name_cxt):
00453     self.bindRecursive(context, name_list, name_cxt)
00454     return
00455 
00456 
00457   ##
00458   # @if jp
00459   #
00460   # @brief NamingContext �� rebind ����
00461   #
00462   # bind �оݤȤ��ƻ��ꤵ�줿���� name ��ʸ����ξ��� rebindByString() �ȡ�
00463   # ����ʳ��ξ��� rebind() ��Ʊ���Ǥ��롣
00464   # �ɤ���ξ���Х���ǥ��󥰤����Ǥ�¸�ߤ�����ˤϡ�
00465   # �������Х���ǥ��󥰤��֤��������롣
00466   #
00467   # @param self
00468   # @param name ���֥������Ȥ��դ���̾���Υ͡��ॳ��ݡ��ͥ��
00469   # @param name_cxt ��Ϣ�դ����� NamingContext
00470   # @param force true�ξ�硢����Υ���ƥ����Ȥ���Ū�˥Х���ɤ���
00471   #              (�ǥե������:true)
00472   #
00473   # @exception NotFound ����� <c_1, c_2, ..., c_(n-1)> ��¸�ߤ��ʤ���
00474   # @exception CannotProceed ���餫����ͳ�ǽ������³�Ǥ��ʤ���
00475   # @exception InvalidName ���� name ��̾����������
00476   #
00477   # @else
00478   #
00479   # @endif
00480   def rebindContext(self, name, name_cxt, force=True):
00481     if isinstance(name, basestring):
00482       self.rebind(self.toName(name), name_cxt, force)
00483     else:
00484       self.rebind(name, name_cxt, force)
00485     return
00486 
00487 
00488   ##
00489   # @if jp
00490   #
00491   # @brief ����Υ���ƥ����Ȥ�Ƶ�Ū�� rebind �� NamingContext �� rebind ����    #
00492   # bind ����륪�֥������Ȥ� NamingContext �Ǥ��뤳�Ȥ������
00493   # rebindRecursive() ��Ʊ���Ǥ��롣
00494   #
00495   # @param self
00496   # @param context bind �򳫻Ϥ��롡NamingContext
00497   # @param name_list ���֥������Ȥ��դ���̾���� NameComponent
00498   # @param name_cxt ��Ϣ�դ����� NamingContext
00499   #
00500   # @else
00501   #
00502   # @brief
00503   #
00504   # @endif
00505   def rebindContextRecursive(self, context, name_list, name_cxt):
00506     self.rebindRecursive(context, name_list, name_cxt)
00507     return
00508 
00509 
00510   ##
00511   # @if jp
00512   #
00513   # @brief Object �� name �����褹��
00514   #
00515   # name �� bind ����Ƥ��륪�֥������Ȼ��Ȥ��֤���
00516   # �͡��ॳ��ݡ��ͥ�� <c_1, c_2, ... c_n> �ϺƵ�Ū�˲�褵��롣
00517   # 
00518   # ���� name ��Ϳ����줿�ͤ�ʸ����ξ��ˤϤޤ��ǽ�� toName() �ˤ�ä�
00519   # NameComponent ���Ѵ�����롣
00520   # 
00521   # CosNaming::resolve() �Ȥۤ�Ʊ����Ư���򤹤뤬�����Ϳ����줿
00522   # �͡��ॵ���ФΥ롼�ȥ���ƥ����Ȥ��Ф��� resolve() ���ƤӽФ��������
00523   # �ۤʤ롣
00524   #
00525   # @param self
00526   # @param name ��褹�٤����֥������Ȥ�̾���Υ͡��ॳ��ݡ��ͥ��
00527   #
00528   # @return ��褵�줿���֥������Ȼ���
00529   #
00530   # @exception NotFound ����� <c_1, c_2, ..., c_(n-1)> ��¸�ߤ��ʤ���
00531   # @exception CannotProceed ���餫����ͳ�ǽ������³�Ǥ��ʤ���
00532   # @exception InvalidName ���� name ��̾����������
00533   #
00534   # @else
00535   #
00536   # @endif
00537   def resolve(self, name):
00538     if isinstance(name, basestring):
00539       name_ = self.toName(name)
00540     else:
00541       name_ = name
00542       
00543     try:
00544       obj = self._rootContext.resolve(name_)
00545       return obj
00546     except CosNaming.NamingContext.NotFound, ex:
00547       return None
00548 
00549 
00550   ##
00551   # @if jp
00552   #
00553   # @brief ���ꤵ�줿̾���Υ��֥������Ȥ� bind ��������
00554   #
00555   # name �� bind ����Ƥ��륪�֥������Ȼ��Ȥ������롣
00556   # �͡��ॳ��ݡ��ͥ�� <c_1, c_2, ... c_n> �ϺƵ�Ū�˲�褵��롣
00557   # 
00558   # ���� name ��Ϳ����줿�ͤ�ʸ����ξ��ˤϤޤ��ǽ�� toName() �ˤ�ä�
00559   # NameComponent ���Ѵ�����롣
00560   # 
00561   # CosNaming::unbind() �Ȥۤ�Ʊ����Ư���򤹤뤬�����Ϳ����줿
00562   # �͡��ॵ���ФΥ롼�ȥ���ƥ����Ȥ��Ф��� unbind() ���ƤӽФ��������
00563   # �ۤʤ롣
00564   #
00565   # @param self
00566   # @param name ������륪�֥������ȤΥ͡��ॳ��ݡ��ͥ��
00567   #
00568   # @exception NotFound ����� <c_1, c_2, ..., c_(n-1)> ��¸�ߤ��ʤ���
00569   # @exception CannotProceed ���餫����ͳ�ǽ������³�Ǥ��ʤ���
00570   # @exception InvalidName ���� name ��̾����������
00571   #
00572   # @else
00573   #
00574   # @endif
00575   # void unbind(const CosNaming::Name& name)
00576   #   throw(NotFound, CannotProceed, InvalidName);
00577   def unbind(self, name):
00578     if isinstance(name, basestring):
00579       name_ = self.toName(name)
00580     else:
00581       name_ = name
00582 
00583     self._rootContext.unbind(name_)
00584     return
00585 
00586 
00587   ##
00588   # @if jp
00589   #
00590   # @brief ����������ƥ����Ȥ���������
00591   #
00592   # Ϳ����줿�͡��ॵ���о���������줿 NamingContext ���֤���
00593   # �֤��줿 NamingContext �� bind ����Ƥ��ʤ���
00594   # 
00595   # @param self
00596   # 
00597   # @return �������줿������ NamingContext
00598   #
00599   # @else
00600   #
00601   # @endif
00602   def newContext(self):
00603     return self._rootContext.new_context()
00604 
00605 
00606   ##
00607   # @if jp
00608   #
00609   # @brief ����������ƥ����Ȥ� bind ����
00610   #
00611   # Ϳ����줿 name ���Ф��ƿ���������ƥ����Ȥ�Х���ɤ��롣
00612   # �������줿��NamingContext �ϥ͡��ॵ���о���������줿��ΤǤ��롣
00613   # 
00614   # ���� name ��Ϳ����줿�ͤ�ʸ����ξ��ˤϤޤ��ǽ�� toName() �ˤ�ä�
00615   # NameComponent ���Ѵ�����롣
00616   # 
00617   # @param self
00618   # @param name NamingContext���դ���̾���Υ͡��ॳ��ݡ��ͥ��
00619   # @param force true�ξ�硢����Υ���ƥ����Ȥ���Ū�˥Х���ɤ���
00620   #              (�ǥե������:true)
00621   #
00622   # @return �������줿������ NamingContext
00623   #
00624   # @exception NotFound ����� <c_1, c_2, ..., c_(n-1)> ��¸�ߤ��ʤ���
00625   # @exception CannotProceed ���餫����ͳ�ǽ������³�Ǥ��ʤ���
00626   # @exception InvalidName ���� name ��̾����������
00627   # @exception AlreadyBound name <n> �� Object �����Ǥ˥Х���ɤ���Ƥ��롣
00628   #
00629   # @else
00630   #
00631   # @endif
00632   def bindNewContext(self, name, force=True):
00633     if force is None:
00634       force = True
00635       
00636     if isinstance(name, basestring):
00637       name_ = self.toName(name)
00638     else:
00639       name_ = name
00640 
00641     try:
00642       return self._rootContext.bind_new_context(name_)
00643     except CosNaming.NamingContext.NotFound:
00644       if force:
00645         self.bindRecursive(self._rootContext, name_, self.newContext())
00646       else:
00647         raise
00648     except CosNaming.NamingContext.CannotProceed, err:
00649       if force:
00650         self.bindRecursive(err.cxt, err.rest_of_name, self.newContext())
00651       else:
00652         raise
00653     return None
00654 
00655 
00656   ##
00657   # @if jp
00658   #
00659   # @brief NamingContext ���󥢥��ƥ��ֲ�����
00660   #
00661   # context �ǻ��ꤵ�줿 NamingContext ���󥢥��ƥ��ֲ����롣
00662   # context ��¾�Υ���ƥ����Ȥ��Х���ɤ���Ƥ������ NotEmpty �㳰��
00663   # ȯ�����롣
00664   # 
00665   # @param self
00666   # @param context �󥢥��ƥ��ֲ����� NamingContext
00667   #
00668   # @exception NotEmpty �о�context ��¾�Υ���ƥ����Ȥ��Х���ɤ���Ƥ��롣
00669   #
00670   # @else
00671   #
00672   # @else
00673   #
00674   # @brief Destroy the naming context
00675   #
00676   # Delete the specified naming context.
00677   # any bindings should be <unbind> in which the given context is bound to
00678   # some names before invoking <destroy> operation on it. 
00679   #
00680   # @param context NamingContext which is destroied.
00681   #     
00682   # @exception NotEmpty 
00683   #
00684   # @else
00685   #
00686   # @endif
00687   def destroy(self, context):
00688     context.destroy()
00689 
00690 
00691   ##
00692   # @if jp
00693   # @brief NamingContext ��Ƶ�Ū�˲��ä��󥢥��ƥ��ֲ�����
00694   #
00695   # context ��Ϳ����줿 NamingContext ���Ф��ơ�name �ǻ��ꤵ�줿
00696   # �͡��ॳ��ݡ��ͥ�� <c_1, ... c_(n-1)> �� NamingContext �Ȥ���
00697   # ��褷�ʤ��顢̾�� <c_n> ���Ф��� �󥢥��ƥ��ֲ���Ԥ���
00698   #
00699   # @param self
00700   # @param context �󥢥��ƥ��ֲ����� NamingContext
00701   #
00702   # @exception NotEmpty �о�context ��¾�Υ���ƥ����Ȥ��Х���ɤ���Ƥ��롣
00703   # @exception NotFound ����� <c_1, c_2, ..., c_(n-1)> ��¸�ߤ��ʤ���
00704   # @exception CannotProceed ���餫����ͳ�ǽ������³�Ǥ��ʤ���
00705   # @exception InvalidName ���� name ��̾����������
00706   #
00707   # @else
00708   # @brief Destroy the naming context recursively
00709   # @endif
00710   def destroyRecursive(self, context):
00711     cont = True
00712     bl = []
00713     bi = 0
00714     bl, bi = context.list(self._blLength)
00715     while cont:
00716       for i in range(len(bl)):
00717         if bl[i].binding_type == CosNaming.ncontext:
00718           obj = context.resolve(bl[i].binding_name)
00719           next_context = obj._narrow(CosNaming.NamingContext)
00720 
00721           self.destroyRecursive(next_context)
00722           context.unbind(bl[i].binding_name)
00723           next_context.destroy()
00724         elif bl[i].binding_type == CosNaming.nobject:
00725           context.unbind(bl[i].binding_name)
00726         else:
00727           assert(0)
00728       if CORBA.is_nil(bi):
00729         cont = False
00730       else:
00731         bi.next_n(self._blLength, bl)
00732 
00733     if not (CORBA.is_nil(bi)):
00734       bi.destroy()
00735     return
00736 
00737 
00738   ##
00739   # @if jp
00740   # @brief ���٤Ƥ� Binding ��������
00741   #
00742   # ��Ͽ����Ƥ������Ƥ�Binding �������롣
00743   #
00744   # @param self
00745   #
00746   # @else
00747   # @brief Destroy all binding
00748   # @endif
00749   def clearAll(self):
00750     self.destroyRecursive(self._rootContext)
00751     return
00752 
00753 
00754   ##
00755   # @if jp
00756   # @brief Ϳ����줿 NamingContext �� Binding ���������
00757   #
00758   # ���ꤵ�줿 NamingContext �� Binding ��������롣
00759   #
00760   # @param self
00761   # @param name_cxt Binding �����о� NamingContext
00762   # @param how_many Binding ��������볬�ؤο���
00763   # @param rbl �������� Binding ���ݻ�����ۥ��
00764   # @param rbi �������� Binding �򤿤ɤ뤿��Υ��ƥ졼��
00765   #
00766   # @else
00767   # @endif
00768   def list(self, name_cxt, how_many, rbl, rbi):
00769     bl, bi = name_cxt.list(how_many)
00770 
00771     for i in bl:
00772       rbl.append(bl)
00773 
00774     rbi.append(bi)
00775   
00776 
00777   #============================================================
00778   # interface of NamingContext
00779   #============================================================
00780 
00781   ##
00782   # @if jp
00783   # @brief Ϳ����줿 NameComponent ��ʸ����ɽ�����֤�
00784   #
00785   # ���ꤵ�줿 NameComponent ��ʸ�����Ѵ����롣
00786   #
00787   # @param self
00788   # @param name_list �Ѵ��о� NameComponent
00789   #
00790   # @return ʸ�����Ѵ����
00791   #
00792   # @exception InvalidName ���� name_list ��̾����������
00793   #
00794   # @else
00795   # @brief Get string representation of given NameComponent
00796   # @endif
00797   def toString(self, name_list):
00798     if len(name_list) == 0:
00799       raise CosNaming.NamingContext.InvalidName
00800 
00801     slen = self.getNameLength(name_list)
00802     string_name = [""]
00803     self.nameToString(name_list, string_name, slen)
00804 
00805     return string_name
00806 
00807 
00808   ##
00809   # @if jp
00810   # @brief Ϳ����줿ʸ����ɽ���� NameComponent ��ʬ�򤹤�
00811   #
00812   # ���ꤵ�줿ʸ����� NameComponent ���Ѵ����롣
00813   #
00814   # @param self
00815   # @param sname �Ѵ��о�ʸ����
00816   #
00817   # @return NameComponent �Ѵ����
00818   #
00819   # @exception InvalidName ���� sname ��������
00820   #
00821   # @else
00822   # @brief Get NameComponent from gien string name representation
00823   # @endif
00824   def toName(self, sname):
00825     if not sname:
00826       raise CosNaming.NamingContext.InvalidName
00827 
00828     string_name = sname
00829     name_comps = []
00830 
00831     nc_length = 0
00832     nc_length = self.split(string_name, "/", name_comps)
00833     if not (nc_length > 0):
00834       raise CosNaming.NamingContext.InvalidName
00835 
00836     name_list = [CosNaming.NameComponent("","") for i in range(nc_length)]
00837 
00838     for i in range(nc_length):
00839       pos = string.rfind(name_comps[i][0:],".")
00840       if pos == -1:
00841         name_list[i].id   = name_comps[i]
00842         name_list[i].kind = ""
00843       else:
00844         name_list[i].id   = name_comps[i][0:pos]
00845         name_list[i].kind = name_comps[i][(pos+1):]
00846 
00847     return name_list
00848 
00849 
00850   ##
00851   # @if jp
00852   # @brief Ϳ����줿 addr �� string_name ���� URLɽ�����������
00853   #
00854   # ���ꤵ�줿���ɥ쥹��̾�Τ�URL���Ѵ����롣
00855   #
00856   # @param self
00857   # @param addr �Ѵ��оݥ��ɥ쥹
00858   # @param string_name �Ѵ��о�̾��
00859   #
00860   # @return URL �Ѵ����
00861   #
00862   # @exception InvalidAddress ���� addr ��������
00863   # @exception InvalidName ���� string_name ��������
00864   #
00865   # @else
00866   # @brief Get URL representation from given addr and string_name
00867   # @endif
00868   def toUrl(self, addr, string_name):
00869     return self._rootContext.to_url(addr, string_name)
00870 
00871 
00872   ##
00873   # @if jp
00874   # @brief Ϳ����줿ʸ����ɽ���� resolve �����֥������Ȥ��֤�
00875   #
00876   # ���ꤵ�줿ʸ����ɽ����resolve�������֥������Ȥ�������롣
00877   #
00878   # @param self
00879   # @param string_name �����оݥ��֥�������ʸ����ɽ��
00880   #
00881   # @return ��褵�줿���֥�������
00882   #
00883   # @exception NotFound ����� <c_1, c_2, ..., c_(n-1)> ��¸�ߤ��ʤ���
00884   # @exception CannotProceed ���餫����ͳ�ǽ������³�Ǥ��ʤ���
00885   # @exception InvalidName ���� name ��̾����������
00886   # @exception AlreadyBound name <n> �� Object �����Ǥ˥Х���ɤ���Ƥ��롣
00887   #
00888   # @else
00889   # @brief Resolve from name of string representation and get object 
00890   # @endif
00891   def resolveStr(self, string_name):
00892     return self.resolve(self.toName(string_name))
00893 
00894 
00895   #============================================================
00896   # Find functions
00897   #============================================================
00898 
00899   ##
00900   # @if jp
00901   #
00902   # @brief ���֥������Ȥ�̾����Х���ɤޤ��ϲ�褹��
00903   #
00904   # ���ꤵ�줿����ƥ����Ȥ��Ф��ƥ��֥������Ȥ� NameComponent �ǻ��ꤵ�줿
00905   # ���֤˥Х���ɤ��롣
00906   # Ʊ��ս�˴���¾�����Ǥ��Х���ɺѤߤξ��ϡ���¸�ΥХ���ɺѤ����Ǥ�
00907   # �������롣
00908   #
00909   # @param self
00910   # @param context bind �⤷���� resole �оݥ���ƥ�����
00911   # @param name_list ���֥������Ȥ��դ���̾���� NameComponent
00912   # @param obj ��Ϣ�դ����� Object
00913   #
00914   # @return NameComponent �ǻ��ꤵ�줿���֤˥Х���ɤ���Ƥ��륪�֥�������
00915   #
00916   # @else
00917   # @brief Bind of resolve the given name component
00918   # @endif
00919   def bindOrResolve(self, context, name_list, obj):
00920     try:
00921       context.bind_context(name_list, obj)
00922       return obj
00923     except CosNaming.NamingContext.AlreadyBound:
00924       obj = context.resolve(name_list)
00925       return obj
00926     return CORBA.Object._nil
00927 
00928 
00929   ##
00930   # @if jp
00931   #
00932   # @brief ����ƥ����Ȥ�̾����Х���ɤޤ��ϲ�褹��
00933   #
00934   # ���ꤵ�줿����ƥ����Ȥ��Ф��� Context�� NameComponent �ǻ��ꤵ�줿���֤�
00935   # �Х���ɤ��롣
00936   # Context �����ξ��Ͽ�������ƥ����Ȥ��������ƥХ���ɤ��롣
00937   # Ʊ��ս�˴���¾�����Ǥ��Х���ɺѤߤξ��ϡ���¸�ΥХ���ɺѤ����Ǥ�
00938   # �������롣
00939   #
00940   # @param self
00941   # @param context bind �⤷���� resole �оݥ���ƥ�����
00942   # @param name_list ����ƥ����Ȥ��դ���̾���� NameComponent
00943   # @param new_context ��Ϣ�դ����� Context(�ǥե������:None)
00944   #
00945   # @return NameComponent �ǻ��ꤵ�줿���֤˥Х���ɤ���Ƥ���Context
00946   #
00947   # @else
00948   # @brief Bind of resolve the given name component
00949   # @endif
00950   def bindOrResolveContext(self, context, name_list, new_context=None):
00951     if new_context is None:
00952       new_cxt = self.newContext()
00953     else:
00954       new_cxt = new_context
00955 
00956     obj = self.bindOrResolve(context, name_list, new_cxt)
00957     return obj._narrow(CosNaming.NamingContext)
00958 
00959 
00960   ##
00961   # @if jp
00962   # @brief �͡��ॵ���Ф�̾�����������
00963   #
00964   # ���ꤷ���͡��ॵ���Ф�̾����������롣
00965   #
00966   # @param self
00967   #
00968   # @return �͡��ॵ���Ф�̾��
00969   #
00970   # @else
00971   # @brief Get the name of naming server
00972   # @endif
00973   def getNameServer(self):
00974     return self._nameServer
00975 
00976 
00977   ##
00978   # @if jp
00979   # @brief �롼�ȥ���ƥ����Ȥ��������
00980   #
00981   # ���ꤷ���͡��ॵ���ФΥ롼�ȥ���ƥ����Ȥ�������롣
00982   #
00983   # @param self
00984   #
00985   # @return �͡��ॵ���ФΥ롼�ȥ���ƥ�����
00986   #
00987   # @else
00988   # @brief Get the root context
00989   # @endif
00990   def getRootContext(self):
00991     return self._rootContext
00992 
00993 
00994   ##
00995   # @if jp
00996   # @brief ���֥������Ȥ��͡��ߥ󥰥���ƥ����Ȥ�Ƚ�̤���
00997   #
00998   # ���ꤷ�����Ǥ��͡��ߥ󥰥���ƥ����Ȥ�Ƚ�̤���
00999   #
01000   # @param self
01001   # @param obj Ƚ���о�����
01002   #
01003   # @return Ƚ�̷��(�͡��ߥ󥰥���ƥ�����:true������ʳ�:false)
01004   #
01005   # @else
01006   # @brief Whether the object is NamingContext
01007   # @endif
01008   def objIsNamingContext(self, obj):
01009     nc = obj._narrow(CosNaming.NamingContext)
01010     if CORBA.is_nil(nc):
01011       return False
01012     else:
01013       return True
01014 
01015 
01016   ##
01017   # @if jp
01018   # @brief Ϳ����줿̾�����͡��ߥ󥰥���ƥ����Ȥ��ɤ���Ƚ�̤���
01019   #
01020   # NameComponent �⤷����ʸ����ǻ��ꤷ�����Ǥ��͡��ߥ󥰥���ƥ����Ȥ�
01021   # Ƚ�̤���
01022   #
01023   # @param self
01024   # @param name_list Ƚ���о�
01025   #
01026   # @return Ƚ�̷��(�͡��ߥ󥰥���ƥ�����:true������ʳ�:false)
01027   #
01028   # @else
01029   # @brief Whether the given name component is NamingContext
01030   # @endif
01031   def nameIsNamingContext(self, name_list):
01032     return self.objIsNamingContext(self.resolve(name_list))
01033 
01034 
01035   ##
01036   # @if jp
01037   # @brief �͡��ॳ��ݡ��ͥ�Ȥ���ʬ���֤�
01038   #
01039   # ���ꤵ�줿�ϰϤΥ͡��ॳ��ݡ��ͥ�Ȥ�������롣
01040   # ��λ���֤����ꤵ��Ƥ��ʤ����ϡ��Ǹ�����Ǥ�������͡��ॳ��ݡ��ͥ��
01041   # ���֤���
01042   #
01043   # @param self
01044   # @param name_list �����о�NameComponent
01045   # @param begin �����ϰϳ��ϰ���
01046   # @param end �����ϰϽ�λ����(�ǥե������:None)
01047   #
01048   # @return NameComponent �������
01049   #
01050   # @else
01051   # @brief Get subset of given name component
01052   # @endif
01053   def subName(self, name_list, begin, end = None):
01054     if end is None or end < 0:
01055       end = len(name_list) - 1
01056 
01057     sub_len = end - (begin -1)
01058     objId = ""
01059     kind  = ""
01060     
01061     sub_name = []
01062     for i in range(sub_len):
01063       sub_name.append(name_list[begin + i])
01064 
01065     return sub_name
01066 
01067 
01068   ##
01069   # @if jp
01070   # @brief �͡��ॳ��ݡ��ͥ�Ȥ�ʸ����ɽ�����������
01071   #
01072   # ���ꤷ���ϰϤΥ͡��ॳ��ݡ��ͥ�Ȥ�ʸ����ɽ����������롣
01073   # ʸ����ɽ���ϡ�NameComponent�ι�����{Nc[0],Nc[1],Nc[2]������}�ξ�硢
01074   #   Nc[0]id.Nc[0].kind/Nc[1]id.Nc[1].kind/Nc[2].id/Nc[2].kind������
01075   # �Ȥ��������Ǽ����Ǥ��롣
01076   # ��������ʸ�����Ĺ�������ꤷ��Ĺ���ʾ�ξ��ϡ�
01077   # ���ꤷ��Ĺ�����ڤ�ΤƤ��롣
01078   #
01079   # @param self
01080   # @param name_list �����о�NameComponent
01081   # @param string_name �������ʸ����
01082   # @param slen �����о�ʸ���������
01083   #
01084   # @else
01085   # @brief Get string representation of name component
01086   # @endif
01087   def nameToString(self, name_list, string_name, slen):
01088     for i in range(len(name_list)):
01089       for id_ in name_list[i].id:
01090         if id_ == "/" or id_ == "." or id_ == "\\":
01091           string_name[0] += "\\"
01092         string_name[0] += id_
01093 
01094       if name_list[i].id == "" or name_list[i].kind != "":
01095         string_name[0] += "."
01096 
01097       for kind_ in name_list[i].kind:
01098         if kind_ == "/" or kind_ == "." or kind_ == "\\":
01099           string_name[0] += "\\"
01100         string_name[0] += kind_
01101 
01102       string_name[0] += "/"
01103 
01104 
01105   ##
01106   # @if jp
01107   # @brief �͡��ॳ��ݡ��ͥ�Ȥ�ʸ����ɽ������ʸ��Ĺ���������
01108   #
01109   # ���ꤷ���͡��ॳ��ݡ��ͥ�Ȥ�ʸ�����ɽ����������Ĺ����������롣
01110   # ʸ����ɽ���ϡ�NameComponent�ι�����{Nc[0],Nc[1],Nc[2]������}�ξ�硢
01111   #   Nc[0]id.Nc[0].kind/Nc[1]id.Nc[1].kind/Nc[2].id/Nc[2].kind������
01112   # �Ȥ��������Ǽ����Ǥ��롣
01113   #
01114   # @param self
01115   # @param name_list �����о�NameComponent
01116   #
01117   # @return ���ꤷ���͡��ॳ��ݡ��ͥ�Ȥ�ʸ����Ĺ��
01118   #
01119   # @else
01120   # @brief Get string length of the name component's string representation
01121   # @endif
01122   def getNameLength(self, name_list):
01123     slen = 0
01124 
01125     for i in range(len(name_list)):
01126       for id_ in name_list[i].id:
01127         if id_ == "/" or id_ == "." or id_ == "\\":
01128           slen += 1
01129         slen += 1
01130       if name_list[i].id == "" or name_list[i].kind == "":
01131         slen += 1
01132 
01133       for kind_ in name_list[i].kind:
01134         if kind_ == "/" or kind_ == "." or kind_ == "\\":
01135           slen += 1
01136         slen += 1
01137 
01138       slen += 1
01139 
01140     return slen
01141 
01142 
01143   ##
01144   # @if jp
01145   # @brief ʸ�����ʬ��
01146   #
01147   # ʸ�������ꤷ���ǥ�ߥ���ʬ�䤹�롣
01148   #
01149   # @param self
01150   # @param input ʬ���о�ʸ����
01151   # @param delimiter ʬ���ѥǥ�ߥ�
01152   # @param results ʬ����
01153   #
01154   # @return ʬ�䤷��ʸ��������ǿ�
01155   #
01156   # @else
01157   # @brief Split of string
01158   # @endif
01159   def split(self, input, delimiter, results):
01160     delim_size = len(delimiter)
01161     found_pos = begin_pos = pre_pos = substr_size = 0
01162 
01163     if input[0:delim_size] == delimiter:
01164       begin_pos = pre_pos = delim_size
01165 
01166     while 1:
01167       found_pos = string.find(input[begin_pos:],delimiter)
01168       
01169       if found_pos == -1:
01170         results.append(input[pre_pos:])
01171         break
01172 
01173       if found_pos > 0 and input[found_pos - 1] == "\\":
01174         begin_pos += found_pos + delim_size
01175       else:
01176         substr_size = found_pos + (begin_pos - pre_pos)
01177         if substr_size > 0:
01178           results.append(input[pre_pos:(pre_pos+substr_size)])
01179         begin_pos += found_pos + delim_size
01180         pre_pos   = begin_pos
01181 
01182     return len(results)


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sat Jun 8 2019 18:49:03