FileDocCategorySizeDatePackage
VersionedObjectForwardingInterceptor.javaAPI DocJBoss 4.2.13277Fri Jul 13 21:02:32 BST 2007org.jboss.aspects.versioned

VersionedObjectForwardingInterceptor

public class VersionedObjectForwardingInterceptor extends Object implements org.jboss.aop.advice.Interceptor
Invoke on a target object
author
Bill Burke
version
$Revision: 57186 $

Fields Summary
Constructors Summary
public VersionedObjectForwardingInterceptor()

   
Methods Summary
public java.lang.StringgetName()

 return "VersionedObjectForwardingInterceptor"; 
public java.lang.Objectinvoke(org.jboss.aop.joinpoint.Invocation invocation)

      Object target = invocation.getTargetObject();
      if (target instanceof Advised)
      {
         ClassAdvisor advisor = (ClassAdvisor)((Advised)target)._getAdvisor();
         // We will have already gone through the interceptor chain so just invoke on the
         // object.
         return advisor.invoke(invocation);
      }
      else
      {
         if (invocation instanceof MethodInvocation)
         {
            // For non-advised methods, we can only do public method invocations
            org.jboss.aop.joinpoint.MethodInvocation methodInvocation = (org.jboss.aop.joinpoint.MethodInvocation)invocation;
            long methodHash = methodInvocation.getMethodHash();
            HashMap methodMap = ClassProxyFactory.getMethodMap(target.getClass());
            MethodPersistentReference ref = (MethodPersistentReference)methodMap.get(new Long(methodHash));
            Method method = (Method)ref.get();
            Object[] args = methodInvocation.getArguments();
            try
            {
               return method.invoke(target, args);
            }
            catch (InvocationTargetException ex)
            {
               throw ex.getTargetException();
            }
         }
         else
         {
            throw new RuntimeException("should only be METHOD invocations on a non-advised target object: " + invocation.getClass().getName());
         }
      }