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),
10 consistency_style_ (1),
11 fault_monitoring_style_ (1),
12 fault_monitoring_granularity_ (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)
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
)
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
)
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
);
103 const CORBA::ULong flen
= factories
->length ();
106 throw PortableGroup::InvalidProperty (
110 for (CORBA::ULong j
= 0; j
< flen
; ++j
)
112 const PortableGroup::FactoryInfo
& factory_info
=
115 if (CORBA::is_nil (factory_info
.the_factory
.in ())
116 || factory_info
.the_location
.length () == 0)
117 throw PortableGroup::InvalidProperty (
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
135 invalid_criteria
.length (len
);
137 /// The invalid criteria index.
140 for (CORBA::ULong i
= 0; i
< len
; ++i
)
142 const PortableGroup::Property
& property
= props
[i
];
145 if (!(property
.val
>>= value
))
146 invalid_criteria
[p
++] = property
;
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
175 && value
!= FT::NOT_MONITORED
)
176 invalid_criteria
[p
++] = property
;
178 else if (property
.nam
== this->fault_monitoring_granularity_
)
180 if ( value
!= FT::MEMB
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
;
192 const CORBA::ULong flen
= factories
->length ();
195 invalid_criteria
[p
++] = property
;
198 for (CORBA::ULong j
= 0; j
< flen
; ++j
)
200 const PortableGroup::FactoryInfo
& factory_info
=
203 if (CORBA::is_nil (factory_info
.the_factory
.in ())
204 || factory_info
.the_location
.length () == 0)
206 invalid_criteria
[p
++] = property
;
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