1 7 package com.sun.corba.se.impl.interceptors; 8 9 import java.io.IOException ; 10 11 import java.lang.reflect.Method ; 12 import java.lang.reflect.InvocationTargetException ; 13 14 import java.util.HashMap ; 15 16 import org.omg.PortableInterceptor.ForwardRequest ; 17 import org.omg.PortableInterceptor.InvalidSlot ; 18 import org.omg.PortableInterceptor.RequestInfo ; 19 import org.omg.PortableInterceptor.LOCATION_FORWARD ; 20 import org.omg.IOP.TaggedProfile ; 21 import org.omg.IOP.TaggedComponent ; 22 import org.omg.IOP.ServiceContextHelper ; 23 import org.omg.Messaging.SYNC_WITH_TRANSPORT ; 24 import org.omg.CORBA.ParameterMode ; 25 26 import org.omg.CORBA.Any ; 27 import org.omg.CORBA.BAD_INV_ORDER ; 28 import org.omg.CORBA.BAD_PARAM ; 29 import org.omg.CORBA.CompletionStatus ; 30 import org.omg.CORBA.Context ; 31 import org.omg.CORBA.ContextList ; 32 import org.omg.CORBA.CTX_RESTRICT_SCOPE ; 33 import org.omg.CORBA.ExceptionList ; 34 import org.omg.CORBA.INTERNAL ; 35 import org.omg.CORBA.LocalObject ; 36 import org.omg.CORBA.NamedValue ; 37 import org.omg.CORBA.NO_IMPLEMENT ; 38 import org.omg.CORBA.NO_RESOURCES ; 39 import org.omg.CORBA.NVList ; 40 import org.omg.CORBA.Object ; 41 import org.omg.CORBA.Policy ; 42 import org.omg.CORBA.SystemException ; 43 import org.omg.CORBA.TypeCode ; 44 import org.omg.CORBA.UNKNOWN ; 45 import org.omg.CORBA.UserException ; 46 import org.omg.CORBA.portable.ApplicationException ; 47 import org.omg.CORBA.portable.Delegate ; 48 import org.omg.CORBA.portable.InputStream ; 49 50 import org.omg.Dynamic.Parameter ; 51 52 import com.sun.corba.se.spi.legacy.connection.Connection; 53 54 import com.sun.corba.se.spi.legacy.interceptor.RequestInfoExt; 55 56 import com.sun.corba.se.spi.ior.IOR; 57 58 import com.sun.corba.se.spi.ior.iiop.GIOPVersion; 59 60 import com.sun.corba.se.spi.orb.ORB; 61 62 import com.sun.corba.se.spi.logging.CORBALogDomains; 63 64 import com.sun.corba.se.spi.servicecontext.ServiceContexts; 65 import com.sun.corba.se.spi.servicecontext.UnknownServiceContext; 66 67 import com.sun.corba.se.impl.encoding.CDRInputStream_1_0; 68 import com.sun.corba.se.impl.encoding.EncapsOutputStream; 69 70 import com.sun.corba.se.impl.orbutil.ORBUtility; 71 import com.sun.corba.se.impl.orbutil.ORBClassLoader; 72 73 import com.sun.corba.se.impl.util.RepositoryId; 74 75 import com.sun.corba.se.impl.logging.InterceptorsSystemException; 76 import com.sun.corba.se.impl.logging.OMGSystemException; 77 78 82 public abstract class RequestInfoImpl 83 extends LocalObject 84 implements RequestInfo , RequestInfoExt 85 { 86 92 protected ORB myORB; 94 protected InterceptorsSystemException wrapper ; 95 protected OMGSystemException stdWrapper ; 96 97 protected int flowStackIndex = 0; 100 101 protected int startingPointCall; 105 106 protected int intermediatePointCall; 111 112 protected int endingPointCall; 116 117 protected short replyStatus = UNINITIALIZED; 120 121 protected static final short UNINITIALIZED = -1; 123 124 protected int currentExecutionPoint; 127 protected static final int EXECUTION_POINT_STARTING = 0; 128 protected static final int EXECUTION_POINT_INTERMEDIATE = 1; 129 protected static final int EXECUTION_POINT_ENDING = 2; 130 131 protected boolean alreadyExecuted; 134 135 protected Connection connection; 137 protected ServiceContexts serviceContexts; 138 139 protected ForwardRequest forwardRequest; 145 protected IOR forwardRequestIOR; 146 147 protected SlotTable slotTable; 149 150 protected Exception exception; 153 154 160 164 void reset() { 165 166 168 flowStackIndex = 0; 169 startingPointCall = 0; 170 intermediatePointCall = 0; 171 endingPointCall = 0; 172 replyStatus = UNINITIALIZED; 173 currentExecutionPoint = EXECUTION_POINT_STARTING; 174 alreadyExecuted = false; 175 connection = null; 176 serviceContexts = null; 177 forwardRequest = null; 178 forwardRequestIOR = null; 179 exception = null; 180 181 } 185 186 190 191 protected static final int MID_REQUEST_ID = 0; 194 protected static final int MID_OPERATION = 1; 195 protected static final int MID_ARGUMENTS = 2; 196 protected static final int MID_EXCEPTIONS = 3; 197 protected static final int MID_CONTEXTS = 4; 198 protected static final int MID_OPERATION_CONTEXT = 5; 199 protected static final int MID_RESULT = 6; 200 protected static final int MID_RESPONSE_EXPECTED = 7; 201 protected static final int MID_SYNC_SCOPE = 8; 202 protected static final int MID_REPLY_STATUS = 9; 203 protected static final int MID_FORWARD_REFERENCE = 10; 204 protected static final int MID_GET_SLOT = 11; 205 protected static final int MID_GET_REQUEST_SERVICE_CONTEXT = 12; 206 protected static final int MID_GET_REPLY_SERVICE_CONTEXT = 13; 207 protected static final int MID_RI_LAST = 13; 209 210 214 215 218 public RequestInfoImpl( ORB myORB ) { 219 super(); 220 221 this.myORB = myORB; 222 wrapper = InterceptorsSystemException.get( myORB, 223 CORBALogDomains.RPC_PROTOCOL ) ; 224 stdWrapper = OMGSystemException.get( myORB, 225 CORBALogDomains.RPC_PROTOCOL ) ; 226 227 PICurrent current = (PICurrent)(myORB.getPIHandler().getPICurrent()); 229 slotTable = current.getSlotTable( ); 230 } 231 232 240 abstract public int request_id (); 241 242 248 abstract public String operation (); 249 250 251 256 abstract public Parameter [] arguments (); 257 258 263 abstract public TypeCode [] exceptions (); 264 265 270 abstract public String [] contexts (); 271 272 277 abstract public String [] operation_context (); 278 279 284 abstract public Any result (); 285 286 296 abstract public boolean response_expected (); 297 298 311 public short sync_scope (){ 312 checkAccess( MID_SYNC_SCOPE ); 313 return SYNC_WITH_TRANSPORT.value; } 315 316 327 public short reply_status (){ 328 checkAccess( MID_REPLY_STATUS ); 329 return replyStatus; 330 } 331 332 341 abstract public Object forward_reference (); 342 343 344 353 public Any get_slot (int id) 354 throws InvalidSlot 355 { 356 return slotTable.get_slot( id ); 361 } 362 363 372 abstract public org.omg.IOP.ServiceContext 373 get_request_service_context(int id); 374 375 384 abstract public org.omg.IOP.ServiceContext 385 get_reply_service_context (int id); 386 387 388 394 395 396 400 401 407 public com.sun.corba.se.spi.legacy.connection.Connection connection() 408 { 409 return connection; 410 } 411 412 416 417 423 private void insertApplicationException( ApplicationException appException, 424 Any result ) 425 throws UNKNOWN 426 { 427 try { 428 RepositoryId repId = RepositoryId.cache.getId( 431 appException.getId() ); 432 String className = repId.getClassName(); 433 434 String helperClassName = className + "Helper"; 436 Class helperClass = ORBClassLoader.loadClass( helperClassName ); 437 Class [] readParams = new Class [1]; 438 readParams[0] = org.omg.CORBA.portable.InputStream .class; 439 Method readMethod = helperClass.getMethod( "read", readParams ); 440 441 InputStream ueInputStream = appException.getInputStream(); 445 ueInputStream.mark( 0 ); 446 UserException userException = null; 447 try { 448 java.lang.Object [] readArguments = new java.lang.Object [1]; 449 readArguments[0] = ueInputStream; 450 userException = (UserException )readMethod.invoke( 451 null, readArguments ); 452 } 453 finally { 454 try { 455 ueInputStream.reset(); 456 } 457 catch( IOException e ) { 458 throw wrapper.markAndResetFailed( e ) ; 459 } 460 } 461 462 insertUserException( userException, result ); 465 } catch( ClassNotFoundException e ) { 466 throw stdWrapper.unknownUserException( CompletionStatus.COMPLETED_MAYBE, e ) ; 467 } catch( NoSuchMethodException e ) { 468 throw stdWrapper.unknownUserException( CompletionStatus.COMPLETED_MAYBE, e ) ; 469 } catch( SecurityException e ) { 470 throw stdWrapper.unknownUserException( CompletionStatus.COMPLETED_MAYBE, e ) ; 471 } catch( IllegalAccessException e ) { 472 throw stdWrapper.unknownUserException( CompletionStatus.COMPLETED_MAYBE, e ) ; 473 } catch( IllegalArgumentException e ) { 474 throw stdWrapper.unknownUserException( CompletionStatus.COMPLETED_MAYBE, e ) ; 475 } catch( InvocationTargetException e ) { 476 throw stdWrapper.unknownUserException( CompletionStatus.COMPLETED_MAYBE, e ) ; 477 } 478 } 479 480 486 private void insertUserException( UserException userException, Any result ) 487 throws UNKNOWN 488 { 489 try { 490 if( userException != null ) { 493 Class exceptionClass = userException.getClass(); 494 String className = exceptionClass.getName(); 495 String helperClassName = className + "Helper"; 496 Class helperClass = ORBClassLoader.loadClass( helperClassName ); 497 498 Class [] insertMethodParams = new Class [2]; 500 insertMethodParams[0] = org.omg.CORBA.Any .class; 501 insertMethodParams[1] = exceptionClass; 502 Method insertMethod = helperClass.getMethod( 503 "insert", insertMethodParams ); 504 505 java.lang.Object [] insertMethodArguments = 507 new java.lang.Object [2]; 508 insertMethodArguments[0] = result; 509 insertMethodArguments[1] = userException; 510 insertMethod.invoke( null, insertMethodArguments ); 511 } 512 } catch( ClassNotFoundException e ) { 513 throw stdWrapper.unknownUserException( CompletionStatus.COMPLETED_MAYBE, e ); 514 } catch( NoSuchMethodException e ) { 515 throw stdWrapper.unknownUserException( CompletionStatus.COMPLETED_MAYBE, e ); 516 } catch( SecurityException e ) { 517 throw stdWrapper.unknownUserException( CompletionStatus.COMPLETED_MAYBE, e ); 518 } catch( IllegalAccessException e ) { 519 throw stdWrapper.unknownUserException( CompletionStatus.COMPLETED_MAYBE, e ); 520 } catch( IllegalArgumentException e ) { 521 throw stdWrapper.unknownUserException( CompletionStatus.COMPLETED_MAYBE, e ); 522 } catch( InvocationTargetException e ) { 523 throw stdWrapper.unknownUserException( CompletionStatus.COMPLETED_MAYBE, e ); 524 } 525 } 526 527 531 532 535 protected Parameter [] nvListToParameterArray( NVList parNVList ) { 536 537 540 int count = parNVList.count(); 541 Parameter [] plist = new Parameter [count]; 542 try { 543 for( int i = 0; i < count; i++ ) { 544 Parameter p = new Parameter (); 545 plist[i] = p; 546 NamedValue nv = parNVList.item( i ); 547 plist[i].argument = nv.value(); 548 plist[i].mode = ParameterMode.from_int( nv.flags() - 1 ); 556 } 557 } catch ( Exception e ) { 558 throw wrapper.exceptionInArguments( e ) ; 559 } 560 561 return plist; 562 } 563 564 570 protected Any exceptionToAny( Exception exception ){ 571 Any result = myORB.create_any(); 572 573 if( exception == null ) { 574 throw wrapper.exceptionWasNull2() ; 577 } else if( exception instanceof SystemException ) { 578 ORBUtility.insertSystemException( 579 (SystemException )exception, result ); 580 } else if( exception instanceof ApplicationException ) { 581 try { 584 ApplicationException appException = 587 (ApplicationException )exception; 588 insertApplicationException( appException, result ); 589 } catch( UNKNOWN e ) { 590 ORBUtility.insertSystemException( e, result ); 596 } 597 } else if( exception instanceof UserException ) { 598 try { 599 UserException userException = (UserException )exception; 600 insertUserException( userException, result ); 601 } catch( UNKNOWN e ) { 602 ORBUtility.insertSystemException( e, result ); 603 } 604 } 605 606 607 return result; 608 } 609 610 615 protected org.omg.IOP.ServiceContext 616 getServiceContext ( HashMap cachedServiceContexts, 617 ServiceContexts serviceContexts, int id ) 618 { 619 org.omg.IOP.ServiceContext result = null; 620 Integer integerId = new Integer ( id ); 621 622 result = (org.omg.IOP.ServiceContext ) 624 cachedServiceContexts.get( integerId ); 625 626 if( result == null ) { 630 com.sun.corba.se.spi.servicecontext.ServiceContext context = 633 serviceContexts.get( id ); 634 if (context == null) 635 throw stdWrapper.invalidServiceContextId() ; 636 637 EncapsOutputStream out = new EncapsOutputStream(myORB); 641 642 context.write( out, GIOPVersion.V1_2 ); 643 InputStream inputStream = out.create_input_stream(); 644 result = ServiceContextHelper.read( inputStream ); 645 646 cachedServiceContexts.put( integerId, result ); 647 } 648 649 653 return result; 654 } 655 656 657 668 protected void addServiceContext( 669 HashMap cachedServiceContexts, 670 ServiceContexts serviceContexts, 671 org.omg.IOP.ServiceContext service_context, 672 boolean replace ) 673 { 674 int id = 0 ; 675 EncapsOutputStream outputStream = new EncapsOutputStream( 677 myORB ); 678 InputStream inputStream = null; 679 UnknownServiceContext coreServiceContext = null; 680 ServiceContextHelper.write( outputStream, service_context ); 681 inputStream = outputStream.create_input_stream(); 682 683 coreServiceContext = new UnknownServiceContext( 685 inputStream.read_long(), 686 (org.omg.CORBA_2_3.portable.InputStream )inputStream ); 687 688 id = coreServiceContext.getId(); 689 690 if (serviceContexts.get(id) != null) 691 if (replace) 692 serviceContexts.delete( id ); 693 else 694 throw stdWrapper.serviceContextAddFailed( new Integer (id) ) ; 695 696 serviceContexts.put( coreServiceContext ); 697 698 cachedServiceContexts.put( new Integer ( id ), service_context ); 700 } 701 702 712 protected void setFlowStackIndex(int num ) { 713 this.flowStackIndex = num; 714 } 715 716 721 protected int getFlowStackIndex() { 722 return this.flowStackIndex; 723 } 724 725 729 protected void setEndingPointCall( int call ) { 730 this.endingPointCall = call; 731 } 732 733 737 protected int getEndingPointCall() { 738 return this.endingPointCall; 739 } 740 741 745 protected void setIntermediatePointCall( int call ) { 746 this.intermediatePointCall = call; 747 } 748 749 753 protected int getIntermediatePointCall() { 754 return this.intermediatePointCall; 755 } 756 757 761 protected void setStartingPointCall( int call ) { 762 this.startingPointCall = call; 763 } 764 765 769 protected int getStartingPointCall() { 770 return this.startingPointCall; 771 } 772 773 777 protected boolean getAlreadyExecuted() { 778 return this.alreadyExecuted; 779 } 780 781 785 protected void setAlreadyExecuted( boolean alreadyExecuted ) { 786 this.alreadyExecuted = alreadyExecuted; 787 } 788 789 792 protected void setReplyStatus( short replyStatus ) { 793 this.replyStatus = replyStatus; 794 } 795 796 800 protected short getReplyStatus() { 801 return this.replyStatus; 802 } 803 804 808 protected void setForwardRequest( ForwardRequest forwardRequest ) { 809 this.forwardRequest = forwardRequest; 810 this.forwardRequestIOR = null; 811 } 812 813 817 protected void setForwardRequest( IOR ior ) { 818 this.forwardRequestIOR = ior; 819 this.forwardRequest = null; 820 } 821 822 825 protected ForwardRequest getForwardRequestException() { 826 if( this.forwardRequest == null ) { 827 if( this.forwardRequestIOR != null ) { 828 org.omg.CORBA.Object obj = iorToObject(this.forwardRequestIOR); 831 this.forwardRequest = new ForwardRequest ( obj ); 832 } 833 } 834 835 return this.forwardRequest; 836 } 837 838 841 protected IOR getForwardRequestIOR() { 842 if( this.forwardRequestIOR == null ) { 843 if( this.forwardRequest != null ) { 844 this.forwardRequestIOR = ORBUtility.getIOR( 845 this.forwardRequest.forward ) ; 846 } 847 } 848 849 return this.forwardRequestIOR; 850 } 851 852 856 protected void setException( Exception exception ) { 857 this.exception = exception; 858 } 859 860 864 Exception getException() { 865 return this.exception; 866 } 867 868 873 protected void setCurrentExecutionPoint( int executionPoint ) { 874 this.currentExecutionPoint = executionPoint; 875 } 876 877 889 protected abstract void checkAccess( int methodID ) 890 throws BAD_INV_ORDER ; 891 892 897 void setSlotTable(SlotTable slotTable) 898 { 899 this.slotTable = slotTable; 900 } 901 902 protected org.omg.CORBA.Object iorToObject( IOR ior ) 903 { 904 return ORBUtility.makeObjectReference( ior ) ; 905 } 906 } 907 | Popular Tags |