1 7 8 package com.sun.corba.se.impl.interceptors; 9 10 import java.util.HashMap ; 11 12 import org.omg.CORBA.Any ; 13 import org.omg.CORBA.BAD_INV_ORDER ; 14 import org.omg.CORBA.BAD_PARAM ; 15 import org.omg.CORBA.CompletionStatus ; 16 import org.omg.CORBA.Context ; 17 import org.omg.CORBA.ContextList ; 18 import org.omg.CORBA.CTX_RESTRICT_SCOPE ; 19 import org.omg.CORBA.ExceptionList ; 20 import org.omg.CORBA.LocalObject ; 21 import org.omg.CORBA.NamedValue ; 22 import org.omg.CORBA.NO_IMPLEMENT ; 23 import org.omg.CORBA.NO_RESOURCES ; 24 import org.omg.CORBA.NVList ; 25 import org.omg.CORBA.Object ; 26 import org.omg.CORBA.ParameterMode ; 27 import org.omg.CORBA.Policy ; 28 import org.omg.CORBA.SystemException ; 29 import org.omg.CORBA.TypeCode ; 30 import org.omg.CORBA.INTERNAL ; 31 import org.omg.CORBA.UserException ; 32 import org.omg.CORBA.portable.ApplicationException ; 33 import org.omg.CORBA.portable.InputStream ; 34 import com.sun.corba.se.spi.servicecontext.ServiceContexts; 35 import com.sun.corba.se.spi.servicecontext.UnknownServiceContext; 36 37 import org.omg.IOP.ServiceContext ; 38 import org.omg.IOP.ServiceContextHelper ; 39 import org.omg.IOP.TaggedProfile ; 40 import org.omg.IOP.TaggedProfileHelper ; 41 import org.omg.IOP.TaggedComponent ; 42 import org.omg.IOP.TaggedComponentHelper ; 43 import org.omg.IOP.TAG_INTERNET_IOP ; 44 import org.omg.Dynamic.Parameter ; 45 import org.omg.PortableInterceptor.ClientRequestInfo ; 46 import org.omg.PortableInterceptor.LOCATION_FORWARD ; 47 import org.omg.PortableInterceptor.SUCCESSFUL ; 48 import org.omg.PortableInterceptor.SYSTEM_EXCEPTION ; 49 import org.omg.PortableInterceptor.TRANSPORT_RETRY ; 50 import org.omg.PortableInterceptor.USER_EXCEPTION ; 51 52 import com.sun.corba.se.pept.protocol.MessageMediator; 53 54 import com.sun.corba.se.spi.ior.IOR; 55 import com.sun.corba.se.spi.ior.iiop.IIOPProfileTemplate; 56 import com.sun.corba.se.spi.ior.iiop.GIOPVersion; 57 import com.sun.corba.se.spi.orb.ORB; 58 import com.sun.corba.se.spi.protocol.CorbaMessageMediator; 59 import com.sun.corba.se.spi.transport.CorbaContactInfo; 60 import com.sun.corba.se.spi.transport.CorbaContactInfoList; 61 import com.sun.corba.se.spi.transport.CorbaContactInfoListIterator; 62 63 import com.sun.corba.se.impl.encoding.CDROutputStream; 64 import com.sun.corba.se.impl.encoding.CDRInputStream_1_0; 65 import com.sun.corba.se.impl.orbutil.ORBUtility; 66 import com.sun.corba.se.impl.protocol.CorbaInvocationInfo; 67 import com.sun.corba.se.impl.util.RepositoryId; 68 69 73 public final class ClientRequestInfoImpl 74 extends RequestInfoImpl 75 implements ClientRequestInfo 76 { 77 78 static final int CALL_SEND_REQUEST = 0; 80 static final int CALL_SEND_POLL = 1; 81 82 static final int CALL_RECEIVE_REPLY = 0; 84 static final int CALL_RECEIVE_EXCEPTION = 1; 85 static final int CALL_RECEIVE_OTHER = 2; 86 87 93 private boolean retryRequest; 96 97 private int entryCount = 0; 102 103 private org.omg.CORBA.Request request; 107 108 private boolean diiInitiate; 110 private CorbaMessageMediator messageMediator; 111 112 private org.omg.CORBA.Object cachedTargetObject; 114 private org.omg.CORBA.Object cachedEffectiveTargetObject; 115 private Parameter [] cachedArguments; 116 private TypeCode [] cachedExceptions; 117 private String [] cachedContexts; 118 private String [] cachedOperationContext; 119 private String cachedReceivedExceptionId; 120 private Any cachedResult; 121 private Any cachedReceivedException; 122 private TaggedProfile cachedEffectiveProfile; 123 private HashMap cachedRequestServiceContexts; 125 private HashMap cachedReplyServiceContexts; 127 private HashMap cachedEffectiveComponents; 129 130 131 protected boolean piCurrentPushed; 132 133 139 143 void reset() { 144 super.reset(); 145 146 148 retryRequest = false; 149 150 153 request = null; 154 diiInitiate = false; 155 messageMediator = null; 156 157 cachedTargetObject = null; 159 cachedEffectiveTargetObject = null; 160 cachedArguments = null; 161 cachedExceptions = null; 162 cachedContexts = null; 163 cachedOperationContext = null; 164 cachedReceivedExceptionId = null; 165 cachedResult = null; 166 cachedReceivedException = null; 167 cachedEffectiveProfile = null; 168 cachedRequestServiceContexts = null; 169 cachedReplyServiceContexts = null; 170 cachedEffectiveComponents = null; 171 172 piCurrentPushed = false; 173 174 startingPointCall = CALL_SEND_REQUEST; 175 endingPointCall = CALL_RECEIVE_REPLY; 176 177 } 178 179 183 184 protected static final int MID_TARGET = MID_RI_LAST + 1; 187 protected static final int MID_EFFECTIVE_TARGET = MID_RI_LAST + 2; 188 protected static final int MID_EFFECTIVE_PROFILE = MID_RI_LAST + 3; 189 protected static final int MID_RECEIVED_EXCEPTION = MID_RI_LAST + 4; 190 protected static final int MID_RECEIVED_EXCEPTION_ID = MID_RI_LAST + 5; 191 protected static final int MID_GET_EFFECTIVE_COMPONENT = MID_RI_LAST + 6; 192 protected static final int MID_GET_EFFECTIVE_COMPONENTS 193 = MID_RI_LAST + 7; 194 protected static final int MID_GET_REQUEST_POLICY = MID_RI_LAST + 8; 195 protected static final int MID_ADD_REQUEST_SERVICE_CONTEXT 196 = MID_RI_LAST + 9; 197 198 protected static final boolean validCall[][] = { 201 { true , true , true , true , true }, 216 { true , true , true , true , true }, 217 { true , false, true , false, false }, 218 { true , false, true , true , true }, 219 { true , false, true , true , true }, 220 { true , false, true , true , true }, 221 { false, false, true , false, false }, 222 { true , true , true , true , true }, 223 { true , false, true , true , true }, 224 { false, false, true , true , true }, 225 { false, false, false, false, true }, 226 { true , true , true , true , true }, 227 { true , false, true , true , true }, 228 { false, false, true , true , true }, 229 { true , true , true , true , true }, 232 { true , true , true , true , true }, 233 { true , true , true , true , true }, 234 { false, false, false, true , false }, 235 { false, false, false, true , false }, 236 { true , false, true , true , true }, 237 { true , false, true , true , true }, 238 { true , false, true , true , true }, 239 { true , false, false, false, false } 240 }; 241 242 243 247 248 253 protected ClientRequestInfoImpl( ORB myORB ) { 254 super( myORB ); 255 startingPointCall = CALL_SEND_REQUEST; 256 endingPointCall = CALL_RECEIVE_REPLY; 257 } 258 259 262 public org.omg.CORBA.Object target (){ 263 if (cachedTargetObject == null) { 266 CorbaContactInfo corbaContactInfo = (CorbaContactInfo) 267 messageMediator.getContactInfo(); 268 cachedTargetObject = 269 iorToObject(corbaContactInfo.getTargetIOR()); 270 } 271 return cachedTargetObject; 272 } 273 274 280 public org.omg.CORBA.Object effective_target() { 281 284 288 if (cachedEffectiveTargetObject == null) { 289 CorbaContactInfo corbaContactInfo = (CorbaContactInfo) 290 messageMediator.getContactInfo(); 291 cachedEffectiveTargetObject = 293 iorToObject(corbaContactInfo.getEffectiveTargetIOR()); 294 } 295 return cachedEffectiveTargetObject; 296 } 297 298 304 public TaggedProfile effective_profile (){ 305 308 if( cachedEffectiveProfile == null ) { 309 CorbaContactInfo corbaContactInfo = (CorbaContactInfo) 310 messageMediator.getContactInfo(); 311 cachedEffectiveProfile = 312 corbaContactInfo.getEffectiveProfile().getIOPProfile(); 313 } 314 315 319 return cachedEffectiveProfile; 320 } 321 322 325 public Any received_exception (){ 326 checkAccess( MID_RECEIVED_EXCEPTION ); 327 328 if( cachedReceivedException == null ) { 329 cachedReceivedException = exceptionToAny( exception ); 330 } 331 332 336 return cachedReceivedException; 337 } 338 339 342 public String received_exception_id (){ 343 checkAccess( MID_RECEIVED_EXCEPTION_ID ); 344 345 if( cachedReceivedExceptionId == null ) { 346 String result = null; 347 348 if( exception == null ) { 349 throw wrapper.exceptionWasNull() ; 353 } else if( exception instanceof SystemException ) { 354 String name = exception.getClass().getName(); 355 result = ORBUtility.repositoryIdOf(name); 356 } else if( exception instanceof ApplicationException ) { 357 result = ((ApplicationException )exception).getId(); 358 } 359 360 363 cachedReceivedExceptionId = result; 364 } 365 366 return cachedReceivedExceptionId; 367 } 368 369 375 public TaggedComponent get_effective_component (int id){ 376 checkAccess( MID_GET_EFFECTIVE_COMPONENT ); 377 378 return get_effective_components( id )[0]; 379 } 380 381 385 public TaggedComponent [] get_effective_components (int id){ 386 checkAccess( MID_GET_EFFECTIVE_COMPONENTS ); 387 Integer integerId = new Integer ( id ); 388 TaggedComponent [] result = null; 389 boolean justCreatedCache = false; 390 391 if( cachedEffectiveComponents == null ) { 392 cachedEffectiveComponents = new HashMap (); 393 justCreatedCache = true; 394 } 395 else { 396 result = (TaggedComponent [])cachedEffectiveComponents.get( 398 integerId ); 399 } 400 401 if( (result == null) && 403 (justCreatedCache || 404 !cachedEffectiveComponents.containsKey( integerId ) ) ) 405 { 406 CorbaContactInfo corbaContactInfo = (CorbaContactInfo) 408 messageMediator.getContactInfo(); 409 IIOPProfileTemplate ptemp = 410 (IIOPProfileTemplate)corbaContactInfo.getEffectiveProfile(). 411 getTaggedProfileTemplate(); 412 result = ptemp.getIOPComponents(myORB, id); 413 cachedEffectiveComponents.put( integerId, result ); 414 } 415 416 if( (result == null) || (result.length == 0) ) { 419 throw stdWrapper.invalidComponentId( integerId ) ; 420 } 421 422 427 return result; 428 } 429 430 433 public Policy get_request_policy (int type){ 434 checkAccess( MID_GET_REQUEST_POLICY ); 435 throw wrapper.piOrbNotPolicyBased() ; 437 } 438 439 445 public void add_request_service_context (ServiceContext service_context, 446 boolean replace) 447 { 448 checkAccess( MID_ADD_REQUEST_SERVICE_CONTEXT ); 449 450 if( cachedRequestServiceContexts == null ) { 451 cachedRequestServiceContexts = new HashMap (); 452 } 453 454 addServiceContext( cachedRequestServiceContexts, 455 messageMediator.getRequestServiceContexts(), 456 service_context, replace ); 457 } 458 459 464 472 473 476 public int request_id (){ 477 484 return messageMediator.getRequestId(); 485 } 486 487 490 public String operation (){ 491 return messageMediator.getOperationName(); 494 } 495 496 499 public Parameter [] arguments (){ 500 checkAccess( MID_ARGUMENTS ); 501 502 if( cachedArguments == null ) { 503 if( request == null ) { 504 throw stdWrapper.piOperationNotSupported1() ; 505 } 506 507 cachedArguments = nvListToParameterArray( request.arguments() ); 510 } 511 512 517 return cachedArguments; 518 } 519 520 523 public TypeCode [] exceptions (){ 524 checkAccess( MID_EXCEPTIONS ); 525 526 if( cachedExceptions == null ) { 527 if( request == null ) { 528 throw stdWrapper.piOperationNotSupported2() ; 529 } 530 531 ExceptionList excList = request.exceptions( ); 534 int count = excList.count(); 535 TypeCode [] excTCList = new TypeCode [count]; 536 try { 537 for( int i = 0; i < count; i++ ) { 538 excTCList[i] = excList.item( i ); 539 } 540 } catch( Exception e ) { 541 throw wrapper.exceptionInExceptions( e ) ; 542 } 543 544 cachedExceptions = excTCList; 545 } 546 547 552 return cachedExceptions; 553 } 554 555 558 public String [] contexts (){ 559 checkAccess( MID_CONTEXTS ); 560 561 if( cachedContexts == null ) { 562 if( request == null ) { 563 throw stdWrapper.piOperationNotSupported3() ; 564 } 565 566 ContextList ctxList = request.contexts( ); 569 int count = ctxList.count(); 570 String [] ctxListToReturn = new String [count]; 571 try { 572 for( int i = 0; i < count; i++ ) { 573 ctxListToReturn[i] = ctxList.item( i ); 574 } 575 } catch( Exception e ) { 576 throw wrapper.exceptionInContexts( e ) ; 577 } 578 579 cachedContexts = ctxListToReturn; 580 } 581 582 586 return cachedContexts; 587 } 588 589 592 public String [] operation_context (){ 593 checkAccess( MID_OPERATION_CONTEXT ); 594 595 if( cachedOperationContext == null ) { 596 if( request == null ) { 597 throw stdWrapper.piOperationNotSupported4() ; 598 } 599 600 Context ctx = request.ctx( ); 603 NVList nvList = ctx.get_values( "", CTX_RESTRICT_SCOPE.value,"*" ); 614 String [] context = new String [(nvList.count() * 2) ]; 615 if( ( nvList != null ) &&( nvList.count() != 0 ) ) { 616 int index = 0; 619 for( int i = 0; i < nvList.count(); i++ ) { 620 NamedValue nv; 621 try { 622 nv = nvList.item( i ); 623 } 624 catch (Exception e ) { 625 return (String []) null; 626 } 627 context[index] = nv.name(); 628 index++; 629 context[index] = nv.value().extract_string(); 630 index++; 631 } 632 } 633 634 cachedOperationContext = context; 635 } 636 637 641 return cachedOperationContext; 642 } 643 644 647 public Any result (){ 648 checkAccess( MID_RESULT ); 649 650 if( cachedResult == null ) { 651 if( request == null ) { 652 throw stdWrapper.piOperationNotSupported5() ; 653 } 654 NamedValue nvResult = request.result( ); 656 657 if( nvResult == null ) { 658 throw wrapper.piDiiResultIsNull() ; 659 } 660 661 cachedResult = nvResult.value(); 662 } 663 664 668 return cachedResult; 669 } 670 671 674 public boolean response_expected (){ 675 return ! messageMediator.isOneWay(); 678 } 679 680 683 public Object forward_reference (){ 684 checkAccess( MID_FORWARD_REFERENCE ); 685 if( replyStatus != LOCATION_FORWARD.value ) { 689 throw stdWrapper.invalidPiCall1() ; 690 } 691 692 IOR ior = getLocatedIOR(); 696 return iorToObject(ior); 697 } 698 699 private IOR getLocatedIOR() 700 { 701 IOR ior; 702 CorbaContactInfoList contactInfoList = (CorbaContactInfoList) 703 messageMediator.getContactInfo().getContactInfoList(); 704 ior = contactInfoList.getEffectiveTargetIOR(); 705 return ior; 706 } 707 708 protected void setLocatedIOR(IOR ior) 709 { 710 ORB orb = (ORB) messageMediator.getBroker(); 711 712 CorbaContactInfoListIterator iterator = (CorbaContactInfoListIterator) 713 ((CorbaInvocationInfo)orb.getInvocationInfo()) 714 .getContactInfoListIterator(); 715 716 iterator.reportRedirect( 719 (CorbaContactInfo)messageMediator.getContactInfo(), 720 ior); 721 } 722 723 726 public org.omg.IOP.ServiceContext get_request_service_context( int id ) { 727 checkAccess( MID_GET_REQUEST_SERVICE_CONTEXT ); 728 729 if( cachedRequestServiceContexts == null ) { 730 cachedRequestServiceContexts = new HashMap (); 731 } 732 733 return getServiceContext(cachedRequestServiceContexts, 734 messageMediator.getRequestServiceContexts(), 735 id); 736 } 737 738 742 public org.omg.IOP.ServiceContext get_reply_service_context( int id ) { 743 checkAccess( MID_GET_REPLY_SERVICE_CONTEXT ); 744 745 if( cachedReplyServiceContexts == null ) { 746 cachedReplyServiceContexts = new HashMap (); 747 } 748 749 764 try { 765 ServiceContexts serviceContexts = 766 messageMediator.getReplyServiceContexts(); 767 if (serviceContexts == null) { 768 throw new NullPointerException (); 769 } 770 return getServiceContext(cachedReplyServiceContexts, 771 serviceContexts, id); 772 } catch (NullPointerException e) { 773 throw stdWrapper.invalidServiceContextId( e ) ; 778 } 779 } 780 781 786 public com.sun.corba.se.spi.legacy.connection.Connection connection() 787 { 788 return (com.sun.corba.se.spi.legacy.connection.Connection) 789 messageMediator.getConnection(); 790 } 791 792 793 794 798 799 protected void setInfo(MessageMediator messageMediator) 800 { 801 this.messageMediator = (CorbaMessageMediator)messageMediator; 802 this.messageMediator.setDIIInfo(request); 804 } 805 806 809 void setRetryRequest( boolean retryRequest ) { 810 this.retryRequest = retryRequest; 811 } 812 813 816 boolean getRetryRequest() { 817 return this.retryRequest; 818 } 819 820 823 void incrementEntryCount() { 824 this.entryCount++; 825 } 826 827 830 void decrementEntryCount() { 831 this.entryCount--; 832 } 833 834 837 int getEntryCount() { 838 return this.entryCount; 839 } 840 841 845 protected void setReplyStatus( short replyStatus ) { 846 super.setReplyStatus( replyStatus ); 847 switch( replyStatus ) { 848 case SUCCESSFUL.value: 849 endingPointCall = CALL_RECEIVE_REPLY; 850 break; 851 case SYSTEM_EXCEPTION.value: 852 case USER_EXCEPTION.value: 853 endingPointCall = CALL_RECEIVE_EXCEPTION; 854 break; 855 case LOCATION_FORWARD.value: 856 case TRANSPORT_RETRY.value: 857 endingPointCall = CALL_RECEIVE_OTHER; 858 break; 859 } 860 } 861 862 865 protected void setDIIRequest(org.omg.CORBA.Request req) { 866 request = req; 867 } 868 869 874 protected void setDIIInitiate( boolean diiInitiate ) { 875 this.diiInitiate = diiInitiate; 876 } 877 878 881 protected boolean isDIIInitiate() { 882 return this.diiInitiate; 883 } 884 885 891 protected void setPICurrentPushed( boolean piCurrentPushed ) { 892 this.piCurrentPushed = piCurrentPushed; 893 } 894 895 protected boolean isPICurrentPushed() { 896 return this.piCurrentPushed; 897 } 898 899 902 protected void setException( Exception exception ) { 903 super.setException( exception ); 904 905 cachedReceivedException = null; 907 cachedReceivedExceptionId = null; 908 } 909 910 protected boolean getIsOneWay() { 911 return ! response_expected(); 912 } 913 914 917 protected void checkAccess( int methodID ) 918 throws BAD_INV_ORDER 919 { 920 int validCallIndex = 0; 923 switch( currentExecutionPoint ) { 924 case EXECUTION_POINT_STARTING: 925 switch( startingPointCall ) { 926 case CALL_SEND_REQUEST: 927 validCallIndex = 0; 928 break; 929 case CALL_SEND_POLL: 930 validCallIndex = 1; 931 break; 932 } 933 break; 934 case EXECUTION_POINT_ENDING: 935 switch( endingPointCall ) { 936 case CALL_RECEIVE_REPLY: 937 validCallIndex = 2; 938 break; 939 case CALL_RECEIVE_EXCEPTION: 940 validCallIndex = 3; 941 break; 942 case CALL_RECEIVE_OTHER: 943 validCallIndex = 4; 944 break; 945 } 946 break; 947 } 948 949 if( !validCall[methodID][validCallIndex] ) { 951 throw stdWrapper.invalidPiCall2() ; 952 } 953 } 954 955 } 956 957 | Popular Tags |