Go to the documentation of this file.00001
00002
00003
00004
00005 #include "tao/CodecFactory/CodecFactory_impl.h"
00006 #include "tao/CodecFactory/CDR_Encaps_Codec.h"
00007 #include "tao/SystemException.h"
00008 #include "tao/ORB_Constants.h"
00009 #include "tao/ORB_Core.h"
00010 #include "tao/Codeset_Manager.h"
00011 #include "ace/Codeset_Symbols.h"
00012 #include "ace/CORBA_macros.h"
00013
00014 ACE_RCSID (CodecFactory_impl,
00015 CodecFactory,
00016 "$Id: CodecFactory_impl.cpp 77455 2007-02-28 12:43:12Z johnnyw $")
00017
00018 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00019
00020 TAO_CodecFactory::TAO_CodecFactory (TAO_ORB_Core * orb_core)
00021 : orb_core_ (orb_core)
00022 {
00023 }
00024
00025 IOP::Codec_ptr
00026 TAO_CodecFactory::create_codec_with_codesets (const IOP::Encoding_1_2 & enc)
00027 {
00028 TAO_Codeset_Translator_Base *char_trans = 0;
00029 TAO_Codeset_Translator_Base *wchar_trans = 0;
00030 CONV_FRAME::CodeSetId ncsc;
00031 CONV_FRAME::CodeSetId ncsw;
00032
00033 TAO_Codeset_Manager *csm = this->orb_core_->codeset_manager ();
00034
00035 if (csm)
00036 {
00037 char_trans = csm->get_char_trans (enc.char_codeset);
00038 wchar_trans = csm->get_wchar_trans (enc.wchar_codeset);
00039 csm->get_ncs (ncsc,ncsw);
00040 }
00041 else
00042 {
00043
00044 throw IOP::CodecFactory::UnsupportedCodeset (enc.wchar_codeset);
00045 }
00046
00047 if (wchar_trans == 0 &&
00048 enc.wchar_codeset != ACE_CODESET_ID_ISO_UTF_16 &&
00049 enc.wchar_codeset != ncsw)
00050 {
00051 throw IOP::CodecFactory::UnsupportedCodeset (enc.wchar_codeset);
00052 }
00053
00054 if (char_trans == 0 &&
00055 enc.char_codeset != ncsc)
00056 {
00057 throw IOP::CodecFactory::UnsupportedCodeset (enc.char_codeset);
00058 }
00059
00060 return this->create_codec_i (enc.major_version,
00061 enc.minor_version,
00062 enc.format,
00063 char_trans,
00064 wchar_trans);
00065 }
00066
00067 IOP::Codec_ptr
00068 TAO_CodecFactory::create_codec (const IOP::Encoding & enc)
00069 {
00070 return this->create_codec_i (enc.major_version,
00071 enc.minor_version,
00072 enc.format,
00073 0,
00074 0);
00075 }
00076
00077 IOP::Codec_ptr
00078 TAO_CodecFactory::create_codec_i (CORBA::Octet major,
00079 CORBA::Octet minor,
00080 IOP::EncodingFormat encoding_format,
00081 TAO_Codeset_Translator_Base * char_trans,
00082 TAO_Codeset_Translator_Base * wchar_trans)
00083 {
00084
00085
00086
00087
00088
00089
00090
00091 IOP::Codec_ptr codec = IOP::Codec::_nil ();
00092
00093 switch (encoding_format)
00094 {
00095
00096
00097
00098
00099 case 0 :
00100 if (major < 1)
00101 {
00102
00103 throw ::CORBA::BAD_PARAM (
00104 CORBA::SystemException::_tao_minor_code (
00105 0,
00106 EINVAL),
00107 CORBA::COMPLETED_NO);
00108 }
00109
00110 ACE_NEW_THROW_EX (codec,
00111 TAO_CDR_Encaps_Codec (major,
00112 minor,
00113 this->orb_core_,
00114 char_trans,
00115 wchar_trans),
00116 CORBA::NO_MEMORY (
00117 CORBA::SystemException::_tao_minor_code (
00118 0,
00119 ENOMEM),
00120 CORBA::COMPLETED_MAYBE));
00121 break;
00122
00123 default:
00124 throw IOP::CodecFactory::UnknownEncoding ();
00125
00126 }
00127
00128 return codec;
00129 }
00130
00131 TAO_END_VERSIONED_NAMESPACE_DECL