All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jboss.weld.bean.builtin.ConversationBean Maven / Gradle / Ivy

There is a newer version: 6.0.0.Beta4
Show newest version
package org.jboss.weld.bean.builtin;

import org.jboss.weld.bootstrap.BeanDeployerEnvironment;
import org.jboss.weld.context.ConversationContext;
import org.jboss.weld.context.conversation.ConversationImpl;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.util.collections.Arrays2;

import javax.enterprise.context.Conversation;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.Instance;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.Set;

public class ConversationBean extends AbstractBuiltInBean {

    private static final Set TYPES = Arrays2.asSet(Conversation.class, Object.class);

    private Instance conversationContexts;

    public ConversationBean(BeanManagerImpl beanManager) {
        super(Conversation.class.getName(), beanManager);
    }

    @Override
    public void initialize(BeanDeployerEnvironment environment) {
        super.initialize(environment);
        this.conversationContexts = getBeanManager().instance().select(ConversationContext.class);
    }

    public Set getTypes() {
        return TYPES;
    }

    public Conversation create(CreationalContext creationalContext) {
        for (ConversationContext conversationContext : getBeanManager().instance().select(ConversationContext.class)) {
            if (conversationContext.isActive()) {
                return conversationContext.getCurrentConversation();
            }
        }
        /*
        * Can't get a "real" Conversation, but we need to return something, so
        * return this dummy Conversation which will simply throw a
        * ContextNotActiveException for every method call as the spec requires.
        */
        return new ConversationImpl(conversationContexts);
    }

    public void destroy(Conversation instance, CreationalContext creationalContext) {

    }

    @Override
    public Class getType() {
        return Conversation.class;
    }

    @Override
    public Class getScope() {
        return RequestScoped.class;
    }

    @Override
    public String getName() {
        return Conversation.class.getName().toLowerCase();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy