2 #include "tao/PortableServer/POAManagerFactory.h"
3 #include "tao/PortableServer/POAManager.h"
5 #include "ace/OS_NS_string.h"
6 #include "ace/CORBA_macros.h"
8 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
10 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
12 TAO_POAManager_Factory::TAO_POAManager_Factory (TAO_Object_Adapter
&object_adapter
) :
13 object_adapter_ (object_adapter
)
17 TAO_POAManager_Factory::~TAO_POAManager_Factory ()
19 this->remove_all_poamanagers ();
22 ::PortableServer::POAManager_ptr
23 TAO_POAManager_Factory::create_POAManager (
25 const ::CORBA::PolicyList
& policies
28 // Validate the policy.
29 TAO_POA_Policy_Set
tao_policies (TAO_POA_Policy_Set (this->object_adapter_
.default_poa_policies ()));
31 // Merge policies from the ORB level.
32 this->object_adapter_
.validator ().merge_policies (tao_policies
.policies ());
34 // Merge in any policies that the user may have specified.
35 tao_policies
.merge_policies (policies
);
37 // If any of the policy objects specified are not valid for the ORB
38 // implementation, if conflicting policy objects are specified, or
39 // if any of the specified policy objects require prior
40 // administrative action that has not been performed, an
41 // InvalidPolicy exception is raised containing the index in the
42 // policies parameter value of the first offending policy object.
43 tao_policies
.validate_policies (this->object_adapter_
.validator (),
44 this->object_adapter_
.orb_core ());
46 PortableServer::POAManager_var poamanager
;
50 poamanager
= this->find (id
);
52 // If we already have a manager with the same name throw an exception
53 if (!CORBA::is_nil (poamanager
.in()))
55 throw ::PortableServer::POAManagerFactory::ManagerAlreadyExists ();
59 // this indirection brought to you by borland's compiler and its refusal
60 // to directly assign the newly created TAO_POA_Manager to a POAManager_var.
62 PortableServer::POAManager_ptr pm
= 0;
64 TAO_POA_Manager (object_adapter_
, id
, policies
, this),
66 (CORBA::SystemException::_tao_minor_code (0, ENOMEM
),
67 CORBA::COMPLETED_NO
));
71 this->register_poamanager (poamanager
.in ());
73 return poamanager
._retn ();
76 ::PortableServer::POAManagerFactory::POAManagerSeq
*
77 TAO_POAManager_Factory::list ()
79 ::PortableServer::POAManagerFactory::POAManagerSeq_var poamanagers
;
80 CORBA::ULong number_of_poamanagers
= static_cast <CORBA::ULong
>
81 (this->poamanager_set_
.size ());
82 ACE_NEW_THROW_EX (poamanagers
,
83 PortableServer::POAManagerFactory::POAManagerSeq (
84 number_of_poamanagers
),
87 poamanagers
->length (number_of_poamanagers
);
89 CORBA::ULong index
= 0;
90 for (POAMANAGERSET::iterator iterator
= this->poamanager_set_
.begin ();
91 iterator
!= this->poamanager_set_
.end ();
94 ::PortableServer::POAManager_ptr poamanager
= (*iterator
);
96 PortableServer::POAManager::_duplicate (poamanager
);
99 return poamanagers
._retn ();
102 ::PortableServer::POAManager_ptr
103 TAO_POAManager_Factory::find (const char * id
)
105 ::PortableServer::POAManager_ptr poamanager
=
106 ::PortableServer::POAManager::_nil();
108 for (POAMANAGERSET::iterator iterator
= this->poamanager_set_
.begin ();
109 iterator
!= this->poamanager_set_
.end ();
112 CORBA::String_var poamanagerid
= (*iterator
)->get_id ();
114 if (ACE_OS::strcmp (id
, poamanagerid
.in()) == 0)
116 poamanager
= PortableServer::POAManager::_duplicate (*iterator
);
125 TAO_POAManager_Factory::remove_all_poamanagers ()
127 for (POAMANAGERSET::iterator iterator
= this->poamanager_set_
.begin ();
128 iterator
!= this->poamanager_set_
.end ();
131 ::PortableServer::POAManager_ptr poamanager
= (*iterator
);
132 CORBA::release (poamanager
);
134 this->poamanager_set_
.reset ();
138 TAO_POAManager_Factory::remove_poamanager (
139 ::PortableServer::POAManager_ptr poamanager
)
141 int retval
= this->poamanager_set_
.remove (poamanager
);
145 CORBA::release (poamanager
);
152 TAO_POAManager_Factory::register_poamanager (
153 ::PortableServer::POAManager_ptr poamanager
)
155 return this->poamanager_set_
.insert (
156 PortableServer::POAManager::_duplicate (poamanager
));
160 TAO_END_VERSIONED_NAMESPACE_DECL