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 "IORManipulation.cpp,v 1.22 2006/04/19 09:38:39 jwillemsen Exp")
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 ACE_ENV_ARG_DECL)
00030 ACE_THROW_SPEC ((CORBA::SystemException,
00031 TAO_IOP::EmptyProfileList,
00032 TAO_IOP::Duplicate,
00033 TAO_IOP::Invalid_IOR))
00034 {
00035
00036
00037
00038
00039
00040
00041
00042 CORBA::ULong i, count=0;
00043 for (i = 0; i < iors.length (); i++)
00044 {
00045 count += iors[i]->_stubobj ()->base_profiles ().profile_count ();
00046 }
00047
00048
00049 if (count == 0)
00050 ACE_THROW_RETURN (TAO_IOP::EmptyProfileList (),
00051 CORBA::Object::_nil ());
00052
00053
00054 TAO_MProfile Merged_Profiles (count);
00055
00056
00057
00058
00059 auto_ptr<TAO_MProfile> tmp_pfiles (iors[0]->_stubobj ()->make_profiles ());
00060 if (Merged_Profiles.add_profiles (tmp_pfiles.get ())< 0)
00061 ACE_THROW_RETURN (TAO_IOP::Invalid_IOR (),
00062 CORBA::Object::_nil ());
00063 CORBA::String_var id =
00064 CORBA::string_dup (iors[0]->_stubobj ()->type_id.in ());
00065
00066 for (i = 1; i < iors.length () ; i++)
00067 {
00068
00069
00070 ACE_AUTO_PTR_RESET (tmp_pfiles,
00071 iors[i]->_stubobj ()->make_profiles (),
00072 TAO_MProfile);
00073
00074
00075
00076 if (Merged_Profiles.is_equivalent (tmp_pfiles.get ()))
00077 ACE_THROW_RETURN (TAO_IOP::Duplicate (),
00078 CORBA::Object::_nil ());
00079
00080
00081 if (id.in () && iors[i]->_stubobj ()->type_id.in () &&
00082 ACE_OS::strcmp (id.in (), iors[i]->_stubobj ()->type_id.in ()))
00083 ACE_THROW_RETURN (TAO_IOP::Invalid_IOR (),
00084 CORBA::Object::_nil ());
00085
00086
00087 if (Merged_Profiles.add_profiles (tmp_pfiles.get ()) < 0)
00088 ACE_THROW_RETURN (TAO_IOP::Invalid_IOR (),
00089 CORBA::Object::_nil ());
00090
00091 }
00092
00093
00094
00095
00096 TAO_ORB_Core *orb_core = TAO_ORB_Core_instance ();
00097
00098 TAO_Stub *stub = orb_core->create_stub (id.in (),
00099 Merged_Profiles
00100 ACE_ENV_ARG_PARAMETER);
00101 ACE_CHECK_RETURN (CORBA::Object::_nil ());
00102
00103
00104
00105 TAO_Stub_Auto_Ptr safe_stub (stub);
00106
00107
00108 CORBA::Object_ptr temp_obj = CORBA::Object::_nil ();
00109 ACE_NEW_THROW_EX (temp_obj,
00110 CORBA::Object (safe_stub.get ()),
00111 CORBA::NO_MEMORY ());
00112
00113 CORBA::Object_var new_obj = temp_obj;
00114
00115 ACE_CHECK_RETURN (CORBA::Object::_nil ());
00116
00117
00118 if (CORBA::is_nil (new_obj.in ()))
00119 {
00120 ACE_THROW_RETURN (TAO_IOP::Invalid_IOR (),
00121 CORBA::Object::_nil ());
00122 }
00123
00124
00125
00126 stub = safe_stub.release ();
00127
00128 return new_obj._retn ();
00129 }
00130
00131 CORBA::Object_ptr
00132 TAO_IOR_Manipulation_impl::add_profiles (
00133 CORBA::Object_ptr ior1,
00134 CORBA::Object_ptr ior2
00135 ACE_ENV_ARG_DECL)
00136 ACE_THROW_SPEC ((CORBA::SystemException,
00137 TAO_IOP::EmptyProfileList,
00138 TAO_IOP::Duplicate,
00139 TAO_IOP::Invalid_IOR))
00140 {
00141
00142
00143 CORBA::Object_ptr buffer [2];
00144 buffer [0] = ior1;
00145 buffer [1] = ior2;
00146 TAO_IOP::TAO_IOR_Manipulation::IORList iors (2, 2, buffer, 0);
00147 return this->merge_iors (iors ACE_ENV_ARG_PARAMETER);
00148 }
00149
00150 CORBA::Object_ptr
00151 TAO_IOR_Manipulation_impl::remove_profiles (
00152 CORBA::Object_ptr group,
00153 CORBA::Object_ptr ior2
00154 ACE_ENV_ARG_DECL)
00155 ACE_THROW_SPEC ((
00156 CORBA::SystemException,
00157 TAO_IOP::Invalid_IOR,
00158 TAO_IOP::EmptyProfileList,
00159 TAO_IOP::NotFound
00160 ))
00161 {
00162
00163 CORBA::String_var id =
00164 CORBA::string_dup (group->_stubobj ()->type_id.in ());
00165 if (id.in () && ior2->_stubobj ()->type_id.in () &&
00166 ACE_OS::strcmp (id.in (), ior2->_stubobj ()->type_id.in ()))
00167 ACE_THROW_RETURN (TAO_IOP::Invalid_IOR (),
00168 CORBA::Object::_nil ());
00169
00170
00171 CORBA::ULong count = group->_stubobj ()->base_profiles ().profile_count ();
00172
00173
00174 if (count == 0 ||
00175 ior2->_stubobj ()->base_profiles ().profile_count () == 0)
00176 ACE_THROW_RETURN (TAO_IOP::EmptyProfileList (),
00177 CORBA::Object::_nil ());
00178
00179
00180 TAO_MProfile Diff_Profiles (count);
00181
00182 auto_ptr<TAO_MProfile> tmp_pfiles (group->_stubobj ()->make_profiles ());
00183 if (Diff_Profiles.add_profiles (tmp_pfiles.get ()) < 0)
00184 ACE_THROW_RETURN (TAO_IOP::Invalid_IOR (),
00185 CORBA::Object::_nil ());
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196 TAO_ORB_Core *orb_core = TAO_ORB_Core_instance ();
00197
00198 TAO_Stub *stub = orb_core->create_stub (id.in (),
00199 Diff_Profiles
00200 ACE_ENV_ARG_PARAMETER);
00201 ACE_CHECK_RETURN (CORBA::Object::_nil ());
00202
00203
00204
00205 TAO_Stub_Auto_Ptr safe_stub (stub);
00206
00207
00208 CORBA::Object_ptr temp_obj = CORBA::Object::_nil ();
00209 ACE_NEW_THROW_EX (temp_obj,
00210 CORBA::Object (safe_stub.get ()),
00211 CORBA::NO_MEMORY ());
00212
00213 CORBA::Object_var new_obj = temp_obj;
00214
00215
00216
00217 stub = safe_stub.release ();
00218
00219
00220 if (CORBA::is_nil (new_obj.in ()))
00221 {
00222 ACE_THROW_RETURN (TAO_IOP::Invalid_IOR (),
00223 CORBA::Object::_nil ());
00224 }
00225
00226
00227
00228 ACE_AUTO_PTR_RESET (tmp_pfiles,
00229 ior2->_stubobj ()->make_profiles (),
00230 TAO_MProfile);
00231
00232 TAO_MProfile& mp = stub -> base_profiles();
00233 if (mp.remove_profiles (tmp_pfiles.get ()) < 0)
00234 ACE_THROW_RETURN (TAO_IOP::NotFound (),
00235 CORBA::Object::_nil ());
00236
00237
00238
00239
00240 return new_obj._retn ();
00241 }
00242
00243 CORBA::Boolean
00244 TAO_IOR_Manipulation_impl::set_property (
00245 TAO_IOP::TAO_IOR_Property_ptr prop,
00246 CORBA::Object_ptr group
00247 ACE_ENV_ARG_DECL)
00248 ACE_THROW_SPEC ((CORBA::SystemException,
00249 TAO_IOP::Invalid_IOR,
00250 TAO_IOP::Duplicate))
00251 {
00252
00253 if (group->_stubobj ()->base_profiles ().profile_count () == 0)
00254 ACE_THROW_RETURN (TAO_IOP::Invalid_IOR (),
00255 0);
00256
00257
00258 return prop->set_property (group
00259 ACE_ENV_ARG_PARAMETER);
00260 }
00261
00262
00263 CORBA::Boolean
00264 TAO_IOR_Manipulation_impl::set_primary (
00265 TAO_IOP::TAO_IOR_Property_ptr prop,
00266 CORBA::Object_ptr new_primary,
00267 CORBA::Object_ptr group
00268 ACE_ENV_ARG_DECL)
00269 ACE_THROW_SPEC ((CORBA::SystemException,
00270 TAO_IOP::Invalid_IOR,
00271 TAO_IOP::Duplicate,
00272 TAO_IOP::MultiProfileList))
00273 {
00274
00275 if (group->_stubobj ()->base_profiles ().profile_count () == 0)
00276 ACE_THROW_RETURN (TAO_IOP::Invalid_IOR (),
00277 0);
00278
00279
00280
00281
00282
00283
00284
00285
00286 return prop->set_primary (new_primary,
00287 group
00288 ACE_ENV_ARG_PARAMETER);
00289 }
00290
00291 CORBA::Object_ptr
00292 TAO_IOR_Manipulation_impl::get_primary (
00293 TAO_IOP::TAO_IOR_Property_ptr prop,
00294 CORBA::Object_ptr group
00295 ACE_ENV_ARG_DECL
00296 )
00297 ACE_THROW_SPEC ((
00298 CORBA::SystemException,
00299 TAO_IOP::NotFound
00300 ))
00301 {
00302
00303 if (group->_stubobj ()->base_profiles ().profile_count () == 0)
00304 ACE_THROW_RETURN (TAO_IOP::NotFound (), 0);
00305
00306
00307
00308
00309
00310 return prop->get_primary (group
00311 ACE_ENV_ARG_PARAMETER);
00312 }
00313
00314 CORBA::Boolean
00315 TAO_IOR_Manipulation_impl::is_primary_set (
00316 TAO_IOP::TAO_IOR_Property_ptr prop,
00317 CORBA::Object_ptr group
00318 ACE_ENV_ARG_DECL)
00319 ACE_THROW_SPEC ((CORBA::SystemException))
00320 {
00321 return prop->is_primary_set (group ACE_ENV_ARG_PARAMETER);
00322 }
00323
00324 CORBA::Boolean
00325 TAO_IOR_Manipulation_impl:: remove_primary_tag (
00326 TAO_IOP::TAO_IOR_Property_ptr prop,
00327 CORBA::Object_ptr group
00328 ACE_ENV_ARG_DECL)
00329 ACE_THROW_SPEC ((CORBA::SystemException))
00330 {
00331 return prop->remove_primary_tag (group ACE_ENV_ARG_PARAMETER);
00332 }
00333
00334 CORBA::ULong
00335 TAO_IOR_Manipulation_impl::is_in_ior (
00336 CORBA::Object_ptr ior1,
00337 CORBA::Object_ptr ior2
00338 ACE_ENV_ARG_DECL)
00339 ACE_THROW_SPEC ((CORBA::SystemException,
00340 TAO_IOP::NotFound))
00341 {
00342 CORBA::ULong count = 0;
00343 TAO_Profile *pfile1, *pfile2;
00344 auto_ptr<TAO_MProfile> tmp_pfiles1 (ior1->_stubobj ()->make_profiles ());
00345 auto_ptr<TAO_MProfile> tmp_pfiles2 (ior2->_stubobj ()->make_profiles ());
00346
00347 tmp_pfiles1->rewind ();
00348 while ((pfile1 = tmp_pfiles1->get_next ()) > 0)
00349 {
00350 tmp_pfiles2->rewind ();
00351 while ((pfile2 = tmp_pfiles2->get_next ()) > 0)
00352 {
00353 if (pfile1->is_equivalent (pfile2))
00354 count++;
00355 }
00356 }
00357
00358 if (count == 0)
00359 ACE_THROW_RETURN (TAO_IOP::NotFound (),
00360 0);
00361
00362 return count;
00363 }
00364
00365 CORBA::ULong
00366 TAO_IOR_Manipulation_impl::get_profile_count (
00367 CORBA::Object_ptr group
00368 ACE_ENV_ARG_DECL)
00369 ACE_THROW_SPEC ((CORBA::SystemException,
00370 TAO_IOP::EmptyProfileList))
00371 {
00372 CORBA::ULong count;
00373 count = group->_stubobj ()->base_profiles ().profile_count ();
00374
00375 if (count == 0)
00376 ACE_THROW_RETURN (TAO_IOP::EmptyProfileList (),
00377 0);
00378
00379 return count;
00380 }
00381
00382 TAO_END_VERSIONED_NAMESPACE_DECL