00001
00002
00003 #include "tao/PortableServer/POAManagerFactory.h"
00004 #include "tao/PortableServer/POAManager.h"
00005
00006 #include "ace/OS_NS_string.h"
00007 #include "ace/CORBA_macros.h"
00008
00009 ACE_RCSID (PortableServer,
00010 POAManagerFactory,
00011 "$Id: POAManagerFactory.cpp 78128 2007-04-20 08:07:58Z johnnyw $")
00012
00013 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
00014
00015 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00016
00017 TAO_POAManager_Factory::TAO_POAManager_Factory (TAO_Object_Adapter &object_adapter) :
00018 object_adapter_ (object_adapter)
00019 {
00020 }
00021
00022 TAO_POAManager_Factory::~TAO_POAManager_Factory (void)
00023 {
00024 this->remove_all_poamanagers ();
00025 }
00026
00027 ::PortableServer::POAManager_ptr
00028 TAO_POAManager_Factory::create_POAManager (
00029 const char * id,
00030 const ::CORBA::PolicyList & policies
00031 )
00032 {
00033
00034 TAO_POA_Policy_Set tao_policies (TAO_POA_Policy_Set (this->object_adapter_.default_poa_policies ()));
00035
00036
00037 this->object_adapter_.validator ().merge_policies (tao_policies.policies ());
00038
00039
00040 tao_policies.merge_policies (policies);
00041
00042
00043
00044
00045
00046
00047
00048 tao_policies.validate_policies (this->object_adapter_.validator (),
00049 this->object_adapter_.orb_core ());
00050
00051 PortableServer::POAManager_var poamanager;
00052
00053 if (id != 0)
00054 {
00055 poamanager = this->find (id);
00056
00057
00058 if (!CORBA::is_nil (poamanager.in()))
00059 {
00060 throw ::PortableServer::POAManagerFactory::ManagerAlreadyExists ();
00061 }
00062 }
00063
00064
00065
00066 {
00067 PortableServer::POAManager_ptr pm = 0;
00068 ACE_NEW_THROW_EX (pm,
00069 TAO_POA_Manager (object_adapter_, id, policies, this),
00070 CORBA::NO_MEMORY
00071 (CORBA::SystemException::_tao_minor_code (0, ENOMEM),
00072 CORBA::COMPLETED_NO));
00073 poamanager = pm;
00074 }
00075
00076 this->register_poamanager (poamanager.in ());
00077
00078 return poamanager._retn ();
00079 }
00080
00081 ::PortableServer::POAManagerFactory::POAManagerSeq *
00082 TAO_POAManager_Factory::list (void)
00083 {
00084 ::PortableServer::POAManagerFactory::POAManagerSeq_var poamanagers;
00085 CORBA::ULong number_of_poamanagers = static_cast <CORBA::ULong>
00086 (this->poamanager_set_.size ());
00087 ACE_NEW_THROW_EX (poamanagers,
00088 PortableServer::POAManagerFactory::POAManagerSeq (
00089 number_of_poamanagers),
00090 CORBA::NO_MEMORY ());
00091
00092 poamanagers->length (number_of_poamanagers);
00093
00094 CORBA::ULong index = 0;
00095 for (POAMANAGERSET::iterator iterator = this->poamanager_set_.begin ();
00096 iterator != this->poamanager_set_.end ();
00097 ++iterator, ++index)
00098 {
00099 ::PortableServer::POAManager_ptr poamanager = (*iterator);
00100 poamanagers[index] =
00101 PortableServer::POAManager::_duplicate (poamanager);
00102 }
00103
00104 return poamanagers._retn ();
00105 }
00106
00107 ::PortableServer::POAManager_ptr
00108 TAO_POAManager_Factory::find (const char * id)
00109 {
00110 ::PortableServer::POAManager_ptr poamanager =
00111 ::PortableServer::POAManager::_nil();
00112
00113 for (POAMANAGERSET::iterator iterator = this->poamanager_set_.begin ();
00114 iterator != this->poamanager_set_.end ();
00115 ++iterator)
00116 {
00117 CORBA::String_var poamanagerid = (*iterator)->get_id ();
00118
00119 if (ACE_OS::strcmp (id, poamanagerid.in()) == 0)
00120 {
00121 poamanager = PortableServer::POAManager::_duplicate (*iterator);
00122 break;
00123 }
00124 }
00125
00126 return poamanager;
00127 }
00128
00129 void
00130 TAO_POAManager_Factory::remove_all_poamanagers (void)
00131 {
00132 for (POAMANAGERSET::iterator iterator = this->poamanager_set_.begin ();
00133 iterator != this->poamanager_set_.end ();
00134 ++iterator)
00135 {
00136 ::PortableServer::POAManager_ptr poamanager = (*iterator);
00137 CORBA::release (poamanager);
00138 }
00139 this->poamanager_set_.reset ();
00140 }
00141
00142 int
00143 TAO_POAManager_Factory::remove_poamanager (
00144 ::PortableServer::POAManager_ptr poamanager)
00145 {
00146 int retval = this->poamanager_set_.remove (poamanager);
00147
00148 if (retval == 0)
00149 {
00150 CORBA::release (poamanager);
00151 }
00152
00153 return retval;
00154 }
00155
00156 int
00157 TAO_POAManager_Factory::register_poamanager (
00158 ::PortableServer::POAManager_ptr poamanager)
00159 {
00160 return this->poamanager_set_.insert (
00161 PortableServer::POAManager::_duplicate (poamanager));
00162 }
00163
00164
00165 TAO_END_VERSIONED_NAMESPACE_DECL
00166
00167 #endif