org.jboss.weld.bean.builtin.ContextBean Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of weld-osgi-bundle Show documentation
Show all versions of weld-osgi-bundle Show documentation
Weld runtime packaged as an OSGi bundle
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;
}
}