1 package demo.dii; 2 3 import org.omg.CORBA.Any ; 4 import org.omg.CosNaming.*; 5 6 public class DiiServer 7 extends org.omg.PortableServer.DynamicImplementation 8 { 9 private String [] ids = {"IDL:dii/server:1.0"}; 10 11 org.omg.CORBA.ORB orb = null; 13 14 serverImpl impl = new serverImpl(); 15 16 public DiiServer( org.omg.CORBA.ORB orb ) 17 { 18 this.orb = orb; 19 } 20 21 22 23 public String [] _all_interfaces(org.omg.PortableServer.POA poa, 24 byte[] objectId) 25 { 26 return ids; 27 } 28 29 30 public void invoke(org.omg.CORBA.ServerRequest request) 31 { 32 String op = request.operation(); 33 try 34 { 35 if( op.equals("_get_long_number")) 36 { 37 Any a = orb.create_any(); 38 a.insert_long( impl.long_number()); 39 request.set_result( a ); 40 } 41 else if( op.equals("_set_long_number")) 42 { 43 44 org.omg.CORBA.NVList params = orb.create_list(0); 45 46 Any numAny = orb.create_any(); 47 numAny.type( orb.get_primitive_tc(org.omg.CORBA.TCKind.tk_long)); 48 params.add_value( "", numAny, org.omg.CORBA.ARG_IN.value ); 49 50 51 request.arguments( params ); 52 53 54 impl.long_number( numAny.extract_long()); 55 56 57 Any s = orb.create_any(); 58 s.type( orb.get_primitive_tc(org.omg.CORBA.TCKind.tk_void )); 59 request.set_result( s ); 60 } 61 else if( op.equals("writeNumber") ) 62 { 63 org.omg.CORBA.NVList params = orb.create_list(0); 64 Any numAny = orb.create_any(); 65 numAny.type( orb.get_primitive_tc(org.omg.CORBA.TCKind.tk_long)); 66 params.add_value( "", numAny,org.omg.CORBA.ARG_IN.value ); 67 request.arguments( params ); 68 Any a = orb.create_any(); 69 a.insert_string( impl.writeNumber( numAny.extract_long() )); 70 request.set_result( a ); 71 } 72 else if( op.equals("add") ) 73 { 74 org.omg.CORBA.NVList params = orb.create_list(0); 75 Any argOneAny = orb.create_any(); 76 Any argTwoAny = orb.create_any(); 77 Any outArgAny = orb.create_any(); 78 argOneAny.type( orb.get_primitive_tc(org.omg.CORBA.TCKind.tk_long)); 79 argTwoAny.type( orb.get_primitive_tc(org.omg.CORBA.TCKind.tk_long)); 80 outArgAny.type( orb.get_primitive_tc(org.omg.CORBA.TCKind.tk_long)); 81 82 83 params.add_value( "", argOneAny, org.omg.CORBA.ARG_IN.value ); 84 params.add_value( "", argTwoAny, org.omg.CORBA.ARG_IN.value ); 85 params.add_value( "", outArgAny, org.omg.CORBA.ARG_OUT.value ); 86 87 88 request.arguments( params ); 89 90 91 org.omg.CORBA.IntHolder iHolder = new org.omg.CORBA.IntHolder (); 92 impl.add( argOneAny.extract_long(), argTwoAny.extract_long(), iHolder ); 93 94 outArgAny.insert_long( iHolder.value); 95 96 Any resultAny = orb.create_any(); 97 resultAny.type(orb.get_primitive_tc(org.omg.CORBA.TCKind.tk_void) ); 98 request.set_result( resultAny ); 99 } 100 else if( op.equals("writeNumberWithEx") ) 101 { 102 org.omg.CORBA.NVList params = orb.create_list(0); 103 Any numAny = orb.create_any(); 104 numAny.type( orb.get_primitive_tc(org.omg.CORBA.TCKind.tk_long)); 105 params.add_value( "", numAny, org.omg.CORBA.ARG_IN.value ); 106 request.arguments( params ); 107 Any a = orb.create_any(); 108 a.insert_string( impl.writeNumberWithEx( numAny.extract_long() )); 109 request.set_result( a ); 110 } 111 else if( op.equals("notify") ) 112 { 113 org.omg.CORBA.NVList params = orb.create_list(0); 114 Any stringAny = orb.create_any(); 115 stringAny.type( orb.get_primitive_tc(org.omg.CORBA.TCKind.tk_string)); 116 params.add_value( "", stringAny, org.omg.CORBA.ARG_IN.value ); 117 request.arguments( params ); 118 impl._notify( stringAny.extract_string() ); 119 Any s = orb.create_any(); 120 s.type( orb.get_primitive_tc(org.omg.CORBA.TCKind.tk_void )); 121 request.set_result( s ); 122 } 123 else if( op.equals("_non_existent") ) 124 { 125 Any s = orb.create_any(); 126 s.type( orb.get_primitive_tc(org.omg.CORBA.TCKind.tk_boolean )); 127 s.insert_boolean( _non_existent()); 128 request.set_result( s ); 129 } 130 135 else if( op.equals("_all_interfaces") ) 136 { 137 throw new org.omg.CORBA.BAD_OPERATION ("Object reference operations not implemented in example!"); 138 } 139 else if( op.equals("_get_interface") ) 140 { 141 throw new org.omg.CORBA.BAD_OPERATION ("Object reference operations not implemented in example!"); 142 } 143 else if( op.equals("_is_a") ) 144 { 145 throw new org.omg.CORBA.BAD_OPERATION ("Object reference operations not implemented in example"); 146 } 147 else 148 { 149 throw new org.omg.CORBA.BAD_OPERATION (op + " not found."); 150 } 151 } 152 catch ( org.omg.CORBA.UserException e ) 153 { 154 System.out.println("Caught: " + e ); 155 156 Any exceptAny = orb.create_any(); 157 try 158 { 159 Class helperClass = Class.forName( e.getClass().getName() + "Helper"); 160 Class anyClass = Class.forName("org.omg.CORBA.Any"); 161 java.lang.reflect.Method insert = 162 helperClass.getDeclaredMethod("insert", 163 new Class [] { anyClass, e.getClass() }); 164 165 insert.invoke( null, new java.lang.Object []{exceptAny, e}); 166 } 167 catch ( Exception sfe ) 168 { 169 sfe.printStackTrace(); 170 } 171 request.set_exception( exceptAny ); 172 } 173 catch ( org.omg.CORBA.SystemException e ) 174 { 175 try 176 { 177 ((org.jacorb.orb.dsi.ServerRequest)request).setSystemException( e ); 178 } 179 catch ( Exception sfe ) 180 { 181 sfe.printStackTrace(); 182 } 183 } 184 catch ( Exception e ) 185 { 186 e.printStackTrace(); 187 } 188 } 189 190 191 public static void main( String [] args ) 192 { 193 try 194 { 195 org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null); 196 org.omg.PortableServer.POA poa = 197 org.omg.PortableServer.POAHelper.narrow(orb.resolve_initial_references("RootPOA")); 198 199 poa.the_POAManager().activate(); 200 201 org.omg.CORBA.Object o = 202 poa.servant_to_reference(new DiiServer( orb )); 203 204 NamingContextExt nc = 206 NamingContextExtHelper.narrow(orb.resolve_initial_references("NameService")); 207 nc.bind( nc.to_name("dii.example"), o); 208 orb.run(); 209 } 210 catch ( Exception e ) 211 { 212 e.printStackTrace(); 213 } 214 } 215 } 216 217 218 | Popular Tags |