1 package demo.any; 2 3 import org.omg.CORBA.Any ; 4 import org.omg.CORBA.TCKind ; 5 import org.omg.CORBA.StringSeqHelper ; 6 import org.omg.CORBA.OctetSeqHelper ; 7 8 public class AnyServerImpl 9 extends AnyServerPOA 10 { 11 org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(); 12 13 public AnyServerImpl(){} 14 15 public java.lang.String generic(Any a) 16 { 17 String result = "<empty>"; 18 try 19 { 20 int kind = a.type().kind().value(); 21 22 switch( kind ) 23 { 24 case TCKind._tk_char: 25 result = "char: " + a.extract_char(); 26 break; 27 case TCKind._tk_longlong: 28 result = "longlong: " + a.extract_longlong(); 29 break; 30 case TCKind._tk_short: 31 result ="Short: " + a.extract_short(); 32 break; 33 case TCKind._tk_double: 34 result = "Double: " + a.extract_double(); 35 break; 36 case TCKind._tk_float: 37 result = "Float: " + a.extract_float(); 38 break; 39 case TCKind._tk_string: 40 result = "String: " + a.extract_string(); 41 break; 42 case TCKind._tk_wstring: 43 result = "WString: " + a.extract_wstring(); 44 break; 45 case TCKind._tk_struct: 46 if( NodeHelper.type().equal( a.type())) 47 { 48 StringBuffer sb = new StringBuffer (); 49 Node t = NodeHelper.extract( a ); 50 sb.append( " " + t.name ); 51 do 52 { 53 t = t.next[0]; 54 sb.append( " " + t.name ); 55 } 56 while( t.next.length > 0 ); 57 result = sb.toString(); 58 } 59 break; 60 case TCKind._tk_union: 61 Nums n = NumsHelper.extract( a ); 62 switch (n.discriminator() ) 63 { 64 case 'l' : 65 result = "Union: l " + n.l(); 66 break; 67 case 'f' : 68 result = "Union: f " + n.f(); 69 break; 70 default : 71 result = "default: " + n.s(); 72 } 73 break; 74 case TCKind._tk_objref: 75 System.out.println("Objectref."); 76 AnyServer s = AnyServerHelper.narrow(a.extract_Object()); 77 Any any = org.omg.CORBA.ORB.init().create_any(); 78 any.insert_string("hallo"); 79 result = s.generic( any ); 80 break; 81 case TCKind._tk_any: 82 System.out.println("Any."); 83 Any inner_any = a.extract_any(); 84 result = generic( inner_any ); 85 break; 86 case TCKind._tk_alias: 87 System.out.print("Alias: "); 88 Any alias_any = a; 89 if( alias_any.type().equal( MyStringSeqHelper.type())) 90 { 91 String [] stra = MyStringSeqHelper.extract( alias_any ); 92 for( int slen = 0; slen < stra.length; slen++ ) 93 result += stra[slen]; 94 } 95 else if( alias_any.type().equal( myWStringHelper.type())) 96 { 97 result = myWStringHelper.extract( alias_any ); 98 } 99 else if( alias_any.type().equal( OctetSeqHelper.type())) 100 { 101 byte[] octets = OctetSeqHelper.extract( a ); 102 result = "Octet Sequence: " + octets[0]; 103 } 104 else if( alias_any.type().equal( stringsHelper.type())) 105 { 106 String [] str3 = stringsHelper.extract( a ); 107 result = "Array: " + str3[1]; 108 } 109 else 110 System.out.println("Unknown alias, type kind: " + 111 alias_any.type().kind().value() ); 112 113 break; 114 default: 115 System.out.println("Unknown, kind " + a.type().kind().value()); 116 117 } 118 } 119 catch ( Exception e ) 120 { 121 e.printStackTrace(); 122 } 123 System.out.println(result); 124 return result; 125 } 126 } 127 128 129 | Popular Tags |