01: package demo.outparam;
02:
03: /**
04: * An example for using out paramters
05: */
06:
07: import org.omg.CORBA.*;
08: import org.omg.CosNaming.*;
09:
10: public class Client {
11: public static void main(String[] args) {
12: try {
13: org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null);
14:
15: // get hold of the naming service
16: NamingContextExt nc = NamingContextExtHelper.narrow(orb
17: .resolve_initial_references("NameService"));
18:
19: NameComponent[] name = new NameComponent[] { new NameComponent(
20: "ParamServer", "service") };
21:
22: // resolve name to get a reference to our server
23: MyServer s = MyServerHelper.narrow(nc.resolve(name));
24:
25: DoubleHolder doh = new DoubleHolder();
26: s.addNums((double) 5, (double) 6, doh);
27: System.out.println("addNums 5 and 6 gives: " + doh.value);
28:
29: String a[];
30: stringSeqHolder sh = new stringSeqHolder();
31: s.op1("hi_there", sh);
32: a = sh.value;
33: System.out.println("String array contains: ");
34: for (int i = 0; i < a.length; i++)
35: System.out.println("\t" + i + ": " + a[i]);
36:
37: MyServerHolder h = new MyServerHolder();
38: s.op2(h);
39: MyServer s2 = h.value;
40: s2.print("Who am I talking to?");
41:
42: my_structHolder moh = new my_structHolder();
43: s.op3(moh);
44: my_struct m = moh.value;
45: System.out.println("Struct contains: " + m.s + " " + m.l);
46:
47: stringArrayHolder sah = new stringArrayHolder();
48: s.op4(sah);
49: String my_array[] = sah.value;
50: System.out.println("Array size: " + my_array.length);
51:
52: StringHolder sh1 = new StringHolder();
53: String sh2 = s.op5(sh1);
54: System.out.println(sh2 + " out: " + sh1.value);
55:
56: // an example for a sequence of sequences of sequences of string
57: //
58: // set up a 3-dimensional string array
59:
60: String[][][] string_cube = new String[1][2][3];
61: for (int i = 0; i < string_cube.length; i++)
62: for (int j = 0; j < string_cube[i].length; j++)
63: for (int k = 0; k < string_cube[i][j].length; k++)
64: string_cube[i][j][k] = "(" + i + "," + k + ","
65: + j + ")";
66:
67: // put it into the appropriate holder for inout semantics
68:
69: stringCubeHolder sf = new stringCubeHolder(string_cube);
70:
71: // invoke the operation
72:
73: s.stringCubeInOut(sf);
74:
75: // get the returned string cube
76:
77: string_cube = sf.value;
78:
79: System.out.println("string_cube after operation: ");
80:
81: for (int i = 0; i < string_cube.length; i++)
82: for (int j = 0; j < string_cube[i].length; j++)
83: for (int k = 0; k < string_cube[i][j].length; k++)
84: System.out.println(string_cube[i][j][k]);
85:
86: System.out
87: .println("---Everything went alright, closing down now---");
88:
89: } catch (Exception e) {
90: e.printStackTrace();
91: }
92: }
93: }
|