00001 // Trader_Constraint_Visitors.cpp,v 1.6 2006/04/25 11:35:29 jwillemsen Exp 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 ACE_DECLARE_NEW_CORBA_ENV; 00035 00036 CORBA::Any *value = 0; 00037 // Retrieve the value of the property from the Property_Evaluator 00038 ACE_TRY 00039 { 00040 value = this->prop_eval_.property_value (prop_index ACE_ENV_ARG_PARAMETER); 00041 ACE_TRY_CHECK; 00042 } 00043 ACE_CATCHANY 00044 { 00045 return -1; 00046 } 00047 ACE_ENDTRY; 00048 // ACE_CHECK_RETURN (-1); 00049 00050 if (value != 0) 00051 { 00052 this->queue_.enqueue_head (TAO_Literal_Constraint (value)); 00053 return_value = 0; 00054 } 00055 } 00056 00057 return return_value; 00058 } 00059 00060 TAO_Trader_Constraint_Validator:: 00061 TAO_Trader_Constraint_Validator 00062 (const CosTradingRepos::ServiceTypeRepository::TypeStruct& type_struct) 00063 { 00064 const CosTradingRepos::ServiceTypeRepository::PropStructSeq& prop_seq = 00065 type_struct.props; 00066 int length = prop_seq.length (); 00067 00068 // Create a map of the service type properties to their types. 00069 for (int i = 0; i < length; i++) 00070 { 00071 CORBA::TypeCode_ptr corba_type = 00072 CORBA::TypeCode::_duplicate (prop_seq[i].value_type.in ()); 00073 00074 CORBA::String_var prop_name_str = (const char*) prop_seq[i].name; 00075 this->type_map_.bind (prop_name_str, corba_type); 00076 } 00077 } 00078 00079 TAO_Trader_Constraint_Validator:: 00080 ~TAO_Trader_Constraint_Validator () 00081 { 00082 } 00083 00084 TAO_END_VERSIONED_NAMESPACE_DECL