protected void assertAroundInvokes(
     String ejbName, int size, AroundInvokesMetaData aroundInvokesMetaData) {
   assertNotNull(aroundInvokesMetaData);
   assertEquals(size, aroundInvokesMetaData.size());
   int count = 1;
   for (AroundInvokeMetaData aroundInvoke : aroundInvokesMetaData) {
     assertEquals(ejbName + "AroundInvoke" + count + "Class", aroundInvoke.getClassName());
     assertEquals(ejbName + "AroundInvoke" + count + "Method", aroundInvoke.getMethodName());
     ++count;
   }
 }
Esempio n. 2
0
  /**
   * Returns all interceptor classes which are present in the passed <code>jbossMetaData</code>.
   *
   * <p>A class is considered an interceptor class, if it is listed in either of the following:
   *
   * <ul>
   *   <li>In the <interceptor> element of ejb-jar.xml
   *   <li>In the <interceptor-binding> element of ejb-jar.xml
   *   <li>In the <class> sub-element of <around-invoke> element in the ejb-jar.xml
   *   <li>Marked as an interceptor class through the use of {@link Interceptors} annotation in a
   *       bean class
   * </ul>
   *
   * @param jbossMetaData The {@link JBossMetaData} which will scanned for interceptor classes
   * @return
   */
  public static Collection<String> getAllInterceptorClasses(JBossMetaData jbossMetaData) {
    Collection<String> allInterceptorClassNames = new HashSet<String>();

    // process <interceptors>
    InterceptorsMetaData interceptorsMetadata = jbossMetaData.getInterceptors();
    if (interceptorsMetadata != null) {
      for (InterceptorMetaData interceptor : interceptorsMetadata) {
        if (interceptor.getInterceptorClass() != null) {
          allInterceptorClassNames.add(interceptor.getInterceptorClass());
        }
      }
    }
    // process <interceptor-bindings> (a.k.a @Interceptors)
    JBossAssemblyDescriptorMetaData assemblyDescriptor = jbossMetaData.getAssemblyDescriptor();
    if (assemblyDescriptor != null) {
      InterceptorBindingsMetaData interceptorBindings = assemblyDescriptor.getInterceptorBindings();
      if (interceptorBindings != null) {
        for (InterceptorBindingMetaData interceptorBinding : interceptorBindings) {
          if (interceptorBinding != null) {
            InterceptorClassesMetaData interceptorClasses =
                interceptorBinding.getInterceptorClasses();
            if (interceptorClasses != null) {
              for (String interceptorClass : interceptorClasses) {
                allInterceptorClassNames.add(interceptorClass);
              }
            }
          }
        }
      }
    }
    // process around-invoke
    JBossEnterpriseBeansMetaData enterpriseBeans = jbossMetaData.getEnterpriseBeans();
    if (enterpriseBeans != null) {
      for (JBossEnterpriseBeanMetaData enterpriseBean : enterpriseBeans) {
        String enterpriseBeanClassName = enterpriseBean.getEjbClass();
        AroundInvokesMetaData aroundInvokes = null;
        if (enterpriseBean.isSession()) {
          JBossSessionBeanMetaData sessionBean = (JBossSessionBeanMetaData) enterpriseBean;
          aroundInvokes = sessionBean.getAroundInvokes();
        } else if (enterpriseBean.isMessageDriven()) {
          JBossMessageDrivenBeanMetaData messageDrivenBean =
              (JBossMessageDrivenBeanMetaData) enterpriseBean;
          aroundInvokes = messageDrivenBean.getAroundInvokes();
        }

        if (aroundInvokes == null || aroundInvokes.isEmpty()) {
          continue;
        }

        for (AroundInvokeMetaData aroundInvoke : aroundInvokes) {
          String targetClass = aroundInvoke.getClassName();
          if (targetClass == null) {
            continue;
          }
          // if the target class name is not the class name of the EJB,
          // then as per the xsd, it is considered an interceptor class
          if (targetClass.equals(enterpriseBeanClassName) == false) {
            // it's an interceptor class
            allInterceptorClassNames.add(targetClass);
          }
        }
      }
    }
    // return the interceptor class names
    return allInterceptorClassNames;
  }