@Override
  protected void processElement(
      InterceptorBindingMetaData interceptorBinding, XMLStreamReader reader)
      throws XMLStreamException {
    final EjbJarElement ejbJarElement = EjbJarElement.forName(reader.getLocalName());
    switch (ejbJarElement) {
      case EJB_NAME:
        String ejbName = getElementText(reader);
        interceptorBinding.setEjbName(ejbName);
        return;

      case INTERCEPTOR_CLASS:
        InterceptorClassesMetaData interceptorClasses = interceptorBinding.getInterceptorClasses();
        if (interceptorClasses == null) {
          interceptorClasses = new InterceptorClassesMetaData();
          interceptorBinding.setInterceptorClasses(interceptorClasses);
        }
        String interceptorClass = getElementText(reader);
        interceptorClasses.add(interceptorClass);
        return;

      case EXCLUDE_DEFAULT_INTERCEPTORS:
        String excludeDefaultInterceptors = getElementText(reader);
        if (excludeDefaultInterceptors == null || excludeDefaultInterceptors.trim().isEmpty()) {
          throw unexpectedValue(
              reader,
              new Exception("Unexpected null or empty value for <exclude-default-interceptors>"));
        }
        interceptorBinding.setExcludeDefaultInterceptors(
            Boolean.parseBoolean(excludeDefaultInterceptors));
        return;

      case EXCLUDE_CLASS_INTERCEPTORS:
        String excludeClassInterceptors = getElementText(reader);
        if (excludeClassInterceptors == null || excludeClassInterceptors.trim().isEmpty()) {
          throw unexpectedValue(
              reader,
              new Exception("Unexpected null or empty value for <exclude-class-interceptors>"));
        }
        interceptorBinding.setExcludeClassInterceptors(
            Boolean.parseBoolean(excludeClassInterceptors));
        return;

      case METHOD:
        NamedMethodMetaData method = NamedMethodMetaDataParser.INSTANCE.parse(reader);
        interceptorBinding.setMethod(method);
        return;

      case INTERCEPTOR_ORDER:
        InterceptorOrderMetaData interceptorOrderMetaData =
            InterceptorOrderMetaDataParser.INSTANCE.parse(reader);
        interceptorBinding.setInterceptorOrder(interceptorOrderMetaData);
        return;
      default:
        super.processElement(interceptorBinding, reader);
    }
  }
 private void assertInterceptorClasses(
     String prefix, int size, InterceptorClassesMetaData interceptorClassesMetaData) {
   assertNotNull(interceptorClassesMetaData);
   assertEquals(size, interceptorClassesMetaData.size());
   int count = 1;
   for (String interceptorClass : interceptorClassesMetaData) {
     assertEquals(prefix + "Class" + count, interceptorClass);
     ++count;
   }
 }
Beispiel #3
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;
  }