CreationalContext<Object> creationalContext = null;
OwbBean<Object> contextual = (OwbBean<Object>)this.bean;
//Context of the bean
Context webbeansContext = getBeanManager().getContext(bean.getScope());
CreationalContextFactory contextFactory = bean.getWebBeansContext().getCreationalContextFactory();
if (webbeansContext instanceof AbstractContext)
{
AbstractContext owbContext = (AbstractContext)webbeansContext;
creationalContext = owbContext.getCreationalContext(contextual);
//No creational context means that no BeanInstanceBag
//Actually this can be occurs like scenarions
//@SessionScoped bean injected into @ApplicationScopedBean
//And session is destroyed and restarted but proxy still
//contained in @ApplicationScopedBean
if(creationalContext == null)
{
creationalContext = contextFactory.getCreationalContext(contextual);
owbContext.initContextualBag((OwbBean<Object>)this.bean, creationalContext);
}
}
// for 3rd party contexts (actually all contexts provided via portable extensions)
// we don't have all the stuff of AbstractContext available
// In this case we may safely simply create a fresh CreationalContext, because
// if an 'old' contextual instance exists, it would have been found by the
// preceding call to Context.get(Contextual) (without any CreationalContext)
if(creationalContext == null)
{
creationalContext = contextFactory.getCreationalContext(contextual);
}
return creationalContext;
}