summaryrefslogtreecommitdiff
path: root/tao/IORManipulation/IORManip_Filter.cpp
blob: 2200f1b154c5145226c62e20bf86f9d70257522b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// $Id$

#include "tao/IORManipulation/IORManip_Filter.h"
#include "tao/IORManipulation/IORManip_Loader.h"
#include "tao/MProfile.h"
#include "tao/ORB_Core.h"
#include "tao/Stub.h"

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

TAO_IORManip_Filter::TAO_IORManip_Filter (void)
{
}


TAO_IORManip_Filter::~TAO_IORManip_Filter (void)
{
}


CORBA::Object_ptr
TAO_IORManip_Filter::sanitize_profiles (CORBA::Object_ptr object,
                                        TAO_Profile* profile)
{
  return this->sanitize (object, profile);
}


CORBA::Object_ptr
TAO_IORManip_Filter::sanitize (CORBA::Object_ptr object,
                               TAO_Profile* guideline)
{
  TAO_MProfile profiles = object->_stubobj ()->base_profiles ();
  TAO_MProfile new_profiles (profiles.profile_count ());
  TAO_Profile* profile = 0;

  while ((profile = profiles.get_next ()) != 0)
    {
      // Call the filter implementation
      this->filter_and_add (profile, new_profiles, guideline);
    }

  // The remainder of this code has been lifted from IORManipulation.cpp
  CORBA::String_var id =
      CORBA::string_dup (object->_stubobj ()->type_id.in ());

  TAO_ORB_Core *orb_core = object->_stubobj ()->orb_core ();
  if (orb_core == 0)
    orb_core = TAO_ORB_Core_instance ();

  TAO_Stub *stub = orb_core->create_stub (id.in (),  // give the id string to stub
                                          new_profiles);

  // Make the stub memory allocation exception safe for the duration
  // of this method.
  TAO_Stub_Auto_Ptr safe_stub (stub);

  // Create the CORBA level proxy
  CORBA::Object_ptr temp_obj = CORBA::Object::_nil ();
  ACE_NEW_THROW_EX (temp_obj,
                    CORBA::Object (safe_stub.get ()),
                    CORBA::NO_MEMORY ());

  CORBA::Object_var new_obj = temp_obj;


  // Clean up in case of errors.
  if (CORBA::is_nil (new_obj.in ()))
    {
      throw TAO_IOP::Invalid_IOR ();
    }

  // Release ownership of the pointers protected by the auto_ptrs since
  // they no longer need to be protected by this point.
  stub = safe_stub.release ();

  return new_obj._retn ();
}

TAO_END_VERSIONED_NAMESPACE_DECL