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/PolicyC.h"
00005 #include "tao/SystemException.h"
00006 
00007 ACE_RCSID (PI,
00008            PolicyFactory_Registry,
00009            "$Id: PolicyFactory_Registry.cpp 78787 2007-07-05 08:02:28Z johnnyw $")
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 {
00038   if (CORBA::is_nil (policy_factory))
00039     {
00040       throw ::CORBA::BAD_PARAM (
00041                    CORBA::SystemException::_tao_minor_code (
00042                      0,
00043                      EINVAL),
00044                    CORBA::COMPLETED_NO);
00045     }
00046 
00047   PortableInterceptor::PolicyFactory_ptr factory =
00048     PortableInterceptor::PolicyFactory::_duplicate (policy_factory);
00049 
00050   const int result = this->factories_.bind (type, factory);
00051 
00052   if (result != 0)
00053     {
00054       // Release the duplicated factory to prevent a memory leak
00055       ::CORBA::release (factory);
00056 
00057       if (result == 1)
00058         {
00059           // PolicyFactory of given type already exists.
00060           throw ::CORBA::BAD_INV_ORDER (CORBA::OMGVMCID | 16,
00061                                         CORBA::COMPLETED_NO);
00062         }
00063       else
00064         {
00065           // Could not add PolicyFactory due to internal bind failures.
00066           throw ::CORBA::INTERNAL ();
00067         }
00068     }
00069 }
00070 
00071 CORBA::Policy_ptr
00072 TAO_PolicyFactory_Registry::create_policy (CORBA::PolicyType type,
00073                                            const CORBA::Any &value)
00074 {
00075   PortableInterceptor::PolicyFactory_ptr policy_factory =
00076     PortableInterceptor::PolicyFactory::_nil ();
00077 
00078   if (this->factories_.find (type, policy_factory) == -1)
00079     {
00080       // Policy factory corresponding to given policy type does not
00081       // exist in policy factory map.
00082       throw ::CORBA::PolicyError (CORBA::BAD_POLICY_TYPE);
00083     }
00084 
00085   return policy_factory->create_policy (type, value);
00086 }
00087 
00088 CORBA::Policy_ptr
00089 TAO_PolicyFactory_Registry::_create_policy (CORBA::PolicyType type)
00090 {
00091   PortableInterceptor::PolicyFactory_ptr policy_factory =
00092     PortableInterceptor::PolicyFactory::_nil ();
00093 
00094   if (this->factories_.find (type, policy_factory) == -1)
00095     {
00096       // Policy factory corresponding to given policy type does not
00097       // exist in policy factory map.
00098       throw ::CORBA::PolicyError (CORBA::BAD_POLICY_TYPE);
00099     }
00100 
00101   return policy_factory->_create_policy (type);
00102 }
00103 
00104 bool
00105 TAO_PolicyFactory_Registry::factory_exists (CORBA::PolicyType & type) const
00106 {
00107   return (this->factories_.find (type) == 0);
00108 }
00109 
00110 
00111 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Sun Jan 27 13:29:59 2008 for TAO_PI by doxygen 1.3.6