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 my_struct = goodDay.helloStruct();

            System.out.println( "Hello returned a struct: ");
            System.out.println( "   a_long  :" + my_struct.a_long);
            System.out.println( "   a_string:" + my_struct.a_string);
        }
        // catch CORBA system exceptions
        catch(SystemException ex) 
	{
            System.err.println(ex);
        }
        catch(IOException ex) 
	{
            System.err.println(ex);
        }
    }
}

