Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

FILE_Parser.cpp

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

Generated on Mon Jun 16 13:48:23 2003 for TAO by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002