Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / ZIOP / ZIOP_PolicyFactory.cpp
blobb7b206c707738a0e84bdba1116cc115c86e70465
1 #include "tao/ZIOP/ZIOP_PolicyFactory.h"
2 #include "tao/ZIOP/ZIOP.h"
3 #include "tao/ZIOP/ZIOP_Policy_i.h"
5 #include "tao/ORB_Constants.h"
6 #include "tao/AnyTypeCode/Any.h"
8 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
10 CORBA::Policy_ptr
11 TAO_ZIOP_PolicyFactory::create_policy (
12 CORBA::PolicyType type,
13 const CORBA::Any &value)
15 CORBA::Policy_ptr policy = CORBA::Policy::_nil ();
17 switch (type)
19 case ZIOP::COMPRESSION_ENABLING_POLICY_ID:
21 ::CORBA::Boolean val;
23 // Extract the value from the any.
24 if (!(value >>= CORBA::Any::to_boolean (val)))
26 throw CORBA::PolicyError (CORBA::BAD_POLICY_VALUE);
29 ACE_NEW_THROW_EX (policy,
30 TAO::CompressionEnablingPolicy (val),
31 CORBA::NO_MEMORY (
32 CORBA::SystemException::_tao_minor_code (
33 TAO::VMCID,
34 ENOMEM),
35 CORBA::COMPLETED_NO));
37 return policy;
39 case ZIOP::COMPRESSOR_ID_LEVEL_LIST_POLICY_ID :
41 const ::Compression::CompressorIdLevelList* val = 0;
43 // Extract the value from the any.
44 if (!(value >>= val))
46 throw CORBA::PolicyError (CORBA::BAD_POLICY_VALUE);
49 ACE_NEW_THROW_EX (policy,
50 TAO::CompressorIdLevelListPolicy (*val),
51 CORBA::NO_MEMORY (
52 CORBA::SystemException::_tao_minor_code (
53 TAO::VMCID,
54 ENOMEM),
55 CORBA::COMPLETED_NO));
57 return policy;
59 case ZIOP::COMPRESSION_LOW_VALUE_POLICY_ID:
61 ::CORBA::ULong val;
63 // Extract the value from the any.
64 if (!(value >>= val))
66 throw CORBA::PolicyError (CORBA::BAD_POLICY_VALUE);
69 ACE_NEW_THROW_EX (policy,
70 TAO::CompressionLowValuePolicy (val),
71 CORBA::NO_MEMORY (
72 CORBA::SystemException::_tao_minor_code (
73 TAO::VMCID,
74 ENOMEM),
75 CORBA::COMPLETED_NO));
77 return policy;
79 case ZIOP::COMPRESSION_MIN_RATIO_POLICY_ID:
81 ::Compression::CompressionRatio val;
83 // Extract the value from the any.
84 if (!(value >>= val))
86 throw CORBA::PolicyError (CORBA::BAD_POLICY_VALUE);
89 ACE_NEW_THROW_EX (policy,
90 TAO::CompressionMinRatioPolicy (val),
91 CORBA::NO_MEMORY (
92 CORBA::SystemException::_tao_minor_code (
93 TAO::VMCID,
94 ENOMEM),
95 CORBA::COMPLETED_NO));
97 return policy;
101 throw CORBA::PolicyError (CORBA::BAD_POLICY_TYPE);
104 CORBA::Policy_ptr
105 TAO_ZIOP_PolicyFactory::_create_policy (CORBA::PolicyType type)
107 CORBA::Policy_ptr policy = CORBA::Policy_ptr ();
109 switch (type)
111 case ZIOP::COMPRESSION_ENABLING_POLICY_ID:
113 ACE_NEW_THROW_EX (policy,
114 TAO::CompressionEnablingPolicy,
115 CORBA::NO_MEMORY (
116 CORBA::SystemException::_tao_minor_code (
117 TAO::VMCID,
118 ENOMEM),
119 CORBA::COMPLETED_NO));
121 return policy;
123 case ZIOP::COMPRESSOR_ID_LEVEL_LIST_POLICY_ID:
125 ACE_NEW_THROW_EX (policy,
126 TAO::CompressorIdLevelListPolicy,
127 CORBA::NO_MEMORY (
128 CORBA::SystemException::_tao_minor_code (
129 TAO::VMCID,
130 ENOMEM),
131 CORBA::COMPLETED_NO));
133 return policy;
136 throw ::CORBA::PolicyError (CORBA::BAD_POLICY_TYPE);
140 TAO_END_VERSIONED_NAMESPACE_DECL