Search in sources :

Example 1 with FallbackContainedBean

use of org.hibernate.resource.beans.container.spi.FallbackContainedBean in project hibernate-orm by hibernate.

the class ManagedBeanRegistryImpl method getBean.

@Override
@SuppressWarnings("unchecked")
public <T> ManagedBean<T> getBean(Class<T> beanClass) {
    final ManagedBean existing = registrations.get(beanClass.getName());
    if (existing != null) {
        return existing;
    }
    final ManagedBean bean;
    if (beanContainer == null) {
        bean = new FallbackContainedBean(beanClass, FallbackBeanInstanceProducer.INSTANCE);
    } else {
        final ContainedBean<T> containedBean = beanContainer.getBean(beanClass, this, FallbackBeanInstanceProducer.INSTANCE);
        if (containedBean instanceof ManagedBean) {
            bean = (ManagedBean) containedBean;
        } else {
            bean = new ContainedBeanManagedBeanAdapter(beanClass, containedBean);
        }
    }
    registrations.put(beanClass.getName(), bean);
    return bean;
}
Also used : FallbackContainedBean(org.hibernate.resource.beans.container.spi.FallbackContainedBean) ManagedBean(org.hibernate.resource.beans.spi.ManagedBean)

Example 2 with FallbackContainedBean

use of org.hibernate.resource.beans.container.spi.FallbackContainedBean in project hibernate-orm by hibernate.

the class ManagedBeanRegistryImpl method getBean.

@Override
@SuppressWarnings("unchecked")
public <T> ManagedBean<T> getBean(String beanName, Class<T> beanContract) {
    final String key = beanContract.getName() + ':' + beanName;
    final ManagedBean existing = registrations.get(key);
    if (existing != null) {
        return existing;
    }
    final ManagedBean bean;
    if (beanContainer == null) {
        bean = new FallbackContainedBean(beanName, beanContract, FallbackBeanInstanceProducer.INSTANCE);
    } else {
        final ContainedBean<T> containedBean = beanContainer.getBean(beanName, beanContract, this, FallbackBeanInstanceProducer.INSTANCE);
        if (containedBean instanceof ManagedBean) {
            bean = (ManagedBean) containedBean;
        } else {
            bean = new ContainedBeanManagedBeanAdapter(beanContract, containedBean);
        }
    }
    registrations.put(key, bean);
    return bean;
}
Also used : FallbackContainedBean(org.hibernate.resource.beans.container.spi.FallbackContainedBean) ManagedBean(org.hibernate.resource.beans.spi.ManagedBean)

Aggregations

FallbackContainedBean (org.hibernate.resource.beans.container.spi.FallbackContainedBean)2 ManagedBean (org.hibernate.resource.beans.spi.ManagedBean)2