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

org.jboss.weld.bean.builtin.ContextBean 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.ContextHolder;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.util.reflection.HierarchyDiscovery;

import javax.enterprise.context.spi.Context;
import javax.enterprise.context.spi.CreationalContext;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.Set;

public class ContextBean extends AbstractBuiltInBean {


    public static  ContextBean of(ContextHolder context, BeanManagerImpl beanManager) {
        return new ContextBean(context, beanManager);
    }

    private final T context;
    private final Class type;
    private final Set types;
    private final Set qualifiers;

    public ContextBean(ContextHolder contextHolder, BeanManagerImpl beanManager) {
        super(contextHolder.getType().getName(), beanManager);
        this.context = contextHolder.getContext();
        this.type = contextHolder.getType();
        this.types = new HierarchyDiscovery(contextHolder.getType()).getTypeClosure();
        this.qualifiers = contextHolder.getQualifiers();
    }

    public Set getTypes() {
        return types;
    }

    public T create(CreationalContext creationalContext) {
        return context;
    }

    public void destroy(T instance, CreationalContext creationalContext) {
        // No-op, this bean is just exposing stuff
    }

    @Override
    public Class getType() {
        return type;
    }

    @Override
    public Set getQualifiers() {
        return qualifiers;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy