use of javax.enterprise.inject.spi.Bean in project jetty.project by eclipse.
the class WebSocketScopeSessionTest method newInstance.
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <T> ScopedInstance<T> newInstance(Class<T> clazz) {
ScopedInstance sbean = new ScopedInstance();
Set<Bean<?>> beans = container.getBeanManager().getBeans(clazz, AnyLiteral.INSTANCE);
if (beans.size() > 0) {
sbean.bean = beans.iterator().next();
sbean.creationalContext = container.getBeanManager().createCreationalContext(sbean.bean);
sbean.instance = container.getBeanManager().getReference(sbean.bean, clazz, sbean.creationalContext);
return sbean;
} else {
throw new RuntimeException(String.format("Can't find class %s", clazz));
}
}
use of javax.enterprise.inject.spi.Bean in project camel by apache.
the class CamelCdiRunner method createTest.
@Override
protected Object createTest() {
BeanManager manager = context.getBeanManager();
Set<Bean<?>> beans = manager.getBeans(getTestClass().getJavaClass(), AnyLiteral.INSTANCE);
Bean<?> bean = beans.iterator().next();
// TODO: manage lifecycle of @Dependent beans
return manager.getReference(bean, bean.getBeanClass(), manager.createCreationalContext(bean));
}
use of javax.enterprise.inject.spi.Bean in project Activiti by Activiti.
the class BusinessProcessContext method get.
@Override
public <T> T get(Contextual<T> contextual) {
Bean<T> bean = (Bean<T>) contextual;
String variableName = bean.getName();
BusinessProcess businessProcess = getBusinessProcess();
Object variable = businessProcess.getVariable(variableName);
if (variable != null) {
if (logger.isDebugEnabled()) {
if (businessProcess.isAssociated()) {
logger.debug("Getting instance of bean '{}' from Execution[{}]", variableName, businessProcess.getExecutionId());
} else {
logger.debug("Getting instance of bean '{}' from transient bean store", variableName);
}
}
return (T) variable;
} else {
return null;
}
}
use of javax.enterprise.inject.spi.Bean in project wildfly by wildfly.
the class WeldContextSetup method teardown.
@SuppressWarnings("unchecked")
public void teardown(Map<String, Object> properties) {
try {
final BeanManager manager = (BeanManager) new InitialContext().lookup("java:comp/BeanManager");
if (manager != null && Container.available()) {
final Bean<BoundSessionContext> sessionContextBean = (Bean<BoundSessionContext>) manager.resolve(manager.getBeans(BoundSessionContext.class, BoundLiteral.INSTANCE));
CreationalContext<?> ctx = manager.createCreationalContext(sessionContextBean);
final BoundSessionContext sessionContext = (BoundSessionContext) manager.getReference(sessionContextBean, BoundSessionContext.class, ctx);
sessionContext.invalidate();
sessionContext.deactivate();
sessionContext.dissociate(sessionContexts.get());
final Bean<BoundRequestContext> requestContextBean = (Bean<BoundRequestContext>) manager.resolve(manager.getBeans(BoundRequestContext.class, BoundLiteral.INSTANCE));
ctx = manager.createCreationalContext(requestContextBean);
final BoundRequestContext requestContext = (BoundRequestContext) manager.getReference(requestContextBean, BoundRequestContext.class, ctx);
requestContext.invalidate();
requestContext.deactivate();
requestContext.dissociate(requestContexts.get());
final Bean<BoundConversationContext> conversationContextBean = (Bean<BoundConversationContext>) manager.resolve(manager.getBeans(BoundConversationContext.class, BoundLiteral.INSTANCE));
ctx = manager.createCreationalContext(conversationContextBean);
final BoundConversationContext conversationContext = (BoundConversationContext) manager.getReference(conversationContextBean, BoundConversationContext.class, ctx);
conversationContext.invalidate();
conversationContext.deactivate();
conversationContext.dissociate(boundRequests.get());
}
} catch (NamingException e) {
WeldLogger.ROOT_LOGGER.failedToTearDownWeldContexts(e);
} finally {
sessionContexts.remove();
requestContexts.remove();
boundRequests.remove();
}
}
use of javax.enterprise.inject.spi.Bean in project wildfly by wildfly.
the class WeldClassIntrospector method getInjectionTarget.
private InjectionTarget getInjectionTarget(Class<?> clazz) {
InjectionTarget<?> target = injectionTargets.get(clazz);
if (target != null) {
return target;
}
final BeanManagerImpl beanManager = BeanManagerProxy.unwrap(this.beanManager.getValue());
Bean<?> bean = null;
Set<Bean<?>> beans = new HashSet<>(beanManager.getBeans(clazz, AnyLiteral.INSTANCE));
Iterator<Bean<?>> it = beans.iterator();
//go through and remove them from the bean set
while (it.hasNext()) {
Bean<?> b = it.next();
if (b.getBeanClass() != clazz) {
it.remove();
}
}
if (beans.size() == 1) {
bean = beans.iterator().next();
}
InjectionTarget<?> newTarget = InjectionTargets.createInjectionTarget(clazz, bean, beanManager, true);
target = injectionTargets.putIfAbsent(clazz, newTarget);
if (target == null) {
return newTarget;
} else {
return target;
}
}
Aggregations