DynSequence_i.cpp

Go to the documentation of this file.
00001 // DynSequence_i.cpp,v 1.31 2006/03/10 07:19:08 jtc Exp
00002 
00003 #include "tao/DynamicAny/DynSequence_i.h"
00004 #include "tao/DynamicAny/DynAnyFactory.h"
00005 #include "tao/AnyTypeCode/Marshal.h"
00006 #include "tao/AnyTypeCode/Any_Unknown_IDL_Type.h"
00007 #include "tao/CDR.h"
00008 
00009 ACE_RCSID (DynamicAny,
00010            DynSequence_i,
00011            "DynSequence_i.cpp,v 1.31 2006/03/10 07:19:08 jtc Exp")
00012 
00013 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00014 
00015 TAO_DynSequence_i::TAO_DynSequence_i (void)
00016 {
00017 }
00018 
00019 TAO_DynSequence_i::~TAO_DynSequence_i (void)
00020 {
00021 }
00022 
00023 void
00024 TAO_DynSequence_i::init_common (void)
00025 {
00026   this->ref_to_component_ = 0;
00027   this->container_is_destroying_ = 0;
00028   this->has_components_ = 1;
00029   this->destroyed_ = 0;
00030   this->current_position_ = -1;
00031   this->component_count_ = static_cast<CORBA::ULong> (this->da_members_.size ());
00032 }
00033 
00034 void
00035 TAO_DynSequence_i::init (const CORBA::Any& any
00036                          ACE_ENV_ARG_DECL)
00037 {
00038   CORBA::TypeCode_var tc = any.type ();
00039 
00040   CORBA::TCKind kind =
00041     TAO_DynAnyFactory::unalias (tc.in ()
00042                                 ACE_ENV_ARG_PARAMETER);
00043   ACE_CHECK;
00044 
00045   if (kind != CORBA::tk_sequence)
00046     {
00047       ACE_THROW (DynamicAny::DynAnyFactory::InconsistentTypeCode ());
00048     }
00049 
00050   this->type_ = tc;
00051 
00052   // Get the CDR stream of the Any, if there isn't one, make one.
00053   TAO::Any_Impl *impl = any.impl ();
00054   CORBA::ULong length;
00055   TAO_OutputCDR out;
00056   TAO_InputCDR cdr (static_cast<ACE_Message_Block *> (0));
00057 
00058   if (impl->encoded ())
00059     {
00060       TAO::Unknown_IDL_Type *unk =
00061         dynamic_cast<TAO::Unknown_IDL_Type *> (impl);
00062 
00063       cdr = unk->_tao_get_cdr ();
00064     }
00065   else
00066     {
00067       impl->marshal_value (out);
00068       TAO_InputCDR tmp_in (out);
00069       cdr = tmp_in;
00070     }
00071 
00072   // If the any is a sequence, first 4 bytes of cdr hold the
00073   // length.
00074   cdr.read_ulong (length);
00075 
00076   // Resize the array.
00077   this->da_members_.size (length);
00078 
00079   this->init_common ();
00080 
00081   // Get the type of the sequence elments.
00082   CORBA::TypeCode_var field_tc =
00083     this->get_element_type (ACE_ENV_SINGLE_ARG_PARAMETER);
00084   ACE_CHECK;
00085 
00086   for (CORBA::ULong i = 0; i < length; ++i)
00087     {
00088       CORBA::Any field_any;
00089       TAO_InputCDR unk_in (cdr);
00090       TAO::Unknown_IDL_Type *field_unk = 0;
00091       ACE_NEW (field_unk,
00092                TAO::Unknown_IDL_Type (field_tc.in (),
00093                                       unk_in));
00094       field_any.replace (field_unk);
00095 
00096       // This recursive step will call the correct constructor
00097       // based on the type of field_any.
00098       this->da_members_[i] =
00099         TAO_DynAnyFactory::make_dyn_any (field_any
00100                                          ACE_ENV_ARG_PARAMETER);
00101       ACE_CHECK;
00102 
00103       // Move to the next field in the CDR stream.
00104       (void) TAO_Marshal_Object::perform_skip (field_tc.in (),
00105                                                &cdr
00106                                                ACE_ENV_ARG_PARAMETER);
00107       ACE_CHECK;
00108     }
00109 }
00110 
00111 void
00112 TAO_DynSequence_i::init (CORBA::TypeCode_ptr tc
00113                          ACE_ENV_ARG_DECL)
00114 {
00115   CORBA::TCKind kind = TAO_DynAnyFactory::unalias (tc
00116                                                    ACE_ENV_ARG_PARAMETER);
00117   ACE_CHECK;
00118 
00119   if (kind != CORBA::tk_sequence)
00120     {
00121       ACE_THROW (DynamicAny::DynAnyFactory::InconsistentTypeCode ());
00122     }
00123 
00124   // Empty sequence.
00125   this->da_members_.size (0);
00126 
00127   this->init_common ();
00128 
00129   this->type_ = CORBA::TypeCode::_duplicate (tc);
00130 }
00131 
00132 // ****************************************************************
00133 
00134 TAO_DynSequence_i *
00135 TAO_DynSequence_i::_narrow (CORBA::Object_ptr _tao_objref
00136                             ACE_ENV_ARG_DECL_NOT_USED)
00137 {
00138   if (CORBA::is_nil (_tao_objref))
00139     {
00140       return 0;
00141     }
00142 
00143   return dynamic_cast<TAO_DynSequence_i *> (_tao_objref);
00144 }
00145 
00146 // ****************************************************************
00147 
00148 CORBA::TypeCode_ptr
00149 TAO_DynSequence_i::get_element_type (ACE_ENV_SINGLE_ARG_DECL)
00150 {
00151   CORBA::TypeCode_var element_type =
00152     CORBA::TypeCode::_duplicate (this->type_.in ());
00153 
00154   // Strip away aliases (if any) on top of the outer type.
00155   CORBA::TCKind kind = element_type->kind (ACE_ENV_SINGLE_ARG_PARAMETER);
00156   ACE_CHECK_RETURN (CORBA::TypeCode::_nil ());
00157 
00158   while (kind != CORBA::tk_sequence)
00159     {
00160       element_type = element_type->content_type (ACE_ENV_SINGLE_ARG_PARAMETER);
00161       ACE_CHECK_RETURN (CORBA::TypeCode::_nil ());
00162 
00163       kind = element_type->kind (ACE_ENV_SINGLE_ARG_PARAMETER);
00164       ACE_CHECK_RETURN (CORBA::TypeCode::_nil ());
00165     }
00166 
00167   // Return the content type.
00168   CORBA::TypeCode_ptr retval =
00169     element_type->content_type (ACE_ENV_SINGLE_ARG_PARAMETER);
00170   ACE_CHECK_RETURN (CORBA::TypeCode::_nil ());
00171 
00172   return retval;
00173 }
00174 
00175 // = Functions specific to DynSequence.
00176 
00177 CORBA::ULong
00178 TAO_DynSequence_i::get_length (ACE_ENV_SINGLE_ARG_DECL)
00179   ACE_THROW_SPEC ((
00180       CORBA::SystemException
00181     ))
00182 {
00183   if (this->destroyed_)
00184     {
00185       ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (),
00186                         0);
00187     }
00188 
00189   return this->component_count_;
00190 }
00191 
00192 void
00193 TAO_DynSequence_i::set_length (CORBA::ULong length
00194                                ACE_ENV_ARG_DECL)
00195   ACE_THROW_SPEC ((
00196       CORBA::SystemException,
00197       DynamicAny::DynAny::InvalidValue
00198     ))
00199 {
00200   if (this->destroyed_)
00201     {
00202       ACE_THROW (CORBA::OBJECT_NOT_EXIST ());
00203     }
00204 
00205   // CORBA::TypeCode::length() does not accept aliased type codes.
00206   CORBA::TypeCode_var stripped_tc =
00207     TAO_DynAnyFactory::strip_alias (this->type_.in ()
00208                                     ACE_ENV_ARG_PARAMETER);
00209   ACE_CHECK;
00210 
00211   CORBA::ULong bound = stripped_tc->length (ACE_ENV_SINGLE_ARG_PARAMETER);
00212   ACE_CHECK;
00213 
00214   if (bound > 0 && length > bound)
00215     {
00216       ACE_THROW (DynamicAny::DynAny::InvalidValue ());
00217     }
00218 
00219   // CORBA 2.3.1 has several explicit rules about resetting the
00220   // current position, depending on the current value of the
00221   // current position, the current size, and the new length.
00222   if (length == 0)
00223     {
00224       this->current_position_ = -1;
00225     }
00226   else if (length > this->component_count_)
00227     {
00228       if (this->current_position_ == -1)
00229         {
00230           // Set it to the first new slot.
00231           this->current_position_ = static_cast<CORBA::Long> (this->component_count_);
00232         }
00233     }
00234   else if (length < this->component_count_)
00235     {
00236       // If the current position will no longer exist..
00237       if (this->current_position_ >= static_cast<CORBA::Long> (length))
00238         {
00239           this->current_position_ = -1;
00240         }
00241     }
00242 
00243   if (length > this->component_count_)
00244     {
00245       // Grow array first, then initialize new members.
00246       this->da_members_.size (length);
00247 
00248       CORBA::TypeCode_var elemtype =
00249         stripped_tc->content_type (ACE_ENV_SINGLE_ARG_PARAMETER);
00250       ACE_CHECK;
00251 
00252       for (CORBA::ULong i = this->component_count_; i < length; ++i)
00253         {
00254           this->da_members_[i] =
00255             TAO_DynAnyFactory::make_dyn_any (elemtype.in ()
00256                                              ACE_ENV_ARG_PARAMETER);
00257           ACE_CHECK;
00258         }
00259     }
00260   else if (length < this->component_count_)
00261     {
00262       // Destroy any dangling members first, then shrink array.
00263       for (CORBA::ULong j = length; j < this->component_count_; ++j)
00264         {
00265           this->da_members_[j]->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
00266           ACE_CHECK;
00267         }
00268 
00269       this->da_members_.size (length);
00270     }
00271 
00272   // Now we can update component_count_.
00273   this->component_count_ = length;
00274 }
00275 
00276 DynamicAny::AnySeq *
00277 TAO_DynSequence_i::get_elements (ACE_ENV_SINGLE_ARG_DECL)
00278   ACE_THROW_SPEC ((
00279       CORBA::SystemException
00280     ))
00281 {
00282   if (this->destroyed_)
00283     {
00284       ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (),
00285                         0);
00286     }
00287 
00288   CORBA::ULong length = static_cast<CORBA::ULong> (this->da_members_.size ());
00289 
00290   DynamicAny::AnySeq *elements;
00291   ACE_NEW_THROW_EX (elements,
00292                     DynamicAny::AnySeq (length),
00293                     CORBA::NO_MEMORY ());
00294   ACE_CHECK_RETURN (0);
00295 
00296   elements->length (length);
00297   DynamicAny::AnySeq_var safe_retval = elements;
00298 
00299   // Initialize each Any.
00300   for (CORBA::ULong i = 0; i < length; ++i)
00301     {
00302       CORBA::Any_var tmp =
00303         this->da_members_[i]->to_any (ACE_ENV_SINGLE_ARG_PARAMETER);
00304 
00305       ACE_CHECK_RETURN (0);
00306 
00307       safe_retval[i] = tmp.in ();
00308     }
00309 
00310   return safe_retval._retn ();
00311 }
00312 
00313 void
00314 TAO_DynSequence_i::set_elements (const DynamicAny::AnySeq & value
00315                                  ACE_ENV_ARG_DECL)
00316   ACE_THROW_SPEC ((
00317       CORBA::SystemException,
00318       DynamicAny::DynAny::TypeMismatch,
00319       DynamicAny::DynAny::InvalidValue
00320     ))
00321 {
00322   if (this->destroyed_)
00323     {
00324       ACE_THROW (CORBA::OBJECT_NOT_EXIST ());
00325     }
00326 
00327   CORBA::TypeCode_var stripped_tc =
00328     TAO_DynAnyFactory::strip_alias (this->type_.in ()
00329                                     ACE_ENV_ARG_PARAMETER);
00330   ACE_CHECK;
00331 
00332   CORBA::ULong length = value.length ();
00333   CORBA::ULong bound = stripped_tc->length (ACE_ENV_SINGLE_ARG_PARAMETER);
00334   ACE_CHECK;
00335 
00336   if (bound > 0 && length > bound)
00337     {
00338       ACE_THROW (DynamicAny::DynAny::InvalidValue ());
00339     }
00340 
00341   // CORBA 2.4.2.
00342   if (length == 0)
00343     {
00344       this->current_position_ = -1;
00345     }
00346   else
00347     {
00348       this->current_position_ = 0;
00349     }
00350 
00351   // If the array grows, we must do it now.
00352   if (length > this->component_count_)
00353     {
00354       this->da_members_.size (length);
00355     }
00356 
00357   CORBA::TypeCode_var element_type =
00358     this->get_element_type (ACE_ENV_SINGLE_ARG_PARAMETER);
00359   ACE_CHECK;
00360 
00361   CORBA::TypeCode_var value_tc;
00362 
00363   for (CORBA::ULong i = 0; i < length; ++i)
00364     {
00365       // Check each arg element for type match.
00366       value_tc = value[i].type ();
00367       CORBA::Boolean equivalent =
00368         value_tc->equivalent (element_type.in ()
00369                               ACE_ENV_ARG_PARAMETER);
00370       ACE_CHECK;
00371 
00372       if (equivalent)
00373         {
00374           // Destroy any existing members.
00375           if (i < this->component_count_)
00376             {
00377               this->da_members_[i]->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
00378               ACE_CHECK;
00379             }
00380 
00381           this->da_members_[i] =
00382             TAO_DynAnyFactory::make_dyn_any (value[i]
00383                                           ACE_ENV_ARG_PARAMETER);
00384           ACE_CHECK;
00385         }
00386       else
00387         {
00388           ACE_THROW (DynamicAny::DynAny::TypeMismatch ());
00389         }
00390     }
00391 
00392   // Destroy any dangling members.
00393   for (CORBA::ULong j = length; j < this->component_count_; ++j)
00394     {
00395       this->da_members_[j]->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
00396       ACE_CHECK;
00397     }
00398 
00399   // If the array shrinks, we must wait until now to do it.
00400   if (length < this->component_count_)
00401     {
00402       this->da_members_.size (length);
00403     }
00404 
00405   // Now we can update component_count_.
00406   this->component_count_ = length;
00407 }
00408 
00409 DynamicAny::DynAnySeq *
00410 TAO_DynSequence_i::get_elements_as_dyn_any (ACE_ENV_SINGLE_ARG_DECL)
00411   ACE_THROW_SPEC ((
00412       CORBA::SystemException
00413     ))
00414 {
00415   if (this->destroyed_)
00416     {
00417       ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (),
00418                         0);
00419     }
00420 
00421   DynamicAny::DynAnySeq *retval = 0;
00422   ACE_NEW_THROW_EX (retval,
00423                     DynamicAny::DynAnySeq (this->component_count_),
00424                     CORBA::NO_MEMORY ());
00425   ACE_CHECK_RETURN (0);
00426 
00427   retval->length (this->component_count_);
00428   DynamicAny::DynAnySeq_var safe_retval (retval);
00429 
00430   for (CORBA::ULong i = 0; i < this->component_count_; ++i)
00431     {
00432       // A deep copy is made only by copy() (CORBA 2.4.2 section 9.2.3.6).
00433       // Set the flag so the caller can't destroy.
00434       this->set_flag (this->da_members_[i].in (),
00435                       0
00436                       ACE_ENV_ARG_PARAMETER);
00437       ACE_CHECK_RETURN (0);
00438 
00439       safe_retval[i] =
00440         DynamicAny::DynAny::_duplicate (this->da_members_[i].in ());
00441       ACE_CHECK_RETURN (0);
00442     }
00443 
00444   return safe_retval._retn ();
00445 }
00446 
00447 void
00448 TAO_DynSequence_i::set_elements_as_dyn_any (
00449     const DynamicAny::DynAnySeq & values
00450     ACE_ENV_ARG_DECL
00451   )
00452   ACE_THROW_SPEC ((
00453       CORBA::SystemException,
00454       DynamicAny::DynAny::TypeMismatch,
00455       DynamicAny::DynAny::InvalidValue
00456     ))
00457 {
00458   if (this->destroyed_)
00459     {
00460       ACE_THROW (CORBA::OBJECT_NOT_EXIST ());
00461     }
00462 
00463   CORBA::TypeCode_var stripped_tc =
00464     TAO_DynAnyFactory::strip_alias (this->type_.in ()
00465                                     ACE_ENV_ARG_PARAMETER);
00466   ACE_CHECK;
00467 
00468   CORBA::ULong length = values.length ();
00469   CORBA::ULong bound = stripped_tc->length (ACE_ENV_SINGLE_ARG_PARAMETER);
00470   ACE_CHECK;
00471 
00472   if (bound > 0 && length > bound)
00473     {
00474       ACE_THROW (DynamicAny::DynAny::InvalidValue ());
00475     }
00476 
00477   // If the array grows, we must do it now.
00478   if (length > this->component_count_)
00479     {
00480       this->da_members_.size (length);
00481     }
00482 
00483   CORBA::TypeCode_var element_type =
00484     this->get_element_type (ACE_ENV_SINGLE_ARG_PARAMETER);
00485   ACE_CHECK;
00486 
00487   CORBA::TypeCode_var val_type;
00488   CORBA::Boolean equivalent;
00489 
00490   for (CORBA::ULong i = 0; i < length; ++i)
00491     {
00492       val_type = values[i]->type (ACE_ENV_SINGLE_ARG_PARAMETER);
00493       ACE_CHECK;
00494 
00495       equivalent = val_type->equivalent (element_type.in ()
00496                                          ACE_ENV_ARG_PARAMETER);
00497 
00498       ACE_CHECK;
00499 
00500       if (equivalent)
00501         {
00502           // Destroy any existing members.
00503           if (i < this->component_count_)
00504             {
00505               this->da_members_[i]->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
00506               ACE_CHECK;
00507             }
00508 
00509           this->da_members_[i] =
00510             values[i]->copy (ACE_ENV_SINGLE_ARG_PARAMETER);
00511           ACE_CHECK;
00512         }
00513       else
00514         {
00515           ACE_THROW (DynamicAny::DynAny::TypeMismatch ());
00516         }
00517     }
00518 
00519   // Destroy any dangling members.
00520   for (CORBA::ULong j = length; j < this->component_count_; ++j)
00521     {
00522       this->da_members_[j]->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
00523       ACE_CHECK;
00524     }
00525 
00526   // If the array shrinks, we must wait until now to do it.
00527   if (length < this->component_count_)
00528     {
00529       this->da_members_.size (length);
00530     }
00531 
00532   // Now we can update component_count_.
00533   this->component_count_ = length;
00534 }
00535 
00536 // ****************************************************************
00537 
00538 void
00539 TAO_DynSequence_i::from_any (const CORBA::Any & any
00540                              ACE_ENV_ARG_DECL)
00541   ACE_THROW_SPEC ((
00542       CORBA::SystemException,
00543       DynamicAny::DynAny::TypeMismatch,
00544       DynamicAny::DynAny::InvalidValue
00545     ))
00546 {
00547   if (this->destroyed_)
00548     {
00549       ACE_THROW (CORBA::OBJECT_NOT_EXIST ());
00550     }
00551 
00552   CORBA::TypeCode_var tc = any.type ();
00553   CORBA::Boolean equivalent =
00554     this->type_.in ()->equivalent (tc.in ()
00555                                    ACE_ENV_ARG_PARAMETER);
00556   ACE_CHECK;
00557 
00558   if (equivalent)
00559     {
00560       // Get the CDR stream of the Any, if there isn't one, make one.
00561       TAO::Any_Impl *impl = any.impl ();
00562       TAO_OutputCDR out;
00563       TAO_InputCDR cdr (static_cast<ACE_Message_Block *> (0));
00564 
00565       if (impl->encoded ())
00566         {
00567           TAO::Unknown_IDL_Type *unk =
00568             dynamic_cast<TAO::Unknown_IDL_Type *> (impl);
00569 
00570           cdr = unk->_tao_get_cdr ();
00571         }
00572       else
00573         {
00574           impl->marshal_value (out);
00575           TAO_InputCDR tmp_in (out);
00576           cdr = tmp_in;
00577         }
00578 
00579 
00580       CORBA::ULong arg_length;
00581 
00582       // If the any is a sequence, first 4 bytes of cdr hold the
00583       // length.
00584       cdr.read_ulong (arg_length);
00585 
00586       // If the array grows, we must do it now.
00587       if (arg_length > this->component_count_)
00588         {
00589           this->da_members_.size (arg_length);
00590         }
00591 
00592       CORBA::TypeCode_var field_tc =
00593         this->get_element_type (ACE_ENV_SINGLE_ARG_PARAMETER);
00594       ACE_CHECK;
00595 
00596       for (CORBA::ULong i = 0; i < arg_length; ++i)
00597         {
00598           CORBA::Any field_any;
00599           TAO_InputCDR unk_in (cdr);
00600           TAO::Unknown_IDL_Type *field_unk = 0;
00601           ACE_NEW (field_unk,
00602                    TAO::Unknown_IDL_Type (field_tc.in (),
00603                                           unk_in));
00604           field_any.replace (field_unk);
00605 
00606           if (i < this->component_count_)
00607             {
00608               this->da_members_[i]->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
00609               ACE_CHECK;
00610             }
00611 
00612           this->da_members_[i] =
00613             TAO_DynAnyFactory::make_dyn_any (field_any
00614                                           ACE_ENV_ARG_PARAMETER);
00615           ACE_CHECK;
00616 
00617           // Move to the next field in the CDR stream.
00618           (void) TAO_Marshal_Object::perform_skip (field_tc.in (),
00619                                                    &cdr
00620                                                    ACE_ENV_ARG_PARAMETER);
00621           ACE_CHECK;
00622         }
00623 
00624       // Destroy any dangling members.
00625       for (CORBA::ULong j = arg_length; j < this->component_count_; ++j)
00626         {
00627           this->da_members_[j]->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
00628           ACE_CHECK;
00629         }
00630 
00631       // If the array shrinks, we must wait until now to do it.
00632       if (arg_length < this->component_count_)
00633         {
00634           this->da_members_.size (arg_length);
00635         }
00636 
00637       // Now we can update component_count_.
00638       this->component_count_ = arg_length;
00639 
00640       this->current_position_ = arg_length ? 0 : -1;
00641     }
00642   else
00643     {
00644       ACE_THROW (DynamicAny::DynAny::TypeMismatch ());
00645     }
00646 }
00647 
00648 CORBA::Any_ptr
00649 TAO_DynSequence_i::to_any (ACE_ENV_SINGLE_ARG_DECL)
00650   ACE_THROW_SPEC ((
00651       CORBA::SystemException
00652     ))
00653 {
00654   if (this->destroyed_)
00655     {
00656       ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (),
00657                         0);
00658     }
00659 
00660   TAO_OutputCDR out_cdr;
00661   out_cdr.write_ulong (this->component_count_);
00662 
00663   CORBA::TypeCode_var field_tc =
00664     this->get_element_type (ACE_ENV_SINGLE_ARG_PARAMETER);
00665   ACE_CHECK_RETURN (0);
00666 
00667   for (CORBA::ULong i = 0; i < this->component_count_; ++i)
00668     {
00669       // Recursive step
00670       CORBA::Any_var field_any =
00671         this->da_members_[i]->to_any (ACE_ENV_SINGLE_ARG_PARAMETER);
00672       ACE_CHECK_RETURN (0);
00673 
00674       TAO::Any_Impl *field_impl = field_any->impl ();
00675       TAO_OutputCDR field_out;
00676       TAO_InputCDR field_cdr (static_cast<ACE_Message_Block *> (0));
00677 
00678       if (field_impl->encoded ())
00679         {
00680           TAO::Unknown_IDL_Type *field_unk =
00681             dynamic_cast<TAO::Unknown_IDL_Type *> (field_impl);
00682 
00683           field_cdr = field_unk->_tao_get_cdr ();
00684         }
00685       else
00686         {
00687           field_impl->marshal_value (field_out);
00688           TAO_InputCDR tmp_in (field_out);
00689           field_cdr = tmp_in;
00690         }
00691 
00692       (void) TAO_Marshal_Object::perform_append (field_tc.in (),
00693                                                  &field_cdr,
00694                                                  &out_cdr
00695                                                  ACE_ENV_ARG_PARAMETER);
00696       ACE_CHECK_RETURN (0);
00697     }
00698 
00699   TAO_InputCDR in_cdr (out_cdr);
00700 
00701   CORBA::Any_ptr retval = 0;
00702   ACE_NEW_THROW_EX (retval,
00703                     CORBA::Any,
00704                     CORBA::NO_MEMORY ());
00705   ACE_CHECK_RETURN (0);
00706 
00707   TAO::Unknown_IDL_Type *unk = 0;
00708   ACE_NEW_THROW_EX (unk,
00709                     TAO::Unknown_IDL_Type (this->type_.in (),
00710                                            in_cdr),
00711                     CORBA::NO_MEMORY ());
00712   ACE_CHECK_RETURN (0);
00713 
00714   retval->replace (unk);
00715   return retval;
00716 }
00717 
00718 CORBA::Boolean
00719 TAO_DynSequence_i::equal (DynamicAny::DynAny_ptr rhs
00720                           ACE_ENV_ARG_DECL)
00721   ACE_THROW_SPEC ((
00722       CORBA::SystemException
00723     ))
00724 {
00725   if (this->destroyed_)
00726     {
00727       ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (),
00728                         0);
00729     }
00730 
00731   CORBA::TypeCode_var tc = rhs->type (ACE_ENV_SINGLE_ARG_PARAMETER);
00732   ACE_CHECK_RETURN (0);
00733 
00734   CORBA::Boolean equivalent = tc->equivalent (this->type_.in ()
00735                                               ACE_ENV_ARG_PARAMETER);
00736   ACE_CHECK_RETURN (0);
00737 
00738   if (!equivalent)
00739     {
00740       return 0;
00741     }
00742 
00743   if (rhs->component_count () != this->component_count_)
00744     {
00745       return 0;
00746     }
00747 
00748   DynamicAny::DynAny_var tmp;
00749   CORBA::Boolean member_equal;
00750 
00751   for (CORBA::ULong i = 0; i < this->component_count_; ++i)
00752     {
00753       rhs->seek (static_cast<CORBA::Long> (i)
00754                  ACE_ENV_ARG_PARAMETER);
00755       ACE_CHECK_RETURN (0);
00756 
00757       tmp = rhs->current_component (ACE_ENV_SINGLE_ARG_PARAMETER);
00758       ACE_CHECK_RETURN (0);
00759 
00760       // Recursive step.
00761       member_equal = tmp->equal (this->da_members_[i].in ()
00762                                  ACE_ENV_ARG_PARAMETER);
00763       ACE_CHECK_RETURN (0);
00764 
00765       if (!member_equal)
00766         {
00767           return 0;
00768         }
00769     }
00770 
00771   return 1;
00772 }
00773 
00774 void
00775 TAO_DynSequence_i::destroy (ACE_ENV_SINGLE_ARG_DECL)
00776   ACE_THROW_SPEC ((
00777       CORBA::SystemException
00778     ))
00779 {
00780   if (this->destroyed_)
00781     {
00782       ACE_THROW (CORBA::OBJECT_NOT_EXIST ());
00783     }
00784 
00785   if (!this->ref_to_component_ || this->container_is_destroying_)
00786     {
00787       // Do a deep destroy.
00788       for (CORBA::ULong i = 0; i < this->component_count_; ++i)
00789         {
00790           this->set_flag (da_members_[i].in (),
00791                           1
00792                           ACE_ENV_ARG_PARAMETER);
00793           ACE_CHECK;
00794 
00795           this->da_members_[i]->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
00796           ACE_CHECK;
00797         }
00798 
00799       this->destroyed_ = 1;
00800     }
00801 }
00802 
00803 DynamicAny::DynAny_ptr
00804 TAO_DynSequence_i::current_component (ACE_ENV_SINGLE_ARG_DECL)
00805   ACE_THROW_SPEC ((
00806       CORBA::SystemException,
00807       DynamicAny::DynAny::TypeMismatch
00808     ))
00809 {
00810   if (this->destroyed_)
00811     {
00812       ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (),
00813                         DynamicAny::DynAny::_nil ());
00814     }
00815 
00816   if (this->current_position_ == -1)
00817     {
00818       return DynamicAny::DynAny::_nil ();
00819     }
00820 
00821   CORBA::ULong index = static_cast<CORBA::ULong> (this->current_position_);
00822 
00823   this->set_flag (this->da_members_[index].in (),
00824                   0
00825                   ACE_ENV_ARG_PARAMETER);
00826   ACE_CHECK_RETURN (DynamicAny::DynAny::_nil ());
00827 
00828   return DynamicAny::DynAny::_duplicate (
00829             this->da_members_[index].in ()
00830           );
00831 }
00832 
00833 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 13:02:09 2006 for TAO_DynamicAny by doxygen 1.3.6