Java Code Examples for javax.enterprise.context.spi.Contextual#destroy()

The following examples show how to use javax.enterprise.context.spi.Contextual#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: RedirectScopeManager.java    From krazo with Apache License 2.0 6 votes vote down vote up
/**
 * Destroy the instance.
 *
 * @param contextual the contextual.
 */
public void destroy(Contextual contextual) {
    String scopeId = (String) request.getAttribute(SCOPE_ID);
    if (null != scopeId) {
        HttpSession session = request.getSession();
        if (contextual instanceof PassivationCapable == false) {
            throw new RuntimeException("Unexpected type for contextual");
        }
        PassivationCapable pc = (PassivationCapable) contextual;
        final String sessionKey = SCOPE_ID + "-" + scopeId;
        Map<String, Object> scopeMap = (Map<String, Object>) session.getAttribute(sessionKey);
        if (null != scopeMap) {
            Object instance = scopeMap.get(INSTANCE + pc.getId());
            CreationalContext<?> creational = (CreationalContext<?>) scopeMap.get(CREATIONAL + pc.getId());
            if (null != instance && null != creational) {
                contextual.destroy(instance, creational);
                creational.release();
            }
        }
    }
}
 
Example 2
Source File: RedirectScopeManager.java    From ozark with Apache License 2.0 6 votes vote down vote up
/**
 * Destroy the instance.
 *
 * @param contextual the contextual.
 */
public void destroy(Contextual contextual) {
    String scopeId = (String) request.getAttribute(SCOPE_ID);
    if (null != scopeId) {
        HttpSession session = request.getSession();
        if (contextual instanceof PassivationCapable == false) {
            throw new RuntimeException("Unexpected type for contextual");
        }
        PassivationCapable pc = (PassivationCapable) contextual;
        final String sessionKey = SCOPE_ID + "-" + scopeId;
        Map<String, Object> scopeMap = (Map<String, Object>) session.getAttribute(sessionKey);
        if (null != scopeMap) {
            Object instance = scopeMap.get(INSTANCE + pc.getId());
            CreationalContext<?> creational = (CreationalContext<?>) scopeMap.get(CREATIONAL + pc.getId());
            if (null != instance && null != creational) {
                contextual.destroy(instance, creational);
                creational.release();
            }
        }
    }
}
 
Example 3
Source File: PortletSessionScopedBeanMap.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
/**
 * Removes & destroys the given bean from the given bean map
 * @param bean
 */
@SuppressWarnings("unchecked")
private <T> void remove(String id, Map<Contextual<?>, BeanInstance<?>> beanMap, Contextual<T> bean) {
   BeanInstance<?> bi = beanMap.get(bean);
   
   if (isDebug) {
      StringBuilder txt = new StringBuilder(80);
      txt.append("Removing bean: ");
      if (bean instanceof Bean<?>) {
         Bean<?> b = (Bean<?>) bean;
         txt.append(b.getBeanClass().getSimpleName());
      }
      txt.append(", window ID: ").append(id);
      if (bi == null) {
         txt.append(", instance is null.");
      }
      LOG.debug(txt.toString());
   }

   if (bi != null) {
      beans.remove(id);
      bi.crco.release();
      bean.destroy((T)bi.instance, (CreationalContext<T>)bi.crco);
   }
}
 
Example 4
Source File: PortletStateScopedBeanHolder.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
/**
 * Removes & destroys the given bean
 * @param bean
 */
@SuppressWarnings("unchecked")
protected <T> void remove(Contextual<T> bean) {
   BeanInstance<?> bi = beans.get(bean);
   
   if (isTrace) {
      StringBuilder txt = new StringBuilder(80);
      txt.append("Removing render state scoped bean: ");
      if (bean instanceof Bean<?>) {
         Bean<?> b = (Bean<?>) bean;
         txt.append(b.getBeanClass().getSimpleName());
      }
      if (bi == null) {
         txt.append(", instance is null.");
      }
      LOG.trace(txt.toString());
   }

   if (bi != null) {
      beans.remove(bean);
      bi.crco.release();
      bean.destroy((T)bi.instance, (CreationalContext<T>)bi.crco);
   }
}
 
Example 5
Source File: PortletRequestScopedBeanHolder.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
/**
 * Removes & destroys the given bean
 * @param bean
 */
@SuppressWarnings("unchecked")
protected <T> void remove(Contextual<T> bean) {
   BeanInstance<?> bi = beans.get(bean);
   
   if (isTrace) {
      StringBuilder txt = new StringBuilder(80);
      txt.append("Removing portlet request scoped bean: ");
      if (bean instanceof Bean<?>) {
         Bean<?> b = (Bean<?>) bean;
         txt.append(b.getBeanClass().getSimpleName());
      }
      if (bi == null) {
         txt.append(", instance is null.");
      }
      LOG.trace(txt.toString());
   }

   if (bi != null) {
      beans.remove(bean);
      bi.crco.release();
      bean.destroy((T)bi.instance, (CreationalContext<T>)bi.crco);
   }
}
 
Example 6
Source File: InjectableReferenceProviders.java    From quarkus with Apache License 2.0 5 votes vote down vote up
/**
 * Unwraps the provider if necessary and invokes {@link Contextual#destroy(Object, CreationalContext)}.
 * 
 * @param <T>
 * @param provider
 * @param instance
 * @param creationalContext
 * @throws IllegalArgumentException If the specified provider is not a bean
 */
@SuppressWarnings("unchecked")
public static <T> void destroy(InjectableReferenceProvider<T> provider, T instance,
        CreationalContext<T> creationalContext) {
    if (provider instanceof CurrentInjectionPointProvider) {
        provider = ((CurrentInjectionPointProvider<T>) provider).getDelegate();
    }
    if (provider instanceof Contextual) {
        Contextual<T> contextual = (Contextual<T>) provider;
        contextual.destroy(instance, creationalContext);
    } else {
        throw new IllegalArgumentException("Injetable reference provider is not a bean: " + provider.getClass());
    }
}
 
Example 7
Source File: EntityManagerContext.java    From openwebbeans-meecrowave with Apache License 2.0 5 votes vote down vote up
private <T> void doDestroy(final Contextual<T> contextual, final BeanInstanceBag<T> bag) {
    if ( bag.beanInstance !=null ) {
        // check null here because in case of missconfiguration, this can raise an NPE and hide the original exception
        contextual.destroy(bag.beanInstance, bag.beanCreationalContext);
    }
    bag.beanCreationalContext.release();
}
 
Example 8
Source File: TransactionContext.java    From openwebbeans-meecrowave with Apache License 2.0 4 votes vote down vote up
private <T> void destroyInstance(final Contextual<T> component, final T instance, final CreationalContext<T> creationalContext) {
    //Destroy component
    component.destroy(instance, creationalContext);
    componentInstanceMap.remove(component);
}
 
Example 9
Source File: AbstractContext.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
public static void destroyBean(Contextual bean, ContextualInstanceInfo<?> contextualInstanceInfo)
{
    bean.destroy(contextualInstanceInfo.getContextualInstance(), contextualInstanceInfo.getCreationalContext());
}