Any_SystemException.cpp

Go to the documentation of this file.
00001 // $Id: Any_SystemException.cpp 77409 2007-02-26 23:48:49Z ossama $
00002 
00003 #include "tao/AnyTypeCode/Any_SystemException.h"
00004 #include "tao/AnyTypeCode/Any.h"
00005 #include "tao/AnyTypeCode/Any_Unknown_IDL_Type.h"
00006 #include "tao/AnyTypeCode/Marshal.h"
00007 #include "tao/AnyTypeCode/TypeCode.h"
00008 
00009 #include "tao/CDR.h"
00010 #include "tao/Exception.h"
00011 #include "tao/CORBA_String.h"
00012 #include "tao/SystemException.h"
00013 
00014 #include "ace/Auto_Ptr.h"
00015 
00016 ACE_RCSID (AnyTypeCode,
00017            Any_SystemException,
00018            "$Id: Any_SystemException.cpp 77409 2007-02-26 23:48:49Z ossama $")
00019 
00020 
00021 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00022 
00023 TAO::Any_SystemException::Any_SystemException (_tao_destructor destructor,
00024                                                CORBA::TypeCode_ptr tc,
00025                                                CORBA::SystemException * const val)
00026   : Any_Impl (destructor,
00027               tc),
00028     value_ (val)
00029 {
00030 }
00031 
00032 TAO::Any_SystemException::Any_SystemException (_tao_destructor destructor,
00033                                                CORBA::TypeCode_ptr tc,
00034                                                const CORBA::SystemException & val)
00035   : Any_Impl (destructor,
00036               tc)
00037 {
00038  this->value_ =
00039    dynamic_cast <CORBA::SystemException *> (val._tao_duplicate ());
00040 }
00041 
00042 TAO::Any_SystemException::Any_SystemException (CORBA::TypeCode_ptr tc)
00043   : Any_Impl (0,
00044               tc)
00045 {
00046 }
00047 
00048 TAO::Any_SystemException::~Any_SystemException (void)
00049 {
00050 }
00051 
00052 void
00053 TAO::Any_SystemException::insert (CORBA::Any & any,
00054                                   _tao_destructor destructor,
00055                                   CORBA::TypeCode_ptr tc,
00056                                   CORBA::SystemException * const value)
00057 {
00058   Any_SystemException *new_impl = 0;
00059   ACE_NEW (new_impl,
00060            Any_SystemException (destructor,
00061                                 tc,
00062                                 value));
00063   any.replace (new_impl);
00064 }
00065 
00066 void
00067 TAO::Any_SystemException::insert_copy (CORBA::Any & any,
00068                                        _tao_destructor destructor,
00069                                        CORBA::TypeCode_ptr tc,
00070                                        const CORBA::SystemException & value)
00071 {
00072   Any_SystemException *new_impl = 0;
00073   ACE_NEW (new_impl,
00074            Any_SystemException (destructor,
00075                                 tc,
00076                                 value));
00077   any.replace (new_impl);
00078 }
00079 
00080 CORBA::Boolean
00081 TAO::Any_SystemException::extract (const CORBA::Any & any,
00082                                    _tao_destructor destructor,
00083                                    CORBA::TypeCode_ptr tc,
00084                                    const CORBA::SystemException *& _tao_elem,
00085                                    TAO::excp_factory f)
00086 {
00087   _tao_elem = 0;
00088 
00089   try
00090     {
00091       CORBA::TypeCode_ptr any_tc = any._tao_get_typecode ();
00092       CORBA::Boolean const _tao_equiv = any_tc->equivalent (tc);
00093 
00094       if (_tao_equiv == false)
00095         {
00096           return false;
00097         }
00098 
00099       TAO::Any_Impl *impl = any.impl ();
00100 
00101       if (!impl->encoded ())
00102         {
00103           TAO::Any_SystemException *narrow_impl =
00104             dynamic_cast <TAO::Any_SystemException *> (impl);
00105 
00106           if (narrow_impl == 0)
00107             {
00108               return false;
00109             }
00110 
00111           _tao_elem = narrow_impl->value_;
00112           return true;
00113         }
00114 
00115       CORBA::SystemException *empty_value =  (*f) ();
00116 
00117       TAO::Any_SystemException *replacement = 0;
00118       ACE_NEW_RETURN (replacement,
00119                       TAO::Any_SystemException (destructor,
00120                                                 any_tc,
00121                                                 empty_value),
00122                       false);
00123 
00124       auto_ptr<TAO::Any_SystemException > replacement_safety (replacement);
00125 
00126       // We know this will work since the unencoded case is covered above.
00127       TAO::Unknown_IDL_Type * const unk =
00128         dynamic_cast<TAO::Unknown_IDL_Type *> (impl);
00129 
00130       if (!unk)
00131         return false;
00132 
00133       // We don't want the rd_ptr of unk to move, in case it is
00134       // shared by another Any. This copies the state, not the buffer.
00135       TAO_InputCDR for_reading (unk->_tao_get_cdr ());
00136 
00137       CORBA::Boolean const good_decode =
00138         replacement->demarshal_value (for_reading);
00139 
00140       if (good_decode)
00141         {
00142           _tao_elem = replacement->value_;
00143           const_cast<CORBA::Any &> (any).replace (replacement);
00144           replacement_safety.release ();
00145           return true;
00146         }
00147     }
00148   catch (const ::CORBA::Exception&)
00149     {
00150     }
00151 
00152   return false;
00153 }
00154 
00155 void
00156 TAO::Any_SystemException::free_value (void)
00157 {
00158   if (this->value_destructor_ != 0)
00159     {
00160       (*this->value_destructor_) (this->value_);
00161       this->value_destructor_ = 0;
00162     }
00163 
00164   ::CORBA::release (this->type_);
00165   this->value_ = 0;
00166 }
00167 
00168 const void *
00169 TAO::Any_SystemException::value (void) const
00170 {
00171   return this->value_;
00172 }
00173 
00174 CORBA::Boolean
00175 TAO::Any_SystemException::marshal_value (TAO_OutputCDR &cdr)
00176 {
00177   try
00178     {
00179       this->value_->_tao_encode (cdr);
00180       return true;
00181     }
00182   catch (const ::CORBA::Exception&)
00183     {
00184     }
00185   return false;
00186 }
00187 
00188 CORBA::Boolean
00189 TAO::Any_SystemException::demarshal_value (TAO_InputCDR &cdr)
00190 {
00191   try
00192     {
00193       this->value_->_tao_decode (cdr);
00194       return true;
00195     }
00196   catch (const ::CORBA::Exception&)
00197     {
00198     }
00199   return false;
00200 }
00201 
00202 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Sun Jan 27 13:21:06 2008 for TAO_AnyTypeCode by doxygen 1.3.6