FILE_Parser.cpp

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

Generated on Thu Nov 9 11:54:11 2006 for TAO by doxygen 1.3.6