00001 // $Id: Trader_Constraint_Visitors.cpp 76626 2007-01-26 13:50:03Z elliott_c $ 00002 00003 #include "orbsvcs/Trader/Trader_Constraint_Visitors.h" 00004 00005 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00006 00007 TAO_Trader_Constraint_Evaluator:: 00008 TAO_Trader_Constraint_Evaluator (CosTrading::Offer* offer, 00009 CORBA::Boolean supports_dp) 00010 : prop_eval_ (*offer, supports_dp) 00011 { 00012 this->props_.close (); 00013 this->props_.open (); 00014 int length = offer->properties.length (); 00015 00016 // Create a map of property names to their values. 00017 for (int i = 0; i < length; i++) 00018 { 00019 CORBA::String_var name = (const char*) offer->properties[i].name; 00020 this->props_.bind (name, i); 00021 } 00022 } 00023 00024 int 00025 TAO_Trader_Constraint_Evaluator:: 00026 visit_property (TAO_Property_Constraint* literal) 00027 { 00028 int return_value = -1, prop_index = 0; 00029 // Handle case where property is not, in fact, mapped to a value 00030 CORBA::String_var prop_name ((const char*) literal->name ()); 00031 00032 if (this->props_.find (prop_name, prop_index) == 0) 00033 { 00034 00035 CORBA::Any *value = 0; 00036 // Retrieve the value of the property from the Property_Evaluator 00037 try 00038 { 00039 value = this->prop_eval_.property_value (prop_index); 00040 } 00041 catch (const CORBA::Exception&) 00042 { 00043 return -1; 00044 } 00045 00046 if (value != 0) 00047 { 00048 this->queue_.enqueue_head (TAO_Literal_Constraint (value)); 00049 return_value = 0; 00050 } 00051 } 00052 00053 return return_value; 00054 } 00055 00056 TAO_Trader_Constraint_Validator:: 00057 TAO_Trader_Constraint_Validator 00058 (const CosTradingRepos::ServiceTypeRepository::TypeStruct& type_struct) 00059 { 00060 const CosTradingRepos::ServiceTypeRepository::PropStructSeq& prop_seq = 00061 type_struct.props; 00062 int length = prop_seq.length (); 00063 00064 // Create a map of the service type properties to their types. 00065 for (int i = 0; i < length; i++) 00066 { 00067 CORBA::TypeCode_ptr corba_type = 00068 CORBA::TypeCode::_duplicate (prop_seq[i].value_type.in ()); 00069 00070 CORBA::String_var prop_name_str = (const char*) prop_seq[i].name; 00071 this->type_map_.bind (prop_name_str, corba_type); 00072 } 00073 } 00074 00075 TAO_Trader_Constraint_Validator:: 00076 ~TAO_Trader_Constraint_Validator () 00077 { 00078 } 00079 00080 TAO_END_VERSIONED_NAMESPACE_DECL