use of javax.enterprise.inject.spi.BeanManager in project wildfly by wildfly.
the class CdiValidatorFactoryService method start.
@Override
public void start(final StartContext context) throws StartException {
final ClassLoader cl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
try {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(classLoader);
BeanManager beanManager = beanManagerInjector.getValue();
// Get the CDI-enabled ValidatorFactory
ValidatorFactory validatorFactory = getReference(ValidatorFactory.class, beanManager);
// Replace the delegate of LazyValidatorFactory
LazyValidatorFactory lazyValidatorFactory = (LazyValidatorFactory) (deploymentUnit.getAttachment(BeanValidationAttachments.VALIDATOR_FACTORY));
lazyValidatorFactory.replaceDelegate(validatorFactory);
} finally {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(cl);
}
}
use of javax.enterprise.inject.spi.BeanManager in project wildfly by wildfly.
the class WeldContextSetup method setup.
@SuppressWarnings("unchecked")
public void setup(Map<String, Object> properties) {
try {
final BeanManager manager = (BeanManager) new InitialContext().lookup(STANDARD_BEAN_MANAGER_JNDI_NAME);
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.associate(sessionContexts.get());
sessionContext.activate();
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.associate(requestContexts.get());
requestContext.activate();
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);
BoundRequest request = new MutableBoundRequest(requestContexts.get(), sessionContexts.get());
boundRequests.set(request);
conversationContext.associate(request);
conversationContext.activate();
}
} catch (NamingException e) {
WeldLogger.ROOT_LOGGER.failedToSetupWeldContexts(e);
}
}
use of javax.enterprise.inject.spi.BeanManager in project wildfly by wildfly.
the class WeldClassIntrospector method createFactory.
@Override
public ManagedReferenceFactory createFactory(Class<?> clazz) {
final BeanManager beanManager = this.beanManager.getValue();
final InjectionTarget injectionTarget = getInjectionTarget(clazz);
return new ManagedReferenceFactory() {
@Override
public ManagedReference getReference() {
final CreationalContext context = beanManager.createCreationalContext(null);
final Object instance = injectionTarget.produce(context);
injectionTarget.inject(instance, context);
injectionTarget.postConstruct(instance);
return new WeldManagedReference(injectionTarget, context, instance);
}
};
}
use of javax.enterprise.inject.spi.BeanManager in project indy by Commonjava.
the class JaxRsBooter method initialize.
@Override
public boolean initialize(final BootOptions bootOptions) {
this.bootOptions = bootOptions;
boolean initialized;
try {
bootOptions.setSystemProperties();
weld = new Weld();
container = weld.initialize();
// injectable version.
final BootOptions cdiOptions = container.instance().select(BootOptions.class).get();
cdiOptions.copyFrom(bootOptions);
final BeanManager bmgr = container.getBeanManager();
logger.info("\n\n\nStarted BeanManager: {}\n\n\n", bmgr);
initialized = true;
} catch (final Throwable e) {
logger.error("Failed to initialize Booter: " + e.getMessage(), e);
exit = ERR_CANT_INIT_BOOTER;
status = new BootStatus(exit, e);
initialized = false;
}
return initialized;
}
use of javax.enterprise.inject.spi.BeanManager in project indy by Commonjava.
the class CdiInjectorFactoryImpl method lookupBeanManager.
@Override
protected BeanManager lookupBeanManager() {
final BeanManager bmgr = CDI.current().getBeanManager();
LoggerFactory.getLogger(getClass()).info("\n\n\n\nRESTEasy Using BeanManager: {}\n\n\n\n", bmgr);
return bmgr;
}
Aggregations