}
// Set list of global interceptors (applied on all business methods)
List<JClassInterceptor> easyBeansGlobalInterceptors = new ArrayList<JClassInterceptor>();
for (String easyBeansInterceptor : easyBeansInterceptorsClasses) {
easyBeansGlobalInterceptors.add(new JClassInterceptor(easyBeansInterceptor, EASYBEANS_INTERCEPTOR));
}
classAnnotationMetadata.setGlobalEasyBeansInterceptors(easyBeansGlobalInterceptors);
// Default interceptors (only once as it is stored in the ejb metadata)
EjbJarArchiveMetadata ejbJarDeployableMetadata = classAnnotationMetadata.getEjbJarDeployableMetadata();
IJInterceptors defaultInterceptorsClasses = ejbJarDeployableMetadata.getDefaultInterceptorsClasses();
Map<InterceptorType, List<? extends IJClassInterceptor>> mapDefaultInterceptors =
ejbJarDeployableMetadata.getDefaultInterceptors();
if (mapDefaultInterceptors == null && defaultInterceptorsClasses != null && defaultInterceptorsClasses.size() > 0) {
Map<InterceptorType, List<? extends IJClassInterceptor>> defaultInterceptors =
new HashMap<InterceptorType, List<? extends IJClassInterceptor>>();
defaultInterceptors.putAll(getInterceptors(classAnnotationMetadata.getClassName(), classAnnotationMetadata,
defaultInterceptorsClasses.getClasses()));
ejbJarDeployableMetadata.setDefaultInterceptors(defaultInterceptors);
}
// And then, set the user interceptors (found in external class)
List<String> externalInterceptorsClasses = new ArrayList<String>();
// Interceptors from other classes (will be analyzed after)
// See 3.5.3 of simplified EJB 3.0 spec : multiple interceptors
// Add interceptor classes found on super classes (if any)
// Invert list of the inheritance on the current class
LinkedList<EasyBeansEjbJarClassMetadata> invertedInheritanceClassesList =
getInvertedSuperClassesMetadata(classAnnotationMetadata);
// Add interceptors found on these classes (order is super super class
// before super class, ie : top level first)
for (EasyBeansEjbJarClassMetadata superMetaData : invertedInheritanceClassesList) {
IJInterceptors classIinterceptors = superMetaData.getAnnotationInterceptors();
if (classIinterceptors != null) {
for (String cls : classIinterceptors.getClasses()) {
externalInterceptorsClasses.add(cls);
}
}
}
// Get the interceptors defined by the user on external classes
Map<InterceptorType, List<? extends IJClassInterceptor>> externalMapClassInterceptors = new HashMap<InterceptorType, List<? extends IJClassInterceptor>>();
externalMapClassInterceptors.putAll(getInterceptors(classAnnotationMetadata.getClassName(), classAnnotationMetadata,
externalInterceptorsClasses));
classAnnotationMetadata.setExternalUserInterceptors(externalMapClassInterceptors);
// interceptor in the bean class ? (LifeCycle event interceptors are not in the bean
// because they don't take an InvocationContext as parameter, this is the intercepted method
List<String> internalInterceptorsClasses = new ArrayList<String>();
if (classAnnotationMetadata.isAroundInvokeMethodMetadata()) {
internalInterceptorsClasses.add(classAnnotationMetadata.getClassName());
}
// Get the interceptors defined by the user on the class
Map<InterceptorType, List<? extends IJClassInterceptor>> internalMapClassInterceptors =
new HashMap<InterceptorType, List<? extends IJClassInterceptor>>();
internalMapClassInterceptors.putAll(getInterceptors(classAnnotationMetadata.getClassName(), classAnnotationMetadata,
internalInterceptorsClasses));
classAnnotationMetadata.setInternalUserInterceptors(internalMapClassInterceptors);
// Now, analyze each interceptors found on methods.
for (EasyBeansEjbJarMethodMetadata methodAnnotationMetaData
: classAnnotationMetadata.getMethodMetadataCollection()) {
// Set global interceptors for a given method (ie : Remove)
Remove remove = methodAnnotationMetaData.getJRemove();
if (remove != null) {
List<JClassInterceptor> easyBeansMethodGlobalInterceptors = new ArrayList<JClassInterceptor>();
String classType = null;
// choose right interceptor class
if (remove.retainIfException()) {
classType = Type.getInternalName(RemoveOnlyWithoutExceptionInterceptor.class);
} else {
classType = Type.getInternalName(RemoveAlwaysInterceptor.class);
}
easyBeansMethodGlobalInterceptors.add(new JClassInterceptor(classType, EASYBEANS_INTERCEPTOR));
// set list
methodAnnotationMetaData.setGlobalEasyBeansInterceptors(easyBeansMethodGlobalInterceptors);
}