Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2014, Red Hat, Inc., and individual contributors
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
  * http://www.apache.org/licenses/LICENSE-2.0
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.jboss.weld.interceptor.proxy;
 
 import java.util.List;
 import java.util.Map;
 
 
Weld's javax.interceptor.InvocationContext implementation. This is a forwarding implementation that delegates most method calls to an underlying javax.interceptor.InvocationContext. This allows multiple interceptor chains to be combined. A call to proceed() invokes the chain of intercepors in the given order. Once the chain finishes, the proceed() method of the delegate is invoked which results in the target method being invoked in case of SimpleInvocationContext. Otherwise, the delegate chain is run.

Author(s):
Jozef Hartinger
 
 
     private int position;
     private final List<InterceptorMethodInvocationchain;
     private final InvocationContext delegate;
 
     public WeldInvocationContext(Constructor<?> constructorObject[] parametersMap<StringObjectcontextDataList<InterceptorMethodInvocationchain) {
         this(new SimpleInvocationContext(constructorparameterscontextData), chainnull);
     }
 
     public WeldInvocationContext(Object targetMethod targetMethodMethod proceedObject[] parametersList<InterceptorMethodInvocationchainCombinedInterceptorAndDecoratorStackMethodHandler currentHandler) {
         this(new SimpleInvocationContext(targettargetMethodproceedparameters), chaincurrentHandler);
     }
 
         this(delegatechainnull);
     }
 
         this. = delegate;
         this. = chain;
         this. = currentHandler;
     }
 
     @Override
     protected InvocationContext delegate() {
         return ;
     }
 
     public boolean hasNextInterceptor() {
         return  < .size();
     }
 
     protected Object invokeNext() throws Exception {
         int oldCurrentPosition = ;
         try {
             InterceptorMethodInvocation nextInterceptorMethodInvocation = .get(++);
             ..invokingNextInterceptorInChain(nextInterceptorMethodInvocation);
             if (nextInterceptorMethodInvocation.expectsInvocationContext()) {
                 return nextInterceptorMethodInvocation.invoke(WeldInvocationContext.this);
             } else {
                 nextInterceptorMethodInvocation.invoke(null);
                 while (hasNextInterceptor()) {
                     nextInterceptorMethodInvocation = .get(++);
                     nextInterceptorMethodInvocation.invoke(null);
                 }
                 return null;
             }
         } finally {
              = oldCurrentPosition;
         }
     }
 
     protected Object interceptorChainCompleted() throws Exception {
         return delegate().proceed();
     }
    @Override
    public Object proceed() throws Exception {
        Stack stack = null;
        /*
         * No need to push the context for the first interceptor as the current context
         * was set by CombinedInterceptorAndDecoratorStackMethodHandler
         */
        if ( != null &&  != 0) {
            stack = InterceptionDecorationContext.startIfNotOnTop();
        }
        try {
            if (hasNextInterceptor()) {
                return invokeNext();
            } else {
                return interceptorChainCompleted();
            }
        } catch (InvocationTargetException e) {
            Throwable cause = e.getCause();
            if (cause instanceof Error) {
                throw (Errorcause;
            }
            if (cause instanceof Exception) {
                throw (Exceptioncause;
            }
            throw new RuntimeException(cause);
        } finally {
            if (stack != null) {
                stack.end();
            }
        }
    }
New to GrepCode? Check out our FAQ X