#include "Naming.h"

/*
 * @func Resolves to an object with the given name in the given context
 */
CORBA::Boolean
Naming::resolveToObject (CosNaming::Name &name,
                         CosNaming::NamingContext_ptr ctx,
                         CORBA::Object_ptr &obj)
{
  try
    {
      CORBA::Object_var objVar = ctx->resolve (name);

      if (CORBA::is_nil (objVar.in ()))
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("ERROR: NULL object reference\n")));
          return 0;
        }

      obj = objVar._retn ();
    }
  catch (const CosNaming::NamingContext::NotFound &ex)
    {
      ex._tao_print_exception (ACE_TEXT ("ERROR: cannot resolve name\n"));
      return 0;
    }

   return 1;
}
