Object_T.cpp

Go to the documentation of this file.
00001 // Object_T.cpp,v 1.9 2006/04/19 09:05:03 jwillemsen Exp
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 
00010 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00011 
00012 namespace TAO
00013 {
00014   template<typename T>
00015   T *
00016   Narrow_Utils<T>::narrow (CORBA::Object_ptr obj,
00017                            const char *repo_id,
00018                            Proxy_Broker_Factory pbf
00019                            ACE_ENV_ARG_DECL)
00020   {
00021     if (CORBA::is_nil (obj))
00022       {
00023         return T::_nil ();
00024       }
00025 
00026     CORBA::Boolean is_it = obj->_is_a (repo_id
00027                                        ACE_ENV_ARG_PARAMETER);
00028     ACE_CHECK_RETURN (T::_nil ());
00029 
00030     if (is_it == 0)
00031       {
00032         return T::_nil ();
00033       }
00034 
00035     return TAO::Narrow_Utils<T>::unchecked_narrow (obj,
00036                                                    repo_id,
00037                                                    pbf
00038                                                    ACE_ENV_ARG_PARAMETER);
00039   }
00040 
00041   template<typename T> T *
00042   Narrow_Utils<T>::unchecked_narrow (CORBA::Object_ptr obj,
00043                                      Proxy_Broker_Factory pbf)
00044   {
00045     ACE_DECLARE_NEW_CORBA_ENV;
00046 
00047     T *proxy = 0;
00048     ACE_TRY
00049       {
00050         proxy =
00051           TAO::Narrow_Utils<T>::unchecked_narrow (obj,
00052                                                   0,
00053                                                   pbf
00054                                                   ACE_ENV_ARG_PARAMETER);
00055         ACE_TRY_CHECK;
00056       }
00057     ACE_CATCHANY
00058       {
00059         // Swallow the exception
00060         return T::_nil ();
00061       }
00062     ACE_ENDTRY;
00063     ACE_CHECK_RETURN (proxy);
00064 
00065     return proxy;
00066   }
00067 
00068   template<typename T> T *
00069   Narrow_Utils<T>::unchecked_narrow (CORBA::Object_ptr obj,
00070                                      const char *,
00071                                      Proxy_Broker_Factory pbf
00072                                      ACE_ENV_ARG_DECL)
00073   {
00074     if (CORBA::is_nil (obj))
00075       {
00076         return T::_nil ();
00077       }
00078 
00079     if (obj->_is_local ())
00080       {
00081         return T::_duplicate (dynamic_cast<T *> (obj));
00082       }
00083 
00084     T_ptr proxy = Narrow_Utils<T>::lazy_evaluation (obj);
00085 
00086     if (!CORBA::is_nil (proxy))
00087       {
00088         return proxy;
00089       }
00090 
00091     TAO_Stub* stub = obj->_stubobj ();
00092 
00093     if (stub == 0)
00094       {
00095         // If we're here, we have been passed a bogus objref.
00096         ACE_THROW_RETURN (CORBA::BAD_PARAM (), T::_nil ());
00097       }
00098 
00099     stub->_incr_refcnt ();
00100 
00101     bool collocated =
00102       !CORBA::is_nil (stub->servant_orb_var ().in ())
00103       && stub->optimize_collocation_objects ()
00104       && obj->_is_collocated ()
00105       && pbf != 0;
00106 
00107     ACE_NEW_THROW_EX (proxy,
00108                       T (stub,
00109                          collocated ? 1 : 0,
00110                          obj->_servant ()),
00111                       CORBA::NO_MEMORY ());
00112     return proxy;
00113   }
00114 
00115   template<typename T>
00116   T *
00117   Narrow_Utils<T>::lazy_evaluation (CORBA::Object_ptr obj)
00118   {
00119     T_ptr default_proxy = T::_nil ();
00120 
00121     // Code for lazily evaluated IORs.
00122     if (!obj->is_evaluated ())
00123       {
00124         ACE_NEW_RETURN (default_proxy,
00125                         T (obj->steal_ior (),
00126                            obj->orb_core ()),
00127                         T::_nil ());
00128       }
00129 
00130     return default_proxy;
00131   }
00132 }
00133 
00134 TAO_END_VERSIONED_NAMESPACE_DECL
00135 
00136 #endif /* TAO_OBJECT_T_CPP */

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