import helloWorld.*;

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

public class Client 
{
    public static void main(String args[]) 
    {
        try 
	{
            // initialize the ORB.
            ORB orb = ORB.init( args, null );

            String ior;
            if( args.length == 1 )
            {
                // get object reference from command-line argument
                ior = args[0] ;
            }
            else
            {
                // get object reference from file
                ior = new BufferedReader( new FileReader("ior")).readLine();
            }

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

            // and narrow it to HelloWorld.GoodDay
            GoodDay goodDay = GoodDayHelper.narrow( obj );

            // check if stringified IOR is of the right type
            if( goodDay == null ) 
	    {
                 System.err.println("stringified IOR is not of type GoodDay");
                 System.exit( 1 );
            }

            // invoke the operation and print the result
            myStruct[] s = goodDay.helloStruct();

            System.out.println("Hello returned an array of size: "+s.length);
            for (int i=0; i<s.length; i++) {
                System.out.println( "["+i+"]  a_long  :" + s[i].a_long);
                System.out.println( "["+i+"]  a_string:" + s[i].a_string);
            }
        }
        // catch CORBA system exceptions
        catch(SystemException ex) 
	{
            System.err.println(ex);
            ex.printStackTrace();
        }
        catch(IOException ex) 
	{
            System.err.println(ex);
            ex.printStackTrace();
        }
    }
}

