01: package demo.unions;
02:
03: import org.omg.CosNaming.*;
04:
05: // an example for using IDL unions
06:
07: public class Client {
08: public static void main(String[] args) {
09: try {
10: org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null);
11: NamingContextExt nc = NamingContextExtHelper.narrow(orb
12: .resolve_initial_references("NameService"));
13:
14: MyServer s = MyServerHelper.narrow(nc.resolve(nc
15: .to_name("union.example")));
16:
17: UnitedColors my_union = new UnitedColors();
18: UnitedColorsHolder my_union_holder = new UnitedColorsHolder();
19:
20: // set up union and make call
21:
22: my_union.s("hallo");
23: s.writeUnion(my_union, my_union_holder);
24:
25: // get the union that came back in the out holder
26:
27: my_union = my_union_holder.value;
28:
29: // examine the contents of the union that came back
30:
31: switch (my_union.discriminator().value()) {
32: case colorT._blue:
33: System.out.println("Blue: " + my_union.s());
34: break;
35: case colorT._red:
36: System.out.println("Red: " + my_union.s());
37: break;
38: default:
39: System.out.println("default: " + my_union.i());
40: }
41:
42: String[] strs = { "hello", "world" };
43:
44: my_union.strs(strs);
45: s.writeUnion(my_union, my_union_holder);
46:
47: /* other union type */
48:
49: Nums n = new Nums();
50: n.l(4711);
51: s.write2ndUnion(n);
52:
53: } catch (Exception se) {
54: se.printStackTrace();
55: }
56: }
57: }
|