*
* @return the final version of {@link Interceptor}
*/
public Interceptor build() {
return new Interceptor() {
final Map<Method, List<Interceptor>> interceptors = new HashMap<Method, List<Interceptor>>(
InterceptorBuilder.this.interceptors);
@Override
public Object intercept(final InvocationContext originalContext) throws Throwable {
Collection<Interceptor> interceptors = this.interceptors.get(originalContext.getMethod());
if (interceptors != null) {
final Iterator<Interceptor> iterator = interceptors.iterator();
if (iterator.hasNext()) {
Interceptor interceptor = iterator.next();
return interceptor.intercept(new InvocationContext() {
@Override
public Object invoke() throws Throwable {
if (iterator.hasNext()) {
return iterator.next().intercept(this);