コード例 #1
0
  @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);
    }
  }
コード例 #2
0
ファイル: JBossMetaData.java プロジェクト: darranl/metadata
  /**
   * 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;
  }
コード例 #3
0
ファイル: JBossMetaData.java プロジェクト: darranl/metadata
  /**
   * 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;
  }
コード例 #4
0
 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;
   }
 }