// Hello.cpp
//
// This CORBA client initializes an ORB, obtains a reference to the 
// HelloServer, and calls HelloServer methods.
//
// Copyright (c) 2000 by BEA Systems, Inc. All Rights Reserved.
//

#include "CosNaming_c.hh"
#include "HelloWorld_c.hh"

USE_STD_NS

int main(int argc, char* const* argv)
{
  try {
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
    if (argc != 2) {
	cout << "Usage: HelloClient <ServerIOR>" << endl;
	return argc;
    }
    // obtain WebLogic Server IOR from command line argument
    const char* ior = argv[1];

    // string to object
    CORBA::Object_ptr o = orb->string_to_object(ior);

    // obtain a naming context
    CosNaming::NamingContext_var context = CosNaming::NamingContext::_narrow(o);
    CosNaming::Name name;
    name.length(1);
    name[0].id = "HelloServer";
    name[0].kind = "";
    name[0].kind = "";

    // resolve and narrow to RMI object
    CORBA::Object_var object = context->resolve(name);
    examples::rmi_iiop::hello::HelloWorld_var hi = 
      examples::rmi_iiop::hello::HelloWorld::_narrow(object);
      
    if(!CORBA::is_nil(hi)) {
	hi->sayHello();
    }
  }
  catch(const CORBA::Exception& e) {
    cout << "Failure: " << e << endl;
  }
  return 0;
}

