1 #include "tao/PI/PolicyFactory_Registry.h"
2 #include "tao/PI/PolicyFactoryC.h"
3 #include "tao/ORB_Constants.h"
4 #include "tao/PolicyC.h"
5 #include "tao/SystemException.h"
7 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
9 TAO_PolicyFactory_Registry::TAO_PolicyFactory_Registry ()
10 : factories_ (TAO_DEFAULT_POLICY_FACTORY_REGISTRY_SIZE
)
14 TAO_PolicyFactory_Registry::~TAO_PolicyFactory_Registry ()
16 const TABLE::iterator
end (this->factories_
.end ());
18 for (TABLE::iterator i
= this->factories_
.begin (); i
!= end
; ++i
)
20 ::CORBA::release ((*i
).int_id_
);
23 this->factories_
.close ();
27 TAO_PolicyFactory_Registry::register_policy_factory (
28 CORBA::PolicyType type
,
29 PortableInterceptor::PolicyFactory_ptr policy_factory
)
31 if (CORBA::is_nil (policy_factory
))
33 throw ::CORBA::BAD_PARAM (
34 CORBA::SystemException::_tao_minor_code (
40 PortableInterceptor::PolicyFactory_ptr factory
=
41 PortableInterceptor::PolicyFactory::_duplicate (policy_factory
);
43 const int result
= this->factories_
.bind (type
, factory
);
47 // Release the duplicated factory to prevent a memory leak
48 ::CORBA::release (factory
);
52 // PolicyFactory of given type already exists.
53 throw ::CORBA::BAD_INV_ORDER (CORBA::OMGVMCID
| 16,
58 // Could not add PolicyFactory due to internal bind failures.
59 throw ::CORBA::INTERNAL ();
65 TAO_PolicyFactory_Registry::create_policy (CORBA::PolicyType type
,
66 const CORBA::Any
&value
)
68 PortableInterceptor::PolicyFactory_ptr policy_factory
=
69 PortableInterceptor::PolicyFactory::_nil ();
71 if (this->factories_
.find (type
, policy_factory
) == -1)
73 // Policy factory corresponding to given policy type does not
74 // exist in policy factory map.
75 throw ::CORBA::PolicyError (CORBA::BAD_POLICY_TYPE
);
78 return policy_factory
->create_policy (type
, value
);
82 TAO_PolicyFactory_Registry::_create_policy (CORBA::PolicyType type
)
84 PortableInterceptor::PolicyFactory_ptr policy_factory
=
85 PortableInterceptor::PolicyFactory::_nil ();
87 if (this->factories_
.find (type
, policy_factory
) == -1)
89 // Policy factory corresponding to given policy type does not
90 // exist in policy factory map.
91 throw ::CORBA::PolicyError (CORBA::BAD_POLICY_TYPE
);
94 return policy_factory
->_create_policy (type
);
98 TAO_PolicyFactory_Registry::factory_exists (CORBA::PolicyType
& type
) const
100 return (this->factories_
.find (type
) == 0);
104 TAO_END_VERSIONED_NAMESPACE_DECL