public static <T> void fireEvents(Class<T> clazz, BaseEjbBean<T> ejbBean,ProcessAnnotatedType<T> event)
{
WebBeansContext webBeansContext = ejbBean.getWebBeansContext();
BeanManagerImpl manager = webBeansContext.getBeanManagerImpl();
AnnotatedElementFactory annotatedElementFactory = webBeansContext.getAnnotatedElementFactory();
AnnotatedType<T> annotatedType = annotatedElementFactory.newAnnotatedType(clazz);
//Fires ProcessAnnotatedType
ProcessAnnotatedTypeImpl<T> processAnnotatedEvent = (ProcessAnnotatedTypeImpl<T>)event;
EjbBeanCreatorImpl<T> ejbBeanCreator = new EjbBeanCreatorImpl<T>(ejbBean);
ejbBeanCreator.checkCreateConditions();
if(processAnnotatedEvent.isVeto())
{
return;
}
if(processAnnotatedEvent.isModifiedAnnotatedType())
{
ejbBeanCreator.setMetaDataProvider(MetaDataProvider.THIRDPARTY);
ejbBeanCreator.setAnnotatedType(annotatedType);
}
//Define meta-data
ejbBeanCreator.defineSerializable();
ejbBeanCreator.defineStereoTypes();
ejbBeanCreator.defineApiType();
ejbBeanCreator.defineScopeType("Session Bean implementation class : " + clazz.getName() + " stereotypes must declare same @ScopeType annotations", false);
ejbBeanCreator.defineQualifier();
ejbBeanCreator.defineName(WebBeansUtil.getManagedBeanDefaultName(clazz.getSimpleName()));
Set<ProducerMethodBean<?>> producerMethodBeans = ejbBeanCreator.defineProducerMethods();
checkProducerMethods(producerMethodBeans, ejbBean);
Set<ProducerFieldBean<?>> producerFieldBeans = ejbBeanCreator.defineProducerFields();
ejbBeanCreator.defineInjectedFields();
ejbBeanCreator.defineInjectedMethods();
Set<ObserverMethod<?>> observerMethods = ejbBeanCreator.defineObserverMethods();
//Fires ProcessInjectionTarget
ProcessInjectionTargetImpl<T> processInjectionTargetEvent =
webBeansContext.getWebBeansUtil().fireProcessInjectionTargetEvent(ejbBean);
webBeansContext.getWebBeansUtil().inspectErrorStack(
"There are errors that are added by ProcessInjectionTarget event observers. Look at logs for further details");
//Put final InjectionTarget instance
manager.putInjectionTargetWrapper(ejbBean, new InjectionTargetWrapper(processInjectionTargetEvent.getInjectionTarget()));
Map<ProducerMethodBean<?>,AnnotatedMethod<?>> annotatedMethods = new HashMap<ProducerMethodBean<?>, AnnotatedMethod<?>>();
for(ProducerMethodBean<?> producerMethod : producerMethodBeans)
{
AnnotatedMethod<?> method = annotatedElementFactory.newAnnotatedMethod(producerMethod.getCreatorMethod(), annotatedType);
ProcessProducerImpl<?, ?> producerEvent =
webBeansContext.getWebBeansUtil().fireProcessProducerEventForMethod(producerMethod,
method);
webBeansContext.getWebBeansUtil().inspectErrorStack(
"There are errors that are added by ProcessProducer event observers for ProducerMethods. Look at logs for further details");
annotatedMethods.put(producerMethod, method);
manager.putInjectionTargetWrapper(producerMethod, new InjectionTargetWrapper(producerEvent.getProducer()));
}
Map<ProducerFieldBean<?>,AnnotatedField<?>> annotatedFields = new HashMap<ProducerFieldBean<?>, AnnotatedField<?>>();
for(ProducerFieldBean<?> producerField : producerFieldBeans)
{
AnnotatedField<?> field = annotatedElementFactory.newAnnotatedField(producerField.getCreatorField(), annotatedType);
ProcessProducerImpl<?, ?> producerEvent =
webBeansContext.getWebBeansUtil().fireProcessProducerEventForField(producerField, field);
webBeansContext.getWebBeansUtil().inspectErrorStack(
"There are errors that are added by ProcessProducer event observers for ProducerFields. Look at logs for further details");
annotatedFields.put(producerField, field);
manager.putInjectionTargetWrapper(producerField, new InjectionTargetWrapper(producerEvent.getProducer()));
}
Map<ObserverMethod<?>,AnnotatedMethod<?>> observerMethodsMap = new HashMap<ObserverMethod<?>, AnnotatedMethod<?>>();
for(ObserverMethod<?> observerMethod : observerMethods)
{
ObserverMethodImpl<?> impl = (ObserverMethodImpl<?>)observerMethod;
AnnotatedMethod<?> method = annotatedElementFactory.newAnnotatedMethod(impl.getObserverMethod(), annotatedType);
observerMethodsMap.put(observerMethod, method);
}
//Fires ProcessManagedBean