blob: be477bfcbddafd2fdb5ce3519f823fb486d8d2e2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
// $Id$
// ============================================================================
//
// = LIBRARY
// TAO/examples/Simple/time
//
// = FILENAME
// Time_Client.java
//
// = DESCRIPTION
// This class implements a Java client interface to the Time example.
//
// = AUTHOR
// Martin Krumpolec <krumpo@pobox.sk>
//
// ============================================================================
import org.omg.CosNaming.*;
import org.omg.CORBA.*;
public class TimeClient
{
public static void main (String args[])
{
try
{
// Create and initialize the ORB.
ORB orb = ORB.init (args, null);
// Use multicast to obtain NS handle.
NS_Resolve ns_resolve =
new NS_Resolve (null);
org.omg.CORBA.Object objRef =
ns_resolve.resolve_name_service (orb);
// Get the root naming context.
NamingContext ncRef =
NamingContextHelper.narrow (objRef);
System.out.println ("got initial NS reference");
// Resolve the Object Reference in Naming.
NameComponent nc =
new NameComponent ("Time", "");
NameComponent path[] = {nc};
Time timeRef =
TimeHelper.narrow (ncRef.resolve (path));
// Call the Time server object and print results.
int time = timeRef.time ();
java.util.Date date =
new java.util.Date (((long) time) * 1000);
System.out.println ("string time is " + date);
}
catch (Exception e)
{
System.out.println ("ERROR : " + e) ;
e.printStackTrace (System.out);
}
}
}
|