01: package demo.arrays;
02:
03: /**
04: * an example for using IDL arrays and sequences
05: * with JacORB
06: */
07:
08: import demo.arrays.MyServerPackage.*;
09: import org.omg.CosNaming.*;
10:
11: class Client {
12: public static void main(String args[]) {
13: org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null);
14: try {
15: // get hold of the naming service
16: NamingContextExt nc = NamingContextExtHelper.narrow(orb
17: .resolve_initial_references("NameService"));
18:
19: // resolve name to get a reference to our server
20: MyServer g = MyServerHelper.narrow(nc.resolve(nc
21: .to_name("arrayServer.example")));
22:
23: // send and receive a *sequence* of integers
24:
25: int[] j = new int[] { 1, 2, 3, 4 };
26: int[] i = g.write2("Hello World!", j);
27: System.out.println("Result: " + i[0]);
28:
29: // send an *array* of integers as an argument
30:
31: int[] a = new int[] { 55, 56, 57 };
32: i = g.write("Again...", a);
33: for (int ii = 0; ii < i.length; ii++)
34: System.out.println(" " + i[ii]);
35:
36: // send an array of object references as an argument
37:
38: MyServer[] svs = new MyServer[] { g, g };
39: g._notify(svs);
40: g.notify2(svs);
41:
42: // send a struct containing an array of shorts
43:
44: short[][] shorts = new short[][] { { 1, 7, 2 },
45: { 2, 6, 2 }, { 3, 5, 2 }, { 4, 4, 2 }, { 5, 3, 2 },
46: { 6, 2, 2 }, { 7, 1, 2 } };
47:
48: arrayContainer ac = new arrayContainer(shorts);
49: g.notify3(ac);
50:
51: // test printLongArray
52: long[] refs = new long[10];
53: for (int ir = 0; ir < refs.length; ir++)
54: refs[ir] = (long) ir;
55:
56: g.printLongArray(refs);
57:
58: // test printLongArray
59: double[] drefs = new double[10];
60: for (int ir = 0; ir < drefs.length; ir++)
61: drefs[ir] = (float) ir;
62:
63: g.printDoubleArray(drefs);
64:
65: } catch (Exception e) {
66: e.printStackTrace();
67: }
68: }
69: }
|