use of javax.enterprise.inject.spi.BeanManager 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.BeanManager in project wildfly by wildfly.
the class WeldClassIntrospector method createInstance.
@Override
public ManagedReference createInstance(final Object instance) {
final BeanManager beanManager = this.beanManager.getValue();
final InjectionTarget injectionTarget = getInjectionTarget(instance.getClass());
final CreationalContext context = beanManager.createCreationalContext(null);
injectionTarget.inject(instance, context);
injectionTarget.postConstruct(instance);
return new WeldManagedReference(injectionTarget, context, instance);
}
use of javax.enterprise.inject.spi.BeanManager in project wildfly by wildfly.
the class CdiBeanValidationFactoryProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final DeploymentUnit topLevelDeployment = deploymentUnit.getParent() == null ? deploymentUnit : deploymentUnit.getParent();
final ServiceName weldStartService = topLevelDeployment.getServiceName().append(ServiceNames.WELD_START_SERVICE_NAME);
if (!WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) {
return;
}
if (!deploymentUnit.hasAttachment(BeanValidationAttachments.VALIDATOR_FACTORY)) {
return;
}
final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
final ServiceName serviceName = deploymentUnit.getServiceName().append(CdiValidatorFactoryService.SERVICE_NAME);
final CdiValidatorFactoryService cdiValidatorFactoryService = new CdiValidatorFactoryService(deploymentUnit);
serviceTarget.addService(serviceName, cdiValidatorFactoryService).addDependency(ServiceNames.beanManagerServiceName(deploymentUnit), new CastingInjector<BeanManager>(cdiValidatorFactoryService.getBeanManagerInjector(), BeanManager.class)).addDependency(weldStartService).install();
}
use of javax.enterprise.inject.spi.BeanManager in project deltaspike by apache.
the class AuditEntityListener method update.
@PreUpdate
public void update(Object entity) {
BeanManager beanManager = BeanManagerProvider.getInstance().getBeanManager();
Set<Bean<?>> beans = beanManager.getBeans(PreUpdateAuditListener.class);
for (Bean<?> bean : beans) {
PreUpdateAuditListener result = (PreUpdateAuditListener) beanManager.getReference(bean, PreUpdateAuditListener.class, beanManager.createCreationalContext(bean));
result.preUpdate(entity);
}
}
use of javax.enterprise.inject.spi.BeanManager in project deltaspike by apache.
the class EntityManagerRefLookup method initGlobalEntityManager.
private synchronized void initGlobalEntityManager() {
// switch into paranoia mode
if (this.globalEntityManagerInitialized == null) {
this.globalEntityManagerInitialized = true;
BeanManager beanManager = BeanManagerProvider.getInstance().getBeanManager();
Set<Bean<?>> beans = beanManager.getBeans(EntityManager.class);
Bean<?> bean = beanManager.resolve(beans);
if (bean == null) {
throw new IllegalStateException("Could not find EntityManager with default qualifier.");
}
globalEntityManagerIsNormalScope = beanManager.isNormalScope(bean.getScope());
if (globalEntityManagerIsNormalScope) {
globalEntityManager = (EntityManager) beanManager.getReference(bean, EntityManager.class, beanManager.createCreationalContext(bean));
}
}
}
Aggregations