FILE_Parser.cpp

Go to the documentation of this file.
00001 // $Id: FILE_Parser.cpp 79237 2007-08-07 09:48:21Z johnnyw $
00002 
00003 #include "tao/FILE_Parser.h"
00004 
00005 #if (TAO_HAS_FILE_PARSER == 1)
00006 
00007 #include "tao/ORB.h"
00008 #include "tao/Object.h"
00009 
00010 #include "ace/Read_Buffer.h"
00011 #include "ace/Malloc_Base.h"
00012 #include "ace/Log_Msg.h"
00013 #include "ace/OS_NS_stdio.h"
00014 #include "ace/OS_NS_string.h"
00015 
00016 ACE_RCSID (tao,
00017            FILE_Parser,
00018            "$Id: FILE_Parser.cpp 79237 2007-08-07 09:48:21Z johnnyw $")
00019 
00020 static const char file_prefix[] = "file:";
00021 
00022 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00023 
00024 TAO_FILE_Parser::~TAO_FILE_Parser (void)
00025 {
00026 }
00027 
00028 
00029 bool
00030 TAO_FILE_Parser::match_prefix (const char *ior_string) const
00031 {
00032   return (ACE_OS::strncmp (ior_string,
00033                            ::file_prefix,
00034                            sizeof (::file_prefix) - 1) == 0);
00035 }
00036 
00037 CORBA::Object_ptr
00038 TAO_FILE_Parser::parse_string (const char *ior, CORBA::ORB_ptr orb)
00039 {
00040   // Skip the prefix, we know it is there because this method in only
00041   // called if <match_prefix> returns 1.
00042   const char *filename =
00043     ior + sizeof (::file_prefix)+1;
00044 
00045   FILE* file = ACE_OS::fopen (ACE_TEXT_CHAR_TO_TCHAR (filename),
00046                               ACE_TEXT("r"));
00047 
00048   if (file == 0)
00049     return CORBA::Object::_nil ();
00050 
00051   ACE_Read_Buffer reader (file, true);
00052 
00053   char* string = reader.read ();
00054 
00055   if (string == 0)
00056     return CORBA::Object::_nil ();
00057 
00058   CORBA::Object_ptr object = CORBA::Object::_nil ();
00059   try
00060     {
00061       object = orb->string_to_object (string);
00062 
00063       reader.alloc ()->free (string);
00064     }
00065   catch (const ::CORBA::Exception&)
00066     {
00067       reader.alloc ()->free (string);
00068       throw;
00069     }
00070 
00071   return object;
00072 }
00073 
00074 TAO_END_VERSIONED_NAMESPACE_DECL
00075 
00076 ACE_STATIC_SVC_DEFINE (TAO_FILE_Parser,
00077                        ACE_TEXT ("FILE_Parser"),
00078                        ACE_SVC_OBJ_T,
00079                        &ACE_SVC_NAME (TAO_FILE_Parser),
00080                        ACE_Service_Type::DELETE_THIS |
00081                                   ACE_Service_Type::DELETE_OBJ,
00082                        0)
00083 
00084 ACE_FACTORY_DEFINE (TAO, TAO_FILE_Parser)
00085 
00086 #endif /* TAO_HAS_FILE_PARSER == 1 */
00087 

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