int
ifr_adding_visitor_structure::visit_enum (AST_Enum *node)
{
    try
    {
        // Is this enum already in the respository?
        CORBA::Contained_var prev_def =
            be_global->repository ()->lookup_id (node->repoID ());

        // If not, create a new entry.
        if (CORBA::is_nil (prev_def.in ()))
        {
            CORBA::ULong member_count =
                static_cast<CORBA::ULong> (node->member_count ());

            CORBA::EnumMemberSeq members (member_count);
            members.length (member_count);

            UTL_ScopedName *member_name = 0;

            // Get a list of the member names.
            for (CORBA::ULong i = 0; i < member_count; ++i)
            {
                member_name = node->value_to_name (i);

                members[i] =
                    CORBA::string_dup (
                        member_name->last_component ()->get_string ()
                    );
            }

            this->ir_current_ =
                be_global->repository ()->create_enum (
                    node->repoID (),
                    node->local_name ()->get_string (),
                    node->version (),
                    members
                );

            node->ifr_added (true);
        }
        else
        {
            // If the line below is true, we are clobbering a previous
            // entry (from another IDL file) of another type. In that
            // case we do what other ORB vendors do, and destroy the
            // original entry, create the new one, and let the user beware.
            if (!node->ifr_added ())
            {
                prev_def->destroy ();

                // This call will take the other branch.
                return this->visit_enum (node);
            }

            this->ir_current_ =
                CORBA::IDLType::_narrow (prev_def.in ());
        }
    }
    catch (const CORBA::Exception& ex)
    {
        ex._tao_print_exception (
            ACE_TEXT (
                "ifr_adding_visitor_structure::visit_enum"));

        return -1;
    }

    return 0;
}
int runDynamic(CORBA::ORB_ptr orb)
{
  try
    {
        // Create typecode for EventKind.

        CORBA::EnumMemberSeq eseq;

        eseq.length(2);

        eseq[0] = CORBA::string_dup("ALARM_EVENT");
        eseq[1] = CORBA::string_dup("LOG_EVENT");

        CORBA::TypeCode_var eventKindTc;

        eventKindTc = orb->create_enum_tc("IDL:DynAnyTest/EventKind:1.0",
                                          "EventKind",
                                          eseq);

        // Create typecode for EventData. EventKind tc is used.

        CORBA::Any label;
        CORBA::UnionMemberSeq useq;

        useq.length(2);

        label <<= DynAnyTest::ALARM_EVENT;
        useq[0].name = CORBA::string_dup("ev_data");
        useq[0].label = label;
        useq[0].type = CORBA::TypeCode::_duplicate(CORBA::_tc_any);
        useq[0].type_def = CORBA::IDLType::_nil ();

        label <<= DynAnyTest::LOG_EVENT;
        useq[1].name = CORBA::string_dup("ev_desc");
        useq[1].label = label;
        useq[1].type = CORBA::TypeCode::_duplicate(CORBA::_tc_string);
        useq[1].type_def = CORBA::IDLType::_nil ();

        CORBA::TypeCode_var eventDataTc;

        eventDataTc = orb->create_union_tc("IDL:DynAnyTest/EventData:1.0",
                                           "EventData",
                                           eventKindTc.in (),
                                           useq);

        // Now create DynUnion

        CORBA::Object_var obj = orb->resolve_initial_references("DynAnyFactory");

        DynamicAny::DynAnyFactory_var dfact =
                    DynamicAny::DynAnyFactory::_narrow(obj.in ());

        if (CORBA::is_nil (dfact.in ()))
          {
            ACE_ERROR_RETURN ((LM_ERROR,
                               "Nil dynamic any factory after narrow\n"),
                              -1);
          }

        DynamicAny::DynAny_var dany =
                    dfact->create_dyn_any_from_type_code(eventDataTc.in ());

        DynamicAny::DynUnion_var dunion =
          DynamicAny::DynUnion::_narrow(dany.in ());

        DynamicAny::DynAny_var disc = dunion->get_discriminator();

        DynamicAny::DynEnum_var denum =
          DynamicAny::DynEnum::_narrow(disc.in ());

        // This fails. The type of discriminator is ulong
        if (CORBA::is_nil (denum.in ()))
          {
            ACE_ERROR_RETURN ((LM_ERROR,
                               "Nil dynamic enum after narrow\n"),
                              -1);
          }

        ACE_DEBUG ((LM_DEBUG, "Dynamic Test Passed\n"));

        denum->destroy();
        dunion->destroy();
    }
  catch (const CORBA::Exception & ex)
    {
      ex._tao_print_exception ("Dynamic Test Failed with exception");
    }
  return 0;
}