//#
//# 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 TimeClient2 {
   /**
    * main
    *
    * @param args Currently forwarded directly to ORB.init.
    */
   public static void main( String args[] ) {
      try {
         // Create and Initialize the ORB
         org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init( args, null );

         // Get the root naming context.
         org.omg.CORBA.Object objectReference =
                        orb.resolve_initial_references( "NameService" );
         org.omg.CosNaming.NamingContextExt ncRef =
                       org.omg.CosNaming.NamingContextExtHelper.narrow(
                                                         objectReference
                                                                      );

         // Resolve a reference into an object.
         String name = "Time";
         org.omg.CORBA.Object object = ncRef.resolve_str( name );
         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();
      }
   }
};

