コード例 #1
0
ファイル: DynAny_Handler.cpp プロジェクト: DOCGroup/DAnCE
    DynamicAny::DynAny_ptr
    DynAny_Handler::extract_into_dynany (const DataType &type,
                                         const DataValue &value,
                                         CORBA::TypeCode_ptr req_tc)
    {
      DANCE_TRACE("DynAny_Handler::extract_into_dynany");

      DynamicAny::DynAny_var retval;

      if (req_tc)
        retval = this->daf_->create_dyn_any_from_type_code (req_tc);

      TCKind::Value tkind = type.kind ().integral ();

      if ((value.count_short () && tkind != TCKind::tk_short_l) ||
          (value.count_long () && tkind != TCKind::tk_long_l) ||
          (value.count_ushort () && tkind != TCKind::tk_ushort_l ) ||
          (value.count_ulong () && tkind != TCKind::tk_ulong_l) ||
          (value.count_float () && tkind != TCKind::tk_float_l) ||
          (value.count_double () && tkind != TCKind::tk_double_l) ||
          (value.count_boolean () && tkind != TCKind::tk_boolean_l) ||
          (value.count_octet () && tkind != TCKind::tk_octet_l) ||
          (value.count_longlong () && tkind != TCKind::tk_longlong_l) ||
          (value.count_ulonglong () && tkind != TCKind::tk_ulonglong_l) ||
          (value.count_string () && !(tkind == TCKind::tk_string_l ||
                                      tkind == TCKind::tk_char_l ||
                                      tkind == TCKind::tk_wchar_l)))
        {
          throw Config_Error (ACE_TEXT (""), ACE_TEXT ("Wrong value type for data type"));
        }

      switch (tkind)
        {
          // ========== BASIC TYPES
        case TCKind::tk_null_l:
        case TCKind::tk_void_l:
          DANCE_ERROR (DANCE_LOG_TERMINAL_ERROR,
            (LM_ERROR,
            ACE_TEXT ("DynAny_Handler::extract_into_dynany - Don't know how to handle null or void types\n")));
          throw Config_Error (ACE_TEXT (""),
            ACE_TEXT ("Null or void types not supported"));
          break;

        case TCKind::tk_short_l:
          {
            if (!req_tc)
              {
                retval = this->daf_->create_dyn_any_from_type_code (CORBA::_tc_short);
              }
            CORBA::Short s = 0;
            if (value.count_short ())
              {
                s = *(*value.begin_short ());
              }
            retval->insert_short (s);
          }
          break;

        case TCKind::tk_long_l:
          {
            if (!req_tc)
              {
                retval = this->daf_->create_dyn_any_from_type_code (CORBA::_tc_long);
              }
            CORBA::Long l = 0;
            if (value.count_long ())
              {
                l = *(*value.begin_long ());
              }
            retval->insert_long (l);
          }
          break;

        case TCKind::tk_ushort_l:
          {
            if (!req_tc)
              {
                retval = this->daf_->create_dyn_any_from_type_code (CORBA::_tc_ushort);
              }
            CORBA::UShort us = 0;
            if (value.count_ushort ())
              {
                us = *(*value.begin_ushort ());
              }
            retval->insert_ushort (us);
          }
          break;

        case TCKind::tk_ulong_l:
          {
            if (!req_tc)
              {
                retval = this->daf_->create_dyn_any_from_type_code (CORBA::_tc_ulong);
              }
            CORBA::ULong ul = 0;
            if (value.count_ulong ())
              {
                ul = *(*value.begin_ulong ());
              }
            retval->insert_ulong (ul);
          }
          break;

        case TCKind::tk_float_l:
          {
            if (!req_tc)
              {
                retval = this->daf_->create_dyn_any_from_type_code (CORBA::_tc_float);
              }
            CORBA::Float f = 0.0f;
            if (value.count_float ())
              {
                f = *(*value.begin_float ());
              }
            retval->insert_float (f);
          }
          break;

        case TCKind::tk_double_l:
          {
            if (!req_tc)
              {
                retval = this->daf_->create_dyn_any_from_type_code (CORBA::_tc_double);
              }
            CORBA::Double d = 0.0;
            if (value.count_double ())
              {
                d = *(*value.begin_double ());
              }
            retval->insert_double (d);
          }
          break;

        case TCKind::tk_boolean_l:
          {
            if (!req_tc)
              {
                retval = this->daf_->create_dyn_any_from_type_code (CORBA::_tc_boolean);
              }
            CORBA::Boolean b = false;
            if (value.count_boolean ())
              {
                b = *(*value.begin_boolean ());
              }
            retval->insert_boolean (b);
          }
          break;

        case TCKind::tk_octet_l:
          {
            if (!req_tc)
              {
                retval = this->daf_->create_dyn_any_from_type_code (CORBA::_tc_octet);
              }
            CORBA::Octet o = 0;
            if (value.count_octet ())
              {
                o = *(*(value.begin_octet ()));
              }
            retval->insert_octet (o);
          }
          break;

        case TCKind::tk_longlong_l:
          {
            if (!req_tc)
              {
                retval = this->daf_->create_dyn_any_from_type_code (CORBA::_tc_longlong);
              }
            CORBA::LongLong ll = 0;
            if (value.count_longlong ())
              {
                ll = *(*value.begin_longlong ());
              }
            retval->insert_longlong (ll);
          }
          break;

        case TCKind::tk_ulonglong_l:
          {
            if (!req_tc)
              {
                retval = this->daf_->create_dyn_any_from_type_code (CORBA::_tc_ulonglong);
              }
            CORBA::ULongLong ull = 0;
            if (value.count_ulonglong ())
              {
                ull = *(*value.begin_ulonglong ());
              }
            retval->insert_ulonglong (ull);
          }
          break;

        case TCKind::tk_string_l:
          return DynString_Handler::extract_into_dynany (type, value, req_tc);

        case TCKind::tk_char_l:
          {
            if (!req_tc)
              {
                retval = this->daf_->create_dyn_any_from_type_code (CORBA::_tc_char);
              }
            CORBA::Char c = 0;
            if (value.count_string ())
              {
                c = *(*value.begin_string ())->c_str ();
              }
            retval->insert_char (c);
          }
          break;

        case TCKind::tk_wchar_l:
          {
            if (!req_tc)
              {
                retval = this->daf_->create_dyn_any_from_type_code (CORBA::_tc_wchar);
              }
            CORBA::WChar wc = 0;
            if (value.count_string ())
              {
                wc = *(*value.begin_string ())->c_str ();
              }
            retval->insert_wchar (wc);
          }
          break;

        case TCKind::tk_enum_l:
          return DynEnum_Handler::extract_into_dynany (type, value, req_tc);

        case TCKind::tk_sequence_l:
          return DynSequence_Handler::extract_into_dynany (type, value, req_tc);

        case TCKind::tk_struct_l:
          return DynStruct_Handler::extract_into_dynany (type, value, req_tc);

        case TCKind::tk_alias_l:
          return DynAlias_Handler::extract_into_dynany (type, value, req_tc);

        case TCKind::tk_array_l:
          return DynArray_Handler::extract_into_dynany (type, value, req_tc);

        case TCKind::tk_longdouble_l:
          // Not supported since a longdouble is defined in the xsd as double.
          // We are then creating a long double initialized with a regular
          // double. This is a very tricky conversion and doesn't work in
          // combination with certain (versions of) compilers.
        case TCKind::tk_wstring_l:
        case TCKind::tk_fixed_l:
        case TCKind::tk_any_l:
        case TCKind::tk_TypeCode_l:
        case TCKind::tk_Principal_l:
        case TCKind::tk_objref_l:
        case TCKind::tk_union_l:
        case TCKind::tk_except_l:
        case TCKind::tk_value_l:
        case TCKind::tk_value_box_l:
        case TCKind::tk_native_l:
        case TCKind::tk_abstract_interface_l:
        case TCKind::tk_local_interface_l:
        case TCKind::tk_component_l:
        case TCKind::tk_home_l:
        case TCKind::tk_event_l:
          DANCE_ERROR (DANCE_LOG_TERMINAL_ERROR, (LM_ERROR,
            DLINFO ACE_TEXT ("DynAny_Handler::extract_into_dynany - Type not supported\n")));
          throw Config_Error (ACE_TEXT (""), ACE_TEXT ("Type not supported"));
        }

      return retval._retn ();
    }
コード例 #2
0
ファイル: DynAlias_Handler.cpp プロジェクト: molixiaoge/ACE
    DynamicAny::DynAny_ptr
    DynAlias_Handler::extract_into_dynany (const DataType &type,
                                           const DataValue &value,
                                           CORBA::TypeCode_ptr req_tc)
    {
      DANCE_TRACE("DynAlias_Handler::extract_into_dynany");

      try
        {
          CORBA::TypeCode_var tc;

          if (req_tc)
            tc = req_tc;
          else
            tc = DynAlias_Handler::create_typecode (type);

          // Make the actual DynAlias
          //          DynamicAny::DynAny_var retval =
          //DYNANY_HANDLER->daf ()->create_dyn_any_from_type_code (tc);
          //          DynamicAny::DynAlias_var retval =
          //            DynamicAny::DynAlias::_narrow (temp.in ());

          DynamicAny::DynAny_var alias = DYNANY_HANDLER->extract_into_dynany (
            type.alias ().elementType (), value, tc);
          return alias._retn ();
          /*
          switch (type.kind ().integral ())
            {
              // ========== BASIC TYPES
            case TCKind::tk_null_l:
            case TCKind::tk_void_l:
              DANCE_DEBUG (DANCE_LOG_TERMINAL_ERROR,
                (LM_WARNING, "I don't know how to handle null or
              void types\n"));

            case TCKind::tk_short_l:
              retval->insert_short (CORBA::Short (static_cast <
                ::XMLSchema::short_ const & > (*value.begin_short ())));
              break;

            case TCKind::tk_long_l:
              retval->insert_long (CORBA::Long (static_cast <
                ::XMLSchema::int_ const& > (*value.begin_long ())));
              break;

            case TCKind::tk_ushort_l:
              retval->insert_ushort (CORBA::UShort (static_cast<
                ::XMLSchema::unsignedShort const & > (*value.begin_ushort ())));
              break;

            case TCKind::tk_ulong_l:
              retval->insert_ulong (CORBA::ULong (static_cast <
                ::XMLSchema::unsignedInt const& > (*value.begin_ulong ())));
              break;

            case TCKind::tk_float_l:
              retval->insert_float (CORBA::Float (*value.begin_float ()));
              break;

            case TCKind::tk_double_l:
              retval->insert_double (CORBA::Double (*value.begin_double ()));
              break;

            case TCKind::tk_boolean_l:
              retval->insert_boolean (static_cast <
                ::XMLSchema::boolean const& > (*value.begin_boolean ()));
              break;

            case TCKind::tk_char_l:
              retval->insert_char (CORBA::Char (
                *value.begin_string ()->c_str ()));
              break;

            case TCKind::tk_octet_l:
              retval->insert_octet (static_cast <
                const unsigned char &> (*value.begin_octet ()));
              break;

            case TCKind::tk_string_l:
              retval->insert_string (value.begin_string ()->c_str ());
              break;

            case TCKind::tk_longlong_l:
              retval->insert_longlong (CORBA::LongLong (static_cast <
                ::XMLSchema::long_ const& > (*value.begin_longlong ())));
              break;

            case TCKind::tk_ulonglong_l:
              retval->insert_ulonglong (CORBA::ULongLong (static_cast <
                ::XMLSchema::unsignedLong const& > (
                  *value.begin_ulonglong ())));
              break;

            case TCKind::tk_wchar_l:
              retval->insert_wchar (CORBA::WChar (
                *value.begin_string ()->c_str ()));
              break;

        case TCKind::tk_enum_l:
          return DynEnum_Handler::extract_into_dynany (type, value);

        case TCKind::tk_sequence_l:
          return DynSequence_Handler::extract_into_dynany (type, value);

        case TCKind::tk_struct_l:
          return DynStruct_Handler::extract_into_dynany (type, value);

        case TCKind::tk_alias_l:
          return DynAlias_Handler::extract_into_dynany (type, value);

        case TCKind::tk_longdouble_l:
        case TCKind::tk_wstring_l:
        case TCKind::tk_wfixed_l:
        case TCKind::tk_any_l:
        case TCKind::tk_TypeCode_l:
        case TCKind::tk_Principal_l:
        case TCKind::tk_objref_l:
        case TCKind::tk_union_l:
        case TCKind::tk_array_l:
        case TCKind::tk_except_l:
        case TCKind::tk_value_l:
        case TCKind::tk_value_box_l:
        case TCKind::tk_native_l:
        case TCKind::tk_abstract_interface_l:
        case TCKind::tk_local_interface_l:
        case TCKind::tk_component_l:
        case TCKind::tk_home_l:
        case TCKind::tk_event_l:
          DANCE_DEBUG (DANCE_LOG_TERMINAL_ERROR,
          (LM_ERROR, "Type not supported\n"));
          throw Config_Error ("", "Type not supported");
        }
          */
          //          retval->assign (alias);

          //          return retval._retn ();
        }
      catch (const DynamicAny::DynAny::InvalidValue&)
        {
          DANCE_DEBUG (DANCE_LOG_TERMINAL_ERROR,
            (LM_ERROR,
              ACE_TEXT ("Invalid value provided in XML when trying to ")
              ACE_TEXT ("initialize an instance of enumerated type %s\n"),
              type.alias ().typeId ().c_str ()));
          throw Config_Error (type.alias ().typeId (),
              ACE_TEXT ("Invalid value provided in XML"));
        }
      catch (Config_Error &ex)
        {
          DANCE_DEBUG (DANCE_LOG_TERMINAL_ERROR,
            (LM_ERROR, ACE_TEXT ("DynAlias_Handler caught Config_Error\n")));
          if (type.alias_p ())
            ex.add_name (type.alias ().typeId ());

          throw ex;
        }
      catch (...)
        {
          DANCE_DEBUG (DANCE_LOG_TERMINAL_ERROR, (LM_ERROR,
            ACE_TEXT ("DynAlias_Handler caught unknown exception\n")));
          throw Config_Error (type.alias ().typeId (),
                              ACE_TEXT ("Unknown exception"));
        }
    }