222 CosNaming::NamingContext_var rootContext;
226 CORBA::Object_var obj;
227 obj =
orb->resolve_initial_references(
"NameService");
230 rootContext = CosNaming::NamingContext::_narrow(obj);
231 if( CORBA::is_nil(rootContext) ) {
232 DEBTRACE(
"Failed to narrow the root naming context.");
236 catch(CORBA::ORB::InvalidName& ex) {
238 DEBTRACE(
"Service required is invalid [does not exist]." );
245 CosNaming::Name contextName;
246 contextName.length(1);
247 contextName[0].id = (
const char*)
"test";
248 contextName[0].kind = (
const char*)
"my_context";
253 CosNaming::NamingContext_var testContext;
256 testContext = rootContext->bind_new_context(contextName);
258 catch(CosNaming::NamingContext::AlreadyBound& ex) {
262 CORBA::Object_var obj;
263 obj = rootContext->resolve(contextName);
264 testContext = CosNaming::NamingContext::_narrow(obj);
265 if( CORBA::is_nil(testContext) ) {
266 DEBTRACE(
"Failed to narrow naming context.");
272 CosNaming::Name objectName;
273 objectName.length(1);
274 objectName[0].id = name;
275 objectName[0].kind = (
const char*)
"Object";
278 testContext->bind(objectName, objref);
280 catch(CosNaming::NamingContext::AlreadyBound& ex) {
281 testContext->rebind(objectName, objref);
284 catch(CORBA::COMM_FAILURE& ex) {
285 DEBTRACE(
"Caught system exception COMM_FAILURE -- unable to contact the "
286 <<
"naming service.");
289 catch(CORBA::SystemException&) {
290 DEBTRACE(
"Caught a CORBA::SystemException while using the naming service.");