Public Member Functions

TAO_PG_Default_Property_Validator Class Reference

Default property validator implementation. More...

#include <PG_Default_Property_Validator.h>

List of all members.

Public Member Functions

 TAO_PG_Default_Property_Validator (void)
 Constructor.
virtual ~TAO_PG_Default_Property_Validator (void)
 Destructor.
virtual void validate_property (const PortableGroup::Properties &props)
virtual void validate_criteria (const PortableGroup::Properties &criteria)

Private Attributes

Pre-initialize property Names.

These properties are pre-initialized once to reduce property validation overhead. Note that the InitialNumberReplicas and MinimumNumberReplicas properties are not validated since there are no restrictions imposed by TAO's PortableGroup implementation regarding the number of such members.

PortableGroup::Name membership_
PortableGroup::Name factories_

Detailed Description

Default property validator implementation.

This Property_Validator verifies that all properties defined in the PortableGroup IDL module are valid. This property validator can be subclassed to validate a different property set.

Definition at line 36 of file PG_Default_Property_Validator.h.


Constructor & Destructor Documentation

TAO_PG_Default_Property_Validator::TAO_PG_Default_Property_Validator ( void   ) 

Constructor.

Definition at line 12 of file PG_Default_Property_Validator.cpp.

  : membership_ (1),
    factories_ (1)
{
  this->membership_.length (1);
  this->membership_[0].id = CORBA::string_dup ("org.omg.PortableGroup.MembershipStyle");

  this->factories_.length (1);
  this->factories_[0].id = CORBA::string_dup ("org.omg.PortableGroup.Factories");
}

TAO_PG_Default_Property_Validator::~TAO_PG_Default_Property_Validator ( void   )  [virtual]

Destructor.

Definition at line 23 of file PG_Default_Property_Validator.cpp.

{
}


Member Function Documentation

void TAO_PG_Default_Property_Validator::validate_criteria ( const PortableGroup::Properties criteria  )  [virtual]

Validate the given properties/criteria. All criteria will be validated regardless of whether or not an invalid property was encountered.

The invalid criteria index.

Definition at line 76 of file PG_Default_Property_Validator.cpp.

{
  const CORBA::ULong len = props.length ();
  PortableGroup::Criteria invalid_criteria;

  // Optimize for the worst case scenario where all properties are
  // invalid.
  invalid_criteria.length (len);

  /// The invalid criteria index.
  CORBA::ULong p = 0;

  for (CORBA::ULong i = 0; i < len; ++i)
    {
      const PortableGroup::Property & property = props[i];

      if (property.nam == this->membership_)
        {
          PortableGroup::MembershipStyleValue membership;
          if (!(property.val >>= membership)
              || (membership != PortableGroup::MEMB_APP_CTRL
                  && membership != PortableGroup::MEMB_INF_CTRL))
            invalid_criteria[p++] = property;
        }
      else if (property.nam == this->factories_)
        {
          PortableGroup::FactoriesValue * factories;
          if (!(property.val >>= factories))
            invalid_criteria[p++] = property;
          else
            {
              const CORBA::ULong flen = factories->length ();

              if (flen == 0)
                invalid_criteria[p++] = property;
              else
                {
                  for (CORBA::ULong j = 0; j < flen; ++j)
                    {
                      const PortableGroup::FactoryInfo & factory_info =
                        (*factories)[j];

                      if (CORBA::is_nil (factory_info.the_factory.in ())
                          || factory_info.the_location.length () == 0)
                        {
                          invalid_criteria[p++] = property;
                          break;
                        }
                    }
                }
            }
        }
    }

  if (p > 0)
    {
      // Reduce the length of the invalid criteria sequence in an
      // effort to optimize the copying that will occur when the below
      // exception is thrown.  Reducing the length is fast since no
      // deallocations should occur.
      invalid_criteria.length (p);

      throw PortableGroup::InvalidCriteria (invalid_criteria);
    }
}

void TAO_PG_Default_Property_Validator::validate_property ( const PortableGroup::Properties props  )  [virtual]

Validate the given properties. Throw an exception when the first invalid property is encountered. The remaining properties will not be validated.

Definition at line 28 of file PG_Default_Property_Validator.cpp.

{
  const CORBA::ULong len = props.length ();

  for (CORBA::ULong i = 0; i < len; ++i)
    {
      const PortableGroup::Property & property = props[i];

      if (property.nam == this->membership_)
        {
          PortableGroup::MembershipStyleValue membership;
          if (!(property.val >>= membership)
              || (membership != PortableGroup::MEMB_APP_CTRL
                  && membership != PortableGroup::MEMB_INF_CTRL))
            throw PortableGroup::InvalidProperty (property.nam, property.val);
        }
      else if (property.nam == this->factories_)
        {
          const PortableGroup::FactoriesValue * factories;
          if (!(property.val >>= factories))
            throw PortableGroup::InvalidProperty (property.nam, property.val);
          else
            {
              const CORBA::ULong flen = factories->length ();

              if (flen == 0)
                throw PortableGroup::InvalidProperty (
                  property.nam,
                  property.val);

              for (CORBA::ULong j = 0; j < flen; ++j)
                {
                  const PortableGroup::FactoryInfo & factory_info =
                    (*factories)[j];

                  if (CORBA::is_nil (factory_info.the_factory.in ())
                      || factory_info.the_location.length () == 0)
                    throw PortableGroup::InvalidProperty (
                      property.nam,
                      property.val);
                }
            }
        }
    }
}


Member Data Documentation

Definition at line 69 of file PG_Default_Property_Validator.h.

Definition at line 68 of file PG_Default_Property_Validator.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines