Type[] types = observerMethod.getGenericParameterTypes();
Annotation[][] annots = observerMethod.getParameterAnnotations();
List<ObserverParams> list = new ArrayList<ObserverParams>();
BeanManagerImpl manager = webBeansContext.getBeanManagerImpl();
ObserverParams param;
if (types.length > 0)
{
int i = 0;
for (Type type : types)
{
Annotation[] annot = annots[i];
boolean observesAnnotation = false;
if (annot.length == 0)
{
annot = new Annotation[1];
annot[0] = new DefaultLiteral();
}
else
{
for (Annotation observersAnnot : annot)
{
if (observersAnnot.annotationType().equals(Observes.class))
{
param = new ObserverParams();
param.instance = event;
list.add(param);
observesAnnotation = true;
break;
}
}
}
if (!observesAnnotation)
{
boolean injectionPointBeanLocalSetOnStack = false;
//Get parameter annotations
Annotation[] bindingTypes = annotationManager.getQualifierAnnotations(annot);
//Define annotated parameter
AnnotatedType<T> annotatedType = (AnnotatedType<T>) annotatedElementFactory.newAnnotatedType(bean.getReturnType());
AnnotatedMethod<T> newAnnotatedMethod = annotatedElementFactory.newAnnotatedMethod(observerMethod, annotatedType);
//Annotated parameter
AnnotatedParameter<T> annotatedParameter = newAnnotatedMethod.getParameters().get(i);
//Creating injection point
InjectionPoint point = InjectionPointFactory.getPartialInjectionPoint(bean, type, observerMethod, annotatedParameter, bindingTypes);
//Injected Bean
Bean<Object> injectedBean = (Bean<Object>)getWebBeansContext().getBeanManagerImpl().getInjectionResolver().getInjectionPointBean(point);
//Set for @Inject InjectionPoint
if(WebBeansUtil.isDependent(injectedBean))
{
if(!InjectionPoint.class.isAssignableFrom(ClassUtil.getClass(point.getType())))
{
injectionPointBeanLocalSetOnStack = InjectionPointBean.setThreadLocal(point);
}
}
if (isEventProviderInjection(point))
{
EventBean.local.set(point);
}
CreationalContext<Object> creational = manager.createCreationalContext(injectedBean);
Object instance = manager.getReference(injectedBean, null, creational);
if (injectionPointBeanLocalSetOnStack)
{
InjectionPointBean.unsetThreadLocal();
}