//#
//# Corba Time Client
//# $Revision: 1.1 $
//# Copyright 2004 by Eric Y. Theriault
//# All Rights Reserved.
//# http://www.eyt.ca/CORBA
//#
package ca.eyt.corba;

/**
 * Implements a class to acquire the Time from a CORBA server.
 *
 * @author Eric Y. Theriault <eric@eyt.ca>
 */
public class TimeClient {
   /**
    * main
    *
    * @param args Currently forwarded directly to ORB.init.
    */
   public static void main( String args[] ) {
      try {
         String ior = null;
         String iorFile = "time.ior";

         // Create and Initialize the ORB
         org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init( args, null );

         // Create the file reader...
         java.io.FileReader fileReader = null;
         java.io.BufferedReader reader = null;
         try {
            fileReader = new java.io.FileReader( iorFile );
            reader = new java.io.BufferedReader( fileReader );
         } catch ( java.io.FileNotFoundException fnfe ) {
            System.err.println( iorFile + " does not exist." );
            System.exit( 1 );
         }

         // Read in the IOR from the file...
         try {
            ior = reader.readLine();
         } catch ( java.io.IOException ioe ) {
            System.err.println( iorFile + ": exception raised: " );
            ioe.printStackTrace();
            System.exit( 1 );
         } finally {
            reader = null;
            try {
               fileReader.close();
            } catch ( java.io.IOException ioe ) {
               System.err.println( iorFile + ": exception raised " +
                                   "closing the file: " );
               ioe.printStackTrace();
            }
            fileReader = null;
         }

         // Resolve the ior into an object.
         org.omg.CORBA.Object object = orb.string_to_object( ior );
         ca.eyt.corba.corba.Time timeImpl =
                         ca.eyt.corba.corba.TimeHelper.narrow( object );


         // OK.  Let's call the Time interface's methods.
         ca.eyt.corba.corba.TimeOfDay time = timeImpl.getTime();
         System.out.println( "Time server's time is: " +
                             time.hour + ":" + time.minute + ":" +
                             time.second );
      } catch ( Throwable t ) {
         System.err.println( "Exception raised: " );
         t.printStackTrace();
      }
   }
};

