PolicyFactory_Registry.cpp

Go to the documentation of this file.
00001 #include "tao/PI/PolicyFactory_Registry.h"
00002 #include "tao/PI/PolicyFactoryC.h"
00003 #include "tao/ORB_Constants.h"
00004 #include "tao/SystemException.h"
00005 #include "tao/PolicyC.h"
00006 
00007 ACE_RCSID (PI,
00008            PolicyFactory_Registry,
00009            "PolicyFactory_Registry.cpp,v 1.4 2006/04/19 09:22:56 jwillemsen Exp")
00010 
00011 
00012 // ****************************************************************
00013 
00014 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00015 
00016 TAO_PolicyFactory_Registry::TAO_PolicyFactory_Registry (void)
00017   : factories_ (TAO_DEFAULT_POLICY_FACTORY_REGISTRY_SIZE)
00018 {
00019 }
00020 
00021 TAO_PolicyFactory_Registry::~TAO_PolicyFactory_Registry (void)
00022 {
00023   const TABLE::iterator end (this->factories_.end ());
00024 
00025   for (TABLE::iterator i = this->factories_.begin (); i != end; ++i)
00026     {
00027       ::CORBA::release ((*i).int_id_);
00028     }
00029 
00030   this->factories_.close ();
00031 }
00032 
00033 void
00034 TAO_PolicyFactory_Registry::register_policy_factory (
00035   CORBA::PolicyType type,
00036   PortableInterceptor::PolicyFactory_ptr policy_factory
00037   ACE_ENV_ARG_DECL)
00038 {
00039   if (CORBA::is_nil (policy_factory))
00040     {
00041       ACE_THROW (CORBA::BAD_PARAM (
00042                    CORBA::SystemException::_tao_minor_code (
00043                      0,
00044                      EINVAL),
00045                    CORBA::COMPLETED_NO));
00046     }
00047 
00048   PortableInterceptor::PolicyFactory_ptr factory =
00049     PortableInterceptor::PolicyFactory::_duplicate (policy_factory);
00050 
00051   const int result = this->factories_.bind (type,
00052                                             factory);
00053 
00054   if (result != 0)
00055     {
00056       // Release the duplicated factory to prevent a memory leak
00057       ::CORBA::release (factory);
00058 
00059       if (result == 1)
00060         {
00061           // PolicyFactory of given type already exists.
00062           ACE_THROW (CORBA::BAD_INV_ORDER (CORBA::OMGVMCID | 16,
00063                                            CORBA::COMPLETED_NO));
00064         }
00065       else
00066         {
00067           // Could not add PolicyFactory due to internal bind failures.
00068           ACE_THROW (CORBA::INTERNAL ());
00069         }
00070     }
00071 }
00072 
00073 CORBA::Policy_ptr
00074 TAO_PolicyFactory_Registry::create_policy (CORBA::PolicyType type,
00075                                            const CORBA::Any &value
00076                                            ACE_ENV_ARG_DECL)
00077 {
00078   PortableInterceptor::PolicyFactory_ptr policy_factory =
00079     PortableInterceptor::PolicyFactory::_nil ();
00080 
00081   if (this->factories_.find (type, policy_factory) == -1)
00082     {
00083       // Policy factory corresponding to given policy type does not
00084       // exist in policy factory map.
00085       ACE_THROW_RETURN (
00086          CORBA::PolicyError (CORBA::BAD_POLICY_TYPE),  // @@ Right exception?
00087          CORBA::Policy::_nil ());
00088     }
00089 
00090   return policy_factory->create_policy (type,
00091                                         value
00092                                         ACE_ENV_ARG_PARAMETER);
00093 }
00094 
00095 CORBA::Policy_ptr
00096 TAO_PolicyFactory_Registry::_create_policy (CORBA::PolicyType type
00097                                             ACE_ENV_ARG_DECL)
00098 {
00099   PortableInterceptor::PolicyFactory_ptr policy_factory =
00100     PortableInterceptor::PolicyFactory::_nil ();
00101 
00102   if (this->factories_.find (type,
00103                              policy_factory) == -1)
00104     {
00105       // Policy factory corresponding to given policy type does not
00106       // exist in policy factory map.
00107       ACE_THROW_RETURN (
00108          CORBA::PolicyError (CORBA::BAD_POLICY_TYPE),  // @@ Right exception?
00109          CORBA::Policy::_nil ());
00110     }
00111 
00112   return policy_factory->_create_policy (type
00113                                          ACE_ENV_ARG_PARAMETER);
00114 }
00115 
00116 bool
00117 TAO_PolicyFactory_Registry::factory_exists (CORBA::PolicyType & type) const
00118 {
00119   return (this->factories_.find (type) == 0);
00120 }
00121 
00122 
00123 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 12:51:39 2006 for TAO_PI by doxygen 1.3.6