Trader_Utils.cpp

Go to the documentation of this file.
00001 // $Id: Trader_Utils.cpp 77001 2007-02-12 07:54:49Z johnnyw $
00002 
00003 #include "orbsvcs/Trader/Trader_Utils.h"
00004 #include "ace/OS_NS_string.h"
00005 
00006 ACE_RCSID(Trader, Trader_Utils, "$Id: Trader_Utils.cpp 77001 2007-02-12 07:54:49Z johnnyw $")
00007 
00008 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00009 
00010 bool
00011 operator== (CORBA::String_var const & lhs,
00012             CORBA::String_var const & rhs)
00013 {
00014   return (ACE_OS::strcmp (lhs.in (), rhs.in ()) == 0);
00015 }
00016 
00017 TAO_Policy_Creator::TAO_Policy_Creator (int num_policies)
00018   : policies_ (num_policies),
00019     num_policies_ (0)
00020 {
00021   for (int i = 0; i < TAO_Policies::REQUEST_ID + 1; i++)
00022     this->poltable_[i] = -1;
00023 }
00024 
00025 void
00026 TAO_Policy_Creator::search_card (CORBA::ULong scard)
00027 {
00028   CosTrading::Policy& policy =
00029     this->fetch_next_policy (TAO_Policies::SEARCH_CARD);
00030   policy.value <<= scard;
00031 }
00032 
00033 void
00034 TAO_Policy_Creator::match_card (CORBA::ULong mcard)
00035 {
00036   CosTrading::Policy& policy =
00037     this->fetch_next_policy (TAO_Policies::MATCH_CARD);
00038   policy.value <<= mcard;
00039 }
00040 
00041 void
00042 TAO_Policy_Creator::return_card (CORBA::ULong rcard)
00043 {
00044   CosTrading::Policy& policy =
00045     this->fetch_next_policy (TAO_Policies::RETURN_CARD);
00046   policy.value <<= rcard;
00047 }
00048 
00049 void
00050 TAO_Policy_Creator::use_modifiable_properties (CORBA::Boolean mod_props)
00051 {
00052   CosTrading::Policy& policy =
00053     this->fetch_next_policy (TAO_Policies::USE_MODIFIABLE_PROPERTIES);
00054   policy.value <<= CORBA::Any::from_boolean (mod_props);
00055 }
00056 
00057 void
00058 TAO_Policy_Creator::use_dynamic_properties (CORBA::Boolean dyn_props)
00059 {
00060   CosTrading::Policy& policy =
00061     this->fetch_next_policy (TAO_Policies::USE_DYNAMIC_PROPERTIES);
00062   policy.value <<= CORBA::Any::from_boolean (dyn_props);
00063 }
00064 
00065 void
00066 TAO_Policy_Creator::use_proxy_offers (CORBA::Boolean prox_offs)
00067 {
00068   CosTrading::Policy& policy =
00069     this->fetch_next_policy (TAO_Policies::USE_PROXY_OFFERS);
00070   policy.value <<= CORBA::Any::from_boolean (prox_offs);
00071 }
00072 
00073 void
00074 TAO_Policy_Creator::starting_trader (const CosTrading::TraderName& name)
00075 {
00076   CosTrading::Policy& policy =
00077     this->fetch_next_policy (TAO_Policies::STARTING_TRADER);
00078   policy.value <<= name;
00079 }
00080 
00081 void
00082 TAO_Policy_Creator::starting_trader (CosTrading::TraderName* name)
00083 {
00084   CosTrading::Policy& policy =
00085     this->fetch_next_policy (TAO_Policies::STARTING_TRADER);
00086   policy.value <<= name;
00087 }
00088 
00089 void
00090 TAO_Policy_Creator::
00091 link_follow_rule (CosTrading::FollowOption follow_option)
00092 {
00093   CosTrading::Policy& policy =
00094     this->fetch_next_policy (TAO_Policies::LINK_FOLLOW_RULE);
00095   policy.value <<= follow_option;
00096 }
00097 
00098 void
00099 TAO_Policy_Creator::hop_count (CORBA::ULong hop_count)
00100 {
00101   CosTrading::Policy& policy =
00102     this->fetch_next_policy (TAO_Policies::HOP_COUNT);
00103   policy.value <<= hop_count;
00104 }
00105 
00106 void
00107 TAO_Policy_Creator::exact_type_match (CORBA::Boolean exact_type)
00108 {
00109   CosTrading::Policy& policy =
00110     this->fetch_next_policy (TAO_Policies::EXACT_TYPE_MATCH);
00111   policy.value <<= CORBA::Any::from_boolean (exact_type);
00112 }
00113 
00114 void
00115 TAO_Policy_Creator::request_id (const CosTrading::Admin::OctetSeq& request_id)
00116 {
00117   CosTrading::Policy& policy =
00118     this->fetch_next_policy (TAO_Policies::REQUEST_ID);
00119   policy.value <<= request_id;
00120 }
00121 
00122 TAO_Policy_Creator::operator const CosTrading::PolicySeq& (void) const
00123 {
00124   return this->policies_;
00125 }
00126 
00127 const CosTrading::PolicySeq&
00128 TAO_Policy_Creator::policy_seq (void) const
00129 {
00130   return this->policies_;
00131 }
00132 
00133 CosTrading::Policy&
00134 TAO_Policy_Creator::fetch_next_policy (TAO_Policies::POLICY_TYPE pol_type)
00135 {
00136   CORBA::ULong index = 0;
00137 
00138   if (this->poltable_[pol_type] == -1)
00139     {
00140       // Expand the policy sequence, and copy in the policy name into
00141       // the new element.
00142       CORBA::ULong length = this->policies_.length ();
00143       this->num_policies_++;
00144 
00145       if (length < this->num_policies_)
00146         this->policies_.length (this->num_policies_);
00147 
00148       index = this->num_policies_ - 1;
00149 
00150       // Ensure the starting trader policy gets the first slot.
00151       if (pol_type != TAO_Policies::STARTING_TRADER
00152           || index == 0)
00153         {
00154           this->policies_[index].name = TAO_Policies::POLICY_NAMES[pol_type];
00155           this->poltable_[pol_type] = index;
00156         }
00157       else
00158         {
00159           // Copy the element in the first slot to the newly
00160           // allocated slot.
00161           TAO_Policies::POLICY_TYPE occupying_policy =
00162             TAO_Policies::STARTING_TRADER;
00163           for (CORBA::ULong i = 0; i < this->num_policies_ - 1; i++)
00164             {
00165               if (this->poltable_[i] == 0)
00166                 {
00167                   occupying_policy =
00168                     static_cast<TAO_Policies::POLICY_TYPE> (i);
00169                   break;
00170                 }
00171             }
00172 
00173           this->poltable_[occupying_policy] = index;
00174           this->poltable_[TAO_Policies::STARTING_TRADER] = 0;
00175           this->policies_[index].name =
00176             TAO_Policies::POLICY_NAMES[occupying_policy];
00177           this->policies_[index].value = this->policies_[0].value;
00178           this->policies_[0].name =
00179             TAO_Policies::POLICY_NAMES[TAO_Policies::STARTING_TRADER];
00180 
00181           index = 0;
00182         }
00183     }
00184   else
00185     index = this->poltable_[pol_type];
00186 
00187   return this->policies_[index];
00188 }
00189 
00190 // Constructor
00191 
00192 TAO_Property_Evaluator::
00193 TAO_Property_Evaluator(const CosTrading::PropertySeq& props,
00194                        CORBA::Boolean supports_dp)
00195   : props_ (props),
00196     supports_dp_ (supports_dp),
00197     dp_cache_ (new CORBA::Any*[props.length ()])
00198 {
00199   if (this->dp_cache_ != 0)
00200     {
00201       for (CORBA::ULong i = 0; i < this->props_.length (); i++)
00202         this->dp_cache_[i] = 0;
00203     }
00204 }
00205 
00206 
00207 TAO_Property_Evaluator::
00208 TAO_Property_Evaluator(CosTrading::Offer& offer,
00209                        CORBA::Boolean supports_dp)
00210   : props_ (offer.properties),
00211     supports_dp_ (supports_dp),
00212     dp_cache_ (new CORBA::Any*[offer.properties.length ()])
00213 {
00214   if (this->dp_cache_ != 0)
00215     for (CORBA::ULong i = 0; i < this->props_.length (); i++)
00216       this->dp_cache_[i] = 0;
00217 }
00218 
00219 TAO_Property_Evaluator::~TAO_Property_Evaluator (void)
00220 {
00221   // Clean up the results of any dynamic properties.
00222   for (CORBA::ULong i = 0; i < this->props_.length (); i++)
00223     if (this->dp_cache_[i] != 0)
00224       delete this->dp_cache_[i];
00225 
00226   delete [] this->dp_cache_;
00227 }
00228 
00229 int
00230 TAO_Property_Evaluator::is_dynamic_property (int index)
00231 {
00232   int return_value = 0;
00233   int num_properties = this->props_.length();
00234 
00235   // Ensure index is in bounds.
00236   if (index >= 0 && index < num_properties)
00237     {
00238       // Obtain the value of the property at index <index>.
00239       const CORBA::Any& value = this->props_[index].value;
00240       CORBA::TypeCode_var type = value.type ();
00241 
00242       // @@ Seth, this will not work on platforms using environment variable.
00243       CORBA::Boolean equal = type->equal (CosTradingDynamic::_tc_DynamicProp);
00244 
00245       if (equal)
00246         return_value = 1;
00247     }
00248 
00249   return return_value;
00250 }
00251 
00252 CORBA::Any*
00253 TAO_Property_Evaluator::property_value (int index)
00254 {
00255   CORBA::Any* prop_val = 0;
00256   CORBA::Boolean in_cache =
00257     this->dp_cache_ != 0 && this->dp_cache_[index] != 0;
00258 
00259   int dynamic = this->is_dynamic_property (index);
00260 
00261   if (!dynamic)
00262     prop_val = (CORBA::Any *) &(this->props_[index].value);
00263   else if (this->supports_dp_ && in_cache)
00264     prop_val = this->dp_cache_[index];
00265   else if (this->supports_dp_)
00266     {
00267       // Property is defined at this point.
00268       CosTradingDynamic::DynamicProp* dp_struct;
00269       const CORBA::String_var name = this->props_[index].name.in ();
00270       const CORBA::Any& value = this->props_[index].value;
00271 
00272       // Extract the DP_Struct.
00273       value >>= dp_struct;
00274 
00275       CosTradingDynamic::DynamicPropEval_var dp_eval =
00276         CosTradingDynamic::DynamicPropEval::_duplicate (dp_struct->eval_if.in ());
00277 
00278       if (CORBA::is_nil (dp_eval.in ()))
00279         {
00280           throw CosTradingDynamic::DPEvalFailure (
00281             name,
00282             CORBA::TypeCode::_nil (),
00283             CORBA::Any ());
00284         }
00285       else
00286         {
00287           CORBA::TypeCode* type = dp_struct->returned_type.in ();
00288           CORBA::Any& info = dp_struct->extra_info;
00289 
00290           try
00291             {
00292               // Retrieve the value of the dynamic property.
00293               prop_val = dp_eval->evalDP(name, type, info);
00294 
00295               if (this->dp_cache_ != 0)
00296                 this->dp_cache_[index] = prop_val;
00297             }
00298           catch (const CORBA::SystemException&)
00299             {
00300               throw
00301                 (CosTradingDynamic::DPEvalFailure (name, type, info));
00302             }
00303         }
00304     }
00305 
00306   return prop_val;
00307 }
00308 
00309 CORBA::TypeCode_ptr
00310 TAO_Property_Evaluator::property_type (int index)
00311 {
00312   CORBA::TypeCode_ptr prop_type = CORBA::TypeCode::_nil();
00313 
00314   // Determine if property is both defined and dynamic.
00315   if (this->is_dynamic_property (index))
00316     {
00317       // Extract type information from the DP_Struct.
00318       const CORBA::Any& value = this->props_[index].value;
00319       CosTradingDynamic::DynamicProp* dp_struct = 0;
00320       value >>= dp_struct;
00321 
00322       // Grab a pointer to the returned_type description
00323       prop_type = CORBA::TypeCode::_duplicate (dp_struct->returned_type.in ());
00324     }
00325   else
00326     // TypeCode is self-evident at this point.
00327     prop_type = this->props_[index].value.type ();
00328 
00329   return prop_type;
00330 }
00331 
00332 TAO_Property_Evaluator_By_Name::
00333 TAO_Property_Evaluator_By_Name (const CosTrading::PropertySeq& properties
00334 ,
00335                                 CORBA::Boolean supports_dp)
00336     : TAO_Property_Evaluator (properties, supports_dp)
00337 {
00338   int length = this->props_.length();
00339 
00340   for (int i = 0; i < length; i++)
00341     {
00342       const CosTrading::Property& prop = this->props_[i];
00343 
00344       if (! TAO_Trader_Base::is_valid_property_name (prop.name))
00345         throw CosTrading::IllegalPropertyName (prop.name);
00346 
00347       CORBA::String_var prop_name = prop.name.in ();
00348       if (this->table_.bind (prop_name, i))
00349         throw CosTrading::DuplicatePropertyName (prop.name);
00350     }
00351 }
00352 
00353 TAO_Property_Evaluator_By_Name::
00354 TAO_Property_Evaluator_By_Name(CosTrading::Offer& offer,
00355                                CORBA::Boolean supports_dp)
00356   : TAO_Property_Evaluator(offer, supports_dp)
00357 {
00358   int length = this->props_.length();
00359 
00360   for (int i = 0; i < length; i++)
00361     {
00362       CORBA::String_var prop_name = (const char*) this->props_[i].name;
00363       this->table_.bind (prop_name, i);
00364     }
00365 }
00366 
00367 int
00368 TAO_Property_Evaluator_By_Name::
00369 is_dynamic_property(const char* property_name)
00370 {
00371   int predicate = 0;
00372   int index = 0;
00373   CORBA::String_var prop_name (property_name);
00374 
00375   // If the property name is in the map, delegate evaluation to our
00376   // superclass. Otherwise, throw an exception.
00377   if (this->table_.find (prop_name, index) == 0)
00378     predicate = this->TAO_Property_Evaluator::is_dynamic_property(index);
00379 
00380   return predicate;
00381 }
00382 
00383 CORBA::Any*
00384 TAO_Property_Evaluator_By_Name::property_value (const char* property_name)
00385 {
00386   int index = 0;
00387   CORBA::Any* prop_value = 0;
00388   CORBA::String_var prop_name (property_name);
00389 
00390   // If the property name is in the map, delegate evaluation to our
00391   // superclass. Otherwise, throw an exception.
00392   if (this->table_.find (prop_name, index) == 0)
00393     {
00394       prop_value =
00395         this->TAO_Property_Evaluator::property_value (index);
00396     }
00397 
00398   return prop_value;
00399 }
00400 
00401 CORBA::TypeCode_ptr
00402 TAO_Property_Evaluator_By_Name::property_type (const char* property_name)
00403 {
00404   int index = 0;
00405   CORBA::String_var prop_name (property_name);
00406   CORBA::TypeCode_ptr prop_type = CORBA::TypeCode::_nil();
00407 
00408   // If the property name is in the map, delegate evaluation to our
00409   // superclass. Otherwise, throw an exception.
00410   if (this->table_.find (prop_name, index) == 0)
00411     prop_type = this->TAO_Property_Evaluator::property_type (index);
00412 
00413   return prop_type;
00414 }
00415 
00416 const CosTrading::Property*
00417 TAO_Property_Evaluator_By_Name::get_property (const char* property_name)
00418 {
00419   int index = 0;
00420   CosTrading::Property* property = 0;
00421   CORBA::String_var prop_name (property_name);
00422 
00423   if (this->table_.find (prop_name, index) == 0)
00424     property = (CosTrading::Property *) &this->props_[index];
00425 
00426   return property;
00427 }
00428 
00429 TAO_Dynamic_Property::~TAO_Dynamic_Property (void)
00430 {
00431 }
00432 
00433 CosTradingDynamic::DynamicProp*
00434 TAO_Dynamic_Property::
00435 construct_dynamic_prop (const char* name,
00436                         CORBA::TypeCode_ptr returned_type,
00437                         const CORBA::Any& extra_info)
00438 {
00439   ACE_UNUSED_ARG (name);
00440 
00441   CosTradingDynamic::DynamicProp* dp_struct = 0;
00442 
00443   ACE_NEW_RETURN (dp_struct,
00444                   CosTradingDynamic::DynamicProp,
00445                   0);
00446 
00447   if (this->prop_.in () == CosTradingDynamic::DynamicPropEval::_nil ())
00448     {
00449       // Seth, we need a way to either propagate exceptions out.
00450 
00451       this->prop_ = this->_this ();
00452 
00453       this->_remove_ref ();
00454     }
00455 
00456   dp_struct->eval_if =
00457     CosTradingDynamic::DynamicPropEval::_duplicate (this->prop_.in ());
00458 
00459   dp_struct->returned_type =
00460     CORBA::TypeCode::_duplicate (returned_type);
00461   dp_struct->extra_info = extra_info;
00462 
00463   return dp_struct;
00464 }
00465 
00466 void
00467 TAO_Dynamic_Property::destroy (void)
00468 {
00469   if (this->prop_.in () != CosTradingDynamic::DynamicPropEval::_nil ())
00470     {
00471       // @@ Seth, we need a way to propagate exceptions out.
00472       PortableServer::POA_var poa = this->_default_POA ();
00473 
00474       PortableServer::ObjectId_var id =
00475         poa->servant_to_id (this);
00476 
00477       poa->deactivate_object (id.in ());
00478     }
00479 }
00480 
00481 const char* TAO_Policies::POLICY_NAMES[] =
00482 {
00483   "starting_trader",
00484   "exact_type_match",
00485   "hop_count",
00486   "link_follow_rule",
00487   "match_card",
00488   "return_card",
00489   "search_card",
00490   "use_dynamic_properties",
00491   "use_modifiable_properties",
00492   "use_proxy_offers",
00493   "request_id"
00494 };
00495 
00496 TAO_Policies::TAO_Policies (TAO_Trader_Base& trader,
00497                             const CosTrading::PolicySeq& policies)
00498   : trader_ (trader)
00499 {
00500   for (int i = 0; i < TAO_NUM_POLICIES; i++)
00501     this->policies_[i] = 0;
00502 
00503   for (CORBA::ULong j = 0; j < policies.length (); j++)
00504     {
00505       const char *pol_name = (const char *) policies[j].name;
00506       size_t length = (pol_name == 0) ? 0 : ACE_OS::strlen (pol_name);
00507       int index = -1;
00508 
00509       if (length < ACE_OS::strlen (POLICY_NAMES[HOP_COUNT]))
00510         throw CosTrading::Lookup::IllegalPolicyName (pol_name);
00511 
00512       switch (pol_name[0])
00513         {
00514         case 'e':
00515           index = EXACT_TYPE_MATCH;
00516           break;
00517         case 'h':
00518           index = HOP_COUNT;
00519           break;
00520         case 'l':
00521           index = LINK_FOLLOW_RULE;
00522           break;
00523         case 'm':
00524           index = MATCH_CARD;
00525           break;
00526         case 'r':
00527           if (pol_name[2] == 't')
00528             index = RETURN_CARD;
00529           else if (pol_name[2] == 'q')
00530             index = REQUEST_ID;
00531           break;
00532         case 's':
00533           if (pol_name[1] == 't')
00534             index = STARTING_TRADER;
00535           else if (pol_name[1] == 'e')
00536             index = SEARCH_CARD;
00537           break;
00538         case 'u':
00539           if (pol_name[4] == 'd')
00540             index = USE_DYNAMIC_PROPERTIES;
00541           if (pol_name[4] == 'm')
00542             index = USE_MODIFIABLE_PROPERTIES;
00543           if (pol_name[4] == 'p')
00544             index = USE_PROXY_OFFERS;
00545         }
00546 
00547       // Match the name of the policy, and insert its value into the
00548       // vector.
00549       if (index == -1 || ACE_OS::strcmp (POLICY_NAMES[index], pol_name) != 0)
00550         throw CosTrading::Lookup::IllegalPolicyName (pol_name);
00551       else if (this->policies_[index] != 0)
00552         throw CosTrading::DuplicatePolicyName (pol_name);
00553       else
00554         this->policies_[index] = (CosTrading::Policy *) &(policies[j]);
00555     }
00556 }
00557 
00558 TAO_Policies::~TAO_Policies (void)
00559 {
00560 }
00561 
00562 CORBA::ULong
00563 TAO_Policies::ulong_prop (POLICY_TYPE pol) const
00564 {
00565   CORBA::ULong return_value = 0, max_value = 0;
00566   const TAO_Import_Attributes_i& import_attrs =
00567     this->trader_.import_attributes ();
00568 
00569   // Discover the default values for each of the possible cardinality
00570   // policies.
00571   switch (pol)
00572     {
00573     case SEARCH_CARD:
00574       return_value = import_attrs.def_search_card ();
00575       max_value = import_attrs.max_search_card ();
00576       break;
00577     case MATCH_CARD:
00578       return_value = import_attrs.def_match_card ();
00579       max_value = import_attrs.max_match_card ();
00580       break;
00581     case RETURN_CARD:
00582       return_value = import_attrs.def_return_card ();
00583       max_value = import_attrs.max_return_card ();
00584       break;
00585     case HOP_COUNT:
00586       return_value = import_attrs.def_hop_count ();
00587       max_value = import_attrs.max_hop_count ();
00588       break;
00589     default:
00590       break;
00591     }
00592 
00593   if (this->policies_[pol] != 0)
00594     {
00595       // Extract the desired policy value.
00596       const CosTrading::Policy* policy = this->policies_[pol];
00597       const CosTrading::PolicyValue& value = policy->value;
00598       CORBA::TypeCode_var type = value.type ();
00599 
00600       CORBA::Boolean equal_ulong = type->equal (CORBA::_tc_ulong);
00601 
00602       if (!equal_ulong)
00603         throw CosTrading::Lookup::PolicyTypeMismatch (*policy);
00604       else
00605         value >>= return_value;
00606 
00607       if (max_value < return_value)
00608         return_value = max_value;
00609     }
00610 
00611   return return_value;
00612 }
00613 
00614 CORBA::ULong
00615 TAO_Policies::search_card (void) const
00616 {
00617   return this->ulong_prop (SEARCH_CARD);
00618 }
00619 
00620 CORBA::ULong
00621 TAO_Policies::match_card (void) const
00622 {
00623   return this->ulong_prop (MATCH_CARD);
00624 }
00625 
00626 CORBA::ULong
00627 TAO_Policies::return_card (void) const
00628 {
00629   return this->ulong_prop (RETURN_CARD);
00630 }
00631 
00632 CORBA::Boolean
00633 TAO_Policies::boolean_prop (POLICY_TYPE pol) const
00634 {
00635   CORBA::Boolean def_value = 1,
00636     return_value = 1;
00637   const TAO_Support_Attributes_i& support_attrs =
00638     this->trader_.support_attributes ();
00639 
00640   switch (pol)
00641     {
00642     case USE_MODIFIABLE_PROPERTIES:
00643       def_value = support_attrs.supports_modifiable_properties ();
00644       break;
00645     case USE_DYNAMIC_PROPERTIES:
00646       def_value = support_attrs.supports_dynamic_properties ();
00647       break;
00648     case USE_PROXY_OFFERS:
00649       def_value = support_attrs.supports_proxy_offers ();
00650       break;
00651     case EXACT_TYPE_MATCH:
00652       def_value = 0;
00653       break;
00654     default:
00655       break;
00656     }
00657 
00658   if (this->policies_[pol] != 0)
00659     {
00660       const CosTrading::Policy* policy = this->policies_[pol];
00661       const CosTrading::PolicyValue& value = policy->value;
00662       CORBA::TypeCode_var type = value.type ();
00663 
00664       CORBA::Boolean equal_boolean =
00665         type->equal (CORBA::_tc_boolean);
00666 
00667       if (!equal_boolean)
00668         throw CosTrading::Lookup::PolicyTypeMismatch (*policy);
00669       else
00670         value >>= CORBA::Any::to_boolean (return_value);
00671 
00672       if (def_value == 0 &&
00673           pol != EXACT_TYPE_MATCH)
00674         return_value = 0;
00675     }
00676   else
00677     return_value = def_value;
00678 
00679   return return_value;
00680 }
00681 
00682 
00683 CORBA::Boolean
00684 TAO_Policies::use_modifiable_properties (void) const
00685 {
00686   return this->boolean_prop (USE_MODIFIABLE_PROPERTIES);
00687 }
00688 
00689 CORBA::Boolean
00690 TAO_Policies::use_dynamic_properties (void) const
00691 {
00692   return this->boolean_prop (USE_DYNAMIC_PROPERTIES);
00693 }
00694 
00695 CORBA::Boolean
00696 TAO_Policies::use_proxy_offers (void) const
00697 {
00698   return this->boolean_prop (USE_PROXY_OFFERS);
00699 }
00700 
00701 CORBA::Boolean
00702 TAO_Policies::exact_type_match (void) const
00703 {
00704   return this->boolean_prop (EXACT_TYPE_MATCH);
00705 }
00706 
00707 
00708 CosTrading::TraderName*
00709 TAO_Policies::starting_trader (void) const
00710 {
00711   CosTrading::TraderName* trader_name = 0;
00712 
00713   if (this->policies_[STARTING_TRADER] != 0)
00714     {
00715       CosTrading::Policy* policy = this->policies_[STARTING_TRADER];
00716       CosTrading::PolicyValue& value = policy->value;
00717       CORBA::TypeCode_var type = value.type ();
00718 
00719       CORBA::Boolean equal_tradername =
00720         type->equal (CosTrading::_tc_TraderName);
00721 
00722       CORBA::Boolean equal_linknameseq =
00723         type->equal (CosTrading::_tc_LinkNameSeq);
00724 
00725       if (!equal_tradername ||
00726           !equal_linknameseq)
00727         throw CosTrading::Lookup::PolicyTypeMismatch (*policy);
00728       else
00729         value >>= trader_name;
00730     }
00731 
00732   return trader_name;
00733 }
00734 
00735 CosTrading::FollowOption
00736 TAO_Policies::link_follow_rule (void) const
00737 {
00738   CosTrading::FollowOption return_value =
00739     this->trader_.import_attributes ().def_follow_policy ();
00740 
00741   if (this->policies_[LINK_FOLLOW_RULE] != 0)
00742     {
00743       CosTrading::FollowOption max_follow_policy =
00744         this->trader_.import_attributes ().max_follow_policy ();
00745 
00746       CosTrading::Policy* policy = this->policies_[LINK_FOLLOW_RULE];
00747       CosTrading::PolicyValue& value = policy->value;
00748       CORBA::TypeCode_var type = value.type ();
00749 
00750       // Extract the link follow rule
00751       CORBA::Boolean type_equal =
00752         type->equal (CosTrading::_tc_FollowOption);
00753 
00754       if (!type_equal)
00755         throw CosTrading::Lookup::PolicyTypeMismatch (*policy);
00756       else
00757         value >>= return_value;
00758 
00759       if (return_value > max_follow_policy)
00760         return_value = max_follow_policy;
00761     }
00762 
00763   return return_value;
00764 }
00765 
00766 CosTrading::FollowOption
00767 TAO_Policies::link_follow_rule (const CosTrading::Link::LinkInfo& link_info) const
00768 {
00769   CosTrading::FollowOption return_value = CosTrading::local_only;
00770   CosTrading::FollowOption trader_max_follow_policy =
00771     this->trader_.import_attributes ().max_follow_policy ();
00772   CosTrading::FollowOption link_limiting_follow_rule =
00773     link_info.limiting_follow_rule;
00774 
00775   // If not defined defaults to trader.def_link_follow_rule
00776   CosTrading::FollowOption query_link_follow_rule =
00777     this->link_follow_rule ();
00778 
00779   return_value = (query_link_follow_rule < trader_max_follow_policy)
00780     ? query_link_follow_rule : trader_max_follow_policy;
00781   return_value = (return_value < link_limiting_follow_rule)
00782     ? return_value : link_limiting_follow_rule;
00783 
00784   return return_value;
00785 }
00786 
00787 CORBA::ULong
00788 TAO_Policies::hop_count (void) const
00789 {
00790   return this->ulong_prop (HOP_COUNT);
00791 }
00792 
00793 CosTrading::Admin::OctetSeq*
00794 TAO_Policies::request_id (void) const
00795 {
00796   CosTrading::Admin::OctetSeq* request_id = 0;
00797 
00798   if (this->policies_[REQUEST_ID] != 0)
00799     {
00800       CosTrading::Policy* policy = this->policies_[REQUEST_ID];
00801       CosTrading::PolicyValue& value = policy->value;
00802       CORBA::TypeCode_var type = value.type ();
00803 
00804       CORBA::Boolean equal_octetseq =
00805         type->equal (CosTrading::Admin::_tc_OctetSeq);
00806 
00807       if (!equal_octetseq)
00808         throw CosTrading::Lookup::PolicyTypeMismatch (*policy);
00809       else
00810         value >>= request_id;
00811     }
00812 
00813   return request_id;
00814 }
00815 
00816 void
00817 TAO_Policies::
00818 copy_in_follow_option (CosTrading::PolicySeq& policy_seq,
00819                        const CosTrading::Link::LinkInfo& link_info) const
00820 {
00821   CosTrading::FollowOption follow_option = CosTrading::local_only;
00822   CosTrading::FollowOption trader_max_follow_policy =
00823     this->trader_.import_attributes ().max_follow_policy ();
00824 
00825   if (this->policies_[LINK_FOLLOW_RULE] != 0)
00826     {
00827       CosTrading::FollowOption query_link_follow_rule =
00828         this->link_follow_rule ();
00829 
00830       follow_option = (CosTrading::FollowOption)
00831         (link_info.limiting_follow_rule < trader_max_follow_policy
00832          ? (link_info.limiting_follow_rule < query_link_follow_rule
00833             ? link_info.limiting_follow_rule
00834             : query_link_follow_rule)
00835          : (trader_max_follow_policy < query_link_follow_rule
00836             ? trader_max_follow_policy
00837             : query_link_follow_rule));
00838     }
00839   else
00840     follow_option = (CosTrading::FollowOption)
00841       (link_info.def_pass_on_follow_rule < trader_max_follow_policy
00842        ? link_info.def_pass_on_follow_rule
00843        : trader_max_follow_policy);
00844 
00845   CORBA::ULong i = 0;
00846   for (i = 0; i < policy_seq.length (); i++)
00847     if (ACE_OS::strcmp (policy_seq[i].name,
00848                         POLICY_NAMES[LINK_FOLLOW_RULE]) == 0)
00849       {
00850         policy_seq[i].value <<= follow_option;
00851         break;
00852       }
00853 
00854   if (i == policy_seq.length ())
00855     {
00856       policy_seq.length (i + 1);
00857       policy_seq[i].name = POLICY_NAMES[LINK_FOLLOW_RULE];
00858       policy_seq[i].value <<= follow_option;
00859     }
00860 }
00861 
00862 void
00863 TAO_Policies::
00864 copy_to_pass (CosTrading::PolicySeq& policy_seq,
00865               const CosTrading::Admin::OctetSeq& request_id) const
00866 {
00867   CORBA::ULong counter = 0;
00868   CosTrading::Policy* policy_buffer =
00869     CosTrading::PolicySeq::allocbuf (REQUEST_ID + 1);
00870 
00871   if (policy_buffer == 0)
00872     return;
00873 
00874   for (int i = 0; i <= REQUEST_ID; i++)
00875     {
00876       CosTrading::Policy& new_policy = policy_buffer[counter];
00877 
00878        if (i == REQUEST_ID)
00879         {
00880           // Set the new request id.
00881           new_policy.name = POLICY_NAMES[REQUEST_ID];
00882           new_policy.value <<= request_id;
00883           counter++;
00884         }
00885        else if (this->policies_[i] != 0)
00886         {
00887           // Copy in the existing policies.
00888           new_policy.name = POLICY_NAMES[i];
00889           new_policy.value = this->policies_[i]->value;
00890           counter++;
00891         }
00892 
00893       // We always require a hop count.
00894       if (i == HOP_COUNT)
00895         {
00896           CORBA::ULong count = this->hop_count ();
00897 
00898           new_policy.name = POLICY_NAMES[HOP_COUNT];
00899           new_policy.value <<= count - 1;
00900 
00901           // Don't count hop count twice.
00902           if (this->policies_[i] == 0)
00903             counter++;
00904         }
00905     }
00906 
00907   policy_seq.replace (REQUEST_ID + 1,
00908                       counter,
00909                       policy_buffer,
00910                       1);
00911 }
00912 
00913 void
00914 TAO_Policies::copy_to_forward (CosTrading::PolicySeq& policy_seq,
00915                                const CosTrading::TraderName& trader_name) const
00916 {
00917   // Create a new policy sequence, shortening the starting trader
00918   // policy by one link.
00919 
00920   CORBA::ULong counter = 0;
00921   CosTrading::Policy* policy_buffer =
00922     CosTrading::PolicySeq::allocbuf (REQUEST_ID + 1);
00923 
00924   if (policy_buffer == 0)
00925     return;
00926 
00927   for (int i = 0; i <= REQUEST_ID; i++)
00928     {
00929       CosTrading::Policy& new_policy = policy_buffer[counter];
00930 
00931       if (this->policies_[i] != 0)
00932         {
00933           // Copy in the existing policies.
00934           if (i == STARTING_TRADER && trader_name.length () > 1)
00935             {
00936               // Eliminate the first link of the trader name.
00937               // Only pass on the property if the sequence
00938               // contains more links after us.
00939 
00940               // The any will sieze control of this memory.
00941               // Allocating here avoids copying in the policy
00942               // any.
00943               CORBA::ULong length = trader_name.length ();
00944               CosTrading::LinkName* buf =
00945                 CosTrading::TraderName::allocbuf (length - 1);
00946 
00947               if (buf != 0)
00948                 {
00949                   for (CORBA::ULong j = 1; j < length; j++)
00950                     buf[j - 1] = CORBA::string_dup (trader_name[j]);
00951 
00952                   new_policy.name = this->policies_[i]->name;
00953                   CosTrading::TraderName new_name (length - 1,
00954                                                    length - 1,
00955                                                    buf,
00956                                                    1);
00957 
00958                   new_policy.value <<= new_name;
00959                   counter++;
00960                 }
00961             }
00962           else if (i != STARTING_TRADER)
00963             {
00964               new_policy.name = this->policies_[i]->name;
00965               new_policy.value = this->policies_[i]->value;
00966               counter++;
00967             }
00968         }
00969     }
00970 
00971   // Create the new sequence
00972   policy_seq.replace (REQUEST_ID + 1,
00973                       counter,
00974                       policy_buffer, 1);
00975 }
00976 
00977 TAO_Offer_Modifier::
00978 TAO_Offer_Modifier (const char* type_name,
00979                     const CosTradingRepos::ServiceTypeRepository::TypeStruct& type_struct,
00980                     CosTrading::Offer* offer)
00981   : type_ (type_name),
00982     offer_ (offer)
00983 {
00984   const CosTradingRepos::ServiceTypeRepository::PropStructSeq&
00985     pstructs = type_struct.props;
00986   CosTrading::PropertySeq& prop_seq = this->offer_->properties;
00987   CORBA::ULong pstructs_length = pstructs.length (),
00988     props_length = prop_seq.length (),
00989     i = 0;
00990 
00991   // Create a mapping of property names to their types.
00992   for (i = 0; i < pstructs_length; i++)
00993     {
00994       CORBA::String_var prop_name = pstructs[i].name.in ();
00995       CORBA::TypeCode_ptr type_code =
00996         CORBA::TypeCode::_duplicate (pstructs[i].value_type.in ());
00997       this->prop_types_.bind (prop_name, type_code);
00998     }
00999 
01000   // Separate the type defined properties into mandatory and readonly
01001   for (i = 0; i < pstructs_length; i++)
01002     {
01003       const char* pname = pstructs[i].name;
01004 
01005       if (pstructs[i].mode ==
01006           CosTradingRepos::ServiceTypeRepository::PROP_MANDATORY)
01007         {
01008           CORBA::String_var prop_name (pname);
01009           this->mandatory_.insert (prop_name);
01010         }
01011       else if (pstructs[i].mode ==
01012                CosTradingRepos::ServiceTypeRepository::PROP_READONLY)
01013         {
01014           CORBA::String_var prop_name (pname);
01015           this->readonly_.insert (prop_name);
01016         }
01017     }
01018 
01019   // Insert the indices of the offer properties into a map.
01020   for (i = 0; i < props_length; i++)
01021     {
01022       CORBA::String_var prop_name =
01023         static_cast<const char*> (prop_seq[i].name);
01024       this->props_.bind (prop_name, &prop_seq[i]);
01025     }
01026 }
01027 
01028 TAO_Offer_Modifier::~TAO_Offer_Modifier (void)
01029 {
01030   for (TAO_Typecode_Table::iterator type_iter (this->prop_types_);
01031        ! type_iter.done ();
01032        type_iter++)
01033     {
01034       CORBA::TypeCode_ptr corba_type = (*type_iter).int_id_;
01035       CORBA::release (corba_type);
01036     }
01037 }
01038 
01039 void
01040 TAO_Offer_Modifier::
01041 delete_properties (const CosTrading::PropertyNameSeq& deletes)
01042 {
01043   // Validate that the listed property names can be deleted
01044   CORBA::ULong i = 0,
01045     length = deletes.length ();
01046   TAO_String_Set delete_me;
01047 
01048   for (i = 0; i < length; i++)
01049     {
01050       const char* dname = static_cast<const char*> (deletes[i]);
01051       if (! TAO_Trader_Base::is_valid_property_name (dname))
01052         throw CosTrading::IllegalPropertyName (dname);
01053       else
01054         {
01055           CORBA::String_var prop_name (dname);
01056           if (this->mandatory_.find (prop_name) == 0)
01057             throw CosTrading::Register::MandatoryProperty (this->type_, dname);
01058           else if (delete_me.insert (prop_name) == 1)
01059             throw CosTrading::DuplicatePropertyName (dname);
01060           else if (this->props_.find (prop_name) == -1)
01061             throw CosTrading::Register::UnknownPropertyName (dname);
01062         }
01063     }
01064 
01065   // Delete those properties from the offer.
01066   for (i = 0; i < length; i++)
01067     {
01068       CORBA::String_var prop_name =
01069         static_cast<const char *> (deletes[i]);
01070       this->props_.unbind (prop_name);
01071     }
01072 }
01073 
01074 void
01075 TAO_Offer_Modifier::
01076 merge_properties (const CosTrading::PropertySeq& modifies)
01077 {
01078   int i = 0, length = 0;
01079   TAO_String_Set modify_me;
01080 
01081   // Ensure that the proposed changes aren't to readonly properties or
01082   // otherwise invalid.
01083   TAO_Property_Evaluator prop_eval (modifies);
01084   for (i = 0, length = modifies.length (); i < length; i++)
01085     {
01086       const char* mname = modifies[i].name;
01087       if (TAO_Trader_Base::is_valid_property_name (mname))
01088         {
01089           CORBA::String_var prop_name (mname);
01090           if (this->readonly_.find (prop_name) == 0)
01091             {
01092               // Can't assign a dynamic property to a property with
01093               // readonly mode, and can't reassign a readonly property.
01094               if (prop_eval.is_dynamic_property (i))
01095                 throw CosTrading::ReadonlyDynamicProperty (this->type_, mname);
01096               else if (this->props_.find (prop_name) == 0)
01097                 throw CosTrading::Register::ReadonlyProperty (
01098                   this->type_,
01099                   mname);
01100             }
01101 
01102           // Validate the property type if the property is defined in
01103           // the service type description.
01104           CORBA::TypeCode_ptr type_def = 0;
01105           if (this->prop_types_.find (prop_name, type_def) == 0)
01106             {
01107               CORBA::TypeCode_var prop_type = prop_eval.property_type (i);
01108 
01109               // @@ Frank: This code used to have this comment and line
01110               //    of code before I fixed the "ACE_TRY" fuzz warning here.
01111               // @@ Seth, are we trying to ignore the exception here?
01112               // CORBA::Environment ACE_TRY_ENV;
01113               // @@ Frank: It seems clear that this is not going to work as
01114               // expected.  Is the purpose to ignore any exceptions from
01115               // equal ()?  For now, exceptions are returned since this
01116               // seemed "safest".
01117 
01118               CORBA::Boolean td_equal =
01119                 type_def->equal (prop_type.in ());
01120 
01121               if (!td_equal)
01122                 throw CosTrading::PropertyTypeMismatch (mname, modifies[i]);
01123             }
01124 
01125           if (modify_me.insert (prop_name) == 1)
01126             throw CosTrading::DuplicatePropertyName (mname);
01127         }
01128       else
01129         throw CosTrading::IllegalPropertyName (mname);
01130     }
01131 }
01132 
01133 void
01134 TAO_Offer_Modifier::affect_change (const CosTrading::PropertySeq& modifies)
01135 {
01136   // Create a new property list reflecting the deletes, modifies, and
01137   // add operations performed, and place this property list in the
01138   // offer.
01139 
01140   // Merge these properties with the original set.
01141   CORBA::ULong i = 0,
01142     merge_length = modifies.length ();
01143 
01144   for (i = 0; i < merge_length; i++)
01145     {
01146       Property_Table::ENTRY* entry = 0;
01147       CORBA::String_var prop_name = modifies[i].name.in ();
01148 
01149       CosTrading::Property* prop =
01150         const_cast<CosTrading::Property*> (&modifies[i]);
01151       if (this->props_.bind (prop_name, prop, entry) == 1)
01152         // We need to rebind here.
01153         entry->int_id_ = prop;
01154     }
01155 
01156   CORBA::ULong num_modified = 0,
01157     original_length = this->offer_->properties.length (),
01158     total_length = static_cast<CORBA::ULong> (this->props_.current_size ());
01159 
01160   // Scrap the existing property sequence and begin a new one
01161   CosTrading::PropertySeq prop_seq (total_length);
01162   //  this->offer_->properties.length (total_length);
01163 
01164   // Copy in the unaffected and modified props into the offer,
01165   // excluding those that were deleted. Let's try and retain their
01166   // relative ordering.
01167   for (i = 0; i < original_length; i++)
01168     {
01169       CosTrading::Property* prop_value = 0;
01170       const char* name = this->offer_->properties[i].name;
01171       CORBA::String_var prop_name (name);
01172       if (this->props_.unbind (prop_name, prop_value) == 0)
01173         prop_seq[num_modified++] = *prop_value;
01174     }
01175 
01176   for (i = 0; i < merge_length; i++)
01177     {
01178       CosTrading::Property* prop_value = 0;
01179       const char* name = modifies[i].name;
01180       CORBA::String_var prop_name (name);
01181       if (this->props_.unbind (prop_name, prop_value) == 0)
01182         prop_seq[num_modified++] = *prop_value;
01183     }
01184 
01185   this->offer_->properties.length (total_length);
01186   for (i = 0; i < total_length; i++)
01187     this->offer_->properties[i] = prop_seq[i];
01188   // Free the old, orphaned sequence.
01189   //  CosTrading::PropertySeq::freebuf (prop_buf);
01190 }
01191 
01192 TAO_Offer_Filter::TAO_Offer_Filter (TAO_Policies& policies)
01193 {
01194   search_card_ = policies.search_card ();
01195 
01196   match_card_ = policies.match_card ();
01197 
01198   return_card_ = policies.return_card ();
01199 
01200   dp_ = policies.use_dynamic_properties ();
01201 
01202   mod_ = policies.use_modifiable_properties ();
01203 
01204   CORBA::Boolean exact_type_match =
01205     policies.exact_type_match ();
01206 
01207   if (exact_type_match == 1)
01208     {
01209       CORBA::String_var exact_match
01210         (TAO_Policies::POLICY_NAMES[TAO_Policies::EXACT_TYPE_MATCH]);
01211       this->limits_.insert (exact_match);
01212     }
01213 }
01214 
01215 void
01216 TAO_Offer_Filter::
01217 configure_type (CosTradingRepos::ServiceTypeRepository::TypeStruct* type_struct)
01218 {
01219   CosTradingRepos::ServiceTypeRepository::PropStructSeq&
01220     prop_seq = type_struct->props;
01221 
01222   // Take note of non-modifiable properties in the type_struct
01223   this->not_mod_props_.reset ();
01224   for (int i = prop_seq.length () - 1; i >= 0; i--)
01225     {
01226       CosTradingRepos::ServiceTypeRepository::PropertyMode mode = prop_seq[i].mode;
01227       if (mode == CosTradingRepos::ServiceTypeRepository::PROP_MANDATORY_READONLY ||
01228           mode == CosTradingRepos::ServiceTypeRepository::PROP_READONLY)
01229         {
01230           CORBA::String_var prop_name ((const char*) prop_seq[i].name);
01231           this->not_mod_props_.insert (prop_name);
01232         }
01233     }
01234 }
01235 
01236 CORBA::Boolean
01237 TAO_Offer_Filter::ok_to_consider (CosTrading::Offer* offer)
01238 {
01239   CORBA::String_var use_mods =
01240     TAO_Policies::POLICY_NAMES[TAO_Policies::USE_MODIFIABLE_PROPERTIES];
01241   CORBA::String_var use_dyns =
01242     TAO_Policies::POLICY_NAMES[TAO_Policies::USE_DYNAMIC_PROPERTIES];
01243   CORBA::Boolean return_value = 1;
01244   TAO_Property_Evaluator prop_eval (*offer);
01245 
01246   // If we should screen offers, determine if this offer is unworthy
01247   // for consideration.
01248   if (! (this->mod_ && this->dp_))
01249     {
01250       for (int i = offer->properties.length () - 1;
01251            i >= 0 && return_value;
01252            i--)
01253         {
01254           // Winnow away the unwanted offers with modifiable or
01255           // dynamic properties.
01256           if (! this->mod_)
01257             {
01258               // Determine if this property name is found in the set
01259               // of modifiable properties for the type being considered.
01260               CORBA::String_var prop_name ((const char*) offer->properties[i].name);
01261               if (this->not_mod_props_.find (prop_name) == -1)
01262                 {
01263                   this->limits_.insert (use_mods);
01264                   return_value = 0;
01265                 }
01266             }
01267 
01268           if (! this->dp_ && return_value)
01269             {
01270               // Determine if this property is dynamic.
01271               if (prop_eval.is_dynamic_property (i))
01272                 {
01273                   this->limits_.insert (use_dyns);
01274                   return_value = 0;
01275                 }
01276             }
01277 
01278           if (return_value == 0)
01279             break;
01280         }
01281     }
01282 
01283   // If we're good to go, consider this offer considered and decrement
01284   // the search cardinality counter.
01285   if (return_value)
01286     {
01287       this->search_card_--;
01288       if (this->search_card_ == 0)
01289         {
01290           CORBA::String_var search_card =
01291             TAO_Policies::POLICY_NAMES[TAO_Policies::SEARCH_CARD];
01292           this->limits_.insert (search_card);
01293         }
01294     }
01295 
01296   return return_value;
01297 }
01298 
01299 CORBA::Boolean
01300 TAO_Offer_Filter::ok_to_consider_more (void)
01301 {
01302   return this->search_card_ > 0 && this->match_card_ > 0;
01303 }
01304 
01305 void
01306 TAO_Offer_Filter::matched_offer (void)
01307 {
01308   this->match_card_--;
01309   this->return_card_--;
01310 
01311   if (this->match_card_ == 0)
01312     {
01313       CORBA::String_var match_card =
01314         TAO_Policies::POLICY_NAMES[TAO_Policies::MATCH_CARD];
01315       this->limits_.insert (match_card);
01316     }
01317 
01318   if (this->return_card_ == 0)
01319     {
01320       CORBA::String_var return_card =
01321         TAO_Policies::POLICY_NAMES[TAO_Policies::MATCH_CARD];
01322       this->limits_.insert (return_card);
01323     }
01324 }
01325 
01326 CORBA::ULong
01327 TAO_Offer_Filter::search_card_remaining (void) const
01328 {
01329   return this->search_card_;
01330 }
01331 
01332 CORBA::ULong
01333 TAO_Offer_Filter::match_card_remaining (void) const
01334 {
01335   return this->match_card_;
01336 }
01337 
01338 CosTrading::PolicyNameSeq*
01339 TAO_Offer_Filter::limits_applied (void)
01340 {
01341   int i = 0;
01342   CORBA::ULong size = static_cast<CORBA::ULong> (this->limits_.size ());
01343   CosTrading::PolicyName* temp =
01344     CosTrading::PolicyNameSeq::allocbuf (size);
01345 
01346   for (TAO_String_Set::iterator p_iter (this->limits_.begin());
01347        ! p_iter.done ();
01348        p_iter.advance ())
01349     {
01350       CORBA::String_var* policy_name_ptr = 0;
01351       p_iter.next (policy_name_ptr);
01352       temp[i++] = CORBA::string_dup (policy_name_ptr->in ());
01353     }
01354 
01355   return new CosTrading::PolicyNameSeq (size, size, temp, 1);
01356 }
01357 
01358 TAO_Property_Filter::
01359 TAO_Property_Filter (const SPECIFIED_PROPS& desired_props)
01360   : policy_  (desired_props._d ())
01361 {
01362   if (this->policy_ == CosTrading::Lookup::some)
01363     {
01364       const CosTrading::PropertyNameSeq&
01365         prop_seq = desired_props.prop_names ();
01366       int length = prop_seq.length ();
01367 
01368       for (int i = 0; i < length; i++)
01369         {
01370           const char* pname = prop_seq[i];
01371 
01372           // Check for errors or duplicates
01373           if (TAO_Trader_Base::is_valid_property_name (pname))
01374             {
01375               CORBA::String_var prop_name (pname);
01376               if (this->props_.insert (prop_name) == 1)
01377                 throw CosTrading::DuplicatePropertyName (pname);
01378             }
01379           else
01380             throw CosTrading::IllegalPropertyName (pname);
01381         }
01382     }
01383 }
01384 
01385 TAO_Property_Filter::
01386 TAO_Property_Filter (const TAO_Property_Filter& prop_filter)
01387   : props_ (prop_filter.props_),
01388     policy_ (prop_filter.policy_)
01389 {
01390 }
01391 
01392 TAO_Property_Filter&
01393 TAO_Property_Filter::operator= (const TAO_Property_Filter& other)
01394 {
01395   this->props_ = other.props_;
01396   this->policy_ = other.policy_;
01397 
01398   return *this;
01399 }
01400 
01401 void
01402 TAO_Property_Filter::filter_offer (CosTrading::Offer* source,
01403                                    CosTrading::Offer& destination)
01404 {
01405   Prop_Queue prop_queue;
01406   CosTrading::PropertySeq& s_props = source->properties;
01407   CosTrading::PropertySeq& d_props = destination.properties;
01408   CORBA::ULong length = static_cast<CORBA::ULong> (s_props.length ()),
01409                elem = 0;
01410 
01411   destination.reference = CORBA::Object::_duplicate (source->reference.in ());
01412   if (this->policy_ == CosTrading::Lookup::some)
01413     {
01414       for (CORBA::ULong i = 0; i < length; i++)
01415         {
01416           if (this->policy_ == CosTrading::Lookup::all)
01417             prop_queue.enqueue_tail (&s_props[i]);
01418           else
01419             {
01420               const char* p_name = s_props[i].name;
01421               CORBA::String_var prop_name (p_name);
01422 
01423               // Save those property that match.
01424               if (this->props_.find (prop_name) == 0)
01425                 prop_queue.enqueue_tail (&s_props[i]);
01426             }
01427         }
01428 
01429       // Shove the matched properties into the destination property
01430       // sequence.
01431       length = static_cast<CORBA::ULong> (prop_queue.size ());
01432       d_props.length (length);
01433       for (Prop_Queue::ITERATOR prop_iter (prop_queue);
01434            ! prop_iter.done ();
01435            prop_iter.advance (), elem++)
01436         {
01437           CosTrading::Property** prop_ptr = 0;
01438 
01439           prop_iter.next (prop_ptr);
01440           d_props[elem] = **prop_ptr;
01441         }
01442     }
01443   else if (this->policy_ == CosTrading::Lookup::all)
01444     //      CosTrading::Property* props = s_props.get_buffer (0);
01445     //      d_props.replace (length, length, props, 0);
01446     d_props = s_props;
01447 }
01448 
01449 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:49:26 2010 for TAO_CosTrader by  doxygen 1.4.7