01: package demo.imr;
02:
03: import java.io.*;
04: import org.omg.CORBA.*;
05:
06: import org.jacorb.util.*;
07:
08: public class Client {
09: public static void main(String args[]) {
10: if (args.length != 1) {
11: System.out
12: .println("Usage: jaco demo.imr.Client <ior_file>");
13: System.exit(1);
14: }
15:
16: try {
17: File f = new File(args[0]);
18:
19: //check if file exists
20: if (!f.exists()) {
21: System.out.println("File " + args[0]
22: + " does not exist.");
23:
24: System.exit(-1);
25: }
26:
27: //check if args[0] points to a directory
28: if (f.isDirectory()) {
29: System.out.println("File " + args[0]
30: + " is a directory.");
31:
32: System.exit(-1);
33: }
34:
35: // initialize the ORB.
36: ORB orb = ORB.init(args, null);
37:
38: BufferedReader br = new BufferedReader(new FileReader(f));
39:
40: // get object reference from command-line argument file
41: org.omg.CORBA.Object obj = orb.string_to_object(br
42: .readLine());
43:
44: br.close();
45:
46: //narrow to correct interface
47: SomeIf demo = SomeIfHelper.narrow(obj);
48:
49: //call remote op
50: System.out.println("Client: will call server");
51: demo.op();
52: System.out.println("Client: successfully called server");
53: } catch (Exception ex) {
54: System.err.println(ex);
55: }
56: }
57: }
|