1 7 8 package com.sun.corba.se.impl.protocol; 9 10 import java.util.Iterator ; 11 import java.util.HashMap ; 12 13 import javax.rmi.CORBA.Tie ; 14 15 import org.omg.CORBA.CompletionStatus ; 16 import org.omg.CORBA.Context ; 17 import org.omg.CORBA.ContextList ; 18 import org.omg.CORBA.ExceptionList ; 19 import org.omg.CORBA.NamedValue ; 20 import org.omg.CORBA.NVList ; 21 import org.omg.CORBA.Request ; 22 import org.omg.CORBA.TypeCode ; 23 24 import org.omg.CORBA.portable.ApplicationException ; 25 import org.omg.CORBA.portable.Delegate ; 26 import org.omg.CORBA.portable.InputStream ; 27 import org.omg.CORBA.portable.OutputStream ; 28 import org.omg.CORBA.portable.RemarshalException ; 29 import org.omg.CORBA.portable.ServantObject ; 30 31 import com.sun.corba.se.pept.broker.Broker; 32 import com.sun.corba.se.pept.encoding.InputObject; 33 import com.sun.corba.se.pept.encoding.OutputObject; 34 import com.sun.corba.se.pept.protocol.ClientInvocationInfo; 35 import com.sun.corba.se.pept.protocol.ClientRequestDispatcher; 36 import com.sun.corba.se.pept.transport.ContactInfo; 37 import com.sun.corba.se.pept.transport.ContactInfoList; 38 import com.sun.corba.se.pept.transport.ContactInfoListIterator; 39 40 import com.sun.corba.se.spi.presentation.rmi.StubAdapter; 41 import com.sun.corba.se.spi.ior.IOR; 42 import com.sun.corba.se.spi.logging.CORBALogDomains; 43 import com.sun.corba.se.spi.orb.ORB; 44 import com.sun.corba.se.spi.protocol.CorbaClientDelegate ; 45 import com.sun.corba.se.spi.transport.CorbaContactInfo; 46 import com.sun.corba.se.spi.transport.CorbaContactInfoList; 47 import com.sun.corba.se.spi.transport.CorbaContactInfoListIterator; 48 49 import com.sun.corba.se.impl.corba.RequestImpl; 50 import com.sun.corba.se.impl.protocol.CorbaInvocationInfo; 51 import com.sun.corba.se.impl.transport.CorbaContactInfoListImpl; 52 import com.sun.corba.se.impl.util.JDKBridge; 53 import com.sun.corba.se.impl.logging.ORBUtilSystemException; 54 55 58 61 public class CorbaClientDelegateImpl extends CorbaClientDelegate 62 { 63 private ORB orb; 64 private ORBUtilSystemException wrapper ; 65 66 private CorbaContactInfoList contactInfoList; 67 68 public CorbaClientDelegateImpl(ORB orb, 69 CorbaContactInfoList contactInfoList) 70 { 71 this.orb = orb; 72 this.wrapper = ORBUtilSystemException.get( orb, 73 CORBALogDomains.RPC_PROTOCOL ) ; 74 this.contactInfoList = contactInfoList; 75 } 76 77 81 public Broker getBroker() 82 { 83 return orb; 84 } 85 86 public ContactInfoList getContactInfoList() 87 { 88 return contactInfoList; 89 } 90 91 95 public OutputStream request(org.omg.CORBA.Object self, 96 String operation, 97 boolean responseExpected) 98 { 99 ClientInvocationInfo invocationInfo = 100 orb.createOrIncrementInvocationInfo(); 101 Iterator contactInfoListIterator = 102 invocationInfo.getContactInfoListIterator(); 103 if (contactInfoListIterator == null) { 104 contactInfoListIterator = contactInfoList.iterator(); 105 invocationInfo.setContactInfoListIterator(contactInfoListIterator); 106 } 107 if (! contactInfoListIterator.hasNext()) { 108 throw ((CorbaContactInfoListIterator)contactInfoListIterator) 109 .getFailureException(); 110 } 111 CorbaContactInfo contactInfo = (CorbaContactInfo) contactInfoListIterator.next(); 112 ClientRequestDispatcher subcontract = contactInfo.getClientRequestDispatcher(); 113 invocationInfo.setClientRequestDispatcher(subcontract); 118 return (OutputStream ) 119 subcontract.beginRequest(self, operation, 120 !responseExpected, contactInfo); 121 } 122 123 public InputStream invoke(org.omg.CORBA.Object self, OutputStream output) 124 throws 125 ApplicationException , 126 RemarshalException 127 { 128 ClientRequestDispatcher subcontract = getClientRequestDispatcher(); 129 return (InputStream ) 130 subcontract.marshalingComplete((Object )self, (OutputObject)output); 131 } 132 133 public void releaseReply(org.omg.CORBA.Object self, InputStream input) 134 { 135 ClientRequestDispatcher subcontract = getClientRequestDispatcher(); 137 subcontract.endRequest(orb, self, (InputObject)input); 138 orb.releaseOrDecrementInvocationInfo(); 139 } 140 141 private ClientRequestDispatcher getClientRequestDispatcher() 142 { 143 return (ClientRequestDispatcher) 144 ((CorbaInvocationInfo)orb.getInvocationInfo()) 145 .getClientRequestDispatcher(); 146 } 147 148 public org.omg.CORBA.Object get_interface_def(org.omg.CORBA.Object obj) 149 { 150 InputStream is = null; 151 org.omg.CORBA.Object stub = null ; 153 154 try { 155 OutputStream os = request(null, "_interface", true); 156 is = (InputStream ) invoke((org.omg.CORBA.Object )null, os); 157 158 org.omg.CORBA.Object objimpl = 159 (org.omg.CORBA.Object ) is.read_Object(); 160 161 if ( !objimpl._is_a("IDL:omg.org/CORBA/InterfaceDef:1.0") ) 163 throw wrapper.wrongInterfaceDef(CompletionStatus.COMPLETED_MAYBE); 164 165 try { 166 stub = (org.omg.CORBA.Object ) 167 JDKBridge.loadClass("org.omg.CORBA._InterfaceDefStub"). 168 newInstance(); 169 } catch (Exception ex) { 170 throw wrapper.noInterfaceDefStub( ex ) ; 171 } 172 173 org.omg.CORBA.portable.Delegate del = 174 StubAdapter.getDelegate( objimpl ) ; 175 StubAdapter.setDelegate( stub, del ) ; 176 } catch (ApplicationException e) { 177 throw wrapper.applicationExceptionInSpecialMethod( e ) ; 179 } catch (RemarshalException e) { 180 return get_interface_def(obj); 181 } finally { 182 releaseReply((org.omg.CORBA.Object )null, (InputStream )is); 183 } 184 185 return stub; 186 } 187 188 public boolean is_a(org.omg.CORBA.Object obj, String dest) 189 { 190 193 195 String [] repositoryIds = StubAdapter.getTypeIds( obj ) ; 196 String myid = contactInfoList.getTargetIOR().getTypeId(); 197 if ( dest.equals(myid) ) { 198 return true; 199 } 200 for ( int i=0; i<repositoryIds.length; i++ ) { 201 if ( dest.equals(repositoryIds[i]) ) { 202 return true; 203 } 204 } 205 206 209 InputStream is = null; 210 try { 211 OutputStream os = request(null, "_is_a", true); 212 os.write_string(dest); 213 is = (InputStream ) invoke((org.omg.CORBA.Object ) null, os); 214 215 return is.read_boolean(); 216 217 } catch (ApplicationException e) { 218 throw wrapper.applicationExceptionInSpecialMethod( e ) ; 220 } catch (RemarshalException e) { 221 return is_a(obj, dest); 222 } finally { 223 releaseReply((org.omg.CORBA.Object )null, (InputStream )is); 224 } 225 } 226 227 public boolean non_existent(org.omg.CORBA.Object obj) 228 { 229 InputStream is = null; 230 try { 231 OutputStream os = request(null, "_non_existent", true); 232 is = (InputStream ) invoke((org.omg.CORBA.Object )null, os); 233 234 return is.read_boolean(); 235 236 } catch (ApplicationException e) { 237 throw wrapper.applicationExceptionInSpecialMethod( e ) ; 239 } catch (RemarshalException e) { 240 return non_existent(obj); 241 } finally { 242 releaseReply((org.omg.CORBA.Object )null, (InputStream )is); 243 } 244 } 245 246 public org.omg.CORBA.Object duplicate(org.omg.CORBA.Object obj) 247 { 248 return obj; 249 } 250 251 public void release(org.omg.CORBA.Object obj) 252 { 253 } 256 257 public boolean is_equivalent(org.omg.CORBA.Object obj, 260 org.omg.CORBA.Object ref) 261 { 262 if ( ref == null ) 263 return false; 264 265 if (!StubAdapter.isStub(ref)) 267 return false ; 268 269 Delegate del = StubAdapter.getDelegate(ref) ; 270 if (del == null) 271 return false ; 272 273 if (del == this) 275 return true; 276 277 if (!(del instanceof CorbaClientDelegateImpl)) 279 return false ; 280 281 CorbaClientDelegateImpl corbaDelegate = (CorbaClientDelegateImpl)del ; 282 CorbaContactInfoList ccil = 283 (CorbaContactInfoList)corbaDelegate.getContactInfoList() ; 284 return this.contactInfoList.getTargetIOR().isEquivalent( 285 ccil.getTargetIOR() ); 286 } 287 288 292 public boolean equals(org.omg.CORBA.Object self, java.lang.Object other) 293 { 294 if (other == null) 295 return false ; 296 297 if (!StubAdapter.isStub(other)) { 298 return false; 299 } 300 301 Delegate delegate = StubAdapter.getDelegate( other ) ; 302 if (delegate == null) 303 return false ; 304 305 if (delegate instanceof CorbaClientDelegateImpl) { 306 CorbaClientDelegateImpl otherDel = (CorbaClientDelegateImpl) 307 delegate ; 308 IOR otherIor = otherDel.contactInfoList.getTargetIOR(); 309 return this.contactInfoList.getTargetIOR().equals(otherIor); 310 } 311 312 return false; 314 } 315 316 public int hashCode(org.omg.CORBA.Object obj) 317 { 318 return this.hashCode() ; 319 } 320 321 public int hash(org.omg.CORBA.Object obj, int maximum) 322 { 323 int h = this.hashCode(); 324 if ( h > maximum ) 325 return 0; 326 return h; 327 } 328 329 public Request request(org.omg.CORBA.Object obj, String operation) 330 { 331 return new RequestImpl(orb, obj, null, operation, null, null, null, 332 null); 333 } 334 335 public Request create_request(org.omg.CORBA.Object obj, 336 Context ctx, 337 String operation, 338 NVList arg_list, 339 NamedValue result) 340 { 341 return new RequestImpl(orb, obj, ctx, operation, arg_list, 342 result, null, null); 343 } 344 345 public Request create_request(org.omg.CORBA.Object obj, 346 Context ctx, 347 String operation, 348 NVList arg_list, 349 NamedValue result, 350 ExceptionList exclist, 351 ContextList ctxlist) 352 { 353 return new RequestImpl(orb, obj, ctx, operation, arg_list, result, 354 exclist, ctxlist); 355 } 356 357 public org.omg.CORBA.ORB orb(org.omg.CORBA.Object obj) 358 { 359 return this.orb; 360 } 361 362 372 public boolean is_local(org.omg.CORBA.Object self) 373 { 374 return contactInfoList.getEffectiveTargetIOR().getProfile(). 376 isLocal(); 377 } 378 379 public ServantObject servant_preinvoke(org.omg.CORBA.Object self, 380 String operation, 381 Class expectedType) 382 { 383 return 384 contactInfoList.getLocalClientRequestDispatcher() 385 .servant_preinvoke(self, operation, expectedType); 386 } 387 388 public void servant_postinvoke(org.omg.CORBA.Object self, 389 ServantObject servant) 390 { 391 contactInfoList.getLocalClientRequestDispatcher() 392 .servant_postinvoke(self, servant); 393 } 394 395 401 public String get_codebase(org.omg.CORBA.Object self) 402 { 403 if (contactInfoList.getTargetIOR() != null) { 404 return contactInfoList.getTargetIOR().getProfile().getCodebase(); 405 } 406 return null; 407 } 408 409 public String toString(org.omg.CORBA.Object self) 410 { 411 return contactInfoList.getTargetIOR().stringify(); 412 } 413 414 419 public int hashCode() 420 { 421 return this.contactInfoList.hashCode(); 422 } 423 } 424 425 427 | Popular Tags |