use of javax.enterprise.inject.spi.BeanManager in project deltaspike by apache.
the class OpenEjbContainerControl method getContextControl.
@Override
public synchronized ContextControl getContextControl() {
if (ctxCtrl == null) {
BeanManager beanManager = getBeanManager();
if (beanManager == null) {
LOG.warning("If the CDI-container was started by the environment, you can't use this helper." + "Instead you can resolve ContextControl manually " + "(e.g. via BeanProvider.getContextualReference(ContextControl.class) ). " + "If the container wasn't started already, you have to use CdiContainer#boot before.");
return null;
}
Set<Bean<?>> beans = beanManager.getBeans(ContextControl.class);
ctxCtrlBean = (Bean<ContextControl>) beanManager.resolve(beans);
ctxCtrlCreationalContext = getBeanManager().createCreationalContext(ctxCtrlBean);
ctxCtrl = (ContextControl) getBeanManager().getReference(ctxCtrlBean, ContextControl.class, ctxCtrlCreationalContext);
}
return ctxCtrl;
}
use of javax.enterprise.inject.spi.BeanManager in project deltaspike by apache.
the class JsfSystemEventBroadcaster method processEvent.
@Override
public void processEvent(SystemEvent e) throws AbortProcessingException {
if (!this.isActivated) {
return;
}
BeanManager beanManager = BeanManagerProvider.getInstance().getBeanManager();
beanManager.fireEvent(e);
}
use of javax.enterprise.inject.spi.BeanManager in project deltaspike by apache.
the class JndiUtilsTest method testLookup.
/**
* Tests {@link JndiUtils#lookup(String, Class)} by looking up the {@link BeanManager}
*/
@Test
public void testLookup() {
BeanManager beanManager = JndiUtils.lookup("java:comp/BeanManager", BeanManager.class);
assertNotNull("JNDI lookup failed", beanManager);
}
use of javax.enterprise.inject.spi.BeanManager in project deltaspike by apache.
the class DeltaSpikeProxyContextualLifecycle method instantiateDelegateInvocationHandler.
protected H instantiateDelegateInvocationHandler() {
Set<Bean<H>> handlerBeans = BeanProvider.getBeanDefinitions(this.delegateInvocationHandlerClass, false, true);
if (handlerBeans.size() != 1) {
StringBuilder beanInfo = new StringBuilder();
for (Bean<H> bean : handlerBeans) {
if (beanInfo.length() != 0) {
beanInfo.append(", ");
}
beanInfo.append(bean);
if (bean instanceof PassivationCapable) {
beanInfo.append(" bean-id: ").append(((PassivationCapable) bean).getId());
}
}
throw new IllegalStateException(handlerBeans.size() + " beans found for " + this.delegateInvocationHandlerClass + " found beans: " + beanInfo.toString());
}
Bean<H> handlerBean = handlerBeans.iterator().next();
BeanManager beanManager = BeanManagerProvider.getInstance().getBeanManager();
CreationalContext<?> creationalContext = beanManager.createCreationalContext(handlerBean);
H handlerInstance = (H) beanManager.getReference(handlerBean, this.delegateInvocationHandlerClass, creationalContext);
if (handlerBean.getScope().equals(Dependent.class)) {
this.creationalContextOfDependentHandler = creationalContext;
}
return handlerInstance;
}
use of javax.enterprise.inject.spi.BeanManager in project aries by apache.
the class CdiBeanTests method testBundleContextInjection.
public void testBundleContextInjection() throws Exception {
BeanManager beanManager = cdiContainer.getBeanManager();
assertNotNull(beanManager);
@SuppressWarnings("serial") Set<Bean<?>> beans = beanManager.getBeans(Object.class, new AnnotationLiteral<BundleContextBeanQualifier>() {
});
Bean<?> bean = beanManager.resolve(beans);
CreationalContext<?> ctx = beanManager.createCreationalContext(bean);
Object bcb = beanManager.getReference(bean, Object.class, ctx);
assertNotNull(bcb);
@SuppressWarnings("unchecked") BeanService<BundleContext> bti = (BeanService<BundleContext>) bcb;
assertNotNull(bti.get());
assertTrue(bti.get() instanceof BundleContext);
}
Aggregations