import helloWorld.*;

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

public class Client 
{
    public static void main(String args[]) 
    {
        // create Holder objects for out parameters
    	ShortHolder minute = new ShortHolder();
    	ShortHolder hour = new ShortHolder();

    	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 GoodDay
            GoodDay goodDay = GoodDayHelper.narrow( obj );

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

            // invoke the operation
            String location = new String( goodDay.hello( hour, minute ) );

            // print results to stdout
            System.out.println("Hello World!");
            if( minute.value < 10 ) 
                System.out.println("The local time in " + location +
                    " is " + hour.value + ":0" + minute.value + "." );
            else
                System.out.println("The local time in " + location +
                    " is " + hour.value + ":" + minute.value + "." );
        }
        // catch exceptions
        catch( SystemException ex) {
            System.err.println(ex);
        }
        catch( IOException ex) {
            System.err.println(ex);
        }
    }
}

