Basic Operations
The basic operations of the naming service are defined either in the interface CosNaming::NamingContext (the subset of operations in the old naming service specification) or in the interface CosNaming::NamingContextExt (the extensions introduced in the CORBA Interoperable Naming Service specification). Some of the basic tasks you need to perform on the naming service are to:
Create object bindings
Create context bindings
Resolve names
Convert name formats
The following IDL fragment highlights some of the operations you can use for these tasks:
//IDL #pragma prefix "omg.org" module CosNaming { ... interface NamingContext { ... void rebind(in Name n, in Object obj) raises(NotFound, CannotProceed, InvalidName); void bind(in Name n, in Object obj) raises(NotFound, CannotProceed, InvalidName, AlreadyBound); Object resolve (in Name n) raises(NotFound, CannotProceed, InvalidName); NamingContext bind_new_context(in Name n) raises(NotFound, AlreadyBound, CannotProceed, InvalidName); ... }; ... interface NamingContextExt: NamingContext { ... typedef string StringName; Object resolve_str(in StringName n) raises(NotFound, CannotProceed, InvalidName, AlreadyBound); StringName to_string(in Name n) raises(InvalidName); Name to_name(in StringName sn) raises(InvalidName); URLString to_url(in Address addr, in StringName sn) raises(InvalidAddress, InvalidName); ... }; };
Parts of the module CosNaming have been omitted from this listing (including the declaration of user exceptions). For a full listing of the IDL, see the later section "Naming Service IDL."
The following sections give the semantics for each of these basic operations.
Create Object Bindings - rebind() and bind()
To create an object binding, you can use either rebind() or bind(). Both operations create an object binding that associates the name n (in raw format) with the naming context nc. The semantics, however, are different:
rebind()the operation creates a new object binding for the given name n or, if a binding already exists with that name, overwrites the existing binding.
bind()the operation creates a new object binding for the given name n as long as there is no existing binding with that name. If a binding already exists, an AlreadyBound exception is thrown.
The semantics of rebind() are more convenient, so you will probably use it instead of bind() most of the time.
Note that these operations create object bindings relative to the naming context on which they are invoked. For example, if you want to create an object binding with the name A/B/C/MyObj, you can either invoke rebind() on the initial naming context, using the full name A/B/C/MyObj, or invoke rebind() on the naming context A/B/C, using the short name MyObj.
Create Context Bindings - bind_new_context()
To create a new context binding, you can use the operation bind_new_context() to create the context in one step. It takes the name of the context you want to create as an argument (in raw format) and returns an object reference for the newly created naming context.
The immediate parent of the context binding you want to create must already exist; otherwise, a NotFound exception is raised. For example, you can create the context A/B/C only if the context A/B already exists.
Resolve Names - resolve_str() and resolve()
To resolve a binding in the naming service, you can use either resolve_str() or resolve(). The only difference between these two operations is that resolve_str() takes a stringified name as its argument, while resolve() takes a raw name.
Note the following points:
The return value is of type Object, so the returned object reference always needs to be narrowed to the actual type before it can be used.
The operation resolve_str() is available only on the interface NamingContextExt. You must narrow your naming context to NamingContextExt before you can access this operation.
The resolve operations can be used to resolve either object or context bindings. For context bindings, narrow to NamingContext or NamingContextExt, as appropriate.
Conversion Operations
Three conversion operations are provided in the interface NamingContextExt. These are to_string(), to_name(), and to_url().
The conversion operations to_string() and to_name() are used to convert back and forth between stringified name format and raw name format. The exception InvalidName is raised by either of these operations if the argument is malformed in some way.