CORBANAME_Parser.cpp

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

Generated on Tue Feb 2 17:37:51 2010 for TAO by  doxygen 1.4.7