Package org.omg.DynamicAny

Examples of org.omg.DynamicAny.DynAny


  {
    try
      {
        Any any = orb.create_any();
        Any av;
        DynAny d1 = null;
        DynAny d2 = null;
        DynAny copy = null;
        String str;
        DynEnum e1;
        DynEnum e2;
        TestEnum e;
        TypeCode type = TestEnumHelper.type();

        //
        // Test: initial value
        //
        d1 = factory.create_dyn_any_from_type_code(type);
        e1 = DynEnumHelper.narrow(d1);
        TEST(e1.get_as_ulong() == 0);
        str = e1.get_as_string();
        TEST(str.equals("red"));

        //
        // Test: set_as_string()
        //
        e1.set_as_string("green");
        TEST(e1.get_as_ulong() == 1);
        str = e1.get_as_string();
        TEST(str.equals("green"));
        e1.set_as_string("blue");
        TEST(e1.get_as_ulong() == 2);
        str = e1.get_as_string();
        TEST(str.equals("blue"));

        //
        // Test: set_as_ulong()
        //
        e1.set_as_ulong(1);
        TEST(e1.get_as_ulong() == 1);
        str = e1.get_as_string();
        TEST(str.equals("green"));
        e1.set_as_ulong(2);
        TEST(e1.get_as_ulong() == 2);
        str = e1.get_as_string();
        TEST(str.equals("blue"));

        //
        // Test: from_any()
        //
        TestEnumHelper.insert(any, TestEnum.green);
        e1.from_any(any);

        //
        // Test: to_any()
        //
        av = e1.to_any();
        e = TestEnumHelper.extract(av);
        TEST(e == TestEnum.green);

        //
        // Test: copy
        //
        copy = e1.copy();
        TEST(e1.equal(copy));

        e1.destroy();
        copy.destroy();

        //
        // Test: set_as_ulong() InvalidValue exception
        //
        try
View Full Code Here


  {
    try
      {
        Any any = orb.create_any();
        Any av;
        DynAny d1 = null;
        DynAny d2 = null;
        DynAny copy = null;
        TypeCode tc;
        String str;
        DynFixed f1;
        DynFixed f2;
        BigDecimal f;

        //
        // Create TypeCode
        //
        tc = orb.create_fixed_tc((short) 5, (short) 2);

        //
        // Test: get_value()
        //
        d1 = factory.create_dyn_any_from_type_code(tc);
        f1 = DynFixedHelper.narrow(d1);
        str = f1.get_value();
        f = new BigDecimal(str);
        TEST(Math.abs(f.floatValue() - 0.0) < Float.MIN_VALUE);

        //
        // Test: set_value()
        //
        TEST(f1.set_value("1.1"));
        TEST(f1.set_value("123.1"));
        TEST(f1.set_value("123.12"));
        TEST(!f1.set_value("123.123"));

        //
        // Test: from_any()
        //
        f = new BigDecimal("98");
        any.insert_fixed(f, tc);
        f1.from_any(any);

        //
        // Test: to_any()
        //
        av = f1.to_any();
        f = av.extract_fixed();
        TEST(f.equals(new BigDecimal("98")));

        //
        // Test: copy
        //
        copy = f1.copy();
        TEST(f1.equal(copy));

        f1.destroy();
        copy.destroy();

        //
        // Test: set_value() InvalidValue exception (part 1)
        //
        try
View Full Code Here

    try
      {
        int i;
        Any any = orb.create_any();
        Any av;
        DynAny d1;
        DynAny d2;
        DynAny copy;
        String str;
        String wstr;
        DynStruct s1;
        DynStruct s2;
        String cp;
        TypeCode type;
        TypeCode tc;
        TestStruct ts = new TestStruct();
        TestStruct pts;
        NameValuePair[] nvpseq;
        NameDynAnyPair[] ndpseq;

        type = TestStructHelper.type();
        d1 = factory.create_dyn_any_from_type_code(type);
        s1 = DynStructHelper.narrow(d1);

        //
        // Test: current_member_name, current_member_kind
        //
        str = s1.current_member_name();
        TEST(str.equals("shortVal"));
        TEST(s1.current_member_kind() == TCKind.tk_short);
        s1.next();
        str = s1.current_member_name();
        TEST(str.equals("ushortVal"));
        TEST(s1.current_member_kind() == TCKind.tk_ushort);
        s1.next();
        str = s1.current_member_name();
        TEST(str.equals("longVal"));
        TEST(s1.current_member_kind() == TCKind.tk_long);
        s1.next();
        str = s1.current_member_name();
        TEST(str.equals("ulongVal"));
        TEST(s1.current_member_kind() == TCKind.tk_ulong);
        s1.next();
        str = s1.current_member_name();
        TEST(str.equals("floatVal"));
        TEST(s1.current_member_kind() == TCKind.tk_float);
        s1.next();
        str = s1.current_member_name();
        TEST(str.equals("doubleVal"));
        TEST(s1.current_member_kind() == TCKind.tk_double);
        s1.next();
        str = s1.current_member_name();
        TEST(str.equals("boolVal"));
        TEST(s1.current_member_kind() == TCKind.tk_boolean);
        s1.next();
        str = s1.current_member_name();
        TEST(str.equals("charVal"));
        TEST(s1.current_member_kind() == TCKind.tk_char);
        s1.next();
        str = s1.current_member_name();
        TEST(str.equals("octetVal"));
        TEST(s1.current_member_kind() == TCKind.tk_octet);
        s1.next();
        str = s1.current_member_name();
        TEST(str.equals("anyVal"));
        TEST(s1.current_member_kind() == TCKind.tk_any);
        s1.next();
        str = s1.current_member_name();
        TEST(str.equals("tcVal"));
        TEST(s1.current_member_kind() == TCKind.tk_TypeCode);
        s1.next();
        str = s1.current_member_name();
        TEST(str.equals("objectVal"));
        TEST(s1.current_member_kind() == TCKind.tk_objref);
        s1.next();
        str = s1.current_member_name();
        TEST(str.equals("stringVal"));
        TEST(s1.current_member_kind() == TCKind.tk_string);
        s1.next();
        str = s1.current_member_name();
        TEST(str.equals("longlongVal"));
        TEST(s1.current_member_kind() == TCKind.tk_longlong);
        s1.next();
        str = s1.current_member_name();
        TEST(str.equals("ulonglongVal"));
        TEST(s1.current_member_kind() == TCKind.tk_ulonglong);
        s1.next();
        str = s1.current_member_name();
        TEST(str.equals("wcharVal"));
        TEST(s1.current_member_kind() == TCKind.tk_wchar);
        s1.next();
        str = s1.current_member_name();
        TEST(str.equals("wstringVal"));
        TEST(s1.current_member_kind() == TCKind.tk_wstring);

        //
        // Test: insert values into members
        //
        s1.rewind();
        s1.insert_short(SHORT_VALUE);
        s1.next();
        s1.insert_ushort(USHORT_VALUE);
        s1.next();
        s1.insert_long(LONG_VALUE);
        s1.next();
        s1.insert_ulong(ULONG_VALUE);
        s1.next();
        s1.insert_float(FLOAT_VALUE);
        s1.next();
        s1.insert_double(DOUBLE_VALUE);
        s1.next();
        s1.insert_boolean(BOOLEAN_VALUE);
        s1.next();
        s1.insert_char(CHAR_VALUE);
        s1.next();
        s1.insert_octet(OCTET_VALUE);
        s1.next();

        DynAny d1c = d1.current_component();

        any.insert_string(ANY_VALUE);
        s1.insert_any(any);
        s1.next();
        s1.insert_typecode(TYPECODE_VALUE);
        s1.next();
        s1.insert_reference(null);
        s1.next();
        s1.insert_string(STRING_VALUE);
        s1.next();
        s1.insert_longlong(LONGLONG_VALUE);
        s1.next();
        s1.insert_ulonglong(ULONGLONG_VALUE);
        s1.next();
        s1.insert_wchar(WCHAR_VALUE);
        s1.next();
        s1.insert_wstring(WSTRING_VALUE);
        s1.next();

        //
        // Test: get values from members
        //
        s1.rewind();
        TEST(s1.get_short() == SHORT_VALUE);
        s1.next();
        TEST(s1.get_ushort() == USHORT_VALUE);
        s1.next();
        TEST(s1.get_long() == LONG_VALUE);
        s1.next();
        TEST(s1.get_ulong() == ULONG_VALUE);
        s1.next();
        TEST(s1.get_float() == FLOAT_VALUE);
        s1.next();
        TEST(s1.get_double() == DOUBLE_VALUE);
        s1.next();
        TEST(s1.get_boolean() == BOOLEAN_VALUE);
        s1.next();
        TEST(s1.get_char() == CHAR_VALUE);
        s1.next();
        TEST(s1.get_octet() == OCTET_VALUE);
        s1.next();
        av = s1.get_any();

        TEST(av.extract_string().equals(ANY_VALUE));
        s1.next();
        tc = s1.get_typecode();
        s1.next();
        TEST(tc.equal(TYPECODE_VALUE));
        TEST(s1.get_reference() == null);
        s1.next();
        str = s1.get_string();
        s1.next();
        TEST(str.equals(STRING_VALUE));
        TEST(s1.get_longlong() == LONGLONG_VALUE);
        s1.next();
        TEST(s1.get_ulonglong() == ULONGLONG_VALUE);
        s1.next();
        TEST(s1.get_wchar() == WCHAR_VALUE);
        s1.next();
        wstr = s1.get_wstring();
        s1.next();
        TEST(wstr.equals(WSTRING_VALUE));

        //
        // Test: get_members
        //
        nvpseq = s1.get_members();
        s1.rewind();
        for (i = 0; i < 11; i++)
          {
            str = s1.current_member_name();
            TEST(str.equals(nvpseq [ i ].id));

            DynAny dv = factory.create_dyn_any(nvpseq [ i ].value);
            DynAny comp = s1.current_component();
            TEST(dv.equal(comp));
            dv.destroy();
            s1.next();
          }
View Full Code Here

              )
  {
    try
      {
        Any badAny = orb.create_any();
        DynAny d1 = null;
        DynAny d2 = null;
        DynAny d3 = null;
        DynAny copy = null;
        TypeCode origTC = getOrigType(tc);

        //
        // Create an any having a TypeCode that will not match tc
        //
View Full Code Here

    {
        final int _length;

        switch (value.type().kind().value()) {
        case TCKind._tk_array:
            DynAny _dynAny = toDynAny(value);
            _length = _dynAny.component_count();
            break;

        case TCKind._tk_sequence:
            DynSequence _dynSequence = toDynSequence(value);
            _length = _dynSequence.get_length();
View Full Code Here

            if (logger_.isDebugEnabled())
            {
                logger_.debug("evaluateNamedValueList(" + any + ", " + name + ")");
            }

            final DynAny _dynAny = toDynAny(any);
            final int _count = _dynAny.component_count();

            DynAny _cursor;
            Any _ret = null;

            _dynAny.rewind();

            if (logger_.isDebugEnabled())
View Full Code Here

       dynFactory = org.omg.DynamicAny.DynAnyFactoryHelper.narrow (obj);
   }

   public void testInsertDynAnyObject() throws Exception
   {
       DynAny dyn_any = null;

       org.omg.CORBA.Object  obj = orb.string_to_object (nameService);

       TypeCode tc = org.omg.CosNaming.NamingContextExtHelper.type();

       dyn_any =
           (DynAny)
           dynFactory.create_dyn_any_from_type_code (tc);

       dyn_any.insert_reference (obj);

       dyn_any.to_any();

       dyn_any.destroy();
   }
View Full Code Here

    * Test accessing a value of some basic type in a DynAny object.
    */
   public void testAccessBasicValue_boolean () throws Exception
   {
      TypeCode tc     = orb.get_primitive_tc (org.omg.CORBA.TCKind.tk_boolean);
      DynAny   dynAny = createDynAnyFromTypeCode (tc);

      String msg = "Value inserted into DynAny object is not equal to value ";
      msg += "extracted from same DynAny object";

      dynAny.insert_boolean (true);
      assertEquals (msg, true, dynAny.get_boolean());
   }
View Full Code Here

    * Test inserting a basic value into a DynAny that has a different typecode.
    */
   public void testInsertMismatch_boolean () throws Exception
   {
      TypeCode tc     = orb.get_primitive_tc (org.omg.CORBA.TCKind.tk_long);
      DynAny   dynAny = createDynAnyFromTypeCode (tc);

      try
      {
          dynAny.insert_boolean (true);
          fail ("should have thrown TypeMismatch");
      }
      catch (TypeMismatch ex)
      {
          // ok
View Full Code Here

    * Test retrieving a basic value from a DynAny that has a different typecode.
    */
   public void testRetrieveMismatch_boolean () throws Exception
   {
      TypeCode tc     = orb.get_primitive_tc (org.omg.CORBA.TCKind.tk_long);
      DynAny   dynAny = createDynAnyFromTypeCode (tc);
      dynAny.insert_long(700);

      try
      {
          dynAny.get_boolean();
          fail ("should have thrown TypeMismatch");
      }
      catch (TypeMismatch ex)
      {
          // ok
View Full Code Here

TOP

Related Classes of org.omg.DynamicAny.DynAny

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.