/*
 * Server to test the passing of arrays of complex types, showing the
 * use of in/inout/out parameters and Holders
 *
 * Note that IDL sequences map to Java arrays
 */

import java.io.*;
import org.omg.PortableServer.*;                                                


public class SeqOfComplexTestImpl extends seqOfComplex.SeqOfComplexTestPOA
{
    

    public int testSeqOfComplex(
                 seqOfComplex.BasicStruct[] inSeqOfComplex,
                 seqOfComplex.BasicStructSeqHolder inoutSeqOfComplex, 
                 seqOfComplex.BasicStructSeqHolder outSeqOfComplex) 
    {
        //Print the parameters as passed
        //        System.out.println("Begining method testSeqOfComplex\n" + 
        //                  "\tin param " + inSeqOfComplex + "\n" + 
        //                 "\tinout param " + inoutSeqOfComplex.value + "\n" + 
        //                   "\tout param " + outSeqOfComplex.value);
        
        //Change the values in the inout array
        inoutSeqOfComplex.value[0].longVal = 6;
        inoutSeqOfComplex.value[0].stringVal = "fromServer";
        inoutSeqOfComplex.value[1].longVal = 6;
        inoutSeqOfComplex.value[1].stringVal = "fromServer";
        
        //Create a new array for the out value then assign values
        outSeqOfComplex.value = 
            new seqOfComplex.BasicStruct[2];
        outSeqOfComplex.value[0]= 
            new seqOfComplex.BasicStruct(6, "fromServer");
        outSeqOfComplex.value[1]= 
            new seqOfComplex.BasicStruct(6, "fromServer");
        
        //Print the parameters as returned
        //System.out.println("Before returning from method testSeqOfComplex\n" + 
        //                  "\tin param " + inSeqOfComplex + "\n" + 
        //                 "\tinout param " + inoutSeqOfComplex.value + "\n" + 
        //                  "\tout param " + outSeqOfComplex.value);

        return 0;
    }

    //Put registration code here in a main for convienence
    public static void main(String[] args)
    {
        try {
            // Initialize the ORB.
            org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null);
            
            POA poa = POAHelper.narrow(orb.resolve_initial_references("RootPOA")); 
            poa.the_POAManager().activate();                   
            // Create the object
            SeqOfComplexTestImpl impl_obj =
                new SeqOfComplexTestImpl();

            // create the object reference                 
            org.omg.CORBA.Object obj = poa.servant_to_reference(impl_obj); 
  

            // print stringified object reference             
            FileWriter out = new FileWriter("ior");         
            out.write( orb.object_to_string( obj ) );     
            out.close();   
                
                // wait for requests                         
                System.out.println("Server started with IOR: "       
                                   + orb.object_to_string(obj)); 
                orb.run();                
            }
        catch(org.omg.CORBA.SystemException ex) {
            ex.printStackTrace();
        }
        catch( java.lang.Exception ie) {            
            System.err.println(ie);       
        }                       

    }
}

