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

org.jboss.weld.contexts.unbound.RequestContextImpl Maven / Gradle / Ivy

Go to download

This jar bundles all the bits of Weld and CDI required for running in a Servlet container.

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

import org.jboss.weld.contexts.AbstractUnboundContext;
import org.jboss.weld.context.RequestContext;
import org.jboss.weld.contexts.beanstore.HashMapBeanStore;

import javax.enterprise.context.RequestScoped;

import java.lang.annotation.Annotation;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import org.jboss.weld.context.api.ContextualInstance;
import org.jboss.weld.serialization.spi.BeanIdentifier;

public class RequestContextImpl extends AbstractUnboundContext implements RequestContext {

    public RequestContextImpl(String contextId) {
        super(contextId, false);
    }

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

    public void activate() {
        // Attach bean store (this context is unbound, so this can simply be thread-scoped
        setBeanStore(new HashMapBeanStore());
        super.activate();
    }

    @Override
    public void deactivate() {
        super.deactivate();
        // Detach the bean store
        setBeanStore(null);
        cleanup();
    }

    @Override
    public Collection> getAllContextualInstances() {
        Set> result = new HashSet<>();
        getBeanStore().iterator().forEachRemaining((BeanIdentifier beanId) -> {
            result.add(getBeanStore().get(beanId));
        });
        return result;
    }

    @Override
    public void clearAndSet(Collection> setOfInstances) {
        getBeanStore().clear();
        for (ContextualInstance contextualInstance : setOfInstances) {
            getBeanStore().put(getId(contextualInstance.getContextual()), contextualInstance);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy