FileDocCategorySizeDatePackage
InvocationContextImpl.javaAPI DocJBoss 4.2.15164Fri Jul 13 20:53:52 BST 2007org.jboss.ejb3.interceptor

InvocationContextImpl

public class InvocationContextImpl extends Object implements javax.interceptor.InvocationContext
author
Kabir Khan
version
$Revision: 60233 $

Fields Summary
private int
currentInterceptor
private int
currentMethod
private int
currentBeanMethod
InterceptorInfo[]
interceptorInfos
Object[]
instances
private Method[]
beanAroundInvokes
private Map
metadata
org.jboss.ejb3.EJBContainerInvocation
wrapped
Constructors Summary
public InvocationContextImpl(org.jboss.ejb3.EJBContainerInvocation inv, InterceptorInfo[] interceptorInfos, Object[] instances, Method[] beanAroundInvokes)

      wrapped = inv;
      this.beanAroundInvokes = beanAroundInvokes;
      
      if (interceptorInfos.length != instances.length)
      {
         throw new RuntimeException("interceptorInfos and instances have different length");
      }
      
      this.interceptorInfos = interceptorInfos;
      this.instances = instances;
   
Methods Summary
public java.util.MapgetContextData()

      if (metadata == null) {
         metadata = ClientInterceptorUtil.getClientMetadataMap(wrapped);
         if (metadata == null)
         {
            metadata = new HashMap();
         }
      }
      return metadata;
   
public java.lang.reflect.MethodgetMethod()

      return wrapped.getMethod();
   
public java.lang.Object[]getParameters()

      return wrapped.getArguments();
   
public java.lang.ObjectgetTarget()

      return wrapped.getTargetObject();
   
public java.lang.Objectproceed()

      if (currentInterceptor < interceptorInfos.length)
      {
         int oldInterceptor = currentInterceptor;
         int oldMethod = currentMethod;
         try
         {
            int curr = currentInterceptor;
            int currMethod = currentMethod++;
            
            InterceptorInfo info = interceptorInfos[curr];
            if (currMethod == info.getAroundInvokes().length)
            {
               curr = ++currentInterceptor;
               currentMethod = 0;
               currMethod = currentMethod++;
               info = (curr < interceptorInfos.length) ? interceptorInfos[curr] : null;
            }
            if (info != null)
            {
               try
               {
                  return info.getAroundInvokes()[currMethod].invoke(instances[curr], this);
               }
               catch (InvocationTargetException e)
               {
                  if (e.getTargetException() instanceof Exception)
                  {
                     throw ((Exception) e.getCause());
                  }
                  else
                  {
                     throw new RuntimeException(e.getCause());
                  }
               }
            }
         }
         finally
         {
            // so that interceptors like clustering can reinvoke down the chain
            currentInterceptor = oldInterceptor;
            currentMethod = oldMethod;
         }
      }
      
      if (beanAroundInvokes != null && currentBeanMethod < beanAroundInvokes.length)
      {
         try
         {
            int curr = currentBeanMethod++;
            return beanAroundInvokes[curr].invoke(getTarget(), this);
         }
         catch (InvocationTargetException e)
         {
            if (e.getTargetException() instanceof Exception)
            {
               throw ((Exception) e.getCause());
            }
            else
            {
               throw new RuntimeException(e.getCause());
            }
         }
         finally
         {
            currentBeanMethod--;;
         }
      }
      try
      {
         return wrapped.invokeNext();
      }
      catch (Exception e)
      {
         throw e;
      }
      catch (Throwable t)
      {
         throw new RuntimeException(t);
      }
   
public voidsetParameters(java.lang.Object[] params)

      wrapped.setArguments(params);