1 // ============================================================================
4 // TAO/examples/Simple/time
10 // This class implements a Java client interface to the Time example.
13 // Martin Krumpolec <krumpo@pobox.sk>
15 // ============================================================================
17 import JACE
.Misc
.GetOpt
;
18 import org
.omg
.CosNaming
.*;
19 import org
.omg
.CORBA
.*;
22 public class Time_Client
24 private ORB orb
= null;
25 private org
.omg
.CORBA
.Object timeRef
= null;
26 private boolean shutdown
= false;
27 private boolean use_naming_service
= false;
28 private String ior_file
= null;
29 private String ior
= null;
31 Time_Client (String args
[])
33 orb
= ORB
.init (args
, null);
37 private void parse_args (String args
[])
39 GetOpt getopt
= new GetOpt (args
, "k:f:xn");
43 while ((ch
= getopt
.next ()) != -1)
48 ior
= getopt
.opt_arg () ();
51 ior_file
= getopt
.opt_arg () ();
54 java
.io
.FileInputStream file
=
55 new FileInputStream(ior_file
);
56 java
.io
.BufferedReader myInput
=
58 (new InputStreamReader (file
));
59 ior
= myInput
.readLine();
63 System
.out
.println ("Error: " + e
);
70 use_naming_service
= true;
80 private Time
get_time_object ()
84 org
.omg
.CORBA
.Object objref
= orb
.string_to_object (ior
);
85 return TimeHelper
.narrow (objref
);
89 if (use_naming_service
)
91 // Use multicast to obtain NS handle.
92 NS_Resolve ns_resolve
=
93 new NS_Resolve (null);
94 org
.omg
.CORBA
.Object objRef
=
95 ns_resolve
.resolve_name_service (orb
);
97 // Get the root naming context.
99 NamingContextHelper
.narrow (objRef
);
100 System
.out
.println ("got initial NS reference");
102 // Resolve the Object Reference in Naming.
104 new NameComponent ("Time", "");
105 NameComponent path
[] = {nc
};
108 return TimeHelper
.narrow (ncRef
.resolve (path
));
112 System
.out
.println ("Error: " + e
);
119 public static void main (String args
[])
123 Time_Client client
= new Time_Client (args
);
124 Time timeRef
= client
.get_time_object ();
128 System
.out
.println ("Unable to resolve Time.");
132 // Call the Time server object and print results.
133 int time
= timeRef
.current_time ();
135 java
.util
.Date date
=
136 new java
.util
.Date (((long) time
) * 1000);
138 System
.out
.println ("string time is " + date
);
143 System
.out
.println ("Shutting down server ...");
148 System
.out
.println ("ERROR : " + e
) ;
149 e
.printStackTrace (System
.out
);