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

InterceptorInfo

public class InterceptorInfo extends Object
We cannot use annotation overrides for the interceptor stuff since they do not have a container associated with them
author
Kabir Khan
version
$Revision: 60233 $

Fields Summary
Class
clazz
org.jboss.ejb3.metamodel.Interceptor
xml
protected Method
aroundInvoke
protected Method
postConstruct
protected Method
postActivate
protected Method
preDestroy
protected Method
prePassivate
protected Method[]
aroundInvokeHierarchy
protected Method[]
postConstructHierarchy
protected Method[]
postActivateHierarchy
protected Method[]
preDestroyHierarchy
protected Method[]
prePassivateHierarchy
boolean
haveCalculatedHierarchy
Constructors Summary
protected InterceptorInfo()

   
public InterceptorInfo(Class clazz)

      this.clazz = clazz;
   
public InterceptorInfo(InterceptorInfo interceptorInfo)

      this.clazz = interceptorInfo.clazz;
      this.aroundInvoke = interceptorInfo.aroundInvoke;
      this.postConstruct = interceptorInfo.postConstruct;
      this.postActivate = interceptorInfo.postActivate;
      this.preDestroy = interceptorInfo.preDestroy;
      this.prePassivate = interceptorInfo.prePassivate;
      this.aroundInvokeHierarchy = interceptorInfo.aroundInvokeHierarchy;
      this.postConstructHierarchy = interceptorInfo.postConstructHierarchy;
      this.postActivateHierarchy = interceptorInfo.postActivateHierarchy;
      this.preDestroyHierarchy = interceptorInfo.preDestroyHierarchy;
      this.prePassivateHierarchy = interceptorInfo.prePassivateHierarchy;
   
Methods Summary
protected voidappendMethodString(java.lang.StringBuffer buf, java.lang.String methodType, java.lang.reflect.Method m)

      if (m != null)
      {
         buf.append(", " + methodType + "=" + m.getName());
      }
   
protected voidappendMethods(java.lang.StringBuffer sb)

      appendMethodString(sb, "aroundInvoke", aroundInvoke);
      appendMethodString(sb, "postConstruct", postConstruct);
      appendMethodString(sb, "postActivate", postActivate);
      appendMethodString(sb, "prePassivate", prePassivate);
      appendMethodString(sb, "preDestroy", preDestroy);
   
public voidcalculateHierarchy(org.jboss.ejb3.interceptor.InterceptorInfo superInfo)

      if (haveCalculatedHierarchy)
      {
         return;
      }
      
      postConstructHierarchy = initaliseMethods((superInfo != null) ? superInfo.postConstructHierarchy : null, postConstruct);
      postActivateHierarchy = initaliseMethods((superInfo != null) ? superInfo.postActivateHierarchy : null, postActivate);
      aroundInvokeHierarchy = initaliseMethods((superInfo != null) ? superInfo.aroundInvokeHierarchy : null, aroundInvoke);
      prePassivateHierarchy = initaliseMethods((superInfo != null) ? superInfo.prePassivateHierarchy : null, prePassivate);
      preDestroyHierarchy = initaliseMethods((superInfo != null) ? superInfo.preDestroyHierarchy : null, preDestroy);
      
      haveCalculatedHierarchy = true;
   
public booleanequals(java.lang.Object obj)

      if (obj instanceof InterceptorInfo)
      {
         return clazz.equals(((InterceptorInfo)obj).getClazz());
      }
      return false;
   
public java.lang.reflect.MethodgetAroundInvoke()

      return aroundInvoke;
   
public java.lang.reflect.Method[]getAroundInvokes()

      return aroundInvokeHierarchy;
   
public java.lang.ClassgetClazz()

      return clazz;
   
public java.lang.reflect.MethodgetPostActivate()

      return postActivate;
   
public java.lang.reflect.Method[]getPostActivates()

      return postActivateHierarchy;
   
public java.lang.reflect.MethodgetPostConstruct()

      return postConstruct;
   
public java.lang.reflect.Method[]getPostConstructs()

      return postConstructHierarchy;
   
public java.lang.reflect.MethodgetPreDestroy()

      return preDestroy;
   
public java.lang.reflect.Method[]getPreDestroys()

      return preDestroyHierarchy;
   
public java.lang.reflect.MethodgetPrePassivate()

      return prePassivate;
   
public java.lang.reflect.Method[]getPrePassivates()

      return prePassivateHierarchy;
   
public org.jboss.ejb3.metamodel.InterceptorgetXml()

      return xml;
   
public inthashCode()

      return clazz.getName().hashCode();
   
public booleanhaveCalculatedHierarchy()

      return haveCalculatedHierarchy;
   
private booleanhaveMethod(java.lang.reflect.Method method)

      try
      {
         clazz.getDeclaredMethod(method.getName(), method.getParameterTypes());
         return true;
      }
      catch (NoSuchMethodException e)
      {
         return false;
      }
   
private java.lang.reflect.Method[]initaliseMethods(java.lang.reflect.Method[] superMethods, java.lang.reflect.Method myMethod)

      if (superMethods == null && myMethod == null)
      {
         return null;
      }
      ArrayList hierarchy = new ArrayList();
      if (superMethods != null)
      {
         //We only want to add superclass interceptor/lifecycle methods if we do not override them
         for (int i = 0 ; i < superMethods.length ; ++i)
         {
            if (!haveMethod(superMethods[i]))
            {
               hierarchy.add(superMethods[i]);
            }
         }
      }
      
      if (myMethod != null)
      {
         hierarchy.add(myMethod);
      }
      
      return (Method[])hierarchy.toArray(new Method[hierarchy.size()]);
   
private java.lang.reflect.MethodmakeAccessible(java.lang.reflect.Method method)

      try
      {
         AccessController.doPrivileged(new PrivilegedExceptionAction() {
            public Object run()
            {
               method.setAccessible(true);
               return null;
            }
         });
      }
      catch (PrivilegedActionException e)
      {
         throw new RuntimeException(e.getException());
      }
      
      return method;
   
protected voidsetAroundInvoke(java.lang.reflect.Method aroundInvoke)

      if (aroundInvoke == null) return;
      
      if (this.aroundInvoke != null && !this.aroundInvoke.equals(aroundInvoke))
      {
         throw new RuntimeException("Interceptors can only have one around-invoke/@AroundInvoke method - " + clazz.getName());
      }
      this.aroundInvoke = makeAccessible(aroundInvoke);
   
protected voidsetPostActivate(java.lang.reflect.Method postActivate)

      if (postActivate == null) return;
      
      if (this.postActivate != null && !this.postActivate.equals(postActivate))
      {
         throw new RuntimeException("Interceptors can only have one post-activate/@PostActivate method - " + clazz.getName());
      }
      this.postActivate = makeAccessible(postActivate);
   
protected voidsetPostConstruct(java.lang.reflect.Method postConstruct)

      if (postConstruct == null) return;
      
      if (this.postConstruct != null && !this.postConstruct.equals(postConstruct))
      {
         throw new RuntimeException("Interceptors can only have one post-construct/@PostConstruct method - " + clazz.getName());
      }
      this.postConstruct = makeAccessible(postConstruct);
   
protected voidsetPreDestroy(java.lang.reflect.Method preDestroy)

      if (preDestroy == null) return;
      
      if (this.preDestroy != null && !this.preDestroy.equals(preDestroy))
      {
         throw new RuntimeException("Interceptors can only have one pre-destroy/@PreDestroy method - " + clazz.getName());
      }
      this.preDestroy = makeAccessible(preDestroy);
   
protected voidsetPrePassivate(java.lang.reflect.Method prePassivate)

      if (prePassivate == null) return;
      
      if (this.prePassivate != null && !this.prePassivate.equals(prePassivate))
      {
         throw new RuntimeException("Interceptors can only have one pre-passivate/@PrePassivate method - " + clazz.getName());
      }
      this.prePassivate = makeAccessible(prePassivate);
   
protected voidsetXml(org.jboss.ejb3.metamodel.Interceptor xml)

      this.xml = xml;
   
public java.lang.StringtoString()

      StringBuffer sb = new StringBuffer("InterceptorInfo{class=" + clazz);
      appendMethods(sb);
      sb.append("}");
      return sb.toString();