TAO_Offer_Modifier Class Reference

This class deletes, modifies, and adds properties to a given offer according to the rules of the modify method on the Register interface. More...

#include <Trader_Utils.h>

Collaboration diagram for TAO_Offer_Modifier:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 TAO_Offer_Modifier (const char *type, const CosTradingRepos::ServiceTypeRepository::TypeStruct &type_struct, CosTrading::Offer *offer)
 ~TAO_Offer_Modifier (void)
void delete_properties (const CosTrading::PropertyNameSeq &deletes)
void merge_properties (const CosTrading::PropertySeq &modifies)
void affect_change (const CosTrading::PropertySeq &modifies)
 Return a reference to the Offer with the changes affected.

Private Types

typedef ACE_Hash_Map_Manager_Ex<
CORBA::String_var, CosTrading::Property *,
ACE_Hash< CORBA::String_var >,
ACE_Equal_To< CORBA::String_var >,
ACE_Null_Mutex
Property_Table

Private Member Functions

 TAO_Offer_Modifier (const TAO_Offer_Modifier &)
TAO_Offer_Modifieroperator= (const TAO_Offer_Modifier &)

Private Attributes

const char * type_
 The type of the offer.
Property_Table props_
 The map of properties in the offer.
TAO_Typecode_Table prop_types_
 Table of property types.
TAO_String_Set readonly_
TAO_String_Set mandatory_
CosTrading::Offeroffer_
 A reference to the offer undergoing change.

Detailed Description

This class deletes, modifies, and adds properties to a given offer according to the rules of the modify method on the Register interface.

Definition at line 546 of file Trader_Utils.h.


Member Typedef Documentation

typedef ACE_Hash_Map_Manager_Ex<CORBA::String_var, CosTrading::Property *, ACE_Hash<CORBA::String_var>, ACE_Equal_To<CORBA::String_var>, ACE_Null_Mutex> TAO_Offer_Modifier::Property_Table [private]

Definition at line 583 of file Trader_Utils.h.


Constructor & Destructor Documentation

TAO_Offer_Modifier::TAO_Offer_Modifier ( const char *  type,
const CosTradingRepos::ServiceTypeRepository::TypeStruct type_struct,
CosTrading::Offer offer 
)

Modify an <offer> of type <type>, whose properties are described by <type_struct>

Definition at line 978 of file Trader_Utils.cpp.

References ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::bind(), ACE_Unbounded_Set_Ex< T, C >::insert(), mandatory_, offer_, CosTradingRepos::ServiceTypeRepository::PROP_MANDATORY, CosTradingRepos::ServiceTypeRepository::PROP_READONLY, prop_types_, CosTrading::Offer::properties, CosTradingRepos::ServiceTypeRepository::TypeStruct::props, props_, and readonly_.

00981   : type_ (type_name),
00982     offer_ (offer)
00983 {
00984   const CosTradingRepos::ServiceTypeRepository::PropStructSeq&
00985     pstructs = type_struct.props;
00986   CosTrading::PropertySeq& prop_seq = this->offer_->properties;
00987   CORBA::ULong pstructs_length = pstructs.length (),
00988     props_length = prop_seq.length (),
00989     i = 0;
00990 
00991   // Create a mapping of property names to their types.
00992   for (i = 0; i < pstructs_length; i++)
00993     {
00994       CORBA::String_var prop_name = pstructs[i].name.in ();
00995       CORBA::TypeCode_ptr type_code =
00996         CORBA::TypeCode::_duplicate (pstructs[i].value_type.in ());
00997       this->prop_types_.bind (prop_name, type_code);
00998     }
00999 
01000   // Separate the type defined properties into mandatory and readonly
01001   for (i = 0; i < pstructs_length; i++)
01002     {
01003       const char* pname = pstructs[i].name;
01004 
01005       if (pstructs[i].mode ==
01006           CosTradingRepos::ServiceTypeRepository::PROP_MANDATORY)
01007         {
01008           CORBA::String_var prop_name (pname);
01009           this->mandatory_.insert (prop_name);
01010         }
01011       else if (pstructs[i].mode ==
01012                CosTradingRepos::ServiceTypeRepository::PROP_READONLY)
01013         {
01014           CORBA::String_var prop_name (pname);
01015           this->readonly_.insert (prop_name);
01016         }
01017     }
01018 
01019   // Insert the indices of the offer properties into a map.
01020   for (i = 0; i < props_length; i++)
01021     {
01022       CORBA::String_var prop_name =
01023         static_cast<const char*> (prop_seq[i].name);
01024       this->props_.bind (prop_name, &prop_seq[i]);
01025     }
01026 }

TAO_Offer_Modifier::~TAO_Offer_Modifier ( void   ) 

Definition at line 1028 of file Trader_Utils.cpp.

References CORBA::release().

01029 {
01030   for (TAO_Typecode_Table::iterator type_iter (this->prop_types_);
01031        ! type_iter.done ();
01032        type_iter++)
01033     {
01034       CORBA::TypeCode_ptr corba_type = (*type_iter).int_id_;
01035       CORBA::release (corba_type);
01036     }
01037 }

TAO_Offer_Modifier::TAO_Offer_Modifier ( const TAO_Offer_Modifier  )  [private]


Member Function Documentation

void TAO_Offer_Modifier::affect_change ( const CosTrading::PropertySeq modifies  ) 

Return a reference to the Offer with the changes affected.

Definition at line 1134 of file Trader_Utils.cpp.

References ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::current_size(), offer_, CosTrading::Offer::properties, and props_.

01135 {
01136   // Create a new property list reflecting the deletes, modifies, and
01137   // add operations performed, and place this property list in the
01138   // offer.
01139 
01140   // Merge these properties with the original set.
01141   CORBA::ULong i = 0,
01142     merge_length = modifies.length ();
01143 
01144   for (i = 0; i < merge_length; i++)
01145     {
01146       Property_Table::ENTRY* entry = 0;
01147       CORBA::String_var prop_name = modifies[i].name.in ();
01148 
01149       CosTrading::Property* prop =
01150         const_cast<CosTrading::Property*> (&modifies[i]);
01151       if (this->props_.bind (prop_name, prop, entry) == 1)
01152         // We need to rebind here.
01153         entry->int_id_ = prop;
01154     }
01155 
01156   CORBA::ULong num_modified = 0,
01157     original_length = this->offer_->properties.length (),
01158     total_length = static_cast<CORBA::ULong> (this->props_.current_size ());
01159 
01160   // Scrap the existing property sequence and begin a new one
01161   CosTrading::PropertySeq prop_seq (total_length);
01162   //  this->offer_->properties.length (total_length);
01163 
01164   // Copy in the unaffected and modified props into the offer,
01165   // excluding those that were deleted. Let's try and retain their
01166   // relative ordering.
01167   for (i = 0; i < original_length; i++)
01168     {
01169       CosTrading::Property* prop_value = 0;
01170       const char* name = this->offer_->properties[i].name;
01171       CORBA::String_var prop_name (name);
01172       if (this->props_.unbind (prop_name, prop_value) == 0)
01173         prop_seq[num_modified++] = *prop_value;
01174     }
01175 
01176   for (i = 0; i < merge_length; i++)
01177     {
01178       CosTrading::Property* prop_value = 0;
01179       const char* name = modifies[i].name;
01180       CORBA::String_var prop_name (name);
01181       if (this->props_.unbind (prop_name, prop_value) == 0)
01182         prop_seq[num_modified++] = *prop_value;
01183     }
01184 
01185   this->offer_->properties.length (total_length);
01186   for (i = 0; i < total_length; i++)
01187     this->offer_->properties[i] = prop_seq[i];
01188   // Free the old, orphaned sequence.
01189   //  CosTrading::PropertySeq::freebuf (prop_buf);
01190 }

void TAO_Offer_Modifier::delete_properties ( const CosTrading::PropertyNameSeq deletes  ) 

Delete the properties whose names were given to the constructor. Ensure we don't delete mandatory properties.

Definition at line 1041 of file Trader_Utils.cpp.

References ACE_Unbounded_Set_Ex< T, C >::insert(), TAO_Trader_Base::is_valid_property_name(), props_, and ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::unbind().

01042 {
01043   // Validate that the listed property names can be deleted
01044   CORBA::ULong i = 0,
01045     length = deletes.length ();
01046   TAO_String_Set delete_me;
01047 
01048   for (i = 0; i < length; i++)
01049     {
01050       const char* dname = static_cast<const char*> (deletes[i]);
01051       if (! TAO_Trader_Base::is_valid_property_name (dname))
01052         throw CosTrading::IllegalPropertyName (dname);
01053       else
01054         {
01055           CORBA::String_var prop_name (dname);
01056           if (this->mandatory_.find (prop_name) == 0)
01057             throw CosTrading::Register::MandatoryProperty (this->type_, dname);
01058           else if (delete_me.insert (prop_name) == 1)
01059             throw CosTrading::DuplicatePropertyName (dname);
01060           else if (this->props_.find (prop_name) == -1)
01061             throw CosTrading::Register::UnknownPropertyName (dname);
01062         }
01063     }
01064 
01065   // Delete those properties from the offer.
01066   for (i = 0; i < length; i++)
01067     {
01068       CORBA::String_var prop_name =
01069         static_cast<const char *> (deletes[i]);
01070       this->props_.unbind (prop_name);
01071     }
01072 }

void TAO_Offer_Modifier::merge_properties ( const CosTrading::PropertySeq modifies  ) 

Copy to the destination the union of the source and destination properties. In the case of duplicate properties, update the destination with the source's value. This class claims the memory in the modifies sequence.

Definition at line 1076 of file Trader_Utils.cpp.

References ACE_Unbounded_Set_Ex< T, C >::insert(), TAO_Property_Evaluator::is_dynamic_property(), TAO_Trader_Base::is_valid_property_name(), and TAO_Property_Evaluator::property_type().

01077 {
01078   int i = 0, length = 0;
01079   TAO_String_Set modify_me;
01080 
01081   // Ensure that the proposed changes aren't to readonly properties or
01082   // otherwise invalid.
01083   TAO_Property_Evaluator prop_eval (modifies);
01084   for (i = 0, length = modifies.length (); i < length; i++)
01085     {
01086       const char* mname = modifies[i].name;
01087       if (TAO_Trader_Base::is_valid_property_name (mname))
01088         {
01089           CORBA::String_var prop_name (mname);
01090           if (this->readonly_.find (prop_name) == 0)
01091             {
01092               // Can't assign a dynamic property to a property with
01093               // readonly mode, and can't reassign a readonly property.
01094               if (prop_eval.is_dynamic_property (i))
01095                 throw CosTrading::ReadonlyDynamicProperty (this->type_, mname);
01096               else if (this->props_.find (prop_name) == 0)
01097                 throw CosTrading::Register::ReadonlyProperty (
01098                   this->type_,
01099                   mname);
01100             }
01101 
01102           // Validate the property type if the property is defined in
01103           // the service type description.
01104           CORBA::TypeCode_ptr type_def = 0;
01105           if (this->prop_types_.find (prop_name, type_def) == 0)
01106             {
01107               CORBA::TypeCode_var prop_type = prop_eval.property_type (i);
01108 
01109               // @@ Frank: This code used to have this comment and line
01110               //    of code before I fixed the "ACE_TRY" fuzz warning here.
01111               // @@ Seth, are we trying to ignore the exception here?
01112               // CORBA::Environment ACE_TRY_ENV;
01113               // @@ Frank: It seems clear that this is not going to work as
01114               // expected.  Is the purpose to ignore any exceptions from
01115               // equal ()?  For now, exceptions are returned since this
01116               // seemed "safest".
01117 
01118               CORBA::Boolean td_equal =
01119                 type_def->equal (prop_type.in ());
01120 
01121               if (!td_equal)
01122                 throw CosTrading::PropertyTypeMismatch (mname, modifies[i]);
01123             }
01124 
01125           if (modify_me.insert (prop_name) == 1)
01126             throw CosTrading::DuplicatePropertyName (mname);
01127         }
01128       else
01129         throw CosTrading::IllegalPropertyName (mname);
01130     }
01131 }

TAO_Offer_Modifier& TAO_Offer_Modifier::operator= ( const TAO_Offer_Modifier  )  [private]


Member Data Documentation

TAO_String_Set TAO_Offer_Modifier::mandatory_ [private]

Definition at line 597 of file Trader_Utils.h.

Referenced by TAO_Offer_Modifier().

CosTrading::Offer* TAO_Offer_Modifier::offer_ [private]

A reference to the offer undergoing change.

Definition at line 600 of file Trader_Utils.h.

Referenced by affect_change(), and TAO_Offer_Modifier().

TAO_Typecode_Table TAO_Offer_Modifier::prop_types_ [private]

Table of property types.

Definition at line 592 of file Trader_Utils.h.

Referenced by TAO_Offer_Modifier().

Property_Table TAO_Offer_Modifier::props_ [private]

The map of properties in the offer.

Definition at line 589 of file Trader_Utils.h.

Referenced by affect_change(), delete_properties(), and TAO_Offer_Modifier().

TAO_String_Set TAO_Offer_Modifier::readonly_ [private]

The set of readonly and mandatory property names in the offer's type.

Definition at line 596 of file Trader_Utils.h.

Referenced by TAO_Offer_Modifier().

const char* TAO_Offer_Modifier::type_ [private]

The type of the offer.

Definition at line 586 of file Trader_Utils.h.


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:49:33 2010 for TAO_CosTrader by  doxygen 1.4.7