PG_Default_Property_Validator.cpp

Go to the documentation of this file.
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            "PG_Default_Property_Validator.cpp,v 1.6 2006/03/14 06:14:34 jtc Exp")
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     ACE_ENV_ARG_DECL)
00031   ACE_THROW_SPEC ((CORBA::SystemException,
00032                    PortableGroup::InvalidProperty,
00033                    PortableGroup::UnsupportedProperty))
00034 {
00035   const CORBA::ULong len = props.length ();
00036 
00037   for (CORBA::ULong i = 0; i < len; ++i)
00038     {
00039       const PortableGroup::Property & property = props[i];
00040 
00041       if (property.nam == this->membership_)
00042         {
00043           PortableGroup::MembershipStyleValue membership;
00044           if (!(property.val >>= membership)
00045               || (membership != PortableGroup::MEMB_APP_CTRL
00046                   && membership != PortableGroup::MEMB_INF_CTRL))
00047             ACE_THROW (PortableGroup::InvalidProperty (property.nam,
00048                                                        property.val));
00049         }
00050       else if (property.nam == this->factories_)
00051         {
00052           const PortableGroup::FactoriesValue * factories;
00053           if (!(property.val >>= factories))
00054             ACE_THROW (PortableGroup::InvalidProperty (property.nam,
00055                                                        property.val));
00056           else
00057             {
00058               const CORBA::ULong flen = factories->length ();
00059 
00060               if (flen == 0)
00061                 ACE_THROW (PortableGroup::InvalidProperty (property.nam,
00062                                                            property.val));
00063 
00064               for (CORBA::ULong j = 0; j < flen; ++j)
00065                 {
00066                   const PortableGroup::FactoryInfo & factory_info =
00067                     (*factories)[j];
00068 
00069                   if (CORBA::is_nil (factory_info.the_factory.in ())
00070                       || factory_info.the_location.length () == 0)
00071                     ACE_THROW (PortableGroup::InvalidProperty (property.nam,
00072                                                                property.val));
00073                 }
00074             }
00075         }
00076     }
00077 }
00078 
00079 void
00080 TAO_PG_Default_Property_Validator::validate_criteria (
00081     const PortableGroup::Properties & props
00082     ACE_ENV_ARG_DECL)
00083   ACE_THROW_SPEC ((CORBA::SystemException,
00084                    PortableGroup::InvalidCriteria,
00085                    PortableGroup::CannotMeetCriteria))
00086 {
00087   const CORBA::ULong len = props.length ();
00088   PortableGroup::Criteria invalid_criteria;
00089 
00090   // Optimize for the worst case scenario where all properties are
00091   // invalid.
00092   invalid_criteria.length (len);
00093 
00094   /// The invalid criteria index.
00095   CORBA::ULong p = 0;
00096 
00097   for (CORBA::ULong i = 0; i < len; ++i)
00098     {
00099       const PortableGroup::Property & property = props[i];
00100 
00101       if (property.nam == this->membership_)
00102         {
00103           PortableGroup::MembershipStyleValue membership;
00104           if (!(property.val >>= membership)
00105               || (membership != PortableGroup::MEMB_APP_CTRL
00106                   && membership != PortableGroup::MEMB_INF_CTRL))
00107             invalid_criteria[p++] = property;
00108         }
00109       else if (property.nam == this->factories_)
00110         {
00111           PortableGroup::FactoriesValue * factories;
00112           if (!(property.val >>= factories))
00113             invalid_criteria[p++] = property;
00114           else
00115             {
00116               const CORBA::ULong flen = factories->length ();
00117 
00118               if (flen == 0)
00119                 invalid_criteria[p++] = property;
00120               else
00121                 {
00122                   for (CORBA::ULong j = 0; j < flen; ++j)
00123                     {
00124                       const PortableGroup::FactoryInfo & factory_info =
00125                         (*factories)[j];
00126 
00127                       if (CORBA::is_nil (factory_info.the_factory.in ())
00128                           || factory_info.the_location.length () == 0)
00129                         {
00130                           invalid_criteria[p++] = property;
00131                           break;
00132                         }
00133                     }
00134                 }
00135             }
00136         }
00137     }
00138 
00139   if (p > 0)
00140     {
00141       // Reduce the length of the invalid criteria sequence in an
00142       // effort to optimize the copying that will occur when the below
00143       // exception is thrown.  Reducing the length is fast since no
00144       // deallocations should occur.
00145       invalid_criteria.length (p);
00146 
00147       ACE_THROW (PortableGroup::InvalidCriteria (invalid_criteria));
00148     }
00149 }
00150 
00151 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 14:03:33 2006 for TAO_PortableGroup by doxygen 1.3.6