IDL-JAVA Method returning Vector

IDL-JAVA Method returning Vector

Post by Raul Gui » Wed, 03 May 2000 04:00:00



How can I set a method returning a Vector in a IDL generated interface?
thanks
 
 
 

IDL-JAVA Method returning Vector

Post by Stephen Crawle » Thu, 18 May 2000 04:00:00



> How can I set a method returning a Vector in a IDL generated interface?
> thanks

You can't pass or return a java.lang.Vector in a CORBA IDL operation
(*).  What you probably ought to do is to declare your IDL something
like this:

  module Foo {
    typedef sequence < string > StringSeq;

    interface Bar {
      StringSeq my_op();
    };
  };

Then in your Java implementation of Bar, implement "my_op" as:

  public java.lang.String[] my_op() {
    java.util.Vector resVec = ...;  // calculate result

    java.lang.String[] res = new java.lang.String[resVec.size()];

    resVec.copyInto(res);

    return res;
  }

(* Actually, you can transfer a java.lang.Vector (or any other Java
type) if you are prepared to write your own code to custom marshal /
unmarshal between a value and a CORBA "sequence <octet>" data type.
However, that's a lot uglier than doing what I've suggested above.)

-- Steve