KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > demo > unions > Client


1 package demo.unions;
2
3 import org.omg.CosNaming.*;
4
5 // an example for using IDL unions
6

7 public class Client
8 {
9     public static void main( String JavaDoc[] args )
10     {
11     try
12     {
13         org.omg.CORBA.ORB JavaDoc orb = org.omg.CORBA.ORB.init(args,null);
14         NamingContextExt nc =
15         NamingContextExtHelper.narrow(orb.resolve_initial_references("NameService"));
16
17         MyServer s = MyServerHelper.narrow(nc.resolve(nc.to_name("union.example")));
18             
19         UnitedColors my_union = new UnitedColors();
20         UnitedColorsHolder my_union_holder = new UnitedColorsHolder();
21
22         // set up union and make call
23

24         my_union.s("hallo");
25         s.writeUnion(my_union, my_union_holder);
26
27         // get the union that came back in the out holder
28

29         my_union = my_union_holder.value;
30
31         // examine the contents of the union that came back
32

33         switch (my_union.discriminator().value() )
34         {
35         case colorT._blue :
36             System.out.println("Blue: " + my_union.s() );
37             break;
38         case colorT._red :
39             System.out.println("Red: " + my_union.s() );
40             break;
41         default :
42             System.out.println("default: " + my_union.i() );
43         }
44         
45         String JavaDoc [] strs = {"hello", "world"};
46         
47         my_union.strs( strs );
48         s.writeUnion(my_union, my_union_holder);
49
50         /* other union type */
51
52         Nums n = new Nums();
53         n.l(4711);
54         s.write2ndUnion(n);
55         
56     }
57     catch (Exception JavaDoc se)
58     {
59         se.printStackTrace();
60     }
61     }
62 }
63
64
65
Popular Tags