* {@inheritDoc}
*/
@Override
public Object getReference(Bean<?> bean, Type beanType, CreationalContext<?> creationalContext)
{
Context context = null;
Object instance = null;
if (bean instanceof SerializableBean)
{
bean = ((SerializableBean)bean).getBean();
}
//Check type if bean type is given
if(beanType != null)
{
if(!ResolutionUtil.checkBeanTypeAssignableToGivenType(bean.getTypes(), beanType, bean instanceof NewBean))
{
throw new IllegalArgumentException("Given bean type : " + beanType + " is not applicable for the bean instance : " + bean);
}
}
if(!(creationalContext instanceof CreationalContextImpl))
{
creationalContext = CreationalContextFactory.getInstance().wrappedCreationalContext(creationalContext, bean);
}
//Get bean context
context = getContext(bean.getScope());
//Scope is normal
if (WebBeansUtil.isScopeTypeNormal(bean.getScope()))
{
instance = getEjbOrJmsProxyReference(bean, beanType,creationalContext);
if(instance != null)
{
return instance;
}
//Create Managed Bean Proxy
instance = JavassistProxyFactory.createNormalScopedBeanProxy((AbstractOwbBean<?>)bean,creationalContext);
//push this proxy instance into creational context
CreationalContextImpl<Object> temp = (CreationalContextImpl<Object>)creationalContext;
temp.setProxyInstance(instance);
}
//Create Pseudo-Scope Bean Instance
else
{
instance = getEjbOrJmsProxyReference(bean, beanType, creationalContext);
if(instance != null)
{
return instance;
}
instance = context.get((Bean<Object>)bean, (CreationalContext<Object>)creationalContext);
instance = JavassistProxyFactory.createDependentScopedBeanProxy((AbstractOwbBean<Object>)bean, instance, (CreationalContext<Object>)creationalContext);
}
return instance;
}