/** * Returns the {@link InterceptorsMetaData} which are applicable for the <code>beanName</code> in * the <code>jbossMetaData</code> * * <p>An interceptor is considered as bound to an EJB if there's atleast one interceptor binding * between the EJB and the interceptor class. The interceptor binding can either be through the * use of <interceptor-binding> element in ejb-jar.xml or through the use of {@link Interceptors} * annotation(s) in the EJB class. * * <p>If the EJB has an around-invoke element which uses class name other than the EJB class name, * then even that class is considered as an interceptor class and is considered to be bound to the * EJB. * * <p>For example: <session> <ejb-name>Dummy</ejb-name> * <ejb-class>org.myapp.ejb.MyBean</ejb-class> <around-invoke> <class>org.myapp.SomeClass</class> * <method-name>blah</method-name> </around-invoke> </session> * * <p>The <code>org.myapp.SomeClass</code> will be considered as a interceptor class bound to the * EJB, <code>org.myapp.ejb.MyBean</code>, even if there is no explicit interceptor binding * between that EJB and the <code>org.myapp.SomeClass</code> * * @param beanName The EJB name * @param jbossMetaData The {@link JBossMetaData} corresponding to the <code>beanName</code> * @return * @throws NullPointerException If either of <code>beanName</code> or <code>jbossMetaData</code> * is null */ public static InterceptorsMetaData getInterceptors(String beanName, JBossMetaData jbossMetaData) { InterceptorsMetaData beanApplicableInterceptors = new InterceptorsMetaData(); if (jbossMetaData.getAssemblyDescriptor() == null) { return beanApplicableInterceptors; } InterceptorBindingsMetaData allInterceptorBindings = jbossMetaData.getAssemblyDescriptor().getInterceptorBindings(); if (allInterceptorBindings == null) { return beanApplicableInterceptors; } InterceptorsMetaData allInterceptors = jbossMetaData.getInterceptors(); if (allInterceptors == null || allInterceptors.isEmpty()) { return beanApplicableInterceptors; } return getInterceptors(beanName, allInterceptors, allInterceptorBindings); }
/** * 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; }