1 直接获取对象引用
1.1 通过 IOR
orb.string_to_object(IOR 串 )
1.2 通过 Corbaoc 的 URL
orb.string_to_object(Corbaoc 的 URL)
1.3 通过 Initial References
orb.resolve_initial_references( 某个 Initial References 的键 )
Initial References 是一堆键 - 值对,在 orb 初始化的时候设置,不同厂商的 orb 有不同的设置方式
2 从名服务获取对象引用
假设 nc 是已经获取的 NamingContextExt 类型的对象,“ XXX ”是某对象在名服务上注册的名字。
2.1 两步走
nc.resolve(nc.to_name("XXX"))
to_name
String to_string (NameComponent [] n)
throws InvalidName
This operation creates a stringified name from the array of Name components.
Parameters:
n - Name of the object
Throws:
org.omg.CosNaming.NamingContextExtPackage.InvalidName - Indicates the name does not identify a binding.
resolve
Object resolve (NameComponent [] n)
throws NotFound ,
The resolve operation is the process of retrieving an object bound to a name in a given context. The given name must exactly match the bound name. The naming service does not return the type of the object. Clients are responsible for "narrowing" the object to the appropriate type. That is, clients typically cast the returned object from Object to a more specialized interface.
Parameters:
n - Name of the object
Throws:
NotFound - Indicates the name does not identify a binding.
CannotProceed - Indicates that the implementation has given up for some reason. The client, however, may be able to continue the operation at the returned naming context.
InvalidName - Indicates that the name is invalid.
2.2 一步到位
nc.resolve_str("XXX")
resolve_str
Object resolve_str (String sn)
throws NotFound ,
This operation resolves the Stringified name into the object reference.
Parameters:
sn - Stringified Name of the object
Throws:
NotFound - Indicates there is no object reference for the given name.
CannotProceed - Indicates that the given compound name is incorrect
org.omg.CosNaming.NamingContextExtPackage.InvalidName - Indicates the name does not identify a binding.