Package org.omg.DynamicAny

Examples of org.omg.DynamicAny.DynSequence


      type = getIntSeq ();
      any = orb.create_any ();
      BoundedDataHelper.insert (any, type);

      DynSequence sequence = createDynAnyFromAny (any);

      assertEquals(Bound.value, sequence.get_length());

      sequence.set_length(5);
      assertEquals(5, sequence.get_length());

      sequence.set_length(0);
      assertEquals(0, sequence.get_length());
   }
View Full Code Here


            DynAny _dynAny = toDynAny(value);
            _length = _dynAny.component_count();
            break;

        case TCKind._tk_sequence:
            DynSequence _dynSequence = toDynSequence(value);
            _length = _dynSequence.get_length();
            break;

        default:
            throw new EvaluationException("Neither array nor sequence");
        }
View Full Code Here

    public EvaluationResult evaluateElementInSequence(EvaluationContext context,
            EvaluationResult element, Any sequence) throws EvaluationException
    {
        try
        {
            final DynSequence _dynSequence = DynSequenceHelper.narrow(toDynAny(sequence));

            _dynSequence.rewind();

            do
            {
                final DynAny _currentComponent = _dynSequence.current_component();

                final EvaluationResult _currentElement = EvaluationResult.fromAny(_currentComponent.to_any());

                if (element.compareTo(_currentElement) == 0)
                {
                    return EvaluationResult.BOOL_TRUE;
                }
            } while (_dynSequence.next());

            return EvaluationResult.BOOL_FALSE;
        } catch (TypeMismatch e)
        {
            throw newEvaluationException(e);
View Full Code Here

                    DynUnion dynunion = (DynUnion)factory.create_dyn_any( a );
                    System.out.println("[Server]: member name " + dynunion.member_name());
                    printAny(dynunion.member().to_any());
                    break;
                case TCKind._tk_sequence:
                    DynSequence dynseq = (DynSequence)factory.create_dyn_any( a );
                    Any[] contents = dynseq.get_elements();
                    System.out.println("[Server]: ** Sequence of length " + contents.length + " **");
                    for( int i = 0; i < contents.length; i++)
                        printAny( contents[i]);
                    break;
                case TCKind._tk_array:
View Full Code Here

        // sequence

        TypeCode seq_tc =
            orb.create_sequence_tc( 2, orb.create_string_tc(0));
        DynSequence dyn_seq =
            (DynSequence)dynFactory.create_dyn_any_from_type_code( seq_tc );

        Any [] string_sequence = new Any[2];
        string_sequence[0] = orb.create_any();
        string_sequence[1] = orb.create_any();
        string_sequence[0].insert_string("hello");
        string_sequence[1].insert_string("world");
        dyn_seq.set_elements( string_sequence );

        System.out.println("[Client]: Passing a sequence of length " +
                dyn_seq.component_count() + "..." +
                s.generic( dyn_seq.to_any() ) );
        dyn_seq.destroy();

        // test the primitive get/set operations for DynSequences

        seq_tc =
            orb.create_sequence_tc( 1, orb.get_primitive_tc(org.omg.CORBA.TCKind.tk_boolean));

        dyn_seq = (DynSequence)dynFactory.create_dyn_any_from_type_code( seq_tc );

        dyn_seq.set_length( 1 );
        dyn_seq.insert_boolean( true );
        dyn_seq.destroy();

        // array

        TypeCode array_tc =
            orb.create_array_tc( 3, orb.create_string_tc(0));
        DynArray dyn_array =
            (DynArray)dynFactory.create_dyn_any_from_type_code( array_tc );

        string_sequence = new Any[3];
        string_sequence[0] = orb.create_any();
        string_sequence[1] = orb.create_any();
        string_sequence[2] = orb.create_any();
        string_sequence[0].insert_string("hello");
        string_sequence[1].insert_string("another");
        string_sequence[2].insert_string("world");
        dyn_array.set_elements( string_sequence );

        System.out.println("[Client]: Passing an array of length " +
                dyn_array.component_count() +
                "..." +  s.generic( dyn_array.to_any() ) );
        dyn_array.destroy();

        // struct

        /*
         * the hardest part is coming up with a correct call to
         * create the struct's TypeCode, which is normally
         * statically generated into the helper class
         */

        TypeCode struct_tc =
            orb.create_struct_tc(
                    "IDL:Node:1.0",
                    "Node",
                    new org.omg.CORBA.StructMember[]
                                                   {
                            new org.omg.CORBA.StructMember( "first",
                                    org.omg.CORBA.ORB.init().create_string_tc(0),
                                    null ),
                                    new org.omg.CORBA.StructMember( "second",
                                            org.omg.CORBA.ORB.init().create_sequence_tc(
                                                    0,
                                                    org.omg.CORBA.ORB.init().create_recursive_tc("IDL:Node:1.0")
                                            ),
                                            null)
                                                   }
            );

        DynStruct dyn_struct =
            (DynStruct)dynFactory.create_dyn_any_from_type_code(
                    struct_tc );

        // Create a list of name value pairs that holds the struct members.
        // This struct has two members, so we have 2 array elements

        // the first struct member is a string,
        // the member name is "first"

        NameValuePair[]  nvp_seq = new NameValuePair[2];
        Any first_member_any = orb.create_any();
        first_member_any.insert_string("first");
        nvp_seq[0] = new NameValuePair("first", first_member_any );

        /*
         the second member is a recursive sequence, ie. the element
             type of the sequence is that of the enclosing  struct, the
             member name is "second". We'll leave that sequence empty,
             but we have to provide an initialized any for the empty
             sequence, so we create a DynAny that initializes an any
             as an empty sequence
         */

        DynSequence second_member =
            (DynSequence)dynFactory.create_dyn_any_from_type_code(
                    struct_tc.member_type(1) );
        nvp_seq[1] =
            new NameValuePair("second", second_member.to_any() );

        // insert the nvp list into the DynStruct
        dyn_struct.set_members( nvp_seq );

        System.out.println("[Client]: Passing a struct..." +
                s.generic( dyn_struct.to_any() ) );

        // test the primitive get/set operations for DynStruct

        dyn_struct.seek(0);
        dyn_struct.insert_string( "newly inserted" );
        System.out.println("[Client]: Passing the struct again..." +
                s.generic( dyn_struct.to_any() ) );

        dyn_struct.destroy();
        second_member.destroy();

        /*              union            */

        // setting up TypeCodes gets even more complicated,
        // but you asked for it...
View Full Code Here


    @Test
    public void testInsertAnyObject() throws Exception
    {
        DynSequence dyn_seq = null;

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

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

        TypeCode seq_tc = orb.create_sequence_tc(2, tc);

        dyn_seq = (DynSequence) factory.create_dyn_any_from_type_code(seq_tc);

        Any[] object_sequence = new Any[2];
        object_sequence[0] = orb.create_any();
        object_sequence[1] = orb.create_any();
        object_sequence[0].insert_Object(obj, tc);
        object_sequence[1].insert_Object(obj, tc);

        dyn_seq.set_elements(object_sequence);

        dyn_seq.to_any();

        dyn_seq.destroy();
    }
View Full Code Here

    }

    @Test
    public void testInsertDynAnyObject() throws Exception
    {
        DynSequence dyn_seq = null;

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

        TypeCode seq_tc = orb.create_sequence_tc(2, tc);

        dyn_seq = (DynSequence) factory.create_dyn_any_from_type_code(seq_tc);

        DynAny[] object_sequence = new DynAny[2];

        object_sequence[0] = factory.create_dyn_any_from_type_code(tc);
        object_sequence[1] = factory.create_dyn_any_from_type_code(tc);

        dyn_seq.set_elements_as_dyn_any(object_sequence);

        dyn_seq.to_any();

        dyn_seq.destroy();
    }
View Full Code Here

      type = getIntSeq ();
      any = orb.create_any ();
      BoundedDataHelper.insert (any, type);

      DynSequence sequence = createDynAnyFromAny (any);

      assertEquals(Bound.value, sequence.get_length());

      sequence.set_length(5);
      assertEquals(5, sequence.get_length());

      sequence.set_length(0);
      assertEquals(0, sequence.get_length());
   }
View Full Code Here

            DynAny _dynAny = toDynAny(value);
            _length = _dynAny.component_count();
            break;

        case TCKind._tk_sequence:
            DynSequence _dynSequence = toDynSequence(value);
            _length = _dynSequence.get_length();
            break;

        default:
            throw new EvaluationException("Neither array nor sequence");
        }
View Full Code Here

    public EvaluationResult evaluateElementInSequence(EvaluationContext context,
            EvaluationResult element, Any sequence) throws EvaluationException
    {
        try
        {
            final DynSequence _dynSequence = DynSequenceHelper.narrow(toDynAny(sequence));

            _dynSequence.rewind();

            do
            {
                final DynAny _currentComponent = _dynSequence.current_component();

                final EvaluationResult _currentElement = EvaluationResult.fromAny(_currentComponent.to_any());

                if (element.compareTo(_currentElement) == 0)
                {
                    return EvaluationResult.BOOL_TRUE;
                }
            } while (_dynSequence.next());

            return EvaluationResult.BOOL_FALSE;
        } catch (TypeMismatch e)
        {
            throw newEvaluationException(e);
View Full Code Here

TOP

Related Classes of org.omg.DynamicAny.DynSequence

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.