00001
00002
00003 #include "tao/PortableServer/POAManagerFactory.h"
00004 #include "tao/PortableServer/POAManager.h"
00005 #include "tao/EndpointPolicy/EndpointPolicyTypeC.h"
00006
00007 #include "ace/OS_NS_string.h"
00008
00009 ACE_RCSID (PortableServer,
00010 POAManagerFactory,
00011 "POAManagerFactory.cpp,v 1.7 2006/06/20 06:31:05 jwillemsen Exp")
00012
00013 #if !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 for (POAMANAGERSET::iterator iterator = this->poamanager_set_.begin ();
00025 iterator != this->poamanager_set_.end ();
00026 ++iterator)
00027 {
00028 ::PortableServer::POAManager_ptr poamanager = (*iterator);
00029 CORBA::release (poamanager);
00030 }
00031 }
00032
00033 ::PortableServer::POAManager_ptr
00034 TAO_POAManager_Factory::create_POAManager (
00035 const char * id,
00036 const ::CORBA::PolicyList & policies
00037 ACE_ENV_ARG_DECL)
00038 ACE_THROW_SPEC ((CORBA::SystemException,
00039 ::PortableServer::POAManagerFactory::ManagerAlreadyExists,
00040 ::CORBA::PolicyError))
00041 {
00042 if (policies.length () > 1
00043 || (policies.length () == 1 &&
00044 policies[0]->policy_type () != EndpointPolicy::ENDPOINT_POLICY_TYPE))
00045 {
00046 ACE_THROW_RETURN (CORBA::PolicyError (CORBA::BAD_POLICY),
00047 ::PortableServer::POAManager::_nil ());
00048 }
00049
00050 PortableServer::POAManager_var poamanager =
00051 PortableServer::POAManager::_nil ();
00052 if (id != 0)
00053 {
00054 poamanager = this->find (id ACE_ENV_ARG_PARAMETER);
00055 ACE_CHECK_RETURN (::PortableServer::POAManager::_nil ());
00056
00057
00058 if (!CORBA::is_nil (poamanager.in()))
00059 {
00060 ACE_THROW_RETURN (
00061 ::PortableServer::POAManagerFactory::ManagerAlreadyExists (),
00062 ::PortableServer::POAManager::_nil ());
00063 }
00064 }
00065
00066
00067
00068 {
00069 PortableServer::POAManager_ptr pm = 0;
00070 ACE_NEW_THROW_EX (pm,
00071 TAO_POA_Manager (object_adapter_, id, policies, this),
00072 CORBA::NO_MEMORY
00073 (CORBA::SystemException::_tao_minor_code (0, ENOMEM),
00074 CORBA::COMPLETED_NO));
00075 ACE_CHECK_RETURN (::PortableServer::POAManager::_nil ());
00076 poamanager = pm;
00077 }
00078
00079 this->register_poamanager (poamanager.in ());
00080
00081 return PortableServer::POAManager::_duplicate (poamanager.in ());
00082 }
00083
00084 ::PortableServer::POAManagerFactory::POAManagerSeq *
00085 TAO_POAManager_Factory::list (
00086 ACE_ENV_SINGLE_ARG_DECL)
00087 ACE_THROW_SPEC ((CORBA::SystemException))
00088 {
00089 ::PortableServer::POAManagerFactory::POAManagerSeq_var poamanagers;
00090 CORBA::ULong number_of_poamanagers = static_cast <CORBA::ULong>
00091 (this->poamanager_set_.size ());
00092 ACE_NEW_THROW_EX (poamanagers,
00093 PortableServer::POAManagerFactory::POAManagerSeq (
00094 number_of_poamanagers),
00095 CORBA::NO_MEMORY ());
00096 ACE_CHECK_RETURN (0);
00097
00098 poamanagers->length (number_of_poamanagers);
00099
00100 CORBA::ULong index = 0;
00101 for (POAMANAGERSET::iterator iterator = this->poamanager_set_.begin ();
00102 iterator != this->poamanager_set_.end ();
00103 ++iterator, ++index)
00104 {
00105 ::PortableServer::POAManager_ptr poamanager = (*iterator);
00106 poamanagers[index] =
00107 PortableServer::POAManager::_duplicate (poamanager);
00108 }
00109
00110 return poamanagers._retn ();
00111 }
00112
00113 ::PortableServer::POAManager_ptr
00114 TAO_POAManager_Factory::find (
00115 const char * id ACE_ENV_ARG_DECL)
00116 ACE_THROW_SPEC ((CORBA::SystemException))
00117 {
00118 ::PortableServer::POAManager_ptr poamanager =
00119 ::PortableServer::POAManager::_nil();
00120
00121 for (POAMANAGERSET::iterator iterator = this->poamanager_set_.begin ();
00122 iterator != this->poamanager_set_.end ();
00123 ++iterator)
00124 {
00125 CORBA::String_var poamanagerid =
00126 (*iterator)->get_id (ACE_ENV_SINGLE_ARG_PARAMETER);
00127 ACE_CHECK_RETURN (::PortableServer::POAManager::_nil());
00128
00129 if (ACE_OS::strcmp (id, poamanagerid.in()) == 0)
00130 {
00131 poamanager = PortableServer::POAManager::_duplicate (*iterator);
00132 break;
00133 }
00134 }
00135
00136 return poamanager;
00137 }
00138
00139 int
00140 TAO_POAManager_Factory::remove_poamanager (
00141 ::PortableServer::POAManager_ptr poamanager)
00142 {
00143 int retval = 0;
00144 retval = this->poamanager_set_.remove (poamanager);
00145
00146 if (retval == 0)
00147 {
00148 CORBA::release (poamanager);
00149 }
00150
00151 return retval;
00152 }
00153
00154 int
00155 TAO_POAManager_Factory::register_poamanager (
00156 ::PortableServer::POAManager_ptr poamanager)
00157 {
00158 return this->poamanager_set_.insert (
00159 PortableServer::POAManager::_duplicate (poamanager));
00160 }
00161
00162
00163 TAO_END_VERSIONED_NAMESPACE_DECL
00164
00165 #endif