Search code examples
javacorbaidl

Add elements in ObjectList in Java using CORBA


I have an unbounded sequence in the IDL file as follows :

struct Info {
            string name;
        };

typedef sequence<Info> InfoList;

InfoList search(in short length); 

ServantClass present in server implments the interface as follows.

public Info[] search(short length) {

 Info[] infolist;

 for(int i =0; i<= length; i++) {
    /*
     *  I want to add/push a 'name' into infolist.
     *  may be something like infolist.push()
     */

 }

}

How can I push name elements into the info objet. Any suggestions?


Solution

  • You could pass the name to Info's constructor

    @Override
    public Info[] search(short length) {
        Info[] infolist = new Info[length];
    
        for (int i = 0; i < infolist.length; i++) {
            infolist[i] = new Info("New Name");
        }
    
        return infolist;
    }