TAO_CORBANAME_Parser Class Reference

Implements the <corbaname:> IOR format. More...

#include <CORBANAME_Parser.h>

Inheritance diagram for TAO_CORBANAME_Parser:

Inheritance graph
[legend]
Collaboration diagram for TAO_CORBANAME_Parser:

Collaboration graph
[legend]
List of all members.

Public Member Functions

virtual ~TAO_CORBANAME_Parser (void)
 The destructor.
virtual bool match_prefix (const char *ior_string) const
virtual CORBA::Object_ptr parse_string (const char *ior, CORBA::ORB_ptr orb)

Private Member Functions

virtual CORBA::Object_ptr parse_string_dynamic_request_helper (CORBA::Object_ptr naming_context, ACE_CString &key_string)

Detailed Description

Implements the <corbaname:> IOR format.

This class implements the <corbaname:> IOR format. It is dynamically loaded by the ORB and used to get reference to a naming service at the given address and port and then resolve an object in that context.

Definition at line 41 of file CORBANAME_Parser.h.


Constructor & Destructor Documentation

TAO_BEGIN_VERSIONED_NAMESPACE_DECL TAO_CORBANAME_Parser::~TAO_CORBANAME_Parser ( void   )  [virtual]

The destructor.

Definition at line 27 of file CORBANAME_Parser.cpp.

00028 {
00029 }


Member Function Documentation

bool TAO_CORBANAME_Parser::match_prefix ( const char *  ior_string  )  const [virtual]

Return true if ior_string starts with a prefix known to this IOR parser

Implements TAO_IOR_Parser.

Definition at line 32 of file CORBANAME_Parser.cpp.

References corbaname_prefix, and ACE_OS::strncmp().

00033 {
00034   return (ACE_OS::strncmp (ior_string,
00035                            corbaname_prefix,
00036                            sizeof corbaname_prefix - 1) == 0);
00037 }

CORBA::Object_ptr TAO_CORBANAME_Parser::parse_string ( const char *  ior,
CORBA::ORB_ptr  orb 
) [virtual]

Parse the ior argument and return an object reference. The call may raise the standard system exceptions (NO_MEMORY, INV_OBJREF, etc.)

Implements TAO_IOR_Parser.

Definition at line 66 of file CORBANAME_Parser.cpp.

References CORBA::Object::_nil(), TAO_Pseudo_Var_T< T >::_retn(), ACE_ERROR_RETURN, ACE_String_Base< CHAR >::c_str(), corbaname_prefix, ACE_String_Base< CHAR >::find(), TAO_Pseudo_Var_T< T >::in(), CORBA::is_nil(), ACE_String_Base< CHAR >::length(), LM_ERROR, ACE_String_Base_Const::npos, CORBA::ORB::string_to_object(), ACE_String_Base< CHAR >::substring(), and TAO_debug_level.

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 }

CORBA::Object_ptr TAO_CORBANAME_Parser::parse_string_dynamic_request_helper ( CORBA::Object_ptr  naming_context,
ACE_CString key_string 
) [private, virtual]

Definition at line 41 of file CORBANAME_Parser.cpp.

References ACE_String_Base< CHAR >::c_str().

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 }


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:39:26 2010 for TAO by  doxygen 1.4.7