KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > demo > outparam > Client


1 package demo.outparam;
2
3 /**
4  * An example for using out paramters
5  */

6
7 import org.omg.CORBA.*;
8 import org.omg.CosNaming.*;
9
10 public class Client
11 {
12     public static void main( String JavaDoc[] args )
13     {
14     try
15     {
16         org.omg.CORBA.ORB JavaDoc orb = org.omg.CORBA.ORB.init(args,null);
17
18         // get hold of the naming service
19
NamingContextExt nc =
20                 NamingContextExtHelper.narrow(
21                        orb.resolve_initial_references("NameService"));
22
23         NameComponent [] name =
24                 new NameComponent[]{
25                     new NameComponent("ParamServer", "service")
26                         };
27
28         // resolve name to get a reference to our server
29
MyServer s = MyServerHelper.narrow(nc.resolve(name));
30
31         DoubleHolder doh = new DoubleHolder();
32         s.addNums( (double)5, (double)6, doh);
33         System.out.println("addNums 5 and 6 gives: " + doh.value);
34
35         String JavaDoc a[];
36         stringSeqHolder sh = new stringSeqHolder( );
37         s.op1( "hi_there" , sh );
38         a = sh.value;
39         System.out.println( "String array contains: ");
40         for( int i = 0; i < a.length; i++ )
41         System.out.println( "\t" + i + ": " + a[i] );
42
43         MyServerHolder h = new MyServerHolder();
44         s.op2(h);
45         MyServer s2 = h.value;
46         s2.print("Who am I talking to?");
47
48         my_structHolder moh = new my_structHolder();
49         s.op3(moh);
50         my_struct m = moh.value;
51         System.out.println( "Struct contains: " + m.s + " " + m.l);
52
53         stringArrayHolder sah = new stringArrayHolder();
54         s.op4(sah);
55         String JavaDoc my_array[] = sah.value;
56         System.out.println("Array size: " + my_array.length );
57
58             StringHolder sh1 = new StringHolder();
59             String JavaDoc sh2 = s.op5( sh1 );
60             System.out.println( sh2 + " out: " + sh1.value );
61
62
63         // an example for a sequence of sequences of sequences of string
64
//
65
// set up a 3-dimensional string array
66

67         String JavaDoc [][][] string_cube = new String JavaDoc[1][2][3];
68         for( int i=0; i<string_cube.length;i++)
69         for( int j = 0; j < string_cube[i].length;j++)
70             for( int k = 0; k < string_cube[i][j].length;k++)
71             string_cube[i][j][k] = "("+i+","+ k + "," +j+")";
72  
73         // put it into the appropriate holder for inout semantics
74

75         stringCubeHolder sf = new stringCubeHolder(string_cube);
76
77         // invoke the operation
78

79         s.stringCubeInOut(sf);
80
81         // get the returned string cube
82

83         string_cube = sf.value;
84
85         System.out.println( "string_cube after operation: ");
86
87         for( int i=0; i<string_cube.length;i++)
88         for( int j = 0; j < string_cube[i].length;j++)
89             for( int k = 0; k < string_cube[i][j].length;k++)
90             System.out.println(string_cube[i][j][k]);
91
92         System.out.println("---Everything went alright, closing down now---");
93
94     }
95     catch ( Exception JavaDoc e)
96     {
97         e.printStackTrace();
98     }
99     }
100 }
101
102
103
104
105
Popular Tags