Storable_Naming_Context_Activator.cpp

Go to the documentation of this file.
00001 //=============================================================================
00002 /**
00003  *  @file   Storable_Naming_Context_Activator.cpp
00004  *
00005  *  $Id: Storable_Naming_Context_Activator.cpp 77188 2007-02-19 12:34:36Z johnnyw $
00006  *
00007  *  @author Byron Harris <harris_b@ociweb.com>
00008  */
00009 //=============================================================================
00010 
00011 
00012 #include "orbsvcs/Naming/Storable_Naming_Context_Activator.h"
00013 
00014 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
00015 #include "orbsvcs/Naming/Naming_Context_Interface.h"
00016 #include "orbsvcs/Naming/Storable_Naming_Context.h"
00017 #include "orbsvcs/Naming/Storable.h"
00018 #include "ace/Auto_Ptr.h"
00019 
00020 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00021 
00022 TAO_Storable_Naming_Context_Activator::TAO_Storable_Naming_Context_Activator (
00023   CORBA::ORB_ptr orb,
00024   TAO_Naming_Service_Persistence_Factory *factory,
00025   const ACE_TCHAR *persistence_directory,
00026   size_t context_size)
00027   : orb_(orb),
00028     factory_(factory),
00029     persistence_directory_(persistence_directory),
00030     context_size_(context_size)
00031 {
00032 }
00033 
00034 TAO_Storable_Naming_Context_Activator::~TAO_Storable_Naming_Context_Activator ()
00035 {
00036   delete factory_;
00037 }
00038 
00039 PortableServer::Servant
00040 TAO_Storable_Naming_Context_Activator::incarnate (
00041     const PortableServer::ObjectId &oid,
00042     PortableServer::POA_ptr poa)
00043 {
00044 
00045   // Make sure complete initialization has been done
00046   ACE_ASSERT (factory_ != 0);
00047 
00048   CORBA::String_var poa_id = PortableServer::ObjectId_to_string (oid);
00049 
00050   // The approached used is to simply verify that there is a
00051   // persistence element that exists that corresponds to the
00052   // poa_id. If so, an empty context is created. Later, when the
00053   // context is accessed it will be determined that the contents of
00054   // the persistence elment needs to be read in.
00055 
00056   // Does this already exist on disk?
00057   ACE_TString file_name(persistence_directory_);
00058   file_name += ACE_TEXT("/");
00059   file_name += ACE_TEXT_CHAR_TO_TCHAR(poa_id.in());
00060   TAO_Storable_Base * fl = factory_->create_stream(ACE_TEXT_ALWAYS_CHAR(file_name.c_str()), ACE_TEXT("rw"));
00061   if (!fl->exists()) {
00062     throw CORBA::OBJECT_NOT_EXIST ();
00063   }
00064 
00065   // Store the stub we will return here.
00066   CosNaming::NamingContext_var result (CosNaming::NamingContext::_nil());
00067 
00068   // Put together a servant for the new Naming Context.
00069 
00070   TAO_Storable_Naming_Context *context_impl = 0;
00071   ACE_NEW_THROW_EX (context_impl,
00072                     TAO_Storable_Naming_Context (orb_,
00073                                                  poa,
00074                                                  poa_id.in (),
00075                                                  factory_,
00076                                                  persistence_directory_,
00077                                                  context_size_),
00078                                                  CORBA::NO_MEMORY ());
00079 
00080   // Put <context_impl> into the auto pointer temporarily, in case next
00081   // allocation fails.
00082   ACE_Auto_Basic_Ptr<TAO_Storable_Naming_Context> temp (context_impl);
00083 
00084   TAO_Naming_Context *context = 0;
00085   ACE_NEW_THROW_EX (context,
00086                     TAO_Naming_Context (context_impl),
00087                     CORBA::NO_MEMORY ());
00088 
00089   // Let <implementation> know about it's <interface>.
00090   context_impl->interface (context);
00091 
00092   // Release auto pointer, and start using reference counting to
00093   // control our servant.
00094   temp.release ();
00095 
00096   return context;
00097 }
00098 
00099 void
00100 TAO_Storable_Naming_Context_Activator::etherealize (
00101     const PortableServer::ObjectId &/*oid*/,
00102     PortableServer::POA_ptr /*adapter*/,
00103     PortableServer::Servant servant,
00104     CORBA::Boolean /*cleanup_in_progress*/,
00105     CORBA::Boolean remaining_activations)
00106 {
00107   if (!remaining_activations)
00108     {
00109       delete servant;
00110     }
00111 }
00112 
00113 TAO_END_VERSIONED_NAMESPACE_DECL
00114 
00115 #endif /* TAO_HAS_MINIMUM_POA */

Generated on Sun Jan 27 16:15:32 2008 for TAO_CosNaming by doxygen 1.3.6