Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / FT_ReplicationManager / FT_Property_Validator.cpp
blob30baef0cd46651def8e0738399376c6b0c48957a
1 #include "FT_Property_Validator.h"
2 #include "orbsvcs/PortableGroup/PG_Operators.h"
3 #include "orbsvcs/FT_ReplicationManagerC.h"
5 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
7 TAO::FT_Property_Validator::FT_Property_Validator (void)
8 : replication_style_ (1),
9 membership_style_ (1),
10 consistency_style_ (1),
11 fault_monitoring_style_ (1),
12 fault_monitoring_granularity_ (1),
13 factories_ (1)
15 this->replication_style_.length (1);
16 this->replication_style_[0].id = CORBA::string_dup (::FT::FT_REPLICATION_STYLE);
18 this->membership_style_.length (1);
19 this->membership_style_[0].id = CORBA::string_dup (::FT::FT_MEMBERSHIP_STYLE);
21 this->consistency_style_.length (1);
22 this->consistency_style_[0].id = CORBA::string_dup (::FT::FT_CONSISTENCY_STYLE);
24 this->fault_monitoring_style_.length (1);
25 this->fault_monitoring_style_[0].id = CORBA::string_dup (::FT::FT_FAULT_MONITORING_STYLE);
27 this->fault_monitoring_granularity_.length (1);
28 this->fault_monitoring_granularity_[0].id = CORBA::string_dup (::FT::FT_FAULT_MONITORING_GRANULARITY);
30 this->factories_.length (1);
31 this->factories_[0].id = CORBA::string_dup (::FT::FT_FACTORIES);
35 TAO::FT_Property_Validator::~FT_Property_Validator (void)
40 void
41 TAO::FT_Property_Validator::validate_property (
42 const PortableGroup::Properties & props)
44 const CORBA::ULong len = props.length ();
46 for (CORBA::ULong i = 0; i < len; ++i)
48 const PortableGroup::Property & property = props[i];
50 if (property.nam == this->replication_style_)
52 FT::ReplicationStyleValue value;
53 if (!(property.val >>= value)
54 || (value != FT::STATELESS
55 && value != FT::COLD_PASSIVE
56 && value != FT::WARM_PASSIVE
57 && value != FT::ACTIVE
58 && value != FT::ACTIVE_WITH_VOTING
59 && value != FT::SEMI_ACTIVE))
60 throw PortableGroup::InvalidProperty (property.nam, property.val);
62 else if (property.nam == this->membership_style_)
64 PortableGroup::MembershipStyleValue value;
65 if (!(property.val >>= value)
66 || (value != PortableGroup::MEMB_APP_CTRL
67 && value != PortableGroup::MEMB_INF_CTRL))
68 throw PortableGroup::InvalidProperty (property.nam, property.val);
70 else if (property.nam == this->consistency_style_)
72 FT::ConsistencyStyleValue value;
73 if (!(property.val >>= value)
74 || (value != FT::CONS_APP_CTRL
75 && value != FT::CONS_INF_CTRL))
76 throw PortableGroup::InvalidProperty (property.nam, property.val);
78 else if (property.nam == this->fault_monitoring_style_)
80 FT::FaultMonitoringStyleValue value;
81 if (!(property.val >>= value)
82 || (value != FT::PULL
83 && value != FT::PUSH
84 && value != FT::NOT_MONITORED))
85 throw PortableGroup::InvalidProperty (property.nam, property.val);
87 else if (property.nam == this->fault_monitoring_granularity_)
89 FT::FaultMonitoringGranularityValue value;
90 if (!(property.val >>= value)
91 || (value != FT::MEMB
92 && value != FT::LOC
93 && value != FT::LOC_AND_TYPE))
94 throw PortableGroup::InvalidProperty (property.nam, property.val);
96 else if (property.nam == this->factories_)
98 const PortableGroup::FactoriesValue * factories;
99 if (!(property.val >>= factories))
100 throw PortableGroup::InvalidProperty (property.nam, property.val);
101 else
103 const CORBA::ULong flen = factories->length ();
105 if (flen == 0)
106 throw PortableGroup::InvalidProperty (
107 property.nam,
108 property.val);
110 for (CORBA::ULong j = 0; j < flen; ++j)
112 const PortableGroup::FactoryInfo & factory_info =
113 (*factories)[j];
115 if (CORBA::is_nil (factory_info.the_factory.in ())
116 || factory_info.the_location.length () == 0)
117 throw PortableGroup::InvalidProperty (
118 property.nam,
119 property.val);
126 void
127 TAO::FT_Property_Validator::validate_criteria (
128 const PortableGroup::Properties & props)
130 const CORBA::ULong len = props.length ();
131 PortableGroup::Criteria invalid_criteria;
133 // Optimize for the worst case scenario where all properties are
134 // invalid.
135 invalid_criteria.length (len);
137 /// The invalid criteria index.
138 CORBA::ULong p = 0;
140 for (CORBA::ULong i = 0; i < len; ++i)
142 const PortableGroup::Property & property = props[i];
143 CORBA::Long value;
145 if (!(property.val >>= value))
146 invalid_criteria[p++] = property;
147 else
149 if (property.nam == this->replication_style_)
151 if ( value != FT::STATELESS
152 && value != FT::COLD_PASSIVE
153 && value != FT::WARM_PASSIVE
154 && value != FT::ACTIVE
155 && value != FT::ACTIVE_WITH_VOTING
156 && value != FT::SEMI_ACTIVE )
157 invalid_criteria[p++] = property;
159 else if (property.nam == this->membership_style_)
161 if ( value != PortableGroup::MEMB_APP_CTRL
162 && value != PortableGroup::MEMB_INF_CTRL )
163 invalid_criteria[p++] = property;
165 else if (property.nam == this->consistency_style_)
167 if ( value != FT::CONS_APP_CTRL
168 && value != FT::CONS_INF_CTRL )
169 invalid_criteria[p++] = property;
171 else if (property.nam == this->fault_monitoring_style_)
173 if ( value != FT::PULL
174 && value != FT::PUSH
175 && value != FT::NOT_MONITORED )
176 invalid_criteria[p++] = property;
178 else if (property.nam == this->fault_monitoring_granularity_)
180 if ( value != FT::MEMB
181 && value != FT::LOC
182 && value != FT::LOC_AND_TYPE )
183 invalid_criteria[p++] = property;
185 else if (property.nam == this->factories_)
187 const PortableGroup::FactoriesValue * factories = 0;
188 if (!(property.val >>= factories))
189 invalid_criteria[p++] = property;
190 else
192 const CORBA::ULong flen = factories->length ();
194 if (flen == 0)
195 invalid_criteria[p++] = property;
196 else
198 for (CORBA::ULong j = 0; j < flen; ++j)
200 const PortableGroup::FactoryInfo & factory_info =
201 (*factories)[j];
203 if (CORBA::is_nil (factory_info.the_factory.in ())
204 || factory_info.the_location.length () == 0)
206 invalid_criteria[p++] = property;
207 break;
216 if (p > 0)
218 // Reduce the length of the invalid criteria sequence in an
219 // effort to optimize the copying that will occur when the below
220 // exception is thrown. Reducing the length is fast since no
221 // deallocations should occur.
222 invalid_criteria.length (p);
224 throw PortableGroup::InvalidCriteria (invalid_criteria);
228 TAO_END_VERSIONED_NAMESPACE_DECL