summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/examples/ORT/Object_Factory_i.cpp
blob: 3a37e2f0116c82f33ff3e768643591095cb6868b (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
// $Id$

#include "Object_Factory_i.h"
#include "tao/PortableServer/POA.h"
#include "tao/PortableServer/ObjectReferenceTemplate.h"

Object_Factory_i::Object_Factory_i (CORBA::ORB_ptr orb,
                                    PortableServer::POA_ptr gateway_poa)
  : orb_ (CORBA::ORB::_duplicate (orb)),
    gateway_poa_ (gateway_poa)
{
  /// Constructor
}


CORBA::Object_ptr
Object_Factory_i::create_object (const char *interface_repository_id,
                                 CORBA::Object_ptr gatewayed_object
                                 ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  CORBA::String_var stringified_object =
    this->orb_->object_to_string (gatewayed_object ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (CORBA::Object::_nil ());

  const PortableServer::ObjectId_var id =
    PortableServer::string_to_ObjectId (stringified_object.in ());

  const PortableInterceptor::ObjectId *obj_id =
    ACE_reinterpret_cast (const PortableInterceptor::ObjectId *,
                          &id.in ());

  TAO_POA *poa = ACE_dynamic_cast (TAO_POA *,
                                   this->gateway_poa_);
  ACE_CHECK_RETURN (CORBA::Object::_nil ());

  PortableInterceptor::ObjectReferenceTemplate *ort_template =
    poa->get_adapter_template();

  TAO_ObjectReferenceTemplate *ort =
    ACE_dynamic_cast (TAO_ObjectReferenceTemplate *,
                      ort_template);

  CORBA::Object_ptr object_ptr =
    ort->make_object (interface_repository_id,
                      *obj_id
                      ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (CORBA::Object::_nil ());

  return object_ptr;
}