void assertInterceptorBindings(
     int size, InterceptorBindingsMetaData interceptorBindingsMetaData) {
   assertNotNull("interceptor bindings is null", interceptorBindingsMetaData);
   assertEquals(size, interceptorBindingsMetaData.size());
   int count = 1;
   for (InterceptorBindingMetaData interceptorBindingMetaData : interceptorBindingsMetaData) {
     // assertId("interceptorBinding" + count, interceptorBindingMetaData);
     assertDescriptions(
         "interceptorBinding" + count, interceptorBindingMetaData.getDescriptions());
     assertTrue(interceptorBindingMetaData.getEjbName().startsWith("interceptorBinding"));
     assertTrue(interceptorBindingMetaData.getEjbName().endsWith("EjbName"));
     if (count == 1) {
       assertInterceptorClasses(
           "interceptorBinding" + count, 2, interceptorBindingMetaData.getInterceptorClasses());
       assertTrue(interceptorBindingMetaData.isExcludeDefaultInterceptors());
       assertTrue(interceptorBindingMetaData.isExcludeClassInterceptors());
       assertFalse(interceptorBindingMetaData.isTotalOrdering());
     } else if (count == 2) {
       assertInterceptorOrder(
           "interceptorBinding" + count, 2, interceptorBindingMetaData.getInterceptorOrder());
       assertFalse(interceptorBindingMetaData.isExcludeDefaultInterceptors());
       assertFalse(interceptorBindingMetaData.isExcludeClassInterceptors());
       assertTrue(interceptorBindingMetaData.isTotalOrdering());
     } else {
       // A second interceptor binding for ejb2 without a method specification
       assertInterceptorClasses(
           "interceptorBinding" + count, 2, interceptorBindingMetaData.getInterceptorClasses());
       assertFalse(interceptorBindingMetaData.isExcludeDefaultInterceptors());
       assertTrue(interceptorBindingMetaData.isExcludeClassInterceptors());
       assertFalse(interceptorBindingMetaData.isTotalOrdering());
     }
     if (count <= 2)
       assertNamedMethod(
           "interceptorBinding" + count + "Method", 2, interceptorBindingMetaData.getMethod());
     ++count;
   }
 }
Exemplo n.º 2
0
  /**
   * Utility method which, given a bean name, all interceptors available in a deployment and the all
   * the interceptor binding information, will return only those interceptors which are applicable
   * to the EJB corresponding to the bean name
   *
   * @param ejbName Name of the EJB
   * @param allInterceptors {@link InterceptorsMetaData} of all interceptors
   * @param allInterceptorBindings {@link InterceptorBindingsMetaData} of all interceptor bindings
   * @return
   */
  private static InterceptorsMetaData getInterceptors(
      String ejbName,
      InterceptorsMetaData allInterceptors,
      InterceptorBindingsMetaData allInterceptorBindings) {
    InterceptorsMetaData beanApplicableInterceptors = new InterceptorsMetaData();
    // the default interceptors (ejbname = *) will be
    // considered as *not* applicable for a bean, if *all* the interceptor
    // bindings for that bean, have set the exclude-default-interceptors to true
    boolean includeDefaultInterceptors = false;
    InterceptorsMetaData defaultInterceptors = new InterceptorsMetaData();
    for (InterceptorBindingMetaData binding : allInterceptorBindings) {
      // the interceptor binding corresponds to the bean we are interested in
      if (ejbName != null && ejbName.equals(binding.getEjbName())) {
        // atleast one interceptor binding on the bean, is interested
        // in the default interceptors (ejbname = *). So set the flag to include the default
        // interceptors in the list of applicable interceptors
        if (binding.isExcludeDefaultInterceptors() == false) {
          includeDefaultInterceptors = true;
        }
        InterceptorClassesMetaData interceptorClasses = null;
        if (binding.isTotalOrdering()) {
          interceptorClasses = binding.getInterceptorOrder();
        } else {
          interceptorClasses = binding.getInterceptorClasses();
        }
        // interceptor binding has no classes, so move on to the next interceptor binding
        if (interceptorClasses == null || interceptorClasses.isEmpty()) {
          continue;
        }
        for (String interceptorClass : interceptorClasses) {
          // get the corresponding interceptor metadata for the interceptor class
          InterceptorMetaData interceptorMetaData = allInterceptors.get(interceptorClass);
          // TODO: the interceptor metadata for a interceptor class will only be
          // null, if the metadata isn't fully populated/processed. Let's not thrown
          // any errors and just ignore such cases for now
          if (interceptorMetaData != null) {
            // include this interceptor metadata as applicable for the bean
            beanApplicableInterceptors.add(interceptorMetaData);
          }
        }
      } else if (binding.getEjbName().equals("*")) // binding for default interceptors
      {
        InterceptorClassesMetaData interceptorClasses = null;
        if (binding.isTotalOrdering()) {
          interceptorClasses = binding.getInterceptorOrder();
        } else {
          interceptorClasses = binding.getInterceptorClasses();
        }
        // no interceptor class, so skip to next interceptor binding
        if (interceptorClasses == null || interceptorClasses.isEmpty()) {
          continue;
        }
        // interceptor binding on the bean, is interested
        // in the default interceptors (ejbname = *). So set the flag to include the default
        // interceptors in the list of applicable interceptors
        if (binding.isExcludeDefaultInterceptors() == false) {
          includeDefaultInterceptors = true;
        }
        for (String interceptorClass : interceptorClasses) {
          InterceptorMetaData interceptorMetaData = allInterceptors.get(interceptorClass);
          // TODO: the interceptor metadata for a interceptor class will only be
          // null, if the metadata isn't fully populated/processed. Let's not thrown
          // any errors and just ignore such cases for now
          if (interceptorMetaData != null) {
            // add the interceptor metadata to the set of default interceptors.
            // Whether or not these default interceptors are applicable for
            // the bean being processed, will be decide later
            defaultInterceptors.add(interceptorMetaData);
          }
        }
      }
    }
    // if the default interceptors (ejb name= *) are to be included
    // for this bean.
    // the default interceptors (ejbname = *) will be
    // considered as *not* applicable for a bean, if *all* the interceptor
    // bindings for that bean, have set the exclude-default-interceptors to true
    if (includeDefaultInterceptors) {
      beanApplicableInterceptors.addAll(defaultInterceptors);
    }

    // return the interceptors which are applicable for the bean
    return beanApplicableInterceptors;
  }