final org.jboss.weld.interceptor.spi.model.InterceptionType interceptionType = org.jboss.weld.interceptor.spi.model.InterceptionType.valueOf(type.name());
final InterceptorInvocation invocation = interceptorMetadata.getInterceptorInvocation(instance, interceptionType);
try {
if (ctx instanceof InterceptorInvocationContext || invocation.getInterceptorMethodInvocations().size() < 2) {
return new SimpleInterceptionChain(invocation).invokeNextInterceptor(ctx);
} else {
/*
* Calling Interceptor.intercept() may result in multiple interceptor method invocations (provided the interceptor class
* interceptor methods on superclasses). This requires cooperation with InvocationContext.
*
* If the InvocationContext used is our InterceptorInvocationContext or if there is no more than 1 InterceptorMethodInvocation
* then no special treatment is required. Otherwise, we use a wrapper InvocationTarget for the purpose of executing the chain of
* interceptor methods of this interceptor.
*/
final InterceptionChain chain = new SimpleInterceptionChain(invocation) {
@Override
protected Object interceptorChainCompleted(InvocationContext context) throws Exception {
return ctx.proceed(); // done with the inner chain, let the outer chain proceed
}
};
return chain.invokeNextInterceptor(new ForwardingInvocationContext() {
@Override
protected InvocationContext delegate() {
return ctx;
}
@Override
public Object proceed() throws Exception {
return chain.invokeNextInterceptor(this);
}
});
}
} catch (RuntimeException e) {
throw e;