CORBA::Boolean Library_impl::queryBook( ::Assignment2::Library::BookIDType bookID, CORBA::String_out libName ) throw( ::CORBA::SystemException, ::Assignment2::Library::NotPresent) { //delete this default false try { //local call }//end try query catch( ::Assignment2::Library::NotPresent ex ) { }//end notpresent exception catch( ... ) { } //copy names of other libraries locally //INITIALIZE ORB //duplicate argv in this context CORBA::ORB_var orb = CORBA::ORB_init(_argc,aargs); //ACQUIRE REFERENCE TO NAMING SERVICE CORBA::Object_var nsobj = orb->resolve_initial_references("NameService"); CosNaming::NamingContext_var nc = CosNaming::NamingContext::_narrow (nsobj); if (CORBA::is_nil (nc)) { cerr << "oops, I cannot access the Naming Service!" << endl; exit (1); }//end if nul ref //CREATE NAMING SERVICE NAME FOR LOOKUP OF _LOCAL LIBRARY_ //this next part is a duplicate of the example text, done twice, once for each library CosNaming::Name name0; name0.length (1); name0[0].id = CORBA::string_dup (lib0Name.c_str()); name0[0].kind = CORBA::string_dup (""); CosNaming::Name name1; name1.length (1); name1[0].id = CORBA::string_dup (lib1Name.c_str()); name1[0].kind = CORBA::string_dup (""); //ATTEMPT LOOKUP OF THIS LIBRARY IN THE NAME SERVICE TREE CORBA::Object_var obj0; cout << "got server " << lib0Name << "..." << flush; CORBA::Object_var obj1; cout << "got server " << lib1Name << "..." << flush; #ifdef HAVE_EXCEPTIONS try { obj0 = nc->resolve (name0); cout << "got 0... "; obj1 = nc->resolve (name1); cout << "got 1... "; }//end attempt to resolve catch (CosNaming::NamingContext::NotFound &exc) { cout << "NotFound exception." << endl; exit (1); }//end if not found catch (CosNaming::NamingContext::CannotProceed &exc) { cout << "CannotProceed exception." << endl; exit (1); }//end if can't go on catch (CosNaming::NamingContext::InvalidName &exc) { cout << "InvalidName exception." << endl; exit (1); }//end if invalid name catch(...) { cout << "unknown error" << endl; exit(1); }//end my own unknown error #else obj = nc->resolve (name0); obj1 = nc->resolve (name1); #endif cout << " done." << endl; /* * The Naming Service returns a generic reference as a CORBA::Object * We need to narrow this to the desired type */ Library_var theLib = Assignment2::Library::_narrow(obj0); //TRY FIRST OTHER LIBRARY Library_var lib1 = Assignment2::Library::_narrow(obj1); //TRY SECOND OTHER LIBRARY //...last-minute logic }//end bool queryBook