Java Code Examples for javax.enterprise.inject.spi.Bean#destroy()

The following examples show how to use javax.enterprise.inject.spi.Bean#destroy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CdiManagedBeanFactory.java    From dolphin-platform with Apache License 2.0 5 votes vote down vote up
@Override
public <T> void destroyDependentInstance(T instance, Class<T> cls) {
    Assert.requireNonNull(instance, "instance");
    Bean bean = beanMap.remove(instance);
    CreationalContext context = contextMap.remove(instance);
    bean.destroy(instance, context);
}
 
Example 2
Source File: CdiTestRunner.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
@Override
public void evaluate() throws Throwable
{
    BeanManager beanManager = BeanManagerProvider.getInstance().getBeanManager();
    Class<?> type = this.method.getMethod().getDeclaringClass();
    Set<Bean<?>> beans = beanManager.getBeans(type);

    if (!USE_TEST_CLASS_AS_CDI_BEAN || beans == null || beans.isEmpty())
    {
        if (!ALLOW_INJECTION_POINT_MANIPULATION)
        {
            BeanProvider.injectFields(this.originalTarget); //fallback to simple injection
        }
        invokeMethod(this.originalTarget);
    }
    else
    {
        Bean<Object> bean = (Bean<Object>) beanManager.resolve(beans);

        CreationalContext<Object> creationalContext = beanManager.createCreationalContext(bean);

        Object target = beanManager.getReference(bean, type, creationalContext);

        try
        {
            invokeMethod(target);
        }
        finally
        {
            if (bean.getScope().equals(Dependent.class))
            {
                bean.destroy(target, creationalContext);
            }
        }
    }
}
 
Example 3
Source File: DependentScopedTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Test
public void test() throws Exception {
    created.clear();
    destroyed.clear();

    final Bean<ColorWheelLocal> colorWheelBean = getBean(ColorWheelLocal.class);

    final CreationalContext<ColorWheelLocal> creationalContext = beanManager.createCreationalContext(colorWheelBean);

    final ColorWheelLocal colorWheel = colorWheelBean.create(creationalContext);

    assertEquals(6, created.size());

    assertEquals(6, colorWheel.getColors().size());

    colorWheelBean.destroy(colorWheel, creationalContext);

    assertEquals(6, destroyed.size());

}