Object_T.cpp

Go to the documentation of this file.
00001 // $Id: Object_T.cpp 76995 2007-02-11 12:51:42Z johnnyw $
00002 
00003 #ifndef TAO_OBJECT_T_CPP
00004 #define TAO_OBJECT_T_CPP
00005 
00006 #include "tao/Object_T.h"
00007 #include "tao/Stub.h"
00008 #include "tao/SystemException.h"
00009 #include "ace/CORBA_macros.h"
00010 
00011 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00012 
00013 namespace TAO
00014 {
00015   template<typename T>
00016   T *
00017   Narrow_Utils<T>::narrow (CORBA::Object_ptr obj,
00018                            const char *repo_id,
00019                            Proxy_Broker_Factory pbf)
00020   {
00021     if (CORBA::is_nil (obj))
00022       {
00023         return T::_nil ();
00024       }
00025 
00026     if (obj->_is_a (repo_id) == false)
00027       {
00028         return T::_nil ();
00029       }
00030 
00031     return TAO::Narrow_Utils<T>::unchecked_narrow (obj, repo_id, pbf);
00032   }
00033 
00034   template<typename T> T *
00035   Narrow_Utils<T>::unchecked_narrow (CORBA::Object_ptr obj,
00036                                      Proxy_Broker_Factory pbf)
00037   {
00038     T *proxy = 0;
00039     try
00040       {
00041         proxy = TAO::Narrow_Utils<T>::unchecked_narrow (obj, 0, pbf);
00042       }
00043     catch (const ::CORBA::Exception&)
00044       {
00045         // Swallow the exception
00046         return T::_nil ();
00047       }
00048 
00049     return proxy;
00050   }
00051 
00052   template<typename T> T *
00053   Narrow_Utils<T>::unchecked_narrow (CORBA::Object_ptr obj,
00054                                      const char *,
00055                                      Proxy_Broker_Factory pbf)
00056   {
00057     if (CORBA::is_nil (obj))
00058       {
00059         return T::_nil ();
00060       }
00061 
00062     if (obj->_is_local ())
00063       {
00064         return T::_duplicate (dynamic_cast<T *> (obj));
00065       }
00066 
00067     T_ptr proxy = Narrow_Utils<T>::lazy_evaluation (obj);
00068 
00069     if (!CORBA::is_nil (proxy))
00070       {
00071         return proxy;
00072       }
00073 
00074     TAO_Stub* stub = obj->_stubobj ();
00075 
00076     if (stub == 0)
00077       {
00078         // If we're here, we have been passed a bogus objref.
00079         throw ::CORBA::BAD_PARAM ();
00080       }
00081 
00082     stub->_incr_refcnt ();
00083 
00084     bool const collocated =
00085       !CORBA::is_nil (stub->servant_orb_var ().in ())
00086       && stub->optimize_collocation_objects ()
00087       && obj->_is_collocated ()
00088       && pbf != 0;
00089 
00090     ACE_NEW_THROW_EX (proxy,
00091                       T (stub,
00092                          collocated,
00093                          obj->_servant ()),
00094                       CORBA::NO_MEMORY ());
00095     return proxy;
00096   }
00097 
00098   template<typename T>
00099   T *
00100   Narrow_Utils<T>::lazy_evaluation (CORBA::Object_ptr obj)
00101   {
00102     T_ptr default_proxy = T::_nil ();
00103 
00104     // Code for lazily evaluated IORs.
00105     if (!obj->is_evaluated ())
00106       {
00107         ACE_NEW_RETURN (default_proxy,
00108                         T (obj->steal_ior (),
00109                            obj->orb_core ()),
00110                         T::_nil ());
00111       }
00112 
00113     return default_proxy;
00114   }
00115 }
00116 
00117 TAO_END_VERSIONED_NAMESPACE_DECL
00118 
00119 #endif /* TAO_OBJECT_T_CPP */

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