Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / CORBANAME_Parser.cpp
blobdb7a72d3511905437035987a4675f44ee1a03c4f
1 // -*- C++ -*-
2 #include "tao/CORBANAME_Parser.h"
4 #if (TAO_HAS_CORBANAME_PARSER == 1)
6 #include "tao/ORB.h"
7 #include "tao/Object.h"
8 #include "tao/SystemException.h"
9 #include "tao/UB_String_Arguments.h"
10 #include "tao/Invocation_Adapter.h"
11 #include "tao/debug.h"
13 #include "ace/Log_Msg.h"
14 #include "ace/SString.h"
15 #include "ace/OS_NS_string.h"
17 static const char corbaname_prefix[] = "corbaname:";
19 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
21 bool
22 TAO_CORBANAME_Parser::match_prefix (const char *ior_string) const
24 return (ACE_OS::strncmp (ior_string,
25 corbaname_prefix,
26 sizeof corbaname_prefix - 1) == 0);
29 CORBA::Object_ptr
30 TAO_CORBANAME_Parser::
31 parse_string_dynamic_request_helper (CORBA::Object_ptr naming_context,
32 ACE_CString &key_string)
34 TAO::Arg_Traits<CORBA::Object>::ret_val _tao_retval;
35 TAO::Arg_Traits<CORBA::Char *>::in_arg_val _tao_id (key_string.c_str ());
37 TAO::Argument *_tao_signature [] =
39 &_tao_retval,
40 &_tao_id
43 TAO::Invocation_Adapter tao_call (naming_context,
44 _tao_signature,
46 "resolve_str",
47 11,
48 TAO::TAO_CO_NONE | TAO::TAO_CO_THRU_POA_STRATEGY);
50 tao_call.invoke (nullptr, 0);
52 return _tao_retval.retn ();
55 CORBA::Object_ptr
56 TAO_CORBANAME_Parser::parse_string (const char *ior, CORBA::ORB_ptr orb)
58 // Skip the prefix, we know it is there because this method in only
59 // called if <match_prefix> returns 1.
60 const char *corbaname =
61 ior + sizeof corbaname_prefix - 1;
63 CORBA::Object_ptr obj = CORBA::Object::_nil ();
65 try
67 // The position of the seperator between the obj_addr and key
68 // string
69 ACE_CString::size_type pos_seperator = 0;
71 ACE_CString corbaname_str (corbaname, nullptr, 1);
73 pos_seperator = corbaname_str.find ("#", 0);
75 // Get the Key String
76 ACE_CString key_string;
78 if (pos_seperator != ACE_CString::npos)
80 key_string = corbaname_str.substring (pos_seperator + 1,
81 ACE_CString::npos);
84 // Prepare a suitable corbaloc string for the name service.
85 // CORBALOC assumes "NameService" for the object key if none
86 // is provided, so just pass everything between "corbaname:"
87 // and "#" as the address
88 ACE_CString corbaloc_addr ("corbaloc:", nullptr, 1);
89 corbaloc_addr += corbaname_str.substring (0, pos_seperator);
91 // Obtain a reference to the naming context
92 CORBA::Object_var name_context =
93 orb->string_to_object (corbaloc_addr.c_str ());
95 // Check if the Object reference is nil.
96 if (CORBA::is_nil (name_context.in ()))
97 TAOLIB_ERROR_RETURN ((LM_ERROR,
98 "Cannot resolve Naming Service: CORBANAME_Parser\n"),
99 0);
101 CORBA::Boolean is_a =
102 name_context->_is_a ("IDL:omg.org/CosNaming/NamingContextExt:1.0");
104 if (!is_a)
106 TAOLIB_ERROR_RETURN ((LM_ERROR,
107 "Cannot narrow Naming Service: "
108 "CORBANAME_Parser\n"),
112 if (key_string.length () != 0)
114 // Make a dynamic request for resolve_str in this naming context
115 obj = this->parse_string_dynamic_request_helper (name_context.in (),
116 key_string);
118 else
119 { // There was no key string which implies that the caller wants
120 // the object reference of the naming service.
121 obj = name_context._retn ();
124 catch (const ::CORBA::SystemException& ex)
126 if (TAO_debug_level >= 4)
128 ex._tao_print_exception ("CORBANAME_Parser");
132 return obj;
136 ACE_STATIC_SVC_DEFINE (TAO_CORBANAME_Parser,
137 ACE_TEXT ("CORBANAME_Parser"),
138 ACE_SVC_OBJ_T,
139 &ACE_SVC_NAME (TAO_CORBANAME_Parser),
140 ACE_Service_Type::DELETE_THIS |
141 ACE_Service_Type::DELETE_OBJ,
144 ACE_FACTORY_DEFINE (TAO, TAO_CORBANAME_Parser)
146 TAO_END_VERSIONED_NAMESPACE_DECL
148 #endif /* TAO_HAS_CORBANAME_PARSER == 1 */