Search in sources :

Example 1 with PassivationCapable

use of javax.enterprise.inject.spi.PassivationCapable in project deltaspike by apache.

the class ViewAccessContext method get.

@Override
public <T> T get(Contextual<T> bean) {
    try {
        return super.get(bean);
    } finally {
        if (bean instanceof PassivationCapable) {
            PassivationCapable pc = (PassivationCapable) bean;
            viewAccessBeanAccessHistory.getAccessedBeans().add(pc.getId());
        }
    }
}
Also used : PassivationCapable(javax.enterprise.inject.spi.PassivationCapable)

Example 2 with PassivationCapable

use of javax.enterprise.inject.spi.PassivationCapable in project deltaspike by apache.

the class ConversationUtils method convertToConversationKey.

public static ConversationKey convertToConversationKey(Contextual<?> contextual, BeanManager beanManager) {
    if (!(contextual instanceof Bean)) {
        if (contextual instanceof PassivationCapable) {
            contextual = beanManager.getPassivationCapableBean(((PassivationCapable) contextual).getId());
        } else {
            throw new IllegalArgumentException(contextual.getClass().getName() + " is not of type " + Bean.class.getName());
        }
    }
    Bean<?> bean = (Bean<?>) contextual;
    //don't cache it (due to the support of different producers)
    ConversationGroup conversationGroupAnnotation = findConversationGroupAnnotation(bean);
    Class<?> conversationGroup;
    if (conversationGroupAnnotation != null) {
        conversationGroup = conversationGroupAnnotation.value();
    } else {
        conversationGroup = bean.getBeanClass();
    }
    Set<Annotation> qualifiers = bean.getQualifiers();
    return new ConversationKey(conversationGroup, qualifiers.toArray(new Annotation[qualifiers.size()]));
}
Also used : PassivationCapable(javax.enterprise.inject.spi.PassivationCapable) ConversationGroup(org.apache.deltaspike.core.api.scope.ConversationGroup) ConversationKey(org.apache.deltaspike.core.impl.scope.conversation.ConversationKey) Annotation(java.lang.annotation.Annotation) Bean(javax.enterprise.inject.spi.Bean)

Example 3 with PassivationCapable

use of javax.enterprise.inject.spi.PassivationCapable in project deltaspike by apache.

the class DeltaSpikeProxyContextualLifecycle method instantiateDelegateInvocationHandler.

protected H instantiateDelegateInvocationHandler() {
    Set<Bean<H>> handlerBeans = BeanProvider.getBeanDefinitions(this.delegateInvocationHandlerClass, false, true);
    if (handlerBeans.size() != 1) {
        StringBuilder beanInfo = new StringBuilder();
        for (Bean<H> bean : handlerBeans) {
            if (beanInfo.length() != 0) {
                beanInfo.append(", ");
            }
            beanInfo.append(bean);
            if (bean instanceof PassivationCapable) {
                beanInfo.append(" bean-id: ").append(((PassivationCapable) bean).getId());
            }
        }
        throw new IllegalStateException(handlerBeans.size() + " beans found for " + this.delegateInvocationHandlerClass + " found beans: " + beanInfo.toString());
    }
    Bean<H> handlerBean = handlerBeans.iterator().next();
    BeanManager beanManager = BeanManagerProvider.getInstance().getBeanManager();
    CreationalContext<?> creationalContext = beanManager.createCreationalContext(handlerBean);
    H handlerInstance = (H) beanManager.getReference(handlerBean, this.delegateInvocationHandlerClass, creationalContext);
    if (handlerBean.getScope().equals(Dependent.class)) {
        this.creationalContextOfDependentHandler = creationalContext;
    }
    return handlerInstance;
}
Also used : PassivationCapable(javax.enterprise.inject.spi.PassivationCapable) BeanManager(javax.enterprise.inject.spi.BeanManager) Bean(javax.enterprise.inject.spi.Bean)

Example 4 with PassivationCapable

use of javax.enterprise.inject.spi.PassivationCapable in project deltaspike by apache.

the class ViewAccessContext method get.

@Override
public <T> T get(Contextual<T> bean, CreationalContext<T> creationalContext) {
    try {
        return super.get(bean, creationalContext);
    } finally {
        if (bean instanceof PassivationCapable) {
            PassivationCapable pc = (PassivationCapable) bean;
            viewAccessBeanAccessHistory.getAccessedBeans().add(pc.getId());
        }
    }
}
Also used : PassivationCapable(javax.enterprise.inject.spi.PassivationCapable)

Aggregations

PassivationCapable (javax.enterprise.inject.spi.PassivationCapable)4 Bean (javax.enterprise.inject.spi.Bean)2 Annotation (java.lang.annotation.Annotation)1 BeanManager (javax.enterprise.inject.spi.BeanManager)1 ConversationGroup (org.apache.deltaspike.core.api.scope.ConversationGroup)1 ConversationKey (org.apache.deltaspike.core.impl.scope.conversation.ConversationKey)1