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