00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file PG_Properties_Support.h 00006 * 00007 * $Id: PG_Properties_Support.h 77001 2007-02-12 07:54:49Z johnnyw $ 00008 * 00009 * This file declares classes to help manage the PortableGroup::Properties 00010 * It serves roughly the same purpose as PG_PropertiesManager, but takes a 00011 * different approach that suits the needs of FT CORBA. 00012 * It would be possible to replace PG_PropertiesManager, or implement it in 00013 * terms of PG_Properties_Support at some time in the future. 00014 * 00015 * @author Dale Wilson <wilson_d@ociweb.com> 00016 */ 00017 //============================================================================= 00018 #ifndef TAO_PG_PROPERTIES_SUPPORT_H 00019 #define TAO_PG_PROPERTIES_SUPPORT_H 00020 00021 #include "orbsvcs/PortableGroup/PG_Property_Set.h" 00022 #include "orbsvcs/PortableGroup/portablegroup_export.h" 00023 00024 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00025 00026 namespace TAO 00027 { 00028 /** 00029 * This Properties Support object manages Property Sets (TAO::PG_Property_Set). 00030 * 00031 * One set, default_properties_, 00032 * acts as a "global" default set of properties. 00033 * 00034 * The collection, properties_map_, contains a set of properties for each 00035 * PortableGroup::type_id. The default set acts as a "parent" for each of 00036 * these type_id sets. 00037 * 00038 * Expected use: When an object group is created that implements the interface 00039 * identified by type_id, the corresponding typed_id propery set acts as a 00040 * parent to the Property set contained in the PG_Object_Group. 00041 * 00042 * This heirarchy of property sets provides the correct property behavior. A 00043 * request for a propery to an ObjectGroup will be satisfied from: 00044 * by the object group group property set, or 00045 * the typed_id property set, or 00046 * the default property set, or 00047 * the request will fail.. 00048 * 00049 * Note that changes to type_id or default properties will be visible 00050 * immediately at the ObjectGroup level. 00051 */ 00052 00053 class TAO_PortableGroup_Export PG_Properties_Support 00054 { 00055 typedef ACE_Hash_Map_Manager< 00056 ACE_CString, 00057 ::TAO::PG_Property_Set *, 00058 TAO_SYNCH_MUTEX> Properties_Map; 00059 typedef ACE_Hash_Map_Iterator< 00060 ACE_CString, 00061 ::TAO::PG_Property_Set *, 00062 TAO_SYNCH_MUTEX> Properties_Map_Iterator; 00063 00064 public: 00065 PG_Properties_Support (); 00066 ~PG_Properties_Support (); 00067 00068 /** 00069 * Set a single default property. 00070 * Overwriting any value previously set for that property. 00071 * Leaving all other properties untouched. 00072 * @param name the name of the property to set 00073 * @value an Any containing the value. 00074 */ 00075 void set_default_property (const char * name, 00076 const PortableGroup::Value & value); 00077 00078 /** 00079 * Update the default property set. 00080 * 00081 * Properties that appear in props are replaced in or added to the default 00082 * property set. Properties that do not appear in props are unchanged. 00083 * 00084 * @param props the set of properties to update the defaults. 00085 */ 00086 void set_default_properties (const PortableGroup::Properties & props); 00087 00088 /** 00089 * Export the default properties in PortableGroup::Properties format. 00090 * 00091 * This produces the properties in a format suitable for use across 00092 * a CORBA interface. 00093 * The caller owns the resulting Properties and must release it to avoid 00094 * resource leaks. 00095 * @returns a newly allocated PortableGroup::Properties. 00096 */ 00097 PortableGroup::Properties * get_default_properties (void); 00098 00099 /** 00100 * Undefine default properties that appear in props. 00101 * 00102 * Properties that are defined in props are removed from the default 00103 * property set. Removal is done by name. The property values do not 00104 * have to match. There is no penalty for attempting to remove a property 00105 * that does not exist. 00106 * @param props a set of propertys to be removed by name. 00107 */ 00108 void remove_default_properties ( 00109 const PortableGroup::Properties & props); 00110 00111 /** 00112 * Override or define properties associated with a type_id. 00113 * 00114 * If a property set does not exist for type_id, a new one will be created. 00115 * Any property included in overrides will be set or replaced in the type_id 00116 * property set. Any property not in overrides will be unchanged. 00117 * 00118 * Contrary to the "throws" specification, this method does not attempt 00119 * to validate the properties because doing so would unnecessarily constrain 00120 * the uses to which this class could be put (although one could strategize the 00121 * validation.) 00122 */ 00123 void set_type_properties ( 00124 const char *type_id, 00125 const PortableGroup::Properties & overrides); 00126 00127 /** 00128 * Export the property set in a PortableGroup::Properties format. 00129 * 00130 * This produces the properties associated with a type_id -- including 00131 * any default properties that have not been overridden at the type_id level 00132 * in a format suitable for use across a CORBA interface. 00133 * 00134 * The caller owns the resulting Properties and must release it to avoid 00135 * resource leaks. 00136 * 00137 * Compare this method to find_typeid_properties which returns a pointer 00138 * to the internal representation of the properties in TAO::PG_Property_Set 00139 * format. This is more efficient, but suitable only for internal use. 00140 * 00141 * @param type_id identifies the set of properties to be exported. 00142 * @returns a newly allocated PortableGroup::Properties that must be released by the caller. 00143 */ 00144 PortableGroup::Properties * get_type_properties ( 00145 const char *type_id); 00146 00147 /** 00148 * Export the property set in a PortableGroup::Properties format. 00149 * 00150 * This method is intended to provide a parent 00151 * for the property set in a newly-created Object Group of the given 00152 * type_id. 00153 * 00154 * Callers who intend to send the property set across a CORBA interface 00155 * should use the get_type_properties method. 00156 * 00157 * @param type_id identifies the set of properties to be found. 00158 * @returns a pointer to a Property_Set owned by this Properties_Support object. 00159 */ 00160 TAO::PG_Property_Set * find_typeid_properties ( 00161 const char *type_id); 00162 00163 /** 00164 * Undefine default properties that appear in props. 00165 * 00166 * Properties that are defined in props are removed from the type_id 00167 * property set. Removal is done by name. The property values do not 00168 * have to match. There is no penalty for attempting to remove a property 00169 * that does not exist. 00170 * @param props a set of propertys to be removed by name from the type_id set. 00171 */ 00172 void remove_type_properties ( 00173 const char *type_id, 00174 const PortableGroup::Properties & props); 00175 00176 /////////////// 00177 // Data Members 00178 private: 00179 /** 00180 * Protect internal state. 00181 */ 00182 TAO_SYNCH_MUTEX internals_; 00183 00184 /// The default property set. 00185 TAO::PG_Property_Set default_properties_; 00186 00187 /// A collection of property sets indexed by type_id. 00188 Properties_Map properties_map_; 00189 }; 00190 } //namespace TAO_PG 00191 00192 TAO_END_VERSIONED_NAMESPACE_DECL 00193 00194 #endif // TAO_PG_PROPERTIES_SUPPORT_H