Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

CORBANAME_Parser.cpp

Go to the documentation of this file.
00001 #include "tao_pch.h"
00002 // $Id: CORBANAME_Parser.cpp,v 1.1.1.2.2.1 2003/03/14 16:05:12 chad Exp $
00003 
00004 #include "CORBANAME_Parser.h"
00005 #include "Invocation.h"
00006 #include "Stub.h"
00007 #include "debug.h"
00008 
00009 #if !defined(__ACE_INLINE__)
00010 #include "CORBANAME_Parser.i"
00011 #endif /* __ACE_INLINE__ */
00012 
00013 ACE_RCSID(tao, CORBANAME_Parser, "$Id: CORBANAME_Parser.cpp,v 1.1.1.2.2.1 2003/03/14 16:05:12 chad Exp $")
00014 
00015 TAO_CORBANAME_Parser::~TAO_CORBANAME_Parser (void)
00016 {
00017 }
00018 
00019 static const char corbaname_prefix[] = "corbaname:";
00020 
00021 int
00022 TAO_CORBANAME_Parser::match_prefix (const char *ior_string) const
00023 {
00024   return (ACE_OS::strncmp (ior_string,
00025                            corbaname_prefix,
00026                            sizeof corbaname_prefix - 1) == 0);
00027 }
00028 
00029 CORBA::Object_ptr
00030 
00031 TAO_CORBANAME_Parser::parse_string_dynamic_request_helper (CORBA::Object_ptr naming_context,
00032                                      ACE_CString &key_string
00033                                      ACE_ENV_ARG_DECL)
00034   ACE_THROW_SPEC ((CORBA::SystemException))
00035 {
00036   CORBA::Object_ptr _tao_retval = CORBA::Object::_nil ();
00037 
00038   CORBA::Object_var _tao_safe_retval (_tao_retval);
00039 
00040   TAO_Stub *istub = naming_context->_stubobj ();
00041   if (istub == 0)
00042     ACE_THROW_RETURN (CORBA::INTERNAL (), 0);
00043 
00044   TAO_GIOP_Twoway_Invocation _tao_call (
00045       istub,
00046       "resolve_str",
00047       11,
00048       1,
00049       istub->orb_core ()
00050     );
00051 
00052   for (;;)
00053     {
00054       _tao_call.start (ACE_ENV_SINGLE_ARG_PARAMETER);
00055       ACE_CHECK_RETURN (CORBA::Object::_nil ());
00056 
00057       CORBA::Short _tao_response_flag = TAO_TWOWAY_RESPONSE_FLAG;
00058 
00059       _tao_call.prepare_header (
00060           ACE_static_cast (CORBA::Octet, _tao_response_flag)
00061            ACE_ENV_ARG_PARAMETER
00062         );
00063       ACE_CHECK_RETURN (CORBA::Object::_nil ());
00064 
00065       TAO_OutputCDR &_tao_out = _tao_call.out_stream ();
00066       if (!(
00067             (_tao_out << key_string.c_str ())
00068           ))
00069         ACE_THROW_RETURN (
00070             CORBA::MARSHAL (TAO_DEFAULT_MINOR_CODE, CORBA::COMPLETED_NO),
00071             CORBA::Object::_nil ()
00072           );
00073 
00074       int _invoke_status = 0;
00075       ACE_TRY
00076         {
00077           _invoke_status = _tao_call.invoke (0, 0 ACE_ENV_ARG_PARAMETER);
00078           ACE_TRY_CHECK (CORBA::Object::_nil ());
00079         }
00080       ACE_CATCH (CORBA::UNKNOWN, ex)
00081         {
00082           ACE_UNUSED_ARG (ex);
00083 
00084           ACE_THROW_RETURN (
00085               CORBA::BAD_PARAM (CORBA::OMGVMCID | 10,
00086                                 CORBA::COMPLETED_YES),
00087               CORBA::Object::_nil ()
00088             );
00089         }
00090       ACE_ENDTRY;
00091       ACE_CHECK_RETURN (CORBA::Object::_nil ());
00092 
00093       if (_invoke_status == TAO_INVOKE_RESTART)
00094         {
00095           _tao_call.restart_flag (1);
00096           continue;
00097         }
00098       if (_invoke_status != TAO_INVOKE_OK)
00099         {
00100           // @@ Is there any way we can reach this point?  Any
00101           //    USER_EXCEPTION response will be caught by the UNKNOWN
00102           //    catch block above.  Any SYSTEM_EXCEPTION response will
00103           //    be simply raised, and any RESTART is handled
00104           //    already...  leave this here "just in case".
00105           ACE_THROW_RETURN (
00106               CORBA::BAD_PARAM (CORBA::OMGVMCID | 10,
00107                                 CORBA::COMPLETED_YES),
00108               CORBA::Object::_nil ()
00109             );
00110         }
00111       TAO_InputCDR &_tao_in = _tao_call.inp_stream ();
00112       if (!(
00113             (_tao_in >> _tao_safe_retval.inout ())
00114           ))
00115         {
00116           ACE_THROW_RETURN (
00117               CORBA::MARSHAL (TAO_DEFAULT_MINOR_CODE, CORBA::COMPLETED_YES),
00118               CORBA::Object::_nil ()
00119             );
00120         }
00121       break;
00122     }
00123 
00124   return _tao_safe_retval._retn ();
00125 }
00126 
00127 CORBA::Object_ptr
00128 TAO_CORBANAME_Parser::parse_string (const char *ior,
00129                                     CORBA::ORB_ptr orb
00130                                     ACE_ENV_ARG_DECL)
00131   ACE_THROW_SPEC ((CORBA::SystemException))
00132 {
00133 
00134   // Skip the prefix, we know it is there because this method in only
00135   // called if <match_prefix> returns 1.
00136   const char *corbaname =
00137     ior + sizeof corbaname_prefix - 1;
00138 
00139   CORBA::Object_ptr obj = CORBA::Object::_nil ();
00140 
00141   ACE_TRY
00142     {
00143       char rir_prot [] = "rir:";
00144 
00145       // The position of the seperator between the obj_addr and key
00146       // string
00147       CORBA::ULong pos_seperator = 0;
00148 
00149       ACE_CString corbaname_str (corbaname, 0, 1);
00150 
00151       pos_seperator = corbaname_str.find ("#", 0);
00152 
00153       // Get the Key String
00154       ACE_CString key_string =
00155         corbaname_str.substring (pos_seperator + 1,
00156                                  -1);
00157 
00158       // Make it in a form understandable by <corbaloc> scheme
00159       ACE_CString corbaloc_addr ("corbaloc:", 0, 1);
00160 
00161       if (ACE_OS::strncmp (corbaname,
00162                            rir_prot,
00163                            sizeof (rir_prot)) != 0)
00164         {
00165           // Implies that <iiop:> protocol is to be used.
00166           // So .. we need to get the host address where an object of
00167           // type NamingContext can be found.
00168           // Get the obj_addr
00169           ACE_CString obj_addr = corbaname_str.substring (0,
00170                                                           pos_seperator);
00171 
00172           corbaloc_addr += obj_addr;
00173 
00174         }
00175 
00176       ACE_CString name_service ("/NameService", 0, 1);
00177       corbaloc_addr += name_service;
00178 
00179       // Obtain a reference to the naming context
00180       CORBA::Object_var name_context =
00181         orb->string_to_object (corbaloc_addr.c_str ()
00182                                 ACE_ENV_ARG_PARAMETER);
00183       ACE_TRY_CHECK;
00184 
00185       // Check if the Object reference is nil.
00186       if (CORBA::is_nil (name_context.in ()))
00187         ACE_ERROR_RETURN ((LM_ERROR,
00188                            "Cannot resolve Naming Service: CORBANAME_Parser\n"),
00189                           0);
00190 
00191       CORBA::Boolean is_a =
00192         name_context->_is_a ("IDL:omg.org/CosNaming/NamingContextExt:1.0"
00193                               ACE_ENV_ARG_PARAMETER);
00194       ACE_TRY_CHECK;
00195 
00196       if (!is_a)
00197         {
00198           ACE_ERROR_RETURN ((LM_ERROR,
00199                              "Cannot narrow Naming Service: "
00200                              "CORBANAME_Parser\n"),
00201                             0);
00202         }
00203 
00204       // Make a dynamic request for resolve_str in this naming context
00205       obj = this->parse_string_dynamic_request_helper (name_context.in (),
00206                                                        key_string
00207                                                         ACE_ENV_ARG_PARAMETER);
00208       ACE_TRY_CHECK;
00209     }
00210   ACE_CATCH (CORBA::SystemException, ex)
00211     {
00212       if (TAO_debug_level >= 4)
00213         {
00214           ACE_PRINT_EXCEPTION (ex, "CORBANAME_Parser");
00215         }
00216     }
00217   ACE_ENDTRY;
00218   ACE_CHECK_RETURN (CORBA::Object::_nil ());
00219 
00220   return obj;
00221 }
00222 
00223 ACE_STATIC_SVC_DEFINE (TAO_CORBANAME_Parser,
00224                        ACE_TEXT ("CORBANAME_Parser"),
00225                        ACE_SVC_OBJ_T,
00226                        &ACE_SVC_NAME (TAO_CORBANAME_Parser),
00227                        ACE_Service_Type::DELETE_THIS |
00228                                   ACE_Service_Type::DELETE_OBJ,
00229                        0)
00230 
00231 ACE_FACTORY_DEFINE (TAO, TAO_CORBANAME_Parser)
00232 
00233 #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
00234 
00235 #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
00236 
00237 #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */

Generated on Mon Jun 16 13:48:11 2003 for TAO by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002