Search in sources :

Example 26 with BeanManager

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);
    }
}
Also used : LazyValidatorFactory(org.jboss.as.ee.beanvalidation.LazyValidatorFactory) ValidatorFactory(javax.validation.ValidatorFactory) LazyValidatorFactory(org.jboss.as.ee.beanvalidation.LazyValidatorFactory) BeanManager(javax.enterprise.inject.spi.BeanManager)

Example 27 with BeanManager

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);
    }
}
Also used : MutableBoundRequest(org.jboss.weld.context.bound.MutableBoundRequest) BoundSessionContext(org.jboss.weld.context.bound.BoundSessionContext) BoundConversationContext(org.jboss.weld.context.bound.BoundConversationContext) InitialContext(javax.naming.InitialContext) Bean(javax.enterprise.inject.spi.Bean) BoundRequestContext(org.jboss.weld.context.bound.BoundRequestContext) BoundRequest(org.jboss.weld.context.bound.BoundRequest) MutableBoundRequest(org.jboss.weld.context.bound.MutableBoundRequest) NamingException(javax.naming.NamingException) BeanManager(javax.enterprise.inject.spi.BeanManager)

Example 28 with BeanManager

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);
        }
    };
}
Also used : CreationalContext(javax.enterprise.context.spi.CreationalContext) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) InjectionTarget(javax.enterprise.inject.spi.InjectionTarget) BeanManager(javax.enterprise.inject.spi.BeanManager)

Example 29 with BeanManager

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;
}
Also used : BootStatus(org.commonjava.indy.boot.BootStatus) BootOptions(org.commonjava.indy.boot.BootOptions) BeanManager(javax.enterprise.inject.spi.BeanManager) Weld(org.jboss.weld.environment.se.Weld)

Example 30 with BeanManager

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;
}
Also used : BeanManager(javax.enterprise.inject.spi.BeanManager)

Aggregations

BeanManager (javax.enterprise.inject.spi.BeanManager)61 Bean (javax.enterprise.inject.spi.Bean)27 Test (org.junit.Test)12 CdiContainer (org.apache.deltaspike.cdise.api.CdiContainer)6 ArrayList (java.util.ArrayList)5 CarRepair (org.apache.deltaspike.cdise.tck.beans.CarRepair)5 InitialContext (javax.naming.InitialContext)4 NamingException (javax.naming.NamingException)4 ValidatorFactory (javax.validation.ValidatorFactory)4 ContextControl (org.apache.deltaspike.cdise.api.ContextControl)4 ServiceName (org.jboss.msc.service.ServiceName)4 CreationalContext (javax.enterprise.context.spi.CreationalContext)3 TransactionManager (javax.transaction.TransactionManager)3 TransactionSynchronizationRegistry (javax.transaction.TransactionSynchronizationRegistry)3 BeanService (org.apache.aries.cdi.test.interfaces.BeanService)3 OpenEJBException (org.apache.openejb.OpenEJBException)3 IOException (java.io.IOException)2 Annotation (java.lang.annotation.Annotation)2 Type (java.lang.reflect.Type)2 MalformedURLException (java.net.MalformedURLException)2