Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / FILE_Parser.cpp
blob6c3d1fef49017829cb804fdb2343204813333bbc
1 #include "tao/FILE_Parser.h"
3 #if (TAO_HAS_FILE_PARSER == 1)
5 #include "tao/ORB.h"
6 #include "tao/Object.h"
8 #include "ace/Read_Buffer.h"
9 #include "ace/Malloc_Base.h"
10 #include "ace/Log_Msg.h"
11 #include "ace/OS_NS_stdio.h"
12 #include "ace/OS_NS_string.h"
14 static const char file_prefix[] = "file:";
16 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
18 bool
19 TAO_FILE_Parser::match_prefix (const char *ior_string) const
21 return (ACE_OS::strncmp (ior_string,
22 ::file_prefix,
23 sizeof (::file_prefix) - 1) == 0);
26 CORBA::Object_ptr
27 TAO_FILE_Parser::parse_string (const char *ior, CORBA::ORB_ptr orb)
29 // Skip the prefix, we know it is there because this method in only
30 // called if <match_prefix> returns 1.
31 const char *filename =
32 ior + sizeof (::file_prefix)+1;
34 FILE* file = ACE_OS::fopen (ACE_TEXT_CHAR_TO_TCHAR (filename),
35 ACE_TEXT("r"));
37 if (file == nullptr)
38 return CORBA::Object::_nil ();
40 ACE_Read_Buffer reader (file, true);
42 char* string = reader.read ();
44 if (string == nullptr)
45 return CORBA::Object::_nil ();
47 CORBA::Object_ptr object = CORBA::Object::_nil ();
48 try
50 object = orb->string_to_object (string);
52 reader.alloc ()->free (string);
54 catch (const ::CORBA::Exception&)
56 reader.alloc ()->free (string);
57 throw;
60 return object;
64 ACE_STATIC_SVC_DEFINE (TAO_FILE_Parser,
65 ACE_TEXT ("FILE_Parser"),
66 ACE_SVC_OBJ_T,
67 &ACE_SVC_NAME (TAO_FILE_Parser),
68 ACE_Service_Type::DELETE_THIS |
69 ACE_Service_Type::DELETE_OBJ,
72 ACE_FACTORY_DEFINE (TAO, TAO_FILE_Parser)
74 TAO_END_VERSIONED_NAMESPACE_DECL
76 #endif /* TAO_HAS_FILE_PARSER == 1 */