public static InterceptorComponent replaceInterceptor ( final Class match , final InterceptorComponent replacement , final InterceptorComponent chain ) { if ( chain == null ) { return null ; } InterceptorComponent current = chain ; InterceptorComponent previous = null ; InterceptorComponent updatedChain = null ; while ( updatedChain == null ) { if ( match . isInstance ( current ) ) { // Found the interceptor that needs to be replaced. replacement . setBackingComponent ( current . getBackingComponent ( ) ) ; if ( previous == null ) { updatedChain = replacement ; } else { previous . setBackingComponent ( replacement ) ; updatedChain = chain ; } } else { previous = current ; WebComponent next = current . getBackingComponent ( ) ; if ( next instanceof InterceptorComponent ) { current = ( InterceptorComponent ) next ; } else { // Reached the end of the chain. No replacement done. updatedChain = chain ; } } } return updatedChain ; }
Utility method for replacing an individual interceptor within an existing chain .