}
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
ProcessSessionBeanImpl<T> processBeanEvent = new GProcessSessionBean((Bean<Object>)ejbBean,annotatedType,ejbBean.getEjbName(),ejbBean.getEjbType());
webBeansContext.getBeanManagerImpl().fireEvent(processBeanEvent, new Annotation[0]);
webBeansContext.getWebBeansUtil().inspectErrorStack(
"There are errors that are added by ProcessSessionBean event observers for managed beans. Look at logs for further details");
//Fires ProcessProducerMethod
webBeansContext.getWebBeansUtil().fireProcessProducerMethodBeanEvent(annotatedMethods,
annotatedType);
webBeansContext.getWebBeansUtil().inspectErrorStack(
"There are errors that are added by ProcessProducerMethod event observers for producer method beans. Look at logs for further details");
//Fires ProcessProducerField
webBeansContext.getWebBeansUtil().fireProcessProducerFieldBeanEvent(annotatedFields);
webBeansContext.getWebBeansUtil().inspectErrorStack(
"There are errors that are added by ProcessProducerField event observers for producer field beans. Look at logs for further details");
//Fire ObservableMethods
webBeansContext.getWebBeansUtil().fireProcessObservableMethodBeanEvent(observerMethodsMap);
webBeansContext.getWebBeansUtil().inspectErrorStack(
"There are errors that are added by ProcessObserverMethod event observers for observer methods. Look at logs for further details");
manager.addBean(ejbBean);
// Let the plugin handle adding the new bean instance as it knows more about its EJB Bean
manager.getBeans().addAll(producerMethodBeans);
ejbBeanCreator.defineDisposalMethods();
manager.getBeans().addAll(producerFieldBeans);
}