00001 #include "orbsvcs/PortableGroup/PG_Default_Property_Validator.h" 00002 #include "orbsvcs/PortableGroup/PG_Operators.h" 00003 00004 00005 ACE_RCSID (PortableGroup, 00006 PG_Default_Property_Validator, 00007 "$Id: PG_Default_Property_Validator.cpp 77001 2007-02-12 07:54:49Z johnnyw $") 00008 00009 00010 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00011 00012 TAO_PG_Default_Property_Validator::TAO_PG_Default_Property_Validator (void) 00013 : membership_ (1), 00014 factories_ (1) 00015 { 00016 this->membership_.length (1); 00017 this->membership_[0].id = CORBA::string_dup ("org.omg.PortableGroup.MembershipStyle"); 00018 00019 this->factories_.length (1); 00020 this->factories_[0].id = CORBA::string_dup ("org.omg.PortableGroup.Factories"); 00021 } 00022 00023 TAO_PG_Default_Property_Validator::~TAO_PG_Default_Property_Validator (void) 00024 { 00025 } 00026 00027 void 00028 TAO_PG_Default_Property_Validator::validate_property ( 00029 const PortableGroup::Properties & props) 00030 { 00031 const CORBA::ULong len = props.length (); 00032 00033 for (CORBA::ULong i = 0; i < len; ++i) 00034 { 00035 const PortableGroup::Property & property = props[i]; 00036 00037 if (property.nam == this->membership_) 00038 { 00039 PortableGroup::MembershipStyleValue membership; 00040 if (!(property.val >>= membership) 00041 || (membership != PortableGroup::MEMB_APP_CTRL 00042 && membership != PortableGroup::MEMB_INF_CTRL)) 00043 throw PortableGroup::InvalidProperty (property.nam, property.val); 00044 } 00045 else if (property.nam == this->factories_) 00046 { 00047 const PortableGroup::FactoriesValue * factories; 00048 if (!(property.val >>= factories)) 00049 throw PortableGroup::InvalidProperty (property.nam, property.val); 00050 else 00051 { 00052 const CORBA::ULong flen = factories->length (); 00053 00054 if (flen == 0) 00055 throw PortableGroup::InvalidProperty ( 00056 property.nam, 00057 property.val); 00058 00059 for (CORBA::ULong j = 0; j < flen; ++j) 00060 { 00061 const PortableGroup::FactoryInfo & factory_info = 00062 (*factories)[j]; 00063 00064 if (CORBA::is_nil (factory_info.the_factory.in ()) 00065 || factory_info.the_location.length () == 0) 00066 throw PortableGroup::InvalidProperty ( 00067 property.nam, 00068 property.val); 00069 } 00070 } 00071 } 00072 } 00073 } 00074 00075 void 00076 TAO_PG_Default_Property_Validator::validate_criteria ( 00077 const PortableGroup::Properties & props) 00078 { 00079 const CORBA::ULong len = props.length (); 00080 PortableGroup::Criteria invalid_criteria; 00081 00082 // Optimize for the worst case scenario where all properties are 00083 // invalid. 00084 invalid_criteria.length (len); 00085 00086 /// The invalid criteria index. 00087 CORBA::ULong p = 0; 00088 00089 for (CORBA::ULong i = 0; i < len; ++i) 00090 { 00091 const PortableGroup::Property & property = props[i]; 00092 00093 if (property.nam == this->membership_) 00094 { 00095 PortableGroup::MembershipStyleValue membership; 00096 if (!(property.val >>= membership) 00097 || (membership != PortableGroup::MEMB_APP_CTRL 00098 && membership != PortableGroup::MEMB_INF_CTRL)) 00099 invalid_criteria[p++] = property; 00100 } 00101 else if (property.nam == this->factories_) 00102 { 00103 PortableGroup::FactoriesValue * factories; 00104 if (!(property.val >>= factories)) 00105 invalid_criteria[p++] = property; 00106 else 00107 { 00108 const CORBA::ULong flen = factories->length (); 00109 00110 if (flen == 0) 00111 invalid_criteria[p++] = property; 00112 else 00113 { 00114 for (CORBA::ULong j = 0; j < flen; ++j) 00115 { 00116 const PortableGroup::FactoryInfo & factory_info = 00117 (*factories)[j]; 00118 00119 if (CORBA::is_nil (factory_info.the_factory.in ()) 00120 || factory_info.the_location.length () == 0) 00121 { 00122 invalid_criteria[p++] = property; 00123 break; 00124 } 00125 } 00126 } 00127 } 00128 } 00129 } 00130 00131 if (p > 0) 00132 { 00133 // Reduce the length of the invalid criteria sequence in an 00134 // effort to optimize the copying that will occur when the below 00135 // exception is thrown. Reducing the length is fast since no 00136 // deallocations should occur. 00137 invalid_criteria.length (p); 00138 00139 throw PortableGroup::InvalidCriteria (invalid_criteria); 00140 } 00141 } 00142 00143 TAO_END_VERSIONED_NAMESPACE_DECL