CORBANAME_Parser.cpp

Go to the documentation of this file.
00001 // CORBANAME_Parser.cpp,v 1.22 2006/03/10 07:19:04 jtc Exp
00002 
00003 #include "tao/CORBANAME_Parser.h"
00004 #include "tao/ORB.h"
00005 #include "tao/Object.h"
00006 #include "tao/SystemException.h"
00007 #include "tao/UB_String_Arguments.h"
00008 #include "tao/Invocation_Adapter.h"
00009 #include "tao/debug.h"
00010 
00011 #include "ace/Log_Msg.h"
00012 #include "ace/SString.h"
00013 #include "ace/OS_NS_string.h"
00014 
00015 
00016 ACE_RCSID (tao,
00017            CORBANAME_Parser,
00018            "CORBANAME_Parser.cpp,v 1.22 2006/03/10 07:19:04 jtc Exp")
00019 
00020 static const char corbaname_prefix[] = "corbaname:";
00021 
00022 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00023 
00024 TAO_CORBANAME_Parser::~TAO_CORBANAME_Parser (void)
00025 {
00026 }
00027 
00028 int
00029 TAO_CORBANAME_Parser::match_prefix (const char *ior_string) const
00030 {
00031   return (ACE_OS::strncmp (ior_string,
00032                            corbaname_prefix,
00033                            sizeof corbaname_prefix - 1) == 0);
00034 }
00035 
00036 CORBA::Object_ptr
00037 TAO_CORBANAME_Parser::
00038 parse_string_dynamic_request_helper (CORBA::Object_ptr naming_context,
00039                                      ACE_CString &key_string
00040                                      ACE_ENV_ARG_DECL)
00041   ACE_THROW_SPEC ((CORBA::SystemException))
00042 {
00043   TAO::Arg_Traits<CORBA::Object>::ret_val _tao_retval;
00044   TAO::Arg_Traits<CORBA::Char *>::in_arg_val _tao_id (key_string.c_str ());
00045 
00046   TAO::Argument *_tao_signature [] =
00047       {
00048         &_tao_retval,
00049         &_tao_id
00050       };
00051 
00052   TAO::Invocation_Adapter tao_call (naming_context,
00053                                     _tao_signature,
00054                                     2,
00055                                     "resolve_str",
00056                                     11,
00057                                     0);
00058 
00059   tao_call.invoke (0, 0 ACE_ENV_ARG_PARAMETER);
00060   ACE_CHECK_RETURN (_tao_retval.excp ());
00061 
00062   return _tao_retval.retn ();
00063 }
00064 
00065 CORBA::Object_ptr
00066 TAO_CORBANAME_Parser::parse_string (const char *ior,
00067                                     CORBA::ORB_ptr orb
00068                                     ACE_ENV_ARG_DECL)
00069   ACE_THROW_SPEC ((CORBA::SystemException))
00070 {
00071 
00072   // Skip the prefix, we know it is there because this method in only
00073   // called if <match_prefix> returns 1.
00074   const char *corbaname =
00075     ior + sizeof corbaname_prefix - 1;
00076 
00077   CORBA::Object_ptr obj = CORBA::Object::_nil ();
00078 
00079   ACE_TRY
00080     {
00081       // The position of the seperator between the obj_addr and key
00082       // string
00083       ssize_t pos_seperator = 0;
00084 
00085       ACE_CString corbaname_str (corbaname, 0, 1);
00086 
00087       pos_seperator = corbaname_str.find ("#", 0);
00088 
00089       // Get the Key String
00090       ACE_CString key_string;
00091 
00092       if (pos_seperator != ACE_CString::npos)
00093         {
00094           key_string = corbaname_str.substring (pos_seperator + 1,
00095                                                 -1);
00096         }
00097 
00098       // Prepare a suitable corbaloc string for the name service.
00099       // CORBALOC assumes "NameService" for the object key if none
00100       // is provided, so just pass everything between "corbaname:"
00101       // and "#" as the address
00102       ACE_CString corbaloc_addr ("corbaloc:", 0, 1);
00103       corbaloc_addr += corbaname_str.substring (0, pos_seperator);
00104 
00105       // Obtain a reference to the naming context
00106       CORBA::Object_var name_context =
00107         orb->string_to_object (corbaloc_addr.c_str ()
00108                                 ACE_ENV_ARG_PARAMETER);
00109       ACE_TRY_CHECK;
00110 
00111       // Check if the Object reference is nil.
00112       if (CORBA::is_nil (name_context.in ()))
00113         ACE_ERROR_RETURN ((LM_ERROR,
00114                            "Cannot resolve Naming Service: CORBANAME_Parser\n"),
00115                           0);
00116 
00117       CORBA::Boolean is_a =
00118         name_context->_is_a ("IDL:omg.org/CosNaming/NamingContextExt:1.0"
00119                               ACE_ENV_ARG_PARAMETER);
00120       ACE_TRY_CHECK;
00121 
00122       if (!is_a)
00123         {
00124           ACE_ERROR_RETURN ((LM_ERROR,
00125                              "Cannot narrow Naming Service: "
00126                              "CORBANAME_Parser\n"),
00127                             0);
00128         }
00129 
00130       if (key_string.length () != 0)
00131         {
00132 
00133           // Make a dynamic request for resolve_str in this naming context
00134           obj = this->parse_string_dynamic_request_helper (name_context.in (),
00135                                                            key_string
00136                                                         ACE_ENV_ARG_PARAMETER);
00137           ACE_TRY_CHECK;
00138         }
00139       else
00140         { // There was no key string which implies that the caller wants
00141           // the object reference of the naming service.
00142           obj = name_context._retn ();
00143         }
00144     }
00145   ACE_CATCH (CORBA::SystemException, ex)
00146     {
00147       if (TAO_debug_level >= 4)
00148         {
00149           ACE_PRINT_EXCEPTION (ex, "CORBANAME_Parser");
00150         }
00151     }
00152   ACE_ENDTRY;
00153   ACE_CHECK_RETURN (CORBA::Object::_nil ());
00154 
00155   return obj;
00156 }
00157 
00158 TAO_END_VERSIONED_NAMESPACE_DECL
00159 
00160 ACE_STATIC_SVC_DEFINE (TAO_CORBANAME_Parser,
00161                        ACE_TEXT ("CORBANAME_Parser"),
00162                        ACE_SVC_OBJ_T,
00163                        &ACE_SVC_NAME (TAO_CORBANAME_Parser),
00164                        ACE_Service_Type::DELETE_THIS |
00165                                   ACE_Service_Type::DELETE_OBJ,
00166                        0)
00167 
00168 ACE_FACTORY_DEFINE (TAO, TAO_CORBANAME_Parser)
00169 

Generated on Thu Nov 9 11:54:10 2006 for TAO by doxygen 1.3.6