1 7 15 16 package com.sun.corba.se.impl.corba; 17 18 19 import org.omg.CORBA.Any ; 20 import org.omg.CORBA.ARG_IN ; 21 import org.omg.CORBA.ARG_OUT ; 22 import org.omg.CORBA.ARG_INOUT ; 23 import org.omg.CORBA.Context ; 24 import org.omg.CORBA.ContextList ; 25 import org.omg.CORBA.Environment ; 26 import org.omg.CORBA.ExceptionList ; 27 import org.omg.CORBA.NVList ; 28 import org.omg.CORBA.NamedValue ; 29 import org.omg.CORBA.Request ; 30 import org.omg.CORBA.SystemException ; 31 import org.omg.CORBA.TCKind ; 32 import org.omg.CORBA.TypeCode ; 33 import org.omg.CORBA.TypeCodePackage.BadKind ; 34 import org.omg.CORBA.UnknownUserException ; 35 import org.omg.CORBA.Bounds ; 36 import org.omg.CORBA.UNKNOWN ; 37 import org.omg.CORBA.INTERNAL ; 38 import org.omg.CORBA.NO_IMPLEMENT ; 39 import org.omg.CORBA.CompletionStatus ; 40 import org.omg.CORBA.WrongTransaction ; 41 42 import org.omg.CORBA.portable.ApplicationException ; 43 import org.omg.CORBA.portable.RemarshalException ; 44 import org.omg.CORBA.portable.InputStream ; 45 import org.omg.CORBA.portable.OutputStream ; 46 47 import com.sun.corba.se.spi.orb.ORB; 48 import com.sun.corba.se.spi.presentation.rmi.StubAdapter; 49 import com.sun.corba.se.spi.logging.CORBALogDomains; 50 import com.sun.corba.se.impl.logging.ORBUtilSystemException; 51 import com.sun.corba.se.impl.corba.AsynchInvoke; 52 53 public class RequestImpl 54 extends Request 55 { 56 59 protected org.omg.CORBA.Object _target; 60 protected String _opName; 61 protected NVList _arguments; 62 protected ExceptionList _exceptions; 63 private NamedValue _result; 64 protected Environment _env; 65 private Context _ctx; 66 private ContextList _ctxList; 67 protected ORB _orb; 68 private ORBUtilSystemException _wrapper; 69 70 protected boolean _isOneWay = false; 72 private int[] _paramCodes; 73 private long[] _paramLongs; 74 private java.lang.Object [] _paramObjects; 75 76 protected boolean gotResponse = false; 80 81 84 public RequestImpl (ORB orb, 87 org.omg.CORBA.Object targetObject, 88 Context ctx, 89 String operationName, 90 NVList argumentList, 91 NamedValue resultContainer, 92 ExceptionList exceptionList, 93 ContextList ctxList) 94 { 95 96 _orb = orb; 98 _wrapper = ORBUtilSystemException.get( orb, 99 CORBALogDomains.OA_INVOCATION ) ; 100 101 _target = targetObject; 103 _ctx = ctx; 104 _opName = operationName; 105 106 if (argumentList == null) 108 _arguments = new NVListImpl(_orb); 109 else 110 _arguments = argumentList; 111 112 _result = resultContainer; 114 115 if (exceptionList == null) 117 _exceptions = new ExceptionListImpl(); 118 else 119 _exceptions = exceptionList; 120 121 if (ctxList == null) 123 _ctxList = new ContextListImpl(_orb); 124 else 125 _ctxList = ctxList; 126 127 _env = new EnvironmentImpl(); 129 130 } 131 132 public org.omg.CORBA.Object target() 133 { 134 return _target; 135 } 136 137 public String operation() 138 { 139 return _opName; 140 } 141 142 public NVList arguments() 143 { 144 return _arguments; 145 } 146 147 public NamedValue result() 148 { 149 return _result; 150 } 151 152 public Environment env() 153 { 154 return _env; 155 } 156 157 public ExceptionList exceptions() 158 { 159 return _exceptions; 160 } 161 162 public ContextList contexts() 163 { 164 return _ctxList; 165 } 166 167 public synchronized Context ctx() 168 { 169 if (_ctx == null) 170 _ctx = new ContextImpl(_orb); 171 return _ctx; 172 } 173 174 public synchronized void ctx(Context newCtx) 175 { 176 _ctx = newCtx; 177 } 178 179 public synchronized Any add_in_arg() 180 { 181 return _arguments.add(org.omg.CORBA.ARG_IN.value).value(); 182 } 183 184 public synchronized Any add_named_in_arg(String name) 185 { 186 return _arguments.add_item(name, org.omg.CORBA.ARG_IN.value).value(); 187 } 188 189 public synchronized Any add_inout_arg() 190 { 191 return _arguments.add(org.omg.CORBA.ARG_INOUT.value).value(); 192 } 193 194 public synchronized Any add_named_inout_arg(String name) 195 { 196 return _arguments.add_item(name, org.omg.CORBA.ARG_INOUT.value).value(); 197 } 198 199 public synchronized Any add_out_arg() 200 { 201 return _arguments.add(org.omg.CORBA.ARG_OUT.value).value(); 202 } 203 204 public synchronized Any add_named_out_arg(String name) 205 { 206 return _arguments.add_item(name, org.omg.CORBA.ARG_OUT.value).value(); 207 } 208 209 public synchronized void set_return_type(TypeCode tc) 210 { 211 if (_result == null) 212 _result = new NamedValueImpl(_orb); 213 _result.value().type(tc); 214 } 215 216 public synchronized Any return_value() 217 { 218 if (_result == null) 219 _result = new NamedValueImpl(_orb); 220 return _result.value(); 221 } 222 223 public synchronized void add_exception(TypeCode exceptionType) 224 { 225 _exceptions.add(exceptionType); 226 } 227 228 public synchronized void invoke() 229 { 230 doInvocation(); 231 } 232 233 public synchronized void send_oneway() 234 { 235 _isOneWay = true; 236 doInvocation(); 237 } 238 239 public synchronized void send_deferred() 240 { 241 AsynchInvoke invokeObject = new AsynchInvoke(_orb, this, false); 242 new Thread (invokeObject).start(); 243 } 244 245 public synchronized boolean poll_response() 246 { 247 return gotResponse; 253 } 254 255 public synchronized void get_response() 256 throws org.omg.CORBA.WrongTransaction 257 { 258 while (gotResponse == false) { 259 try { 262 wait(); 263 } 264 catch (InterruptedException e) {} 265 } 266 } 267 268 271 275 protected void doInvocation() 276 { 277 org.omg.CORBA.portable.Delegate delegate = StubAdapter.getDelegate( 278 _target ) ; 279 280 _orb.getPIHandler().initiateClientPIRequest( true ); 285 _orb.getPIHandler().setClientPIInfo( this ); 286 287 InputStream $in = null; 288 try { 289 OutputStream $out = delegate.request(null, _opName, !_isOneWay); 290 try { 292 for (int i=0; i<_arguments.count() ; i++) { 293 NamedValue nv = _arguments.item(i); 294 switch (nv.flags()) { 295 case ARG_IN.value: 296 nv.value().write_value($out); 297 break; 298 case ARG_OUT.value: 299 break; 300 case ARG_INOUT.value: 301 nv.value().write_value($out); 302 break; 303 } 304 } 305 } catch ( org.omg.CORBA.Bounds ex ) { 306 throw _wrapper.boundsErrorInDiiRequest( ex ) ; 307 } 308 309 $in = delegate.invoke(null, $out); 310 } catch (ApplicationException e) { 311 } catch (RemarshalException e) { 316 doInvocation(); 317 } catch( SystemException ex ) { 318 _env.exception(ex); 319 throw ex; 323 } finally { 324 delegate.releaseReply(null, $in); 325 } 326 } 327 328 public void unmarshalReply(InputStream is) 330 { 331 if ( _result != null ) { 333 Any returnAny = _result.value(); 334 TypeCode returnType = returnAny.type(); 335 if ( returnType.kind().value() != TCKind._tk_void ) 336 returnAny.read_value(is, returnType); 337 } 338 339 try { 341 for ( int i=0; i<_arguments.count() ; i++) { 342 NamedValue nv = _arguments.item(i); 343 switch( nv.flags() ) { 344 case ARG_IN.value: 345 break; 346 case ARG_OUT.value: 347 case ARG_INOUT.value: 348 Any any = nv.value(); 349 any.read_value(is, any.type()); 350 break; 351 } 352 } 353 } 354 catch ( org.omg.CORBA.Bounds ex ) { 355 } 357 } 358 } 359 | Popular Tags |