use of com.sun.enterprise.deployment.annotation.context.ManagedBeanContext in project Payara by payara.
the class ManagedBeanHandler method processAnnotation.
public HandlerProcessingResult processAnnotation(AnnotationInfo element) throws AnnotationProcessorException {
AnnotatedElementHandler aeHandler = element.getProcessingContext().getHandler();
if (aeHandler instanceof ManagedBeanContext) {
// Ignore @ManagedBean processing during ManagedBean class processing itself
return getDefaultProcessedResult();
}
ManagedBeanDescriptor managedBeanDesc = new ManagedBeanDescriptor();
ManagedBean resourceAn = (ManagedBean) element.getAnnotation();
// name() is optional
String logicalName = resourceAn.value();
if (!logicalName.equals("")) {
managedBeanDesc.setName(logicalName);
}
Class managedBeanClass = (Class) element.getAnnotatedElement();
managedBeanDesc.setBeanClassName(managedBeanClass.getName());
Class[] classInterceptors = null;
Map<AccessibleObject, Class[]> methodLevelInterceptors = new HashMap<AccessibleObject, Class[]>();
Map<String, InterceptorDescriptor> interceptorDescs = new HashMap<String, InterceptorDescriptor>();
// For now, just process the javax.interceptor related annotations directly instead
// of relying on the annotation framework. All the existing javax.interceptor
// handlers are very tightly coupled to ejb so it would be more work to abstract those
// than to just process the annotations directly. Also, do javax.interceptor
// annotation processing reflectively to avoid dependency on javax.interceptor from
// DOL module.
// TODO refactor javax.interceptor annotation handlers to support both ejb and non-ejb
// related interceptors
Annotation interceptorsAnn = getClassAnnotation(managedBeanClass, "javax.interceptor.Interceptors");
if (interceptorsAnn != null) {
try {
Method m = interceptorsAnn.annotationType().getDeclaredMethod("value");
classInterceptors = (Class[]) m.invoke(interceptorsAnn);
} catch (Exception e) {
AnnotationProcessorException ape = new AnnotationProcessorException(e.getMessage(), element);
ape.initCause(e);
throw ape;
}
}
Class nextIntClass = managedBeanClass;
while (nextIntClass != Object.class) {
Method managedBeanAroundInvoke = getMethodForMethodAnnotation(nextIntClass, "javax.interceptor.AroundInvoke");
if ((managedBeanAroundInvoke != null) && !(methodOverridden(managedBeanAroundInvoke, nextIntClass, managedBeanClass))) {
LifecycleCallbackDescriptor desc = new LifecycleCallbackDescriptor();
desc.setLifecycleCallbackClass(nextIntClass.getName());
desc.setLifecycleCallbackMethod(managedBeanAroundInvoke.getName());
managedBeanDesc.addAroundInvokeDescriptor(desc);
}
nextIntClass = nextIntClass.getSuperclass();
}
for (Method m : managedBeanClass.getMethods()) {
processForAnnotations(element, m, methodLevelInterceptors, managedBeanDesc, managedBeanClass);
}
for (Constructor c : managedBeanClass.getDeclaredConstructors()) {
processForAnnotations(element, c, methodLevelInterceptors, managedBeanDesc, managedBeanClass);
}
if (aeHandler instanceof ResourceContainerContext) {
((ResourceContainerContext) aeHandler).addManagedBean(managedBeanDesc);
// process managed bean class annotations
ManagedBeanContext managedBeanContext = new ManagedBeanContext(managedBeanDesc);
ProcessingContext procContext = element.getProcessingContext();
procContext.pushHandler(managedBeanContext);
procContext.getProcessor().process(procContext, new Class[] { managedBeanClass });
List<InterceptorDescriptor> classInterceptorChain = new LinkedList<InterceptorDescriptor>();
if (classInterceptors != null) {
for (Class i : classInterceptors) {
InterceptorDescriptor nextInterceptor = processInterceptor(i, managedBeanContext, procContext);
// Add interceptor to class-level chain
classInterceptorChain.add(nextInterceptor);
interceptorDescs.put(i.getName(), nextInterceptor);
}
managedBeanDesc.setClassInterceptorChain(classInterceptorChain);
}
for (Map.Entry<AccessibleObject, Class[]> next : methodLevelInterceptors.entrySet()) {
AccessibleObject o = next.getKey();
Class[] interceptors = next.getValue();
boolean excludeClassInterceptors = (getMethodAnnotation(o, "javax.interceptor.ExcludeClassInterceptors") != null);
List<InterceptorDescriptor> methodInterceptorChain = excludeClassInterceptors ? new LinkedList<InterceptorDescriptor>() : new LinkedList<InterceptorDescriptor>(classInterceptorChain);
for (Class nextInterceptor : interceptors) {
InterceptorDescriptor interceptorDesc = interceptorDescs.get(nextInterceptor.getName());
if (interceptorDesc == null) {
interceptorDesc = processInterceptor(nextInterceptor, managedBeanContext, procContext);
interceptorDescs.put(nextInterceptor.getName(), interceptorDesc);
}
methodInterceptorChain.add(interceptorDesc);
}
MethodDescriptor mDesc = getMethodDescriptor(o, managedBeanClass);
if (mDesc != null) {
managedBeanDesc.setMethodLevelInterceptorChain(mDesc, methodInterceptorChain);
}
}
}
return getDefaultProcessedResult();
}
Aggregations