1 7 package com.sun.corba.se.impl.interceptors; 8 9 import org.omg.CORBA.CompletionStatus ; 10 import org.omg.CORBA.INTERNAL ; 11 import org.omg.CORBA.SystemException ; 12 import org.omg.CORBA.portable.Delegate ; 13 import org.omg.PortableInterceptor.LOCATION_FORWARD ; 14 import org.omg.PortableInterceptor.SUCCESSFUL ; 15 import org.omg.PortableInterceptor.SYSTEM_EXCEPTION ; 16 import org.omg.PortableInterceptor.TRANSPORT_RETRY ; 17 import org.omg.PortableInterceptor.USER_EXCEPTION ; 18 import org.omg.PortableInterceptor.ClientRequestInfo ; 19 import org.omg.PortableInterceptor.ClientRequestInterceptor ; 20 import org.omg.PortableInterceptor.ForwardRequest ; 21 import org.omg.PortableInterceptor.IORInterceptor ; 22 import org.omg.PortableInterceptor.IORInterceptor_3_0 ; 23 import org.omg.PortableInterceptor.ServerRequestInfo ; 24 import org.omg.PortableInterceptor.ServerRequestInterceptor ; 25 import org.omg.PortableInterceptor.ObjectReferenceTemplate ; 26 27 import com.sun.corba.se.spi.ior.IOR; 28 import com.sun.corba.se.spi.oa.ObjectAdapter; 29 import com.sun.corba.se.spi.orb.ORB; 30 import com.sun.corba.se.impl.orbutil.ORBUtility; 31 32 39 public class InterceptorInvoker { 40 41 private ORB orb; 43 44 private InterceptorList interceptorList; 46 47 private boolean enabled = false; 51 52 private PICurrent current; 54 55 59 64 InterceptorInvoker( ORB orb, InterceptorList interceptorList, 65 PICurrent piCurrent ) 66 { 67 this.orb = orb; 68 this.interceptorList = interceptorList; 69 this.enabled = false; 70 this.current = piCurrent; 71 } 72 73 76 void setEnabled( boolean enabled ) { 77 this.enabled = enabled; 78 } 79 80 84 85 90 void objectAdapterCreated( ObjectAdapter oa ) { 91 if( enabled ) { 93 IORInfoImpl info = new IORInfoImpl( oa ); 95 96 IORInterceptor [] iorInterceptors = 98 (IORInterceptor [])interceptorList.getInterceptors( 99 InterceptorList.INTERCEPTOR_TYPE_IOR ); 100 int size = iorInterceptors.length; 101 102 109 for( int i = (size - 1); i >= 0; i-- ) { 110 IORInterceptor interceptor = iorInterceptors[i]; 111 try { 112 interceptor.establish_components( info ); 113 } 114 catch( Exception e ) { 115 } 118 } 119 120 info.makeStateEstablished() ; 122 123 for( int i = (size - 1); i >= 0; i-- ) { 124 IORInterceptor interceptor = iorInterceptors[i]; 125 if (interceptor instanceof IORInterceptor_3_0 ) { 126 IORInterceptor_3_0 interceptor30 = (IORInterceptor_3_0 )interceptor ; 127 interceptor30.components_established( info ); 130 } 131 } 132 133 info.makeStateDone() ; 138 } 139 } 140 141 void adapterManagerStateChanged( int managerId, short newState ) 142 { 143 if (enabled) { 144 IORInterceptor [] interceptors = 145 (IORInterceptor [])interceptorList.getInterceptors( 146 InterceptorList.INTERCEPTOR_TYPE_IOR ); 147 int size = interceptors.length; 148 149 for( int i = (size - 1); i >= 0; i-- ) { 150 try { 151 IORInterceptor interceptor = interceptors[i]; 152 if (interceptor instanceof IORInterceptor_3_0 ) { 153 IORInterceptor_3_0 interceptor30 = (IORInterceptor_3_0 )interceptor ; 154 interceptor30.adapter_manager_state_changed( managerId, 155 newState ); 156 } 157 } catch (Exception exc) { 158 } 160 } 161 } 162 } 163 164 void adapterStateChanged( ObjectReferenceTemplate [] templates, 165 short newState ) 166 { 167 if (enabled) { 168 IORInterceptor [] interceptors = 169 (IORInterceptor [])interceptorList.getInterceptors( 170 InterceptorList.INTERCEPTOR_TYPE_IOR ); 171 int size = interceptors.length; 172 173 for( int i = (size - 1); i >= 0; i-- ) { 174 try { 175 IORInterceptor interceptor = interceptors[i]; 176 if (interceptor instanceof IORInterceptor_3_0 ) { 177 IORInterceptor_3_0 interceptor30 = (IORInterceptor_3_0 )interceptor ; 178 interceptor30.adapter_state_changed( templates, newState ); 179 } 180 } catch (Exception exc) { 181 } 183 } 184 } 185 } 186 187 191 192 196 void invokeClientInterceptorStartingPoint( ClientRequestInfoImpl info ) { 197 if( enabled ) { 199 try { 200 current.pushSlotTable( ); 204 info.setPICurrentPushed( true ); 205 info.setCurrentExecutionPoint( info.EXECUTION_POINT_STARTING ); 206 207 ClientRequestInterceptor [] clientInterceptors = 209 (ClientRequestInterceptor [])interceptorList. 210 getInterceptors( InterceptorList.INTERCEPTOR_TYPE_CLIENT ); 211 int size = clientInterceptors.length; 212 213 int flowStackIndex = size; 217 boolean continueProcessing = true; 218 219 for( int i = 0; continueProcessing && (i < size); i++ ) { 226 try { 227 clientInterceptors[i].send_request( info ); 228 229 233 242 } 243 catch( ForwardRequest e ) { 244 flowStackIndex = i; 249 info.setForwardRequest( e ); 250 info.setEndingPointCall( 251 ClientRequestInfoImpl.CALL_RECEIVE_OTHER ); 252 info.setReplyStatus( LOCATION_FORWARD.value ); 253 254 updateClientRequestDispatcherForward( info ); 255 256 continueProcessing = false; 262 } 263 catch( SystemException e ) { 264 flowStackIndex = i; 269 info.setEndingPointCall( 270 ClientRequestInfoImpl.CALL_RECEIVE_EXCEPTION ); 271 info.setReplyStatus( SYSTEM_EXCEPTION.value ); 272 info.setException( e ); 273 274 continueProcessing = false; 280 } 281 } 282 283 info.setFlowStackIndex( flowStackIndex ); 285 } 286 finally { 287 current.resetSlotTable( ); 289 } 290 } } 292 293 297 void invokeClientInterceptorEndingPoint( ClientRequestInfoImpl info ) { 298 if( enabled ) { 300 try { 301 304 info.setCurrentExecutionPoint( info.EXECUTION_POINT_ENDING ); 305 306 ClientRequestInterceptor [] clientInterceptors = 308 (ClientRequestInterceptor [])interceptorList. 309 getInterceptors( InterceptorList.INTERCEPTOR_TYPE_CLIENT ); 310 int flowStackIndex = info.getFlowStackIndex(); 311 312 int endingPointCall = info.getEndingPointCall(); 315 316 if( ( endingPointCall == 319 ClientRequestInfoImpl.CALL_RECEIVE_REPLY ) && 320 info.getIsOneWay() ) 321 { 322 endingPointCall = ClientRequestInfoImpl.CALL_RECEIVE_OTHER; 323 info.setEndingPointCall( endingPointCall ); 324 } 325 326 for( int i = (flowStackIndex - 1); i >= 0; i-- ) { 332 333 try { 334 switch( endingPointCall ) { 335 case ClientRequestInfoImpl.CALL_RECEIVE_REPLY: 336 clientInterceptors[i].receive_reply( info ); 337 break; 338 case ClientRequestInfoImpl.CALL_RECEIVE_EXCEPTION: 339 clientInterceptors[i].receive_exception( info ); 340 break; 341 case ClientRequestInfoImpl.CALL_RECEIVE_OTHER: 342 clientInterceptors[i].receive_other( info ); 343 break; 344 } 345 } 346 catch( ForwardRequest e ) { 347 348 endingPointCall = 352 ClientRequestInfoImpl.CALL_RECEIVE_OTHER; 353 info.setEndingPointCall( endingPointCall ); 354 info.setReplyStatus( LOCATION_FORWARD.value ); 355 info.setForwardRequest( e ); 356 updateClientRequestDispatcherForward( info ); 357 } 358 catch( SystemException e ) { 359 360 endingPointCall = 364 ClientRequestInfoImpl.CALL_RECEIVE_EXCEPTION; 365 info.setEndingPointCall( endingPointCall ); 366 info.setReplyStatus( SYSTEM_EXCEPTION.value ); 367 info.setException( e ); 368 } 369 } 370 } 371 finally { 372 if (info != null && info.isPICurrentPushed()) { 375 current.popSlotTable( ); 376 } 379 } 380 } } 382 383 387 388 391 void invokeServerInterceptorStartingPoint( ServerRequestInfoImpl info ) { 392 if( enabled ) { 394 try { 395 current.pushSlotTable(); 397 info.setSlotTable(current.getSlotTable()); 398 399 current.pushSlotTable( ); 402 403 info.setCurrentExecutionPoint( info.EXECUTION_POINT_STARTING ); 404 405 ServerRequestInterceptor [] serverInterceptors = 407 (ServerRequestInterceptor [])interceptorList. 408 getInterceptors( InterceptorList.INTERCEPTOR_TYPE_SERVER ); 409 int size = serverInterceptors.length; 410 411 int flowStackIndex = size; 415 boolean continueProcessing = true; 416 417 for( int i = 0; continueProcessing && (i < size); i++ ) { 420 421 try { 422 serverInterceptors[i]. 423 receive_request_service_contexts( info ); 424 } 425 catch( ForwardRequest e ) { 426 flowStackIndex = i; 431 info.setForwardRequest( e ); 432 info.setIntermediatePointCall( 433 ServerRequestInfoImpl.CALL_INTERMEDIATE_NONE ); 434 info.setEndingPointCall( 435 ServerRequestInfoImpl.CALL_SEND_OTHER ); 436 info.setReplyStatus( LOCATION_FORWARD.value ); 437 438 continueProcessing = false; 444 } 445 catch( SystemException e ) { 446 447 flowStackIndex = i; 452 info.setException( e ); 453 info.setIntermediatePointCall( 454 ServerRequestInfoImpl.CALL_INTERMEDIATE_NONE ); 455 info.setEndingPointCall( 456 ServerRequestInfoImpl.CALL_SEND_EXCEPTION ); 457 info.setReplyStatus( SYSTEM_EXCEPTION.value ); 458 459 continueProcessing = false; 465 } 466 467 } 468 469 info.setFlowStackIndex( flowStackIndex ); 471 } 472 finally { 473 current.popSlotTable( ); 476 } 478 } } 480 481 484 void invokeServerInterceptorIntermediatePoint( 485 ServerRequestInfoImpl info ) 486 { 487 int intermediatePointCall = info.getIntermediatePointCall(); 488 if( enabled && ( intermediatePointCall != 490 ServerRequestInfoImpl.CALL_INTERMEDIATE_NONE ) ) 491 { 492 495 info.setCurrentExecutionPoint( info.EXECUTION_POINT_INTERMEDIATE ); 496 497 ServerRequestInterceptor [] serverInterceptors = 499 (ServerRequestInterceptor []) 500 interceptorList.getInterceptors( 501 InterceptorList.INTERCEPTOR_TYPE_SERVER ); 502 int size = serverInterceptors.length; 503 504 for( int i = 0; i < size; i++ ) { 507 508 try { 509 serverInterceptors[i].receive_request( info ); 510 } 511 catch( ForwardRequest e ) { 512 513 info.setForwardRequest( e ); 518 info.setEndingPointCall( 519 ServerRequestInfoImpl.CALL_SEND_OTHER ); 520 info.setReplyStatus( LOCATION_FORWARD.value ); 521 break; 522 } 523 catch( SystemException e ) { 524 525 info.setException( e ); 530 info.setEndingPointCall( 531 ServerRequestInfoImpl.CALL_SEND_EXCEPTION ); 532 info.setReplyStatus( SYSTEM_EXCEPTION.value ); 533 break; 534 } 535 } 536 } } 538 539 543 void invokeServerInterceptorEndingPoint( ServerRequestInfoImpl info ) { 544 if( enabled ) { 546 try { 547 550 557 ServerRequestInterceptor [] serverInterceptors = 559 (ServerRequestInterceptor [])interceptorList. 560 getInterceptors( InterceptorList.INTERCEPTOR_TYPE_SERVER ); 561 int flowStackIndex = info.getFlowStackIndex(); 562 563 int endingPointCall = info.getEndingPointCall(); 566 567 for( int i = (flowStackIndex - 1); i >= 0; i-- ) { 570 try { 571 switch( endingPointCall ) { 572 case ServerRequestInfoImpl.CALL_SEND_REPLY: 573 serverInterceptors[i].send_reply( info ); 574 break; 575 case ServerRequestInfoImpl.CALL_SEND_EXCEPTION: 576 serverInterceptors[i].send_exception( info ); 577 break; 578 case ServerRequestInfoImpl.CALL_SEND_OTHER: 579 serverInterceptors[i].send_other( info ); 580 break; 581 } 582 } 583 catch( ForwardRequest e ) { 584 endingPointCall = 588 ServerRequestInfoImpl.CALL_SEND_OTHER; 589 info.setEndingPointCall( endingPointCall ); 590 info.setForwardRequest( e ); 591 info.setReplyStatus( LOCATION_FORWARD.value ); 592 info.setForwardRequestRaisedInEnding(); 593 } 594 catch( SystemException e ) { 595 endingPointCall = 599 ServerRequestInfoImpl.CALL_SEND_EXCEPTION; 600 info.setEndingPointCall( endingPointCall ); 601 info.setException( e ); 602 info.setReplyStatus( SYSTEM_EXCEPTION.value ); 603 } 604 } 605 606 info.setAlreadyExecuted( true ); 609 } 610 finally { 611 current.popSlotTable(); 613 } 614 } } 616 617 621 622 626 private void updateClientRequestDispatcherForward( 627 ClientRequestInfoImpl info ) 628 { 629 ForwardRequest forwardRequest = info.getForwardRequestException(); 630 631 if( forwardRequest != null ) { 636 org.omg.CORBA.Object object = forwardRequest.forward; 637 638 IOR ior = ORBUtility.getIOR( object ) ; 640 info.setLocatedIOR( ior ); 641 } 642 } 643 644 } 645 | Popular Tags |