KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > demo > arrays > Client


1 package demo.arrays;
2
3 /**
4  * an example for using IDL arrays and sequences
5  * with JacORB
6  */

7
8 import demo.arrays.MyServerPackage.*;
9 import org.omg.CosNaming.*;
10
11 class Client
12 {
13     public static void main(String JavaDoc args[])
14     {
15     org.omg.CORBA.ORB JavaDoc orb = org.omg.CORBA.ORB.init(args,null);
16     try
17     {
18         // get hold of the naming service
19
NamingContextExt nc =
20         NamingContextExtHelper.narrow(orb.resolve_initial_references("NameService"));
21
22         // resolve name to get a reference to our server
23
MyServer g = MyServerHelper.narrow(nc.resolve(nc.to_name("arrayServer.example")));
24
25         // send and receive a *sequence* of integers
26

27         int[] j = new int[]{1,2,3,4};
28         int[] i = g.write2("Hello World!", j);
29         System.out.println("Result: " + i[0]);
30
31         // send an *array* of integers as an argument
32

33         int[] a = new int[] {55,56,57};
34         i = g.write("Again...", a);
35         for( int ii = 0; ii < i.length; ii++)
36         System.out.println(" " + i[ii]);
37
38         // send an array of object references as an argument
39

40         MyServer[] svs = new MyServer[]{g,g};
41         g._notify( svs);
42         g.notify2( svs );
43
44         // send a struct containing an array of shorts
45

46         short [][] shorts = new short[][]{{1,7,2},{2,6,2},{3,5,2},{4,4,2},{5,3,2},{6,2,2},{7,1,2}};
47
48         arrayContainer ac =
49         new arrayContainer( shorts );
50         g.notify3( ac );
51
52
53             // test printLongArray
54
long[] refs = new long[10];
55             for (int ir=0; ir<refs.length; ir++ )
56                 refs[ir] = (long)ir;
57             
58             g.printLongArray(refs);
59
60             // test printLongArray
61
double[] drefs = new double[10];
62             for (int ir = 0; ir < drefs.length; ir++ )
63                 drefs[ir] = (float)ir;
64             
65             g.printDoubleArray( drefs);
66
67     
68     }
69     catch (Exception JavaDoc e)
70     {
71         e.printStackTrace();
72     }
73     }
74 }
75
76
77
Popular Tags