1 package demo.any; 2 3 import java.io.*; 4 import org.omg.CORBA.Any ; 5 import org.omg.PortableServer.*; 6 import org.omg.CosNaming.*; 7 import org.omg.CORBA.OctetSeqHelper ; 8 import org.omg.CORBA.StringSeqHelper ; 9 10 public class Client 11 extends AnyServerPOA 12 { 13 public static AnyServer s = null; 14 private static int counter; 15 16 private synchronized static void incr(int val) 17 { 18 counter += val; 19 } 20 21 public java.lang.String generic(Any a) 22 { 23 System.out.println("Someone called me!"); 24 incr(-1); 25 return "call back succeeded!"; 26 } 27 28 public static void main( String [] args ) 29 { 30 try 31 { 32 org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args,null); 33 34 NamingContextExt nc = 36 NamingContextExtHelper.narrow(orb.resolve_initial_references("NameService")); 37 38 AnyServer s = 39 AnyServerHelper.narrow(nc.resolve(nc.to_name("AnyServer.service"))); 40 41 Any a = org.omg.CORBA.ORB.init().create_any(); 43 44 char ch = 'c'; 46 System.out.print("Passing a char..."); 47 a.insert_char( (char)ch ); 48 System.out.println( s.generic( a ) ); 49 50 long l = 4711; 52 System.out.print("Passing a longlong..."); 53 a.insert_longlong( l ); 54 System.out.println( s.generic( a ) ); 55 56 System.out.print("Passing a short..."); 58 a.insert_short( (short)5 ); 59 System.out.println( s.generic( a ) ); 60 61 System.out.print("Passing a float..."); 63 a.insert_float( (float)3.14); 64 System.out.println( s.generic( a ) ); 65 66 System.out.print("Passing a string..."); 68 a.type( orb.create_string_tc(0)); 69 a.insert_string("Hi there"); 70 System.out.println( s.generic( a ) ); 71 72 System.out.print("Passing a Wstring..."); 74 a.insert_wstring( "Hi there" ); 77 78 System.out.println("Any.kind: " + a.type().kind().value() ); 79 80 System.out.println( s.generic( a ) ); 81 82 84 String [] str = {"hello","world"}; 85 MyStringSeqHelper.insert( a, str ); 86 System.out.print("Alias? " + a.type()); 87 System.out.print("Passing a sequence of strings..."); 88 System.out.println( s.generic( a ) ); 89 90 System.out.print("Passing a sequence of octets..."); 91 byte [] octets = {1,2,3,4}; 92 OctetSeqHelper.insert( a, octets ); 93 System.out.println( s.generic( a ) ); 94 95 97 System.out.print("Passing an array..."); 98 String [] str2 = {"hello","another","world"}; 99 stringsHelper.insert( a, str2 ); 100 System.out.println( s.generic( a ) ); 101 102 System.out.print("Passing a struct..."); 104 Node tail = new Node("tail" , new Node[0] ); 105 Node head = new Node("head" , new Node[]{tail} ); 106 NodeHelper.insert( a, head ); 107 System.out.println( s.generic( a ) ); 108 109 System.out.print("Passing a union..."); 111 Nums n = new Nums(); 112 n.l(4711); 113 NumsHelper.insert( a, n ); 114 System.out.println( s.generic( a ) ); 115 116 117 118 incr(1); 120 System.out.print("Passing an object..."); 121 POA poa = POAHelper.narrow(orb.resolve_initial_references("RootPOA")); 122 poa.the_POAManager().activate(); 123 124 Client c = new Client(); 125 poa.activate_object(c); 126 127 128 129 a.insert_Object(c._this_object()); 130 System.out.println( "Output of generic: " + s.generic( a ) ); 131 132 incr(1); 133 134 System.out.print("Passing object again"); 135 136 137 138 AnyServerHelper.insert( a, c._this()); 139 System.out.println( "Output of generic: " + s.generic( a ) ); 140 141 142 143 144 System.out.print("Passing an any"); 145 Any inner_any = orb.create_any(); 146 inner_any.insert_string("Hello in any"); 147 a.insert_any(inner_any); 148 System.out.println( "Output of generic: " + s.generic( a ) ); 149 150 while( counter > 0 ) 151 { 152 System.out.print("Going to sleep to wait for incoming calls"); 153 Thread.currentThread().sleep(3000); 154 } 155 orb.shutdown(true); 156 } 157 catch ( Exception e) 158 { 159 e.printStackTrace(); 160 } 161 } 162 } 163 164 165 | Popular Tags |