Go to the documentation of this file.00001 #include "tao/IORManipulation/IORManipulation.h"
00002
00003 #include "tao/MProfile.h"
00004 #include "tao/Profile.h"
00005 #include "tao/Stub.h"
00006 #include "tao/ORB_Core.h"
00007
00008 #include "ace/Auto_Ptr.h"
00009 #include "ace/OS_NS_string.h"
00010
00011
00012 ACE_RCSID (IORManipulation,
00013 IORManipulation,
00014 "$Id: IORManipulation.cpp 79949 2007-11-07 15:33:49Z johnnyw $")
00015
00016 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00017
00018 TAO_IOR_Manipulation_impl::TAO_IOR_Manipulation_impl (void)
00019 {
00020 }
00021
00022 TAO_IOR_Manipulation_impl::~TAO_IOR_Manipulation_impl (void)
00023 {
00024 }
00025
00026 CORBA::Object_ptr
00027 TAO_IOR_Manipulation_impl::merge_iors (
00028 const TAO_IOP::TAO_IOR_Manipulation::IORList & iors)
00029 {
00030
00031
00032
00033
00034
00035
00036
00037 CORBA::ULong i, count=0;
00038 for (i = 0; i < iors.length (); i++)
00039 {
00040 count += iors[i]->_stubobj ()->base_profiles ().profile_count ();
00041 }
00042
00043
00044 if (count == 0)
00045 throw TAO_IOP::EmptyProfileList ();
00046
00047
00048 TAO_MProfile Merged_Profiles (count);
00049
00050
00051
00052
00053 auto_ptr<TAO_MProfile> tmp_pfiles (iors[0]->_stubobj ()->make_profiles ());
00054 if (Merged_Profiles.add_profiles (tmp_pfiles.get ())< 0)
00055 throw TAO_IOP::Invalid_IOR ();
00056 CORBA::String_var id =
00057 CORBA::string_dup (iors[0]->_stubobj ()->type_id.in ());
00058
00059 for (i = 1; i < iors.length () ; i++)
00060 {
00061
00062
00063 ACE_AUTO_PTR_RESET (tmp_pfiles,
00064 iors[i]->_stubobj ()->make_profiles (),
00065 TAO_MProfile);
00066
00067
00068
00069 if (Merged_Profiles.is_equivalent (tmp_pfiles.get ()))
00070 throw TAO_IOP::Duplicate ();
00071
00072
00073 if (id.in () && iors[i]->_stubobj ()->type_id.in () &&
00074 ACE_OS::strcmp (id.in (), iors[i]->_stubobj ()->type_id.in ()))
00075 throw TAO_IOP::Invalid_IOR ();
00076
00077
00078 if (Merged_Profiles.add_profiles (tmp_pfiles.get ()) < 0)
00079 throw TAO_IOP::Invalid_IOR ();
00080
00081 }
00082
00083
00084
00085
00086 TAO_ORB_Core *orb_core = TAO_ORB_Core_instance ();
00087
00088 TAO_Stub *stub = orb_core->create_stub (id.in (),
00089 Merged_Profiles);
00090
00091
00092
00093 TAO_Stub_Auto_Ptr safe_stub (stub);
00094
00095
00096 CORBA::Object_ptr temp_obj = CORBA::Object::_nil ();
00097 ACE_NEW_THROW_EX (temp_obj,
00098 CORBA::Object (safe_stub.get ()),
00099 CORBA::NO_MEMORY ());
00100
00101 CORBA::Object_var new_obj = temp_obj;
00102
00103
00104
00105 if (CORBA::is_nil (new_obj.in ()))
00106 {
00107 throw TAO_IOP::Invalid_IOR ();
00108 }
00109
00110
00111
00112 stub = safe_stub.release ();
00113
00114 return new_obj._retn ();
00115 }
00116
00117 CORBA::Object_ptr
00118 TAO_IOR_Manipulation_impl::add_profiles (
00119 CORBA::Object_ptr ior1,
00120 CORBA::Object_ptr ior2)
00121 {
00122
00123
00124 CORBA::Object_ptr buffer [2];
00125 buffer [0] = ior1;
00126 buffer [1] = ior2;
00127 TAO_IOP::TAO_IOR_Manipulation::IORList iors (2, 2, buffer, 0);
00128 return this->merge_iors (iors);
00129 }
00130
00131 CORBA::Object_ptr
00132 TAO_IOR_Manipulation_impl::remove_profiles (
00133 CORBA::Object_ptr group,
00134 CORBA::Object_ptr ior2
00135 )
00136 {
00137
00138 CORBA::String_var id =
00139 CORBA::string_dup (group->_stubobj ()->type_id.in ());
00140 if (id.in () && ior2->_stubobj ()->type_id.in () &&
00141 ACE_OS::strcmp (id.in (), ior2->_stubobj ()->type_id.in ()))
00142 throw TAO_IOP::Invalid_IOR ();
00143
00144
00145 CORBA::ULong count = group->_stubobj ()->base_profiles ().profile_count ();
00146
00147
00148 if (count == 0 ||
00149 ior2->_stubobj ()->base_profiles ().profile_count () == 0)
00150 throw TAO_IOP::EmptyProfileList ();
00151
00152
00153 TAO_MProfile Diff_Profiles (count);
00154
00155 auto_ptr<TAO_MProfile> tmp_pfiles (group->_stubobj ()->make_profiles ());
00156 if (Diff_Profiles.add_profiles (tmp_pfiles.get ()) < 0)
00157 throw TAO_IOP::Invalid_IOR ();
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168 TAO_ORB_Core *orb_core = TAO_ORB_Core_instance ();
00169
00170 TAO_Stub *stub = orb_core->create_stub (id.in (),
00171 Diff_Profiles
00172 );
00173
00174
00175
00176 TAO_Stub_Auto_Ptr safe_stub (stub);
00177
00178
00179 CORBA::Object_ptr temp_obj = CORBA::Object::_nil ();
00180 ACE_NEW_THROW_EX (temp_obj,
00181 CORBA::Object (safe_stub.get ()),
00182 CORBA::NO_MEMORY ());
00183
00184 CORBA::Object_var new_obj = temp_obj;
00185
00186
00187
00188 stub = safe_stub.release ();
00189
00190
00191 if (CORBA::is_nil (new_obj.in ()))
00192 {
00193 throw TAO_IOP::Invalid_IOR ();
00194 }
00195
00196
00197
00198 ACE_AUTO_PTR_RESET (tmp_pfiles,
00199 ior2->_stubobj ()->make_profiles (),
00200 TAO_MProfile);
00201
00202 TAO_MProfile& mp = stub -> base_profiles();
00203 if (mp.remove_profiles (tmp_pfiles.get ()) < 0)
00204 throw TAO_IOP::NotFound ();
00205
00206
00207
00208
00209 return new_obj._retn ();
00210 }
00211
00212 CORBA::Boolean
00213 TAO_IOR_Manipulation_impl::set_property (
00214 TAO_IOP::TAO_IOR_Property_ptr prop,
00215 CORBA::Object_ptr group)
00216 {
00217
00218 if (group->_stubobj ()->base_profiles ().profile_count () == 0)
00219 throw TAO_IOP::Invalid_IOR ();
00220
00221
00222 return prop->set_property (group);
00223 }
00224
00225
00226 CORBA::Boolean
00227 TAO_IOR_Manipulation_impl::set_primary (
00228 TAO_IOP::TAO_IOR_Property_ptr prop,
00229 CORBA::Object_ptr new_primary,
00230 CORBA::Object_ptr group)
00231 {
00232
00233 if (group->_stubobj ()->base_profiles ().profile_count () == 0)
00234 throw TAO_IOP::Invalid_IOR ();
00235
00236
00237
00238
00239
00240
00241
00242 return prop->set_primary (new_primary, group);
00243 }
00244
00245 CORBA::Object_ptr
00246 TAO_IOR_Manipulation_impl::get_primary (
00247 TAO_IOP::TAO_IOR_Property_ptr prop,
00248 CORBA::Object_ptr group)
00249 {
00250
00251 if (group->_stubobj ()->base_profiles ().profile_count () == 0)
00252 throw TAO_IOP::NotFound ();
00253
00254
00255
00256
00257
00258 return prop->get_primary (group);
00259 }
00260
00261 CORBA::Boolean
00262 TAO_IOR_Manipulation_impl::is_primary_set (
00263 TAO_IOP::TAO_IOR_Property_ptr prop,
00264 CORBA::Object_ptr group)
00265 {
00266 return prop->is_primary_set (group);
00267 }
00268
00269 CORBA::Boolean
00270 TAO_IOR_Manipulation_impl:: remove_primary_tag (
00271 TAO_IOP::TAO_IOR_Property_ptr prop,
00272 CORBA::Object_ptr group)
00273 {
00274 return prop->remove_primary_tag (group);
00275 }
00276
00277 CORBA::ULong
00278 TAO_IOR_Manipulation_impl::is_in_ior (
00279 CORBA::Object_ptr ior1,
00280 CORBA::Object_ptr ior2)
00281 {
00282 CORBA::ULong count = 0;
00283 TAO_Profile *pfile1 = 0, *pfile2 = 0;
00284 auto_ptr<TAO_MProfile> tmp_pfiles1 (ior1->_stubobj ()->make_profiles ());
00285 auto_ptr<TAO_MProfile> tmp_pfiles2 (ior2->_stubobj ()->make_profiles ());
00286
00287 tmp_pfiles1->rewind ();
00288 while ((pfile1 = tmp_pfiles1->get_next ()) > 0)
00289 {
00290 tmp_pfiles2->rewind ();
00291 while ((pfile2 = tmp_pfiles2->get_next ()) > 0)
00292 {
00293 if (pfile1->is_equivalent (pfile2))
00294 ++count;
00295 }
00296 }
00297
00298 if (count == 0)
00299 throw TAO_IOP::NotFound ();
00300
00301 return count;
00302 }
00303
00304 CORBA::ULong
00305 TAO_IOR_Manipulation_impl::get_profile_count (CORBA::Object_ptr group)
00306 {
00307 CORBA::ULong const count = group->_stubobj ()->base_profiles ().profile_count ();
00308
00309 if (count == 0)
00310 throw TAO_IOP::EmptyProfileList ();
00311
00312 return count;
00313 }
00314
00315 TAO_END_VERSIONED_NAMESPACE_DECL