01: package demo.value.idl;
02:
03: import java.io.*;
04: import org.omg.CORBA.*;
05:
06: public class Client {
07: public static void main(String args[]) {
08: if (args.length != 1) {
09: System.out
10: .println("Usage: java demo.value.idl.Client <ior_file>");
11: System.exit(1);
12: }
13:
14: try {
15: File f = new File(args[0]);
16:
17: //check if file exists
18: if (!f.exists()) {
19: System.out.println("File " + args[0]
20: + " does not exist.");
21:
22: System.exit(-1);
23: }
24:
25: //check if args[0] points to a directory
26: if (f.isDirectory()) {
27: System.out.println("File " + args[0]
28: + " is a directory.");
29:
30: System.exit(-1);
31: }
32:
33: // initialize the ORB.
34: ORB orb = ORB.init(args, null);
35:
36: BufferedReader br = new BufferedReader(new FileReader(f));
37:
38: // get object reference from command-line argument file
39: org.omg.CORBA.Object obj = orb.string_to_object(br
40: .readLine());
41: br.close();
42:
43: ValueServer s = ValueServerHelper.narrow(obj);
44:
45: // invoke operations and print the results
46: boxedLong p1 = new boxedLong(774);
47: boxedLong p2 = new boxedLong(774);
48:
49: System.out.println("Passing two integers: "
50: + s.receive_long(p1, p2));
51:
52: System.out.println("Passing one integer twice: "
53: + s.receive_long(p1, p1));
54:
55: System.out.println("Passing two strings: "
56: + s.receive_string("hello", "hello"));
57:
58: System.out.println("Passing null: "
59: + s.receive_string("hello", null));
60:
61: Node n1 = new NodeImpl(1);
62: Node n2 = new NodeImpl(2);
63: Node n3 = new NodeImpl(3);
64: Node n4 = new NodeImpl(4);
65:
66: n1.next = n2;
67: n2.next = n3;
68: n3.next = n4;
69: n4.next = n1;
70:
71: System.out.println("Passing a list structure: "
72: + s.receive_list(n1));
73: } catch (Exception ex) {
74: System.err.println(ex);
75: }
76: }
77: }
|